[llvm] [SeperateConstOffsetFromGEP] Update splitGEP to handle case where including base offset results in an offset that's too large (PR #177653)

Matt Arsenault via llvm-commits llvm-commits at lists.llvm.org
Wed Feb 4 09:19:55 PST 2026


================
@@ -1095,7 +1094,26 @@ bool SeparateConstOffsetFromGEP::splitGEP(GetElementPtrInst *GEP) {
             GEP->getResultElementType(),
             /*BaseGV=*/nullptr, AccumulativeByteOffset.getSExtValue(),
             /*HasBaseReg=*/true, /*Scale=*/0, AddrSpace)) {
-      return Changed;
+      // If the addressing mode was not legal and the base byte offset was not
+      // 0, it could be a case where the total offset became too large to what
+      // the addressing mode can represent. Try again without extracting the
+      // base offset.
+      if (ExtractBase) {
+        ExtractBase = false;
+        BaseByteOffset = APInt(IdxWidth, 0);
+        AccumulativeByteOffset = NonBaseByteOffset;
+        if (TTI.isLegalAddressingMode(
----------------
arsenm wrote:

This the question of "is this offset legal". It doesn't tell you this is the largest possible offset. If you knew the maximum offsets, you could split the offset into an adjusted base pointer, plus offset-sized adjustments off that 

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


More information about the llvm-commits mailing list