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

Yingwei Zheng via llvm-commits llvm-commits at lists.llvm.org
Sat Aug 30 09:02:13 PDT 2025


================
@@ -1109,10 +1113,43 @@ void State::addInfoForInductions(BasicBlock &BB) {
   }
 }
 
+static bool getConstraintFromMemoryAccess(GetElementPtrInst &GEP,
+                                          uint64_t AccessSize,
+                                          CmpPredicate &Pred, Value *&A,
+                                          Value *&B, const DataLayout &DL,
+                                          const TargetLibraryInfo &TLI) {
+  auto Offset = collectOffsets(cast<GEPOperator>(GEP), DL);
+  if (!Offset.NW.isInBounds())
+    return false;
+
+  if (Offset.VariableOffsets.size() != 1)
+    return false;
+
+  ObjectSizeOpts Opts;
+  // Workaround for gep inbounds, ptr null, idx.
+  Opts.NullIsUnknownSize = true;
+  ObjectSizeOffsetVisitor Visitor(DL, &TLI, GEP.getContext(), Opts);
+  SizeOffsetAPInt Data = Visitor.compute(Offset.BasePtr);
+  if (!Data.bothKnown() || !Data.Offset.isZero())
+    return false;
----------------
dtcxzyw wrote:

I can switch to use `getBaseObjectSize` after https://github.com/llvm/llvm-project/pull/155911 lands.

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


More information about the llvm-commits mailing list