aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
diff options
context:
space:
mode:
authorJan Patrick Lehr <JanPatrick.Lehr@amd.com>2024-07-29 11:34:26 +0200
committerGitHub <noreply@github.com>2024-07-29 11:34:26 +0200
commita347bdb2b828272359e49a8ce9de9d6412950838 (patch)
tree005f6b86a7258086797786de38b9bda969e62341 /llvm/lib/Transforms/Utils/SimplifyCFG.cpp
parent03e17da510963ce6b7a1d0ab4d67f753a6cc7495 (diff)
downloadllvm-a347bdb2b828272359e49a8ce9de9d6412950838.zip
llvm-a347bdb2b828272359e49a8ce9de9d6412950838.tar.gz
llvm-a347bdb2b828272359e49a8ce9de9d6412950838.tar.bz2
Revert "[SimplifyCFG] Skip threading if the target may have divergent branches" (#100994)
Reverts llvm/llvm-project#100185 See comments on PR (PR not accepted, outstanding review comments, breaks HIP-clang buildbot)
Diffstat (limited to 'llvm/lib/Transforms/Utils/SimplifyCFG.cpp')
-rw-r--r--llvm/lib/Transforms/Utils/SimplifyCFG.cpp27
1 files changed, 12 insertions, 15 deletions
diff --git a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
index 1a17524..f23e288 100644
--- a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
+++ b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
@@ -3246,12 +3246,7 @@ bool SimplifyCFGOpt::SpeculativelyExecuteBB(BranchInst *BI,
}
/// Return true if we can thread a branch across this block.
-static bool BlockIsSimpleEnoughToThreadThrough(BasicBlock *BB,
- const TargetTransformInfo &TTI) {
- // Skip threading if the branch may be divergent.
- if (TTI.hasBranchDivergence(BB->getParent()))
- return false;
-
+static bool BlockIsSimpleEnoughToThreadThrough(BasicBlock *BB) {
int Size = 0;
EphemeralValueTracker EphTracker;
@@ -3306,9 +3301,10 @@ static ConstantInt *getKnownValueOnEdge(Value *V, BasicBlock *From,
/// If we have a conditional branch on something for which we know the constant
/// value in predecessors (e.g. a phi node in the current block), thread edges
/// from the predecessor to their ultimate destination.
-static std::optional<bool> FoldCondBranchOnValueKnownInPredecessorImpl(
- BranchInst *BI, DomTreeUpdater *DTU, const DataLayout &DL,
- const TargetTransformInfo &TTI, AssumptionCache *AC) {
+static std::optional<bool>
+FoldCondBranchOnValueKnownInPredecessorImpl(BranchInst *BI, DomTreeUpdater *DTU,
+ const DataLayout &DL,
+ AssumptionCache *AC) {
SmallMapVector<ConstantInt *, SmallSetVector<BasicBlock *, 2>, 2> KnownValues;
BasicBlock *BB = BI->getParent();
Value *Cond = BI->getCondition();
@@ -3336,7 +3332,7 @@ static std::optional<bool> FoldCondBranchOnValueKnownInPredecessorImpl(
// Now we know that this block has multiple preds and two succs.
// Check that the block is small enough and values defined in the block are
// not used outside of it.
- if (!BlockIsSimpleEnoughToThreadThrough(BB, TTI))
+ if (!BlockIsSimpleEnoughToThreadThrough(BB))
return false;
for (const auto &Pair : KnownValues) {
@@ -3463,14 +3459,15 @@ static std::optional<bool> FoldCondBranchOnValueKnownInPredecessorImpl(
return false;
}
-static bool FoldCondBranchOnValueKnownInPredecessor(
- BranchInst *BI, DomTreeUpdater *DTU, const DataLayout &DL,
- const TargetTransformInfo &TTI, AssumptionCache *AC) {
+static bool FoldCondBranchOnValueKnownInPredecessor(BranchInst *BI,
+ DomTreeUpdater *DTU,
+ const DataLayout &DL,
+ AssumptionCache *AC) {
std::optional<bool> Result;
bool EverChanged = false;
do {
// Note that None means "we changed things, but recurse further."
- Result = FoldCondBranchOnValueKnownInPredecessorImpl(BI, DTU, DL, TTI, AC);
+ Result = FoldCondBranchOnValueKnownInPredecessorImpl(BI, DTU, DL, AC);
EverChanged |= Result == std::nullopt || *Result;
} while (Result == std::nullopt);
return EverChanged;
@@ -7546,7 +7543,7 @@ bool SimplifyCFGOpt::simplifyCondBranch(BranchInst *BI, IRBuilder<> &Builder) {
// If this is a branch on something for which we know the constant value in
// predecessors (e.g. a phi node in the current block), thread control
// through this block.
- if (FoldCondBranchOnValueKnownInPredecessor(BI, DTU, DL, TTI, Options.AC))
+ if (FoldCondBranchOnValueKnownInPredecessor(BI, DTU, DL, Options.AC))
return requestResimplify();
// Scan predecessor blocks for conditional branches.