[llvm] 92bf8f3 - [NFC][SimplifyCFG] `shouldFoldCondBranchesToCommonDestination()`: report the common succ
Roman Lebedev via llvm-commits
llvm-commits at lists.llvm.org
Sun Dec 4 09:59:07 PST 2022
Author: Roman Lebedev
Date: 2022-12-04T20:58:54+03:00
New Revision: 92bf8f3f79639f37724b0f68a3c21d8bb3c9a972
URL: https://github.com/llvm/llvm-project/commit/92bf8f3f79639f37724b0f68a3c21d8bb3c9a972
DIFF: https://github.com/llvm/llvm-project/commit/92bf8f3f79639f37724b0f68a3c21d8bb3c9a972.diff
LOG: [NFC][SimplifyCFG] `shouldFoldCondBranchesToCommonDestination()`: report the common succ
Added:
Modified:
llvm/lib/Transforms/Utils/SimplifyCFG.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
index 6cdd18fe9041..a1bc89e7d809 100644
--- a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
+++ b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
@@ -3521,7 +3521,7 @@ static bool extractPredSuccWeights(BranchInst *PBI, BranchInst *BI,
/// Determine if the two branches share a common destination and deduce a glue
/// that joins the branches' conditions to arrive at the common destination if
/// that would be profitable.
-static std::optional<std::pair<Instruction::BinaryOps, bool>>
+static std::optional<std::tuple<BasicBlock *, Instruction::BinaryOps, bool>>
shouldFoldCondBranchesToCommonDestination(BranchInst *BI, BranchInst *PBI,
const TargetTransformInfo *TTI) {
assert(BI && PBI && BI->isConditional() && PBI->isConditional() &&
@@ -3544,19 +3544,19 @@ shouldFoldCondBranchesToCommonDestination(BranchInst *BI, BranchInst *PBI,
if (PBI->getSuccessor(0) == BI->getSuccessor(0)) {
// Speculate the 2nd condition unless the 1st is probably true.
if (PBITrueProb.isUnknown() || PBITrueProb < Likely)
- return {{Instruction::Or, false}};
+ return {{BI->getSuccessor(0), Instruction::Or, false}};
} else if (PBI->getSuccessor(1) == BI->getSuccessor(1)) {
// Speculate the 2nd condition unless the 1st is probably false.
if (PBITrueProb.isUnknown() || PBITrueProb.getCompl() < Likely)
- return {{Instruction::And, false}};
+ return {{BI->getSuccessor(1), Instruction::And, false}};
} else if (PBI->getSuccessor(0) == BI->getSuccessor(1)) {
// Speculate the 2nd condition unless the 1st is probably true.
if (PBITrueProb.isUnknown() || PBITrueProb < Likely)
- return {{Instruction::And, true}};
+ return {{BI->getSuccessor(1), Instruction::And, true}};
} else if (PBI->getSuccessor(1) == BI->getSuccessor(0)) {
// Speculate the 2nd condition unless the 1st is probably false.
if (PBITrueProb.isUnknown() || PBITrueProb.getCompl() < Likely)
- return {{Instruction::Or, true}};
+ return {{BI->getSuccessor(0), Instruction::Or, true}};
}
return std::nullopt;
}
@@ -3569,9 +3569,10 @@ static bool performBranchToCommonDestFolding(BranchInst *BI, BranchInst *PBI,
BasicBlock *PredBlock = PBI->getParent();
// Determine if the two branches share a common destination.
+ BasicBlock *CommonSucc;
Instruction::BinaryOps Opc;
bool InvertPredCond;
- std::tie(Opc, InvertPredCond) =
+ std::tie(CommonSucc, Opc, InvertPredCond) =
*shouldFoldCondBranchesToCommonDestination(BI, PBI, TTI);
LLVM_DEBUG(dbgs() << "FOLDING BRANCH TO COMMON DEST:\n" << *PBI << *BB);
@@ -3730,10 +3731,11 @@ bool llvm::FoldBranchToCommonDest(BranchInst *BI, DomTreeUpdater *DTU,
continue;
// Determine if the two branches share a common destination.
+ BasicBlock *CommonSucc;
Instruction::BinaryOps Opc;
bool InvertPredCond;
if (auto Recipe = shouldFoldCondBranchesToCommonDestination(BI, PBI, TTI))
- std::tie(Opc, InvertPredCond) = *Recipe;
+ std::tie(CommonSucc, Opc, InvertPredCond) = *Recipe;
else
continue;
More information about the llvm-commits
mailing list