Index: lib/Transforms/Scalar/SCCP.cpp =================================================================== --- lib/Transforms/Scalar/SCCP.cpp +++ lib/Transforms/Scalar/SCCP.cpp @@ -1926,7 +1926,8 @@ if (Inst->getType()->isVoidTy()) continue; if (tryToReplaceWithConstant(Solver, Inst)) { - if (!isa(Inst) && !isa(Inst)) + if ((!isa(Inst) || !Inst->mayHaveSideEffects()) && + !isa(Inst)) Inst->eraseFromParent(); // Hey, we just changed something! MadeChanges = true; Index: test/Transforms/IPConstantProp/remove-call-inst.ll =================================================================== --- test/Transforms/IPConstantProp/remove-call-inst.ll +++ test/Transforms/IPConstantProp/remove-call-inst.ll @@ -6,7 +6,7 @@ ; CHECK: define i32 @main() #0 { ; CHECK-NEXT: entry: -; CHECK-NEXT: %call2 = tail call i32 @wwrite(i64 0) [[NUW:#[0-9]+]] +; CHECK-NOT: call ; CHECK-NEXT: ret i32 123 define i32 @main() noreturn nounwind { @@ -31,4 +31,3 @@ ; CHECK: attributes #0 = { noreturn nounwind } ; CHECK: attributes #1 = { nounwind readnone } -; CHECK: attributes [[NUW]] = { nounwind } Index: test/Transforms/IPConstantProp/user-with-multiple-uses.ll =================================================================== --- test/Transforms/IPConstantProp/user-with-multiple-uses.ll +++ test/Transforms/IPConstantProp/user-with-multiple-uses.ll @@ -15,7 +15,7 @@ ret i32 %call2 } -define internal i32 @wwrite(i64 %i) nounwind readnone { +define internal i32 @wwrite(i64 %i) nounwind { entry: switch i64 %i, label %sw.default [ i64 3, label %return @@ -30,5 +30,4 @@ } ; CHECK: attributes #0 = { noreturn nounwind } -; CHECK: attributes #1 = { nounwind readnone } -; CHECK: attributes [[NUW]] = { nounwind } +; CHECK: attributes #1 = { nounwind }