[llvm] r285380 - [Reassociate] Removing instructions mutates the IR.

Davide Italiano via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 27 19:47:09 PDT 2016


Author: davide
Date: Thu Oct 27 21:47:09 2016
New Revision: 285380

URL: http://llvm.org/viewvc/llvm-project?rev=285380&view=rev
Log:
[Reassociate] Removing instructions mutates the IR.

Fixes PR 30784. Discussed with Justin, who pointed out that
in the new PassManager infrastructure we can have more fine-grained
control on which analyses we want to preserve, but this is the
best we can do with the current infrastructure.

Added:
    llvm/trunk/test/Transforms/Reassociate/reassociate-deadinst.ll
Modified:
    llvm/trunk/lib/Transforms/Scalar/Reassociate.cpp

Modified: llvm/trunk/lib/Transforms/Scalar/Reassociate.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/Reassociate.cpp?rev=285380&r1=285379&r2=285380&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/Reassociate.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/Reassociate.cpp Thu Oct 27 21:47:09 2016
@@ -2198,8 +2198,10 @@ PreservedAnalyses ReassociatePass::run(F
     // trivially dead instructions have been removed.
     while (!ToRedo.empty()) {
       Instruction *I = ToRedo.pop_back_val();
-      if (isInstructionTriviallyDead(I))
+      if (isInstructionTriviallyDead(I)) {
         RecursivelyEraseDeadInsts(I, ToRedo);
+        MadeChange = true;
+      }
     }
 
     // Now that we have removed dead instructions, we can reoptimize the

Added: llvm/trunk/test/Transforms/Reassociate/reassociate-deadinst.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/Reassociate/reassociate-deadinst.ll?rev=285380&view=auto
==============================================================================
--- llvm/trunk/test/Transforms/Reassociate/reassociate-deadinst.ll (added)
+++ llvm/trunk/test/Transforms/Reassociate/reassociate-deadinst.ll Thu Oct 27 21:47:09 2016
@@ -0,0 +1,16 @@
+; RUN: opt -inline -functionattrs -reassociate %s -S | FileCheck %s
+
+; CHECK-NOT: func1
+; CHECK-LABEL: main
+; CHECK-NEXT: ret void
+
+define internal i16 @func1() noinline #0 {
+  ret i16 0
+}
+
+define void @main(i16 %argc, i16** %argv) #0 {
+  %_tmp0 = call i16 @func1()
+  %_tmp2 = zext i16 %_tmp0 to i32
+  ret void
+}
+attributes #0 = { minsize nounwind optsize }




More information about the llvm-commits mailing list