[llvm] [AArch64] Don't merge branch conditions that both compare memory loads (PR #206504)

David Green via llvm-commits llvm-commits at lists.llvm.org
Fri Jul 3 09:02:49 PDT 2026


================
@@ -32130,6 +32130,31 @@ AArch64TargetLowering::getJumpConditionMergingParams(Instruction::BinaryOps Opc,
     return false;
   };
 
+  // Returns true if \p V is an integer comparison whose operands trace back to
+  // a memory load. Merging such a condition forces the loaded value to be held
+  // in a register up to the single merged branch (AArch64 is load-store, so it
+  // cannot fold the load into the compare the way x86 can). When the branch
+  // dominates a large region -- e.g. a Cactus/Kranc interior-point bounds guard
+  // (imin[d] < imax[d]) that dominates a 10k+ instruction stencil kernel -- the
+  // extended live ranges cascade into stack spills throughout the body. The
+  // latency-based cost model below cannot see register pressure, so carve it
+  // out.
+  auto ComparesLoadedValue = [](const Value *V) {
+    const auto *Cmp = dyn_cast<ICmpInst>(V);
+    if (!Cmp)
+      return false;
+    for (const Value *Op : {Cmp->getOperand(0), Cmp->getOperand(1)}) {
----------------
davemgreen wrote:

Remember to add this (providing it works)

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


More information about the llvm-commits mailing list