[PATCH] D94470: [LSR] Don't break a critical edge if parent ends with "callbr"
Bill Wendling via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Jan 12 14:52:54 PST 2021
void updated this revision to Diff 316249.
void added a comment.
Move testcase.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D94470/new/
https://reviews.llvm.org/D94470
Files:
llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp
llvm/test/Transforms/LoopStrengthReduce/callbr-critical-edge-splitting.ll
Index: llvm/test/Transforms/LoopStrengthReduce/callbr-critical-edge-splitting.ll
===================================================================
--- /dev/null
+++ llvm/test/Transforms/LoopStrengthReduce/callbr-critical-edge-splitting.ll
@@ -0,0 +1,38 @@
+; RUN: opt < %s -o /dev/null -loop-reduce
+
+target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+
+; Test that we don't try to break a critical edge to a block ending in a callbr
+; instruction. See https://github.com/ClangBuiltLinux/linux/issues/1252
+
+define dso_local i32 @test1() local_unnamed_addr {
+entry:
+ br label %for.cond
+
+for.cond: ; preds = %for.inc, %entry
+ callbr void asm sideeffect "", "X,X,~{dirflag},~{fpsr},~{flags}"(i8* blockaddress(@test1, %cond.true.i), i8* blockaddress(@test1, %for.end))
+ to label %asm.fallthrough.i.i [label %cond.true.i, label %for.end]
+
+asm.fallthrough.i.i: ; preds = %for.cond
+ unreachable
+
+cond.true.i: ; preds = %for.cond
+ br label %do.body.i.i.do.body.i.i_crit_edge
+
+do.body.i.i.do.body.i.i_crit_edge: ; preds = %do.body.i.i.do.body.i.i_crit_edge, %cond.true.i
+ %pgocount711 = phi i64 [ %0, %do.body.i.i.do.body.i.i_crit_edge ], [ 0, %cond.true.i ]
+ %0 = add nuw nsw i64 %pgocount711, 1
+ br i1 undef, label %do.body.i.i.rdrand_int.exit.i_crit_edge, label %do.body.i.i.do.body.i.i_crit_edge
+
+do.body.i.i.rdrand_int.exit.i_crit_edge: ; preds = %do.body.i.i.do.body.i.i_crit_edge
+ %1 = add i64 %0, undef
+ br i1 undef, label %for.end, label %for.inc
+
+for.inc: ; preds = %do.body.i.i.rdrand_int.exit.i_crit_edge
+ br label %for.cond
+
+for.end: ; preds = %do.body.i.i.rdrand_int.exit.i_crit_edge, %for.cond
+ %pgocount.promoted24 = phi i64 [ undef, %for.cond ], [ %1, %do.body.i.i.rdrand_int.exit.i_crit_edge ]
+ ret i32 undef
+}
Index: llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp
===================================================================
--- llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp
+++ llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp
@@ -5579,16 +5579,23 @@
<< "\n");
return;
}
- // Bail out if we have a PHI on an EHPad that gets a value from a
- // CatchSwitchInst. Because the CatchSwitchInst cannot be split, there is
- // no good place to stick any instructions.
+
if (auto *PN = dyn_cast<PHINode>(U.getUser())) {
auto *FirstNonPHI = PN->getParent()->getFirstNonPHI();
if (isa<FuncletPadInst>(FirstNonPHI) ||
isa<CatchSwitchInst>(FirstNonPHI))
+ // Bail out if we have a PHI on an EHPad that gets a value from a
+ // CatchSwitchInst. Because the CatchSwitchInst cannot be split, there
+ // is no good place to stick any instructions.
for (BasicBlock *PredBB : PN->blocks())
if (isa<CatchSwitchInst>(PredBB->getFirstNonPHI()))
return;
+
+ // Also bail out if we have a PHI with a value from a block ending in a
+ // CallBrInst, because those also can't be split for similar reasons.
+ for (BasicBlock *PredBB : PN->blocks())
+ if (isa<CallBrInst>(PredBB->getTerminator()))
+ return;
}
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D94470.316249.patch
Type: text/x-patch
Size: 3451 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210112/2bf77495/attachment.bin>
More information about the llvm-commits
mailing list