Skip to content

Commit e0d1f5d

Browse files
authored
Disabled FoldCondBranchOnPHI in simplify cfg (#3180)
1 parent d0fa5e3 commit e0d1f5d

2 files changed

Lines changed: 61 additions & 0 deletions

File tree

lib/Transforms/Utils/SimplifyCFG.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1672,6 +1672,7 @@ static bool SpeculativelyExecuteBB(BranchInst *BI, BasicBlock *ThenBB,
16721672
return true;
16731673
}
16741674

1675+
#if 0 // HLSL Change - Unused function
16751676
/// \returns True if this block contains a CallInst with the NoDuplicate
16761677
/// attribute.
16771678
static bool HasNoDuplicateCall(const BasicBlock *BB) {
@@ -1684,6 +1685,7 @@ static bool HasNoDuplicateCall(const BasicBlock *BB) {
16841685
}
16851686
return false;
16861687
}
1688+
#endif
16871689

16881690
/// Return true if we can thread a branch across this block.
16891691
static bool BlockIsSimpleEnoughToThreadThrough(BasicBlock *BB) {
@@ -1709,6 +1711,7 @@ static bool BlockIsSimpleEnoughToThreadThrough(BasicBlock *BB) {
17091711
return true;
17101712
}
17111713

1714+
#if 0 // HLSL Change - Unused function
17121715
/// If we have a conditional branch on a PHI node value that is defined in the
17131716
/// same block as the branch and if any PHI entries are constants, thread edges
17141717
/// corresponding to that entry to be branches to their ultimate destination.
@@ -1807,6 +1810,7 @@ static bool FoldCondBranchOnPHI(BranchInst *BI, const DataLayout &DL) {
18071810

18081811
return false;
18091812
}
1813+
#endif
18101814

18111815
/// Given a BB that starts with the specified two-entry PHI node,
18121816
/// see if we can eliminate it.
@@ -4573,12 +4577,14 @@ bool SimplifyCFGOpt::SimplifyCondBranch(BranchInst *BI, IRBuilder<> &Builder) {
45734577
return SimplifyCFG(BB, TTI, BonusInstThreshold, AC) | true;
45744578
}
45754579

4580+
#if 0 // HLSL Change - this transformation creates unstructured flow
45764581
// If this is a branch on a phi node in the current block, thread control
45774582
// through this block if any PHI node entries are constants.
45784583
if (PHINode *PN = dyn_cast<PHINode>(BI->getCondition()))
45794584
if (PN->getParent() == BI->getParent())
45804585
if (FoldCondBranchOnPHI(BI, DL))
45814586
return SimplifyCFG(BB, TTI, BonusInstThreshold, AC) | true;
4587+
#endif // HLSL Change
45824588

45834589
// Scan predecessor blocks for conditional branches.
45844590
for (pred_iterator PI = pred_begin(BB), E = pred_end(BB); PI != E; ++PI)
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
// RUN: %dxc /Zi -E main -T ps_6_0 %s | FileCheck %s
2+
3+
// the FoldCondBranchOnPhi transformation in simplify cfg
4+
// often creates unstructured flow. This test makes sure
5+
// that transformation doesn't happen.
6+
7+
// CHECK: %[[cond:.+]] = phi i1
8+
// CHECK-SAME: [ false
9+
// CHECK: br i1 %[[cond]]
10+
11+
cbuffer cb : register(b0) {
12+
uint a,b,c,d,e,f,g,h,i,j,k,l,m,n;
13+
float nums[10];
14+
};
15+
16+
bool foo() {
17+
[branch]
18+
if (a) {
19+
return false;
20+
}
21+
22+
[branch]
23+
if (b & c) {
24+
25+
[branch]
26+
if (g && h) {
27+
return true;
28+
}
29+
30+
[branch]
31+
if (e && f) {
32+
return true;
33+
}
34+
return false;
35+
}
36+
37+
return true;
38+
}
39+
40+
[RootSignature("CBV(b0)")]
41+
float main(uint ia : IA) : SV_Target {
42+
float ret = 0;
43+
if (foo()) {
44+
int i = 0;
45+
[loop]
46+
do {
47+
ret += sin(nums[i]);
48+
i++;
49+
}
50+
while(i < ia);
51+
}
52+
return ret;
53+
}
54+
55+

0 commit comments

Comments
 (0)