[llvm] Skip if then else diamonds (PR #82135)

via llvm-commits llvm-commits at lists.llvm.org
Sat Feb 17 15:05:13 PST 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-backend-aarch64

Author: AtariDreams (AtariDreams)

<details>
<summary>Changes</summary>



---
Full diff: https://github.com/llvm/llvm-project/pull/82135.diff


1 Files Affected:

- (modified) llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp (+26-2) 


``````````diff
diff --git a/llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp b/llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp
index 6655931181c2d5..e1c266247a37d4 100644
--- a/llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp
+++ b/llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp
@@ -3317,6 +3317,29 @@ unsigned AArch64TTIImpl::getMaxInterleaveFactor(ElementCount VF) {
   return ST->getMaxInterleaveFactor();
 }
 
+static bool isPartOfIfThenElseDiamond(const BasicBlock *BB) {
+  if (!BB)
+    return false;
+  auto *BI = dyn_cast<BranchInst>(BB->getTerminator());
+  if (!BI || !BI->isConditional())
+    return false;
+
+  BasicBlock *Succ0 = BI->getSuccessor(0);
+  BasicBlock *Succ1 = BI->getSuccessor(1);
+
+  if (!Succ0->getSinglePredecessor())
+    return false;
+  if (!Succ1->getSinglePredecessor())
+    return false;
+
+  BasicBlock *Succ0Succ = Succ0->getSingleSuccessor();
+  BasicBlock *Succ1Succ = Succ1->getSingleSuccessor();
+  // Ignore triangles.
+  if (!Succ0Succ || !Succ1Succ || Succ0Succ != Succ1Succ)
+    return false;
+  return true;
+}
+
 // For Falkor, we want to avoid having too many strided loads in a loop since
 // that can exhaust the HW prefetcher resources.  We adjust the unroller
 // MaxCount preference below to attempt to ensure unrolling doesn't create too
@@ -3327,9 +3350,10 @@ getFalkorUnrollingPreferences(Loop *L, ScalarEvolution &SE,
   enum { MaxStridedLoads = 7 };
   auto countStridedLoads = [](Loop *L, ScalarEvolution &SE) {
     int StridedLoads = 0;
-    // FIXME? We could make this more precise by looking at the CFG and
-    // e.g. not counting loads in each side of an if-then-else diamond.
     for (const auto BB : L->blocks()) {
+      // Skip blocks that are part of an if-then-else diamond
+      if (isPartOfIfThenElseDiamond(BB))
+        continue;
       for (auto &I : *BB) {
         LoadInst *LMemI = dyn_cast<LoadInst>(&I);
         if (!LMemI)

``````````

</details>


https://github.com/llvm/llvm-project/pull/82135


More information about the llvm-commits mailing list