[PATCH] D86210: [llvm-reduce] Skip terminators when reducing instructions.
Florian Hahn via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Sun Aug 23 09:56:21 PDT 2020
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG51a82828fb29: [llvm-reduce] Skip terminators when reducing instructions. (authored by fhahn).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D86210/new/
https://reviews.llvm.org/D86210
Files:
llvm/test/Reduce/do-not-remove-terminator.ll
llvm/test/Reduce/remove-funcs.ll
llvm/test/Reduce/remove-instructions.ll
llvm/tools/llvm-reduce/deltas/ReduceInstructions.cpp
Index: llvm/tools/llvm-reduce/deltas/ReduceInstructions.cpp
===================================================================
--- llvm/tools/llvm-reduce/deltas/ReduceInstructions.cpp
+++ llvm/tools/llvm-reduce/deltas/ReduceInstructions.cpp
@@ -24,10 +24,14 @@
std::set<Instruction *> InstToKeep;
for (auto &F : *Program)
- for (auto &BB : F)
- for (auto &Inst : BB)
+ for (auto &BB : F) {
+ // Removing the terminator would make the block invalid. Only iterate over
+ // instructions before the terminator.
+ InstToKeep.insert(BB.getTerminator());
+ for (auto &Inst : make_range(BB.begin(), std::prev(BB.end())))
if (O.shouldKeep())
InstToKeep.insert(&Inst);
+ }
std::vector<Instruction *> InstToDelete;
for (auto &F : *Program)
@@ -49,7 +53,8 @@
int InstCount = 0;
for (auto &F : *Program)
for (auto &BB : F)
- InstCount += BB.getInstList().size();
+ // Well-formed blocks have terminators, which we cannot remove.
+ InstCount += BB.getInstList().size() - 1;
outs() << "Number of instructions: " << InstCount << "\n";
return InstCount;
Index: llvm/test/Reduce/remove-instructions.ll
===================================================================
--- llvm/test/Reduce/remove-instructions.ll
+++ llvm/test/Reduce/remove-instructions.ll
@@ -4,8 +4,12 @@
; RUN: cat %t | FileCheck -implicit-check-not=uninteresting %s
; REQUIRES: plugins
-; We're testing all direct uses of %interesting are conserved
+; We're testing all direct uses of %interesting are conserved. The terminator
+; (ret) must also be preserved.
+
; CHECK-COUNT-5: %interesting
+; CHECK: ret
+
define i32 @main() #0 {
entry:
%uninteresting1 = alloca i32, align 4
@@ -18,6 +22,5 @@
store i32 %uninteresting3, i32* %interesting, align 4
%1 = load i32, i32* %interesting, align 4
store i32 %1, i32* %uninteresting2, align 4
- ; CHECK-NOT: ret
ret i32 0
}
Index: llvm/test/Reduce/remove-funcs.ll
===================================================================
--- llvm/test/Reduce/remove-funcs.ll
+++ llvm/test/Reduce/remove-funcs.ll
@@ -20,6 +20,7 @@
; CHECK-FINAL-NEXT: entry:
; CHECK-FINAL-NEXT: %call2 = call i32 @interesting()
+; CHECK-FINAL-NEXT: ret i32 5
; CHECK-FINAL-NEXT: }
define i32 @uninteresting2() {
Index: llvm/test/Reduce/do-not-remove-terminator.ll
===================================================================
--- /dev/null
+++ llvm/test/Reduce/do-not-remove-terminator.ll
@@ -0,0 +1,19 @@
+; RUN: llvm-reduce --test FileCheck --test-arg --check-prefixes=CHECK-INTERESTINGNESS --test-arg %s --test-arg --input-file %s -o %t
+; RUN: cat %t | FileCheck --check-prefixes=CHECK-FINAL %s
+
+; Make sure we do not remove the terminator of the entry block. The interesting
+; check only requires the result to define the function @test.
+
+; Test case for PR43798.
+
+; CHECK-INTERESTINGNESS: define i32 @test
+
+; CHECK-FINAL: define i32 @test
+; CHECK-FINAL-NEXT: entry:
+; CHECK-FINAL-NEXT: ret i32
+
+define i32 @test(i32 %x) {
+entry:
+ %add = add i32 %x, %x
+ ret i32 %add
+}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D86210.287261.patch
Type: text/x-patch
Size: 3123 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200823/fcac00fd/attachment.bin>
More information about the llvm-commits
mailing list