OSDN Git Service

[Reduce] Argument reduction: don't try to drop terminator instructions
authorRoman Lebedev <lebedev.ri@gmail.com>
Mon, 20 Jul 2020 19:25:15 +0000 (22:25 +0300)
committerRoman Lebedev <lebedev.ri@gmail.com>
Mon, 20 Jul 2020 21:06:03 +0000 (00:06 +0300)
Newly-added test previously crashed.

While it is up for debate whether or not instruction reduction
should be indiscriminate in instruction dropping (there you can
just ensure that the test case is still -verify'ies), here
if we drop terminator, CloneFunctionInto() will immediately crash.

So let's not do that :)

llvm/test/Reduce/remove-args-used-by-ret.ll [new file with mode: 0644]
llvm/tools/llvm-reduce/deltas/ReduceArguments.cpp

diff --git a/llvm/test/Reduce/remove-args-used-by-ret.ll b/llvm/test/Reduce/remove-args-used-by-ret.ll
new file mode 100644 (file)
index 0000000..13b7fe5
--- /dev/null
@@ -0,0 +1,14 @@
+; RUN: llvm-reduce --test FileCheck --test-arg --check-prefixes=CHECK-ALL,CHECK-INTERESTINGNESS --test-arg %s --test-arg --input-file %s -o %t
+; RUN: cat %t | FileCheck --check-prefixes=CHECK-ALL,CHECK-FINAL %s
+
+; We can't drop arguments if they are used by terminator instructions.
+
+define i32 @t(i32 %a0, i32 %a1, i32 %a2) {
+; CHECK-ALL-LABEL: @t
+; CHECK-FINAL-NOT: %a1
+;
+; CHECK-INTERESTINGNESS: ret i32
+; CHECK-FINAL: ret i32 undef
+
+  ret i32 %a1
+}
index 88c3e32..e0e1d1c 100644 (file)
@@ -73,7 +73,8 @@ static void extractArgumentsFromModule(std::vector<Chunk> ChunksToKeep,
         continue;
       auto *I = cast<Instruction>(V);
       I->replaceAllUsesWith(UndefValue::get(I->getType()));
-      I->eraseFromParent();
+      if (!I->isTerminator())
+        I->eraseFromParent();
     }
 
     // No arguments to reduce