[PATCH] D129193: [JumpThreading] Avoid threadThroughTwoBasicBlocks when PredPred BB ends with indirectbranch
ChenYang Li via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Jul 6 05:40:51 PDT 2022
Ch1p created this revision.
Herald added a subscriber: hiraditya.
Herald added a project: All.
Ch1p requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D129193
Files:
llvm/lib/Transforms/Scalar/JumpThreading.cpp
llvm/test/Transforms/JumpThreading/indirectbr-in-predpred.ll
Index: llvm/test/Transforms/JumpThreading/indirectbr-in-predpred.ll
===================================================================
--- /dev/null
+++ llvm/test/Transforms/JumpThreading/indirectbr-in-predpred.ll
@@ -0,0 +1,33 @@
+; RUN: opt -S < %s -jump-threading | FileCheck %s
+
+; CHECK: %indirect.goto.dest = select i1 %cmp, i8* blockaddress(@test1, %PredBB1), i8* blockaddress(@test1, %PredPredBB2)
+; CHECK: indirectbr i8* %indirect.goto.dest, [label %PredBB1, label %PredPredBB2]
+define i1 @test1(i32 %0) #0 {
+PredPredBB1:
+ %cmp = icmp ne i32 %0, 0
+ %1 = add i32 32, %0
+ %indirect.goto.dest = select i1 %cmp, i8* blockaddress(@test1, %PredBB1), i8* blockaddress(@test1, %PredPredBB2)
+ indirectbr i8* %indirect.goto.dest, [label %PredBB1, label %PredPredBB2]
+
+PredPredBB2: ; preds = %PredPredBB1
+ %cmp1 = icmp ne i32 %0, 1
+ br i1 %cmp1, label %PredBB1, label %BB2
+
+PredBB1: ; preds = %PredPredBB2, %PredPredBB1
+ %num = phi i32 [ 0, %PredPredBB1 ], [ %1, %PredPredBB2 ]
+ %cmp2 = icmp eq i32 %1, 100
+ br i1 %cmp2, label %BB1, label %BB2
+
+BB1: ; preds = %PredBB1
+ %cmp3 = icmp eq i32 %num, 0
+ br i1 %cmp3, label %BB2, label %BB3
+
+BB2: ; preds = %BB1, %PredBB1, %PredPredBB2
+ %2 = or i1 %cmp, true
+ ret i1 %2
+
+BB3: ; preds = %BB1
+ ret i1 true
+}
+
+attributes #0 = { nounwind }
Index: llvm/lib/Transforms/Scalar/JumpThreading.cpp
===================================================================
--- llvm/lib/Transforms/Scalar/JumpThreading.cpp
+++ llvm/lib/Transforms/Scalar/JumpThreading.cpp
@@ -2173,6 +2173,9 @@
BasicBlock *ZeroPred = nullptr;
BasicBlock *OnePred = nullptr;
for (BasicBlock *P : predecessors(PredBB)) {
+ // If PredPred ends with IndirectBrInst, we can't handle it.
+ if (isa<IndirectBrInst>(P->getTerminator()))
+ continue;
if (ConstantInt *CI = dyn_cast_or_null<ConstantInt>(
evaluateOnPredecessorEdge(BB, P, Cond))) {
if (CI->isZero()) {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D129193.442535.patch
Type: text/x-patch
Size: 2168 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220706/92635219/attachment.bin>
More information about the llvm-commits
mailing list