[clang] [llvm] [InstCombine] Infer nusw + nneg -> nuw for getelementptr (PR #111144)
Yingwei Zheng via cfe-commits
cfe-commits at lists.llvm.org
Sat Oct 5 21:23:42 PDT 2024
================
@@ -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
More information about the cfe-commits
mailing list