Skip to content

Commit 1518865

Browse files
authored
Revert "[SimplifyCFG] Avoid threading for loop headers (#151142)"
This reverts commit ea2f539.
1 parent 101ad14 commit 1518865

File tree

7 files changed

+14
-80
lines changed

7 files changed

+14
-80
lines changed

llvm/lib/Transforms/Utils/SimplifyCFG.cpp

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,6 @@ class SimplifyCFGOpt {
291291
bool simplifyBranch(BranchInst *Branch, IRBuilder<> &Builder);
292292
bool simplifyUncondBranch(BranchInst *BI, IRBuilder<> &Builder);
293293
bool simplifyCondBranch(BranchInst *BI, IRBuilder<> &Builder);
294-
bool foldCondBranchOnValueKnownInPredecessor(BranchInst *BI);
295294

296295
bool tryToSimplifyUncondBranchWithICmpInIt(ICmpInst *ICI,
297296
IRBuilder<> &Builder);
@@ -3690,19 +3689,15 @@ foldCondBranchOnValueKnownInPredecessorImpl(BranchInst *BI, DomTreeUpdater *DTU,
36903689
return false;
36913690
}
36923691

3693-
bool SimplifyCFGOpt::foldCondBranchOnValueKnownInPredecessor(BranchInst *BI) {
3694-
// Note: If BB is a loop header then there is a risk that threading introduces
3695-
// a non-canonical loop by moving a back edge. So we avoid this optimization
3696-
// for loop headers if NeedCanonicalLoop is set.
3697-
if (Options.NeedCanonicalLoop && is_contained(LoopHeaders, BI->getParent()))
3698-
return false;
3699-
3692+
static bool foldCondBranchOnValueKnownInPredecessor(BranchInst *BI,
3693+
DomTreeUpdater *DTU,
3694+
const DataLayout &DL,
3695+
AssumptionCache *AC) {
37003696
std::optional<bool> Result;
37013697
bool EverChanged = false;
37023698
do {
37033699
// Note that None means "we changed things, but recurse further."
3704-
Result =
3705-
foldCondBranchOnValueKnownInPredecessorImpl(BI, DTU, DL, Options.AC);
3700+
Result = foldCondBranchOnValueKnownInPredecessorImpl(BI, DTU, DL, AC);
37063701
EverChanged |= Result == std::nullopt || *Result;
37073702
} while (Result == std::nullopt);
37083703
return EverChanged;
@@ -8123,7 +8118,7 @@ bool SimplifyCFGOpt::simplifyCondBranch(BranchInst *BI, IRBuilder<> &Builder) {
81238118
// If this is a branch on something for which we know the constant value in
81248119
// predecessors (e.g. a phi node in the current block), thread control
81258120
// through this block.
8126-
if (foldCondBranchOnValueKnownInPredecessor(BI))
8121+
if (foldCondBranchOnValueKnownInPredecessor(BI, DTU, DL, Options.AC))
81278122
return requestResimplify();
81288123

81298124
// Scan predecessor blocks for conditional branches.

llvm/test/CodeGen/ARM/2013-05-05-IfConvertBug.ll

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2-
; RUN: llc -keep-loops="false" < %s -mtriple=thumbv7-apple-ios -mcpu=cortex-a8 | FileCheck %s
3-
; RUN: llc -keep-loops="false" < %s -mtriple=thumbv8 | FileCheck -check-prefix=CHECK-V8 %s
4-
; RUN: llc -keep-loops="false" < %s -mtriple=thumbv7 -arm-restrict-it | FileCheck -check-prefix=CHECK-RESTRICT-IT %s
2+
; RUN: llc < %s -mtriple=thumbv7-apple-ios -mcpu=cortex-a8 | FileCheck %s
3+
; RUN: llc < %s -mtriple=thumbv8 | FileCheck -check-prefix=CHECK-V8 %s
4+
; RUN: llc < %s -mtriple=thumbv7 -arm-restrict-it | FileCheck -check-prefix=CHECK-RESTRICT-IT %s
55

66
define i32 @t1(i32 %a, i32 %b, ptr %retaddr) {
77
; CHECK-LABEL: t1:

llvm/test/Transforms/SimplifyCFG/2008-07-13-InfLoopMiscompile.ll

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2-
; RUN: opt < %s -passes=simplifycfg -simplifycfg-require-and-preserve-domtree=1 -keep-loops="false" -S | FileCheck %s
2+
; RUN: opt < %s -passes=simplifycfg -simplifycfg-require-and-preserve-domtree=1 -S | FileCheck %s
33
; PR2540
44
; Outval should end up with a select from 0/2, not all constants.
55

@@ -52,3 +52,4 @@ func_1.exit: ; preds = %cowblock, %entry
5252
}
5353

5454
declare i32 @printf(ptr, ...) nounwind
55+

llvm/test/Transforms/SimplifyCFG/2025-07-29-non-canoncial-loop.ll

Lines changed: 0 additions & 62 deletions
This file was deleted.

llvm/test/Transforms/SimplifyCFG/branch-phi-thread.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2-
; RUN: opt < %s -passes=simplifycfg,adce -simplifycfg-require-and-preserve-domtree=1 -keep-loops="false" -S | FileCheck %s
2+
; RUN: opt < %s -passes=simplifycfg,adce -simplifycfg-require-and-preserve-domtree=1 -S | FileCheck %s
33

44
declare void @f1()
55

llvm/test/Transforms/SimplifyCFG/jump-threading.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2-
; RUN: opt -S -passes=simplifycfg -keep-loops="false" < %s | FileCheck %s
2+
; RUN: opt -S -passes=simplifycfg < %s | FileCheck %s
33

44
declare void @foo()
55
declare void @bar()

llvm/test/Transforms/SimplifyCFG/two-entry-phi-return.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2-
; RUN: opt < %s -passes=simplifycfg -simplifycfg-require-and-preserve-domtree=1 -keep-loops="false" -S | FileCheck %s
2+
; RUN: opt < %s -passes=simplifycfg -simplifycfg-require-and-preserve-domtree=1 -S | FileCheck %s
33

44
define i1 @qux(ptr %m, ptr %n, ptr %o, ptr %p) nounwind {
55
; CHECK-LABEL: @qux(

0 commit comments

Comments
 (0)