diff --git a/clang/test/CodeGenCUDA/managed-var.cu b/clang/test/CodeGenCUDA/managed-var.cu --- a/clang/test/CodeGenCUDA/managed-var.cu +++ b/clang/test/CodeGenCUDA/managed-var.cu @@ -146,7 +146,7 @@ // HOST: %3 = getelementptr inbounds [100 x %struct.vec], [100 x %struct.vec]* %2, i64 0, i64 1, i32 1 // HOST: %4 = ptrtoint float* %3 to i64 // HOST: %5 = sub i64 %4, %1 -// HOST: %6 = sdiv i64 %5, 4 +// HOST: %6 = sdiv exact i64 %5, 4 // HOST: %7 = sitofp i64 %6 to float // HOST: ret float %7 float addr_taken2() { diff --git a/llvm/lib/IR/ReplaceConstant.cpp b/llvm/lib/IR/ReplaceConstant.cpp --- a/llvm/lib/IR/ReplaceConstant.cpp +++ b/llvm/lib/IR/ReplaceConstant.cpp @@ -20,53 +20,9 @@ // Replace a constant expression by instructions with equivalent operations at // a specified location. Instruction *createReplacementInstr(ConstantExpr *CE, Instruction *Instr) { - IRBuilder Builder(Instr); - unsigned OpCode = CE->getOpcode(); - switch (OpCode) { - case Instruction::GetElementPtr: { - SmallVector CEOpVec(CE->operands()); - ArrayRef CEOps(CEOpVec); - return dyn_cast( - Builder.CreateInBoundsGEP(cast(CE)->getSourceElementType(), - CEOps[0], CEOps.slice(1))); - } - case Instruction::Add: - case Instruction::Sub: - case Instruction::Mul: - case Instruction::UDiv: - case Instruction::SDiv: - case Instruction::FDiv: - case Instruction::URem: - case Instruction::SRem: - case Instruction::FRem: - case Instruction::Shl: - case Instruction::LShr: - case Instruction::AShr: - case Instruction::And: - case Instruction::Or: - case Instruction::Xor: - return dyn_cast( - Builder.CreateBinOp((Instruction::BinaryOps)OpCode, CE->getOperand(0), - CE->getOperand(1), CE->getName())); - case Instruction::Trunc: - case Instruction::ZExt: - case Instruction::SExt: - case Instruction::FPToUI: - case Instruction::FPToSI: - case Instruction::UIToFP: - case Instruction::SIToFP: - case Instruction::FPTrunc: - case Instruction::FPExt: - case Instruction::PtrToInt: - case Instruction::IntToPtr: - case Instruction::BitCast: - case Instruction::AddrSpaceCast: - return dyn_cast( - Builder.CreateCast((Instruction::CastOps)OpCode, CE->getOperand(0), - CE->getType(), CE->getName())); - default: - llvm_unreachable("Unhandled constant expression!\n"); - } + auto *CEInstr = CE->getAsInstruction(); + CEInstr->insertBefore(Instr); + return CEInstr; } void convertConstantExprsToInstructions(Instruction *I, ConstantExpr *CE,