[llvm] [VPlan] Invert condition if needed when creating inner regions. (PR #132292)
Florian Hahn via llvm-commits
llvm-commits at lists.llvm.org
Sun Apr 27 12:52:32 PDT 2025
================
@@ -386,33 +386,53 @@ std::unique_ptr<VPlan> VPlanTransforms::buildPlainCFG(
/// Checks if \p HeaderVPB is a loop header block in the plain CFG; that is, it
/// has exactly 2 predecessors (preheader and latch), where the block
/// dominates the latch and the preheader dominates the block. If it is a
-/// header block return true, making sure the preheader appears first and
-/// the latch second. Otherwise return false.
-static bool canonicalHeader(VPBlockBase *HeaderVPB,
- const VPDominatorTree &VPDT) {
+/// header block return true and canonicalize the predecessors of the header
+/// (making sure the preheader appears first and the latch second) and the
+/// successors of the latch (making sure the loop exit comes first). Otherwise
+/// return false.
+static bool canonicalHeaderAndLatch(VPBlockBase *HeaderVPB,
+ const VPDominatorTree &VPDT) {
ArrayRef<VPBlockBase *> Preds = HeaderVPB->getPredecessors();
if (Preds.size() != 2)
return false;
auto *PreheaderVPBB = Preds[0];
auto *LatchVPBB = Preds[1];
- if (VPDT.dominates(PreheaderVPBB, HeaderVPB) &&
- VPDT.dominates(HeaderVPB, LatchVPBB))
- return true;
+ if (!VPDT.dominates(PreheaderVPBB, HeaderVPB) ||
+ !VPDT.dominates(HeaderVPB, LatchVPBB)) {
+ std::swap(PreheaderVPBB, LatchVPBB);
- std::swap(PreheaderVPBB, LatchVPBB);
+ if (!VPDT.dominates(PreheaderVPBB, HeaderVPB) ||
+ !VPDT.dominates(HeaderVPB, LatchVPBB)) {
+ return false;
+ } else {
----------------
fhahn wrote:
done thanks
https://github.com/llvm/llvm-project/pull/132292
More information about the llvm-commits
mailing list