Skip to content
This repository was archived by the owner on Feb 5, 2019. It is now read-only.

Commit fbbabf3

Browse files
committed
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
1 parent 3aa4a35 commit fbbabf3

File tree

2 files changed

+21
-22
lines changed

2 files changed

+21
-22
lines changed

lib/Transforms/Scalar/SCCP.cpp

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1538,17 +1538,6 @@ static bool tryToReplaceWithConstant(SCCPSolver &Solver, Value *V) {
15381538
return true;
15391539
}
15401540

1541-
static bool tryToReplaceInstWithConstant(SCCPSolver &Solver, Instruction *Inst,
1542-
bool shouldEraseFromParent) {
1543-
if (!tryToReplaceWithConstant(Solver, Inst))
1544-
return false;
1545-
1546-
// Delete the instruction.
1547-
if (shouldEraseFromParent)
1548-
Inst->eraseFromParent();
1549-
return true;
1550-
}
1551-
15521541
// runSCCP() - Run the Sparse Conditional Constant Propagation algorithm,
15531542
// and return true if the function was modified.
15541543
//
@@ -1597,8 +1586,9 @@ static bool runSCCP(Function &F, const DataLayout &DL,
15971586
if (Inst->getType()->isVoidTy() || isa<TerminatorInst>(Inst))
15981587
continue;
15991588

1600-
if (tryToReplaceInstWithConstant(Solver, Inst,
1601-
true /* shouldEraseFromParent */)) {
1589+
if (tryToReplaceWithConstant(Solver, Inst)) {
1590+
if (isInstructionTriviallyDead(Inst))
1591+
Inst->eraseFromParent();
16021592
// Hey, we just changed something!
16031593
MadeChanges = true;
16041594
++NumInstRemoved;
@@ -1789,10 +1779,9 @@ static bool runIPSCCP(Module &M, const DataLayout &DL,
17891779
Instruction *Inst = &*BI++;
17901780
if (Inst->getType()->isVoidTy())
17911781
continue;
1792-
if (tryToReplaceInstWithConstant(
1793-
Solver, Inst,
1794-
!isa<CallInst>(Inst) &&
1795-
!isa<TerminatorInst>(Inst) /* shouldEraseFromParent */)) {
1782+
if (tryToReplaceWithConstant(Solver, Inst)) {
1783+
if (!isa<CallInst>(Inst) && !isa<TerminatorInst>(Inst))
1784+
Inst->eraseFromParent();
17961785
// Hey, we just changed something!
17971786
MadeChanges = true;
17981787
++IPNumInstRemoved;

test/Transforms/SCCP/calltest.ll

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
1-
; RUN: opt < %s -sccp -loop-deletion -simplifycfg -S | not grep br
1+
; RUN: opt < %s -sccp -loop-deletion -simplifycfg -S | FileCheck %s
22

3+
declare double @sqrt(double) readnone nounwind
4+
%empty = type {}
5+
declare %empty @has_side_effects()
6+
7+
define double @test_0(i32 %param) {
8+
; CHECK-LABEL: @test_0(
9+
; CHECK-NOT: br
10+
entry:
311
; No matter how hard you try, sqrt(1.0) is always 1.0. This allows the
412
; optimizer to delete this loop.
513

6-
declare double @sqrt(double)
7-
8-
define double @test(i32 %param) {
9-
entry:
1014
br label %Loop
1115
Loop: ; preds = %Loop, %entry
1216
%I2 = phi i32 [ 0, %entry ], [ %I3, %Loop ] ; <i32> [#uses=1]
@@ -19,3 +23,9 @@ Exit: ; preds = %Loop
1923
ret double %V
2024
}
2125

26+
define i32 @test_1() {
27+
; CHECK-LABEL: @test_1(
28+
; CHECK: call %empty @has_side_effects()
29+
%1 = call %empty @has_side_effects()
30+
ret i32 0
31+
}

0 commit comments

Comments
 (0)