[PATCH] D142293: [InstCombine] Add PHINode operands to worklist on instruction erasure
Luke Lau via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Sat Jan 21 17:12:01 PST 2023
luke updated this revision to Diff 491111.
luke added a comment.
Remove erroneous include
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D142293/new/
https://reviews.llvm.org/D142293
Files:
llvm/lib/Transforms/InstCombine/InstCombineInternal.h
llvm/test/Transforms/InstCombine/phi-elimination-iteration.ll
Index: llvm/test/Transforms/InstCombine/phi-elimination-iteration.ll
===================================================================
--- /dev/null
+++ llvm/test/Transforms/InstCombine/phi-elimination-iteration.ll
@@ -0,0 +1,21 @@
+; RUN: opt < %s -passes=instcombine -S -debug 2>&1 | FileCheck %s
+define void @f() {
+entry:
+ br label %a
+a:
+ %phi.a = phi i32 [ 0, %entry ], [ %x, %a ]
+ %x = add i32 %phi.a, 1
+ br i1 false, label %a, label %b
+b:
+ %phi.b = phi i32 [ %x, %a ], [ %y, %b ]
+ %y = add i32 %phi.b, 1
+ br label %b
+}
+
+; CHECK: INSTCOMBINE ITERATION #1
+; CHECK: INSTCOMBINE ITERATION #2
+; CHECK-NOT: INSTCOMBINE ITERATION #3
+; CHECK-LABEL: a:
+; CHECK-NEXT: br i1 false, label %a, label %b
+; CHECK-LABEL: b:
+; CHECK-NEXT: br label %b
Index: llvm/lib/Transforms/InstCombine/InstCombineInternal.h
===================================================================
--- llvm/lib/Transforms/InstCombine/InstCombineInternal.h
+++ llvm/lib/Transforms/InstCombine/InstCombineInternal.h
@@ -412,8 +412,14 @@
// Make sure that we reprocess all operands now that we reduced their
// use counts.
for (Use &Operand : I.operands())
- if (auto *Inst = dyn_cast<Instruction>(Operand))
+ if (auto *Inst = dyn_cast<Instruction>(Operand)) {
Worklist.add(Inst);
+ // If this instruction uses a phi node then we need to process the phi
+ // node, as it may potentially be able to delete it
+ for (Use &OpOp : Inst->operands())
+ if (auto *PN = dyn_cast<PHINode>(OpOp))
+ Worklist.add(PN);
+ }
Worklist.remove(&I);
I.eraseFromParent();
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D142293.491111.patch
Type: text/x-patch
Size: 1641 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230122/e17c4c2a/attachment.bin>
More information about the llvm-commits
mailing list