[Reassociate] Removing instructions mutates the IR.
authorDavide Italiano <davide@freebsd.org>
Fri, 28 Oct 2016 02:47:09 +0000 (02:47 +0000)
committerDavide Italiano <davide@freebsd.org>
Fri, 28 Oct 2016 02:47:09 +0000 (02:47 +0000)
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.

llvm-svn: 285380

llvm/lib/Transforms/Scalar/Reassociate.cpp
llvm/test/Transforms/Reassociate/reassociate-deadinst.ll [new file with mode: 0644]

index 1ec7fce..ac0d7b8 100644 (file)
@@ -2198,8 +2198,10 @@ PreservedAnalyses ReassociatePass::run(Function &F, FunctionAnalysisManager &) {
     // 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
diff --git a/llvm/test/Transforms/Reassociate/reassociate-deadinst.ll b/llvm/test/Transforms/Reassociate/reassociate-deadinst.ll
new file mode 100644 (file)
index 0000000..6a12c47
--- /dev/null
@@ -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 }