================
@@ -3096,6 +3096,15 @@ Instruction 
*InstCombinerImpl::visitGetElementPtrInst(GetElementPtrInst &GEP) {
     }
   }
 
+  // nusw + nneg -> nuw
+  if (GEP.hasNoUnsignedSignedWrap() && !GEP.hasNoUnsignedWrap() &&
+      all_of(GEP.indices(), [&](Value *Idx) {
+        return isKnownNonNegative(Idx, SQ.getWithInstruction(&GEP));
+      })) {
+    GEP.setNoWrapFlags(GEP.getNoWrapFlags() | 
GEPNoWrapFlags::noUnsignedWrap());
----------------
dtcxzyw wrote:

Should drop duplicate logic in other places:
```
SelectionDAGBuilder::visitGetElementPtr
InstCombinerImpl::visitPtrToInt
llvm/lib/Transforms/Scalar/LICM.cpp:hoistGEP
SeparateConstOffsetFromGEP::reorderGEP
```


https://github.com/llvm/llvm-project/pull/111144
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to