Skip to content

Commit a347bdb

Browse files
authored
Revert "[SimplifyCFG] Skip threading if the target may have divergent branches" (#100994)
Reverts #100185 See comments on PR (PR not accepted, outstanding review comments, breaks HIP-clang buildbot)
1 parent 03e17da commit a347bdb

File tree

3 files changed

+12
-98
lines changed

3 files changed

+12
-98
lines changed

llvm/lib/Transforms/Utils/SimplifyCFG.cpp

+12-15
Original file line numberDiff line numberDiff line change
@@ -3246,12 +3246,7 @@ bool SimplifyCFGOpt::SpeculativelyExecuteBB(BranchInst *BI,
32463246
}
32473247

32483248
/// Return true if we can thread a branch across this block.
3249-
static bool BlockIsSimpleEnoughToThreadThrough(BasicBlock *BB,
3250-
const TargetTransformInfo &TTI) {
3251-
// Skip threading if the branch may be divergent.
3252-
if (TTI.hasBranchDivergence(BB->getParent()))
3253-
return false;
3254-
3249+
static bool BlockIsSimpleEnoughToThreadThrough(BasicBlock *BB) {
32553250
int Size = 0;
32563251
EphemeralValueTracker EphTracker;
32573252

@@ -3306,9 +3301,10 @@ static ConstantInt *getKnownValueOnEdge(Value *V, BasicBlock *From,
33063301
/// If we have a conditional branch on something for which we know the constant
33073302
/// value in predecessors (e.g. a phi node in the current block), thread edges
33083303
/// from the predecessor to their ultimate destination.
3309-
static std::optional<bool> FoldCondBranchOnValueKnownInPredecessorImpl(
3310-
BranchInst *BI, DomTreeUpdater *DTU, const DataLayout &DL,
3311-
const TargetTransformInfo &TTI, AssumptionCache *AC) {
3304+
static std::optional<bool>
3305+
FoldCondBranchOnValueKnownInPredecessorImpl(BranchInst *BI, DomTreeUpdater *DTU,
3306+
const DataLayout &DL,
3307+
AssumptionCache *AC) {
33123308
SmallMapVector<ConstantInt *, SmallSetVector<BasicBlock *, 2>, 2> KnownValues;
33133309
BasicBlock *BB = BI->getParent();
33143310
Value *Cond = BI->getCondition();
@@ -3336,7 +3332,7 @@ static std::optional<bool> FoldCondBranchOnValueKnownInPredecessorImpl(
33363332
// Now we know that this block has multiple preds and two succs.
33373333
// Check that the block is small enough and values defined in the block are
33383334
// not used outside of it.
3339-
if (!BlockIsSimpleEnoughToThreadThrough(BB, TTI))
3335+
if (!BlockIsSimpleEnoughToThreadThrough(BB))
33403336
return false;
33413337

33423338
for (const auto &Pair : KnownValues) {
@@ -3463,14 +3459,15 @@ static std::optional<bool> FoldCondBranchOnValueKnownInPredecessorImpl(
34633459
return false;
34643460
}
34653461

3466-
static bool FoldCondBranchOnValueKnownInPredecessor(
3467-
BranchInst *BI, DomTreeUpdater *DTU, const DataLayout &DL,
3468-
const TargetTransformInfo &TTI, AssumptionCache *AC) {
3462+
static bool FoldCondBranchOnValueKnownInPredecessor(BranchInst *BI,
3463+
DomTreeUpdater *DTU,
3464+
const DataLayout &DL,
3465+
AssumptionCache *AC) {
34693466
std::optional<bool> Result;
34703467
bool EverChanged = false;
34713468
do {
34723469
// Note that None means "we changed things, but recurse further."
3473-
Result = FoldCondBranchOnValueKnownInPredecessorImpl(BI, DTU, DL, TTI, AC);
3470+
Result = FoldCondBranchOnValueKnownInPredecessorImpl(BI, DTU, DL, AC);
34743471
EverChanged |= Result == std::nullopt || *Result;
34753472
} while (Result == std::nullopt);
34763473
return EverChanged;
@@ -7546,7 +7543,7 @@ bool SimplifyCFGOpt::simplifyCondBranch(BranchInst *BI, IRBuilder<> &Builder) {
75467543
// If this is a branch on something for which we know the constant value in
75477544
// predecessors (e.g. a phi node in the current block), thread control
75487545
// through this block.
7549-
if (FoldCondBranchOnValueKnownInPredecessor(BI, DTU, DL, TTI, Options.AC))
7546+
if (FoldCondBranchOnValueKnownInPredecessor(BI, DTU, DL, Options.AC))
75507547
return requestResimplify();
75517548

75527549
// Scan predecessor blocks for conditional branches.

llvm/test/Transforms/SimplifyCFG/AMDGPU/skip-threading.ll

-44
This file was deleted.

llvm/test/Transforms/SimplifyCFG/convergent.ll

-39
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@
44
; RUN: opt -S -passes='simplifycfg<hoist-common-insts;sink-common-insts>' < %s | FileCheck -check-prefixes=CHECK,SINK %s
55

66
declare void @foo() convergent
7-
declare void @bar1()
8-
declare void @bar2()
9-
declare void @bar3()
107
declare i32 @tid()
118
declare i32 @mbcnt(i32 %a, i32 %b) convergent
129
declare i32 @bpermute(i32 %a, i32 %b) convergent
@@ -48,42 +45,6 @@ exit:
4845
ret i32 %a
4946
}
5047

51-
define i32 @test_01a(i32 %a) {
52-
; CHECK-LABEL: @test_01a(
53-
; CHECK-NEXT: entry:
54-
; CHECK-NEXT: [[COND:%.*]] = icmp eq i32 [[A:%.*]], 0
55-
; CHECK-NEXT: br i1 [[COND]], label [[EXIT_CRITEDGE:%.*]], label [[IF_FALSE:%.*]]
56-
; CHECK: if.false:
57-
; CHECK-NEXT: call void @bar1()
58-
; CHECK-NEXT: call void @bar2()
59-
; CHECK-NEXT: call void @bar3()
60-
; CHECK-NEXT: br label [[EXIT:%.*]]
61-
; CHECK: exit.critedge:
62-
; CHECK-NEXT: call void @bar2()
63-
; CHECK-NEXT: br label [[EXIT]]
64-
; CHECK: exit:
65-
; CHECK-NEXT: ret i32 [[A]]
66-
;
67-
entry:
68-
%cond = icmp eq i32 %a, 0
69-
br i1 %cond, label %merge, label %if.false
70-
71-
if.false:
72-
call void @bar1()
73-
br label %merge
74-
75-
merge:
76-
call void @bar2()
77-
br i1 %cond, label %exit, label %if.false.2
78-
79-
if.false.2:
80-
call void @bar3()
81-
br label %exit
82-
83-
exit:
84-
ret i32 %a
85-
}
86-
8748
define void @test_02(ptr %y.coerce) convergent {
8849
; NOSINK-LABEL: @test_02(
8950
; NOSINK-NEXT: entry:

0 commit comments

Comments
 (0)