[llvm-branch-commits] [llvm-branch] r276660 - Merging r276389:

Hans Wennborg via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Mon Jul 25 10:27:29 PDT 2016


Author: hans
Date: Mon Jul 25 12:27:28 2016
New Revision: 276660

URL: http://llvm.org/viewvc/llvm-project?rev=276660&view=rev
Log:
Merging r276389:
------------------------------------------------------------------------
r276389 | majnemer | 2016-07-21 21:54:44 -0700 (Thu, 21 Jul 2016) | 6 lines

Don't remove side effecting instructions due to ConstantFoldInstruction

Just because we can constant fold the result of an instruction does not
imply that we can delete the instruction.  It may have side effects.

This fixes PR28655.
------------------------------------------------------------------------

Modified:
    llvm/branches/release_39/   (props changed)
    llvm/branches/release_39/lib/Transforms/IPO/GlobalOpt.cpp
    llvm/branches/release_39/lib/Transforms/InstCombine/InstructionCombining.cpp
    llvm/branches/release_39/lib/Transforms/Scalar/ConstantProp.cpp
    llvm/branches/release_39/lib/Transforms/Scalar/JumpThreading.cpp
    llvm/branches/release_39/lib/Transforms/Scalar/LICM.cpp
    llvm/branches/release_39/test/Transforms/ConstProp/calls.ll
    llvm/branches/release_39/test/Transforms/InstCombine/call.ll
    llvm/branches/release_39/test/Transforms/InstCombine/log-pow.ll

Propchange: llvm/branches/release_39/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Mon Jul 25 12:27:28 2016
@@ -1,3 +1,3 @@
 /llvm/branches/Apple/Pertwee:110850,110961
 /llvm/branches/type-system-rewrite:133420-134817
-/llvm/trunk:155241,275870,275879,275898,275935,275946,276181,276358,276364,276368,276479
+/llvm/trunk:155241,275870,275879,275898,275935,275946,276181,276358,276364,276368,276389,276479

Modified: llvm/branches/release_39/lib/Transforms/IPO/GlobalOpt.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/release_39/lib/Transforms/IPO/GlobalOpt.cpp?rev=276660&r1=276659&r2=276660&view=diff
==============================================================================
--- llvm/branches/release_39/lib/Transforms/IPO/GlobalOpt.cpp (original)
+++ llvm/branches/release_39/lib/Transforms/IPO/GlobalOpt.cpp Mon Jul 25 12:27:28 2016
@@ -44,6 +44,7 @@
 #include "llvm/Transforms/Utils/CtorUtils.h"
 #include "llvm/Transforms/Utils/Evaluator.h"
 #include "llvm/Transforms/Utils/GlobalStatus.h"
+#include "llvm/Transforms/Utils/Local.h"
 #include <algorithm>
 using namespace llvm;
 
@@ -779,7 +780,8 @@ static void ConstantPropUsersOf(Value *V
         // Instructions could multiply use V.
         while (UI != E && *UI == I)
           ++UI;
-        I->eraseFromParent();
+        if (isInstructionTriviallyDead(I, TLI))
+          I->eraseFromParent();
       }
 }
 

Modified: llvm/branches/release_39/lib/Transforms/InstCombine/InstructionCombining.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/release_39/lib/Transforms/InstCombine/InstructionCombining.cpp?rev=276660&r1=276659&r2=276660&view=diff
==============================================================================
--- llvm/branches/release_39/lib/Transforms/InstCombine/InstructionCombining.cpp (original)
+++ llvm/branches/release_39/lib/Transforms/InstCombine/InstructionCombining.cpp Mon Jul 25 12:27:28 2016
@@ -2830,7 +2830,8 @@ bool InstCombiner::run() {
         // Add operands to the worklist.
         replaceInstUsesWith(*I, C);
         ++NumConstProp;
-        eraseInstFromFunction(*I);
+        if (isInstructionTriviallyDead(I, TLI))
+          eraseInstFromFunction(*I);
         MadeIRChange = true;
         continue;
       }
@@ -2851,7 +2852,8 @@ bool InstCombiner::run() {
         // Add operands to the worklist.
         replaceInstUsesWith(*I, C);
         ++NumConstProp;
-        eraseInstFromFunction(*I);
+        if (isInstructionTriviallyDead(I, TLI))
+          eraseInstFromFunction(*I);
         MadeIRChange = true;
         continue;
       }
@@ -3007,7 +3009,8 @@ static bool AddReachableCodeToWorklist(B
                        << *Inst << '\n');
           Inst->replaceAllUsesWith(C);
           ++NumConstProp;
-          Inst->eraseFromParent();
+          if (isInstructionTriviallyDead(Inst, TLI))
+            Inst->eraseFromParent();
           continue;
         }
 

Modified: llvm/branches/release_39/lib/Transforms/Scalar/ConstantProp.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/release_39/lib/Transforms/Scalar/ConstantProp.cpp?rev=276660&r1=276659&r2=276660&view=diff
==============================================================================
--- llvm/branches/release_39/lib/Transforms/Scalar/ConstantProp.cpp (original)
+++ llvm/branches/release_39/lib/Transforms/Scalar/ConstantProp.cpp Mon Jul 25 12:27:28 2016
@@ -19,6 +19,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "llvm/Transforms/Scalar.h"
+#include "llvm/Transforms/Utils/Local.h"
 #include "llvm/ADT/Statistic.h"
 #include "llvm/Analysis/ConstantFolding.h"
 #include "llvm/IR/Constant.h"
@@ -90,11 +91,13 @@ bool ConstantPropagation::runOnFunction(
 
         // Remove the dead instruction.
         WorkList.erase(I);
-        I->eraseFromParent();
+        if (isInstructionTriviallyDead(I, TLI)) {
+          I->eraseFromParent();
+          ++NumInstKilled;
+        }
 
         // We made a change to the function...
         Changed = true;
-        ++NumInstKilled;
       }
   }
   return Changed;

Modified: llvm/branches/release_39/lib/Transforms/Scalar/JumpThreading.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/release_39/lib/Transforms/Scalar/JumpThreading.cpp?rev=276660&r1=276659&r2=276660&view=diff
==============================================================================
--- llvm/branches/release_39/lib/Transforms/Scalar/JumpThreading.cpp (original)
+++ llvm/branches/release_39/lib/Transforms/Scalar/JumpThreading.cpp Mon Jul 25 12:27:28 2016
@@ -758,7 +758,8 @@ bool JumpThreadingPass::ProcessBlock(Bas
         ConstantFoldInstruction(I, BB->getModule()->getDataLayout(), TLI);
     if (SimpleVal) {
       I->replaceAllUsesWith(SimpleVal);
-      I->eraseFromParent();
+      if (isInstructionTriviallyDead(I, TLI))
+        I->eraseFromParent();
       Condition = SimpleVal;
     }
   }

Modified: llvm/branches/release_39/lib/Transforms/Scalar/LICM.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/release_39/lib/Transforms/Scalar/LICM.cpp?rev=276660&r1=276659&r2=276660&view=diff
==============================================================================
--- llvm/branches/release_39/lib/Transforms/Scalar/LICM.cpp (original)
+++ llvm/branches/release_39/lib/Transforms/Scalar/LICM.cpp Mon Jul 25 12:27:28 2016
@@ -377,9 +377,11 @@ bool llvm::hoistRegion(DomTreeNode *N, A
               &I, I.getModule()->getDataLayout(), TLI)) {
         DEBUG(dbgs() << "LICM folding inst: " << I << "  --> " << *C << '\n');
         CurAST->copyValue(&I, C);
-        CurAST->deleteValue(&I);
         I.replaceAllUsesWith(C);
-        I.eraseFromParent();
+        if (isInstructionTriviallyDead(&I, TLI)) {
+          CurAST->deleteValue(&I);
+          I.eraseFromParent();
+        }
         continue;
       }
 

Modified: llvm/branches/release_39/test/Transforms/ConstProp/calls.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/release_39/test/Transforms/ConstProp/calls.ll?rev=276660&r1=276659&r2=276660&view=diff
==============================================================================
--- llvm/branches/release_39/test/Transforms/ConstProp/calls.ll (original)
+++ llvm/branches/release_39/test/Transforms/ConstProp/calls.ll Mon Jul 25 12:27:28 2016
@@ -1,47 +1,47 @@
 ; RUN: opt < %s -constprop -S | FileCheck %s
 ; RUN: opt < %s -constprop -disable-simplify-libcalls -S | FileCheck %s --check-prefix=FNOBUILTIN
 
-declare double @acos(double)
-declare double @asin(double)
-declare double @atan(double)
-declare double @atan2(double, double)
-declare double @ceil(double)
-declare double @cos(double)
-declare double @cosh(double)
-declare double @exp(double)
-declare double @exp2(double)
-declare double @fabs(double)
-declare double @floor(double)
-declare double @fmod(double, double)
-declare double @log(double)
-declare double @log10(double)
-declare double @pow(double, double)
-declare double @sin(double)
-declare double @sinh(double)
-declare double @sqrt(double)
-declare double @tan(double)
-declare double @tanh(double)
+declare double @acos(double) readnone nounwind
+declare double @asin(double) readnone nounwind
+declare double @atan(double) readnone nounwind
+declare double @atan2(double, double) readnone nounwind
+declare double @ceil(double) readnone nounwind
+declare double @cos(double) readnone nounwind
+declare double @cosh(double) readnone nounwind
+declare double @exp(double) readnone nounwind
+declare double @exp2(double) readnone nounwind
+declare double @fabs(double) readnone nounwind
+declare double @floor(double) readnone nounwind
+declare double @fmod(double, double) readnone nounwind
+declare double @log(double) readnone nounwind
+declare double @log10(double) readnone nounwind
+declare double @pow(double, double) readnone nounwind
+declare double @sin(double) readnone nounwind
+declare double @sinh(double) readnone nounwind
+declare double @sqrt(double) readnone nounwind
+declare double @tan(double) readnone nounwind
+declare double @tanh(double) readnone nounwind
 
-declare float @acosf(float)
-declare float @asinf(float)
-declare float @atanf(float)
-declare float @atan2f(float, float)
-declare float @ceilf(float)
-declare float @cosf(float)
-declare float @coshf(float)
-declare float @expf(float)
-declare float @exp2f(float)
-declare float @fabsf(float)
-declare float @floorf(float)
-declare float @fmodf(float, float)
-declare float @logf(float)
-declare float @log10f(float)
-declare float @powf(float, float)
-declare float @sinf(float)
-declare float @sinhf(float)
-declare float @sqrtf(float)
-declare float @tanf(float)
-declare float @tanhf(float)
+declare float @acosf(float) readnone nounwind
+declare float @asinf(float) readnone nounwind
+declare float @atanf(float) readnone nounwind
+declare float @atan2f(float, float) readnone nounwind
+declare float @ceilf(float) readnone nounwind
+declare float @cosf(float) readnone nounwind
+declare float @coshf(float) readnone nounwind
+declare float @expf(float) readnone nounwind
+declare float @exp2f(float) readnone nounwind
+declare float @fabsf(float) readnone nounwind
+declare float @floorf(float) readnone nounwind
+declare float @fmodf(float, float) readnone nounwind
+declare float @logf(float) readnone nounwind
+declare float @log10f(float) readnone nounwind
+declare float @powf(float, float) readnone nounwind
+declare float @sinf(float) readnone nounwind
+declare float @sinhf(float) readnone nounwind
+declare float @sqrtf(float) readnone nounwind
+declare float @tanf(float) readnone nounwind
+declare float @tanhf(float) readnone nounwind
 
 define double @T() {
 ; CHECK-LABEL: @T(

Modified: llvm/branches/release_39/test/Transforms/InstCombine/call.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/release_39/test/Transforms/InstCombine/call.ll?rev=276660&r1=276659&r2=276660&view=diff
==============================================================================
--- llvm/branches/release_39/test/Transforms/InstCombine/call.ll (original)
+++ llvm/branches/release_39/test/Transforms/InstCombine/call.ll Mon Jul 25 12:27:28 2016
@@ -276,3 +276,14 @@ define <2 x i16> @test16() {
   %X = call <2 x i16> bitcast (i32 ()* @test16a to <2 x i16> ()*)( )
   ret <2 x i16> %X
 }
+
+declare i32 @pr28655(i32 returned %V)
+
+define i32 @test17() {
+entry:
+  %C = call i32 @pr28655(i32 0)
+  ret i32 %C
+}
+; CHECK-LABEL: @test17(
+; CHECK: call i32 @pr28655(i32 0)
+; CHECK: ret i32 0

Modified: llvm/branches/release_39/test/Transforms/InstCombine/log-pow.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/release_39/test/Transforms/InstCombine/log-pow.ll?rev=276660&r1=276659&r2=276660&view=diff
==============================================================================
--- llvm/branches/release_39/test/Transforms/InstCombine/log-pow.ll (original)
+++ llvm/branches/release_39/test/Transforms/InstCombine/log-pow.ll Mon Jul 25 12:27:28 2016
@@ -55,7 +55,8 @@ define double @log_exp2_not_fast(double
 ; CHECK-NEXT:  %call3 = call fast double @log(double %call2)
 ; CHECK-NEXT:  ret double %call3
 
-declare double @log(double)
+declare double @log(double) #0
 declare double @exp2(double)
 declare double @llvm.pow.f64(double, double)
 
+attributes #0 = { nounwind readnone }




More information about the llvm-branch-commits mailing list