llvm.org GIT mirror llvm / fbbabf3
Merging r279647: ------------------------------------------------------------------------ r279647 | sanjoy | 2016-08-24 11:10:21 -0700 (Wed, 24 Aug 2016) | 5 lines [SCCP] Don't delete side-effecting instructions I'm not sure if the `!isa<CallInst>(Inst) && !isa<TerminatorInst>(Inst))` bit is correct either, but this fixes the case we know is broken. ------------------------------------------------------------------------ git-svn-id: https://llvm.org/svn/llvm-project/llvm/branches/release_39@279689 91177308-0d34-0410-b5e6-96231b3b80d8 Hans Wennborg 3 years ago
2 changed file(s) with 21 addition(s) and 22 deletion(s). Raw diff Collapse all Expand all
15371537 return true;
15381538 }
15391539
1540 static bool tryToReplaceInstWithConstant(SCCPSolver &Solver, Instruction *Inst,
1541 bool shouldEraseFromParent) {
1542 if (!tryToReplaceWithConstant(Solver, Inst))
1543 return false;
1544
1545 // Delete the instruction.
1546 if (shouldEraseFromParent)
1547 Inst->eraseFromParent();
1548 return true;
1549 }
1550
15511540 // runSCCP() - Run the Sparse Conditional Constant Propagation algorithm,
15521541 // and return true if the function was modified.
15531542 //
15961585 if (Inst->getType()->isVoidTy() || isa(Inst))
15971586 continue;
15981587
1599 if (tryToReplaceInstWithConstant(Solver, Inst,
1600 true /* shouldEraseFromParent */)) {
1588 if (tryToReplaceWithConstant(Solver, Inst)) {
1589 if (isInstructionTriviallyDead(Inst))
1590 Inst->eraseFromParent();
16011591 // Hey, we just changed something!
16021592 MadeChanges = true;
16031593 ++NumInstRemoved;
17881778 Instruction *Inst = &*BI++;
17891779 if (Inst->getType()->isVoidTy())
17901780 continue;
1791 if (tryToReplaceInstWithConstant(
1792 Solver, Inst,
1793 !isa(Inst) &&
1794 !isa(Inst) /* shouldEraseFromParent */)) {
1781 if (tryToReplaceWithConstant(Solver, Inst)) {
1782 if (!isa(Inst) && !isa(Inst))
1783 Inst->eraseFromParent();
17951784 // Hey, we just changed something!
17961785 MadeChanges = true;
17971786 ++IPNumInstRemoved;
None ; RUN: opt < %s -sccp -loop-deletion -simplifycfg -S | not grep br
0 ; RUN: opt < %s -sccp -loop-deletion -simplifycfg -S | FileCheck %s
11
2 declare double @sqrt(double) readnone nounwind
3 %empty = type {}
4 declare %empty @has_side_effects()
5
6 define double @test_0(i32 %param) {
7 ; CHECK-LABEL: @test_0(
8 ; CHECK-NOT: br
9 entry:
210 ; No matter how hard you try, sqrt(1.0) is always 1.0. This allows the
311 ; optimizer to delete this loop.
412
5 declare double @sqrt(double)
6
7 define double @test(i32 %param) {
8 entry:
913 br label %Loop
1014 Loop: ; preds = %Loop, %entry
1115 %I2 = phi i32 [ 0, %entry ], [ %I3, %Loop ] ; [#uses=1]
1822 ret double %V
1923 }
2024
25 define i32 @test_1() {
26 ; CHECK-LABEL: @test_1(
27 ; CHECK: call %empty @has_side_effects()
28 %1 = call %empty @has_side_effects()
29 ret i32 0
30 }