[llvm] [ConstraintElim] Check top-level GEP flags, object size first (NFC) (PR #227270)

Florian Hahn via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 30 03:22:12 PDT 2026


================
@@ -1415,30 +1415,36 @@ static bool getConstraintFromMemoryAccess(GetElementPtrInst &GEP,
                                           CmpPredicate &Pred, Value *&A,
                                           Value *&B, const DataLayout &DL,
                                           const TargetLibraryInfo &TLI) {
-  auto Offset = collectOffsets(cast<GEPOperator>(GEP), DL);
-  if (!Offset.NW.hasNoUnsignedWrap())
+  if (!GEP.hasNoUnsignedWrap())
     return false;
 
-  if (Offset.VariableOffsets.size() != 1)
-    return false;
-
-  uint64_t BitWidth = Offset.ConstantOffset.getBitWidth();
-  auto &[Index, Scale] = Offset.VariableOffsets.front();
-  // Bail out on non-canonical GEPs.
-  if (Index->getType()->getScalarSizeInBits() != BitWidth)
-    return false;
+  Value *Base = GEP.getPointerOperand();
+  if (auto *InnerGEP = dyn_cast<GetElementPtrInst>(Base))
+    Base = InnerGEP->getPointerOperand();
 
   ObjectSizeOpts Opts;
   // Workaround for gep inbounds, ptr null, idx.
   Opts.NullIsUnknownSize = true;
   // Be conservative since we are not clear on whether an out of bounds access
   // to the padding is UB or not.
   Opts.RoundToAlign = true;
-  std::optional<TypeSize> Size =
-      getBaseObjectSize(Offset.BasePtr, DL, &TLI, Opts);
+  std::optional<TypeSize> Size = getBaseObjectSize(Base, DL, &TLI, Opts);
   if (!Size || Size->isScalable())
     return false;
 
+  auto Offset = collectOffsets(cast<GEPOperator>(GEP), DL);
+  if (Offset.BasePtr != Base || !Offset.NW.hasNoUnsignedWrap())
----------------
fhahn wrote:

I couldn't find any. It could be if `collectOffsets` would look through more than one GEP or getBaseObjectSize would look through the the pointer, but I don't think that's the case currently.

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


More information about the llvm-commits mailing list