[llvm] [ConstraintElim] Use constraints from bounded memory accesses (PR #155253)

Yingwei Zheng via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 26 09:12:32 PDT 2025


================
@@ -1960,6 +2030,26 @@ static bool eliminateConstraints(Function &F, DominatorTree &DT, LoopInfo &LI,
         }
         continue;
       }
+
+      auto &DL = F.getDataLayout();
+      auto AddFactsAboutIndices = [&](Value *Ptr, Type *AccessType) {
+        CmpPredicate Pred;
+        Value *A, *B;
+        if (getConstraintFromMemoryAccess(
+                *cast<GetElementPtrInst>(Ptr),
+                DL.getTypeStoreSize(AccessType).getFixedValue(), Pred, A, B, DL,
+                TLI))
+          AddFact(Pred, A, B);
+      };
+
+      if (auto *LI = dyn_cast<LoadInst>(CB.Inst)) {
+        AddFactsAboutIndices(LI->getPointerOperand(), LI->getAccessType());
+        continue;
+      }
+      if (auto *SI = dyn_cast<StoreInst>(CB.Inst)) {
+        AddFactsAboutIndices(SI->getPointerOperand(), SI->getAccessType());
+        continue;
+      }
----------------
dtcxzyw wrote:

Condition facts also apply to instructions before the memory access. To use condition facts, we should guarantee that the load/store will execute when the BB is entered. See https://github.com/llvm/llvm-project/blob/fbd2f479474a5d071f234e9349f9543c235c0d25/llvm/lib/Transforms/Scalar/ConstraintElimination.cpp#L1805-L1836

InstFact only: https://github.com/dtcxzyw/llvm-opt-benchmark/pull/2708
InstFact + CondFact (https://github.com/llvm/llvm-project/commit/ab1cde986fe8537499fe8b6fe5b71fa2a87110c3): https://github.com/dtcxzyw/llvm-opt-benchmark/pull/2709

https://llvm-compile-time-tracker.com/compare.php?from=a98537f1678fd87fc1b1f7972498144ec79360fd&to=ab1cde986fe8537499fe8b6fe5b71fa2a87110c3&stat=instructions%3Au


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


More information about the llvm-commits mailing list