[PATCH] D113787: [llvm-reduce] keep terminator instructions during ReduceGlobalVars
Dwight Guth via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Nov 12 11:12:08 PST 2021
dwightguth created this revision.
dwightguth added a reviewer: aeubanks.
dwightguth requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
Previously we were deleting instructions that use a global variable when
we delete the global variable. However, this obviously does not work if
the instruction is a terminator instruction as the resulting basic block
will have no terminator, resulting in invalid IR. To fix this, we simply
ensure that terminator instructions are never added to the list of
instructions to delete.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D113787
Files:
llvm/test/tools/llvm-reduce/remove-global-vars-terminator.ll
llvm/tools/llvm-reduce/deltas/ReduceGlobalVars.cpp
Index: llvm/tools/llvm-reduce/deltas/ReduceGlobalVars.cpp
===================================================================
--- llvm/tools/llvm-reduce/deltas/ReduceGlobalVars.cpp
+++ llvm/tools/llvm-reduce/deltas/ReduceGlobalVars.cpp
@@ -38,7 +38,8 @@
if (!GVsToKeep.count(&GV)) {
for (auto *U : GV.users())
if (auto *Inst = dyn_cast<Instruction>(U))
- InstToRemove.push_back(Inst);
+ if (!Inst->isTerminator())
+ InstToRemove.push_back(Inst);
GV.replaceAllUsesWith(UndefValue::get(GV.getType()));
ToRemove.push_back(&GV);
Index: llvm/test/tools/llvm-reduce/remove-global-vars-terminator.ll
===================================================================
--- /dev/null
+++ llvm/test/tools/llvm-reduce/remove-global-vars-terminator.ll
@@ -0,0 +1,21 @@
+; Test that llvm-reduce does not create invalid IR when the global-variables
+; delta pass processes a global variable that is used by a basic block
+; terminator
+
+; RUN: llvm-reduce --abort-on-invalid-reduction --delta-passes=global-variables --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 --implicit-check-not=uninteresting %s
+
+; CHECK-INTERESTINGNESS: @interesting = {{.*}}global i32{{.*}}, align 4
+
+; CHECK-FINAL: @interesting = global i32 0, align 4
+ at interesting = global i32 0, align 4
+
+ at uninteresting = global i32 1, align 4
+
+define i32* @foo() {
+entry:
+ ; CHECK-ALL: store i32 5, i32* @interesting, align 4
+ store i32 5, i32* @interesting, align 4
+
+ ret i32* @uninteresting
+}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D113787.386896.patch
Type: text/x-patch
Size: 1671 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20211112/1bc0330d/attachment.bin>
More information about the llvm-commits
mailing list