[llvm] [CodeGenPrepare] Drop nuw on gep unmerging if the new index is negative (PR #193488)

Antonio Frighetto via llvm-commits llvm-commits at lists.llvm.org
Wed Apr 22 09:28:10 PDT 2026


================
@@ -8801,10 +8801,13 @@ static bool tryUnmergingGEPsAcrossIndirectBr(GetElementPtrInst *GEPI,
   }
   if (UGEPIs.size() == 0)
     return false;
-  // Check the materializing cost of (Uidx-Idx).
+  // Check materializing cost of (Uidx-Idx) and drop nuw flag if necessary.
   for (GetElementPtrInst *UGEPI : UGEPIs) {
     ConstantInt *UGEPIIdx = cast<ConstantInt>(UGEPI->getOperand(1));
     APInt NewIdx = UGEPIIdx->getValue() - GEPIIdx->getValue();
+    if (NewIdx.isNegative() && UGEPI->hasNoUnsignedWrap())
+      UGEPI->setNoWrapFlags(GEPNoWrapFlags::none());
----------------
antoniofrighetto wrote:

Ugh, right, better always to check the LangRef.

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


More information about the llvm-commits mailing list