<p dir="ltr">Thanks for the quick fix!</p>
<div class="gmail_extra"><br><div class="gmail_quote">On Aug 24, 2016 8:18 PM, "Sanjoy Das via llvm-commits" <<a href="mailto:llvm-commits@lists.llvm.org">llvm-commits@lists.llvm.org</a>> wrote:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: sanjoy<br>
Date: Wed Aug 24 13:10:21 2016<br>
New Revision: 279647<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=279647&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project?rev=279647&view=rev</a><br>
Log:<br>
[SCCP] Don't delete side-effecting instructions<br>
<br>
I'm not sure if the `!isa<CallInst>(Inst) &&<br>
!isa<TerminatorInst>(Inst))` bit is correct either, but this fixes the<br>
case we know is broken.<br>
<br>
Modified:<br>
llvm/trunk/lib/Transforms/<wbr>Scalar/SCCP.cpp<br>
llvm/trunk/test/Transforms/<wbr>SCCP/calltest.ll<br>
<br>
Modified: llvm/trunk/lib/Transforms/<wbr>Scalar/SCCP.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/SCCP.cpp?rev=279647&r1=279646&r2=279647&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/llvm/trunk/lib/<wbr>Transforms/Scalar/SCCP.cpp?<wbr>rev=279647&r1=279646&r2=<wbr>279647&view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- llvm/trunk/lib/Transforms/<wbr>Scalar/SCCP.cpp (original)<br>
+++ llvm/trunk/lib/Transforms/<wbr>Scalar/SCCP.cpp Wed Aug 24 13:10:21 2016<br>
@@ -1559,17 +1559,6 @@ static bool tryToReplaceWithConstant(SCC<br>
return true;<br>
}<br>
<br>
-static bool tryToReplaceInstWithConstant(<wbr>SCCPSolver &Solver, Instruction *Inst,<br>
- bool shouldEraseFromParent) {<br>
- if (!tryToReplaceWithConstant(<wbr>Solver, Inst))<br>
- return false;<br>
-<br>
- // Delete the instruction.<br>
- if (shouldEraseFromParent)<br>
- Inst->eraseFromParent();<br>
- return true;<br>
-}<br>
-<br>
// runSCCP() - Run the Sparse Conditional Constant Propagation algorithm,<br>
// and return true if the function was modified.<br>
//<br>
@@ -1618,8 +1607,9 @@ static bool runSCCP(Function &F, const D<br>
if (Inst->getType()->isVoidTy() || isa<TerminatorInst>(Inst))<br>
continue;<br>
<br>
- if (tryToReplaceInstWithConstant(<wbr>Solver, Inst,<br>
- true /* shouldEraseFromParent */)) {<br>
+ if (tryToReplaceWithConstant(<wbr>Solver, Inst)) {<br>
+ if (isInstructionTriviallyDead(<wbr>Inst))<br>
+ Inst->eraseFromParent();<br>
// Hey, we just changed something!<br>
MadeChanges = true;<br>
++NumInstRemoved;<br>
@@ -1823,10 +1813,9 @@ static bool runIPSCCP(Module &M, const D<br>
Instruction *Inst = &*BI++;<br>
if (Inst->getType()->isVoidTy())<br>
continue;<br>
- if (tryToReplaceInstWithConstant(<br>
- Solver, Inst,<br>
- !isa<CallInst>(Inst) &&<br>
- !isa<TerminatorInst>(Inst) /* shouldEraseFromParent */)) {<br>
+ if (tryToReplaceWithConstant(<wbr>Solver, Inst)) {<br>
+ if (!isa<CallInst>(Inst) && !isa<TerminatorInst>(Inst))<br>
+ Inst->eraseFromParent();<br>
// Hey, we just changed something!<br>
MadeChanges = true;<br>
++IPNumInstRemoved;<br>
<br>
Modified: llvm/trunk/test/Transforms/<wbr>SCCP/calltest.ll<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/SCCP/calltest.ll?rev=279647&r1=279646&r2=279647&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/llvm/trunk/test/<wbr>Transforms/SCCP/calltest.ll?<wbr>rev=279647&r1=279646&r2=<wbr>279647&view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- llvm/trunk/test/Transforms/<wbr>SCCP/calltest.ll (original)<br>
+++ llvm/trunk/test/Transforms/<wbr>SCCP/calltest.ll Wed Aug 24 13:10:21 2016<br>
@@ -1,12 +1,16 @@<br>
-; RUN: opt < %s -sccp -loop-deletion -simplifycfg -S | not grep br<br>
+; RUN: opt < %s -sccp -loop-deletion -simplifycfg -S | FileCheck %s<br>
<br>
+declare double @sqrt(double) readnone nounwind<br>
+%empty = type {}<br>
+declare %empty @has_side_effects()<br>
+<br>
+define double @test_0(i32 %param) {<br>
+; CHECK-LABEL: @test_0(<br>
+; CHECK-NOT: br<br>
+entry:<br>
; No matter how hard you try, sqrt(1.0) is always 1.0. This allows the<br>
; optimizer to delete this loop.<br>
<br>
-declare double @sqrt(double)<br>
-<br>
-define double @test(i32 %param) {<br>
-entry:<br>
br label %Loop<br>
Loop: ; preds = %Loop, %entry<br>
%I2 = phi i32 [ 0, %entry ], [ %I3, %Loop ] ; <i32> [#uses=1]<br>
@@ -19,3 +23,9 @@ Exit: ; preds = %Loop<br>
ret double %V<br>
}<br>
<br>
+define i32 @test_1() {<br>
+; CHECK-LABEL: @test_1(<br>
+; CHECK: call %empty @has_side_effects()<br>
+ %1 = call %empty @has_side_effects()<br>
+ ret i32 0<br>
+}<br>
<br>
<br>
______________________________<wbr>_________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@lists.llvm.org">llvm-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/llvm-commits</a><br>
</blockquote></div></div>