================ @@ -3087,12 +3087,22 @@ Instruction *InstCombinerImpl::visitGetElementPtrInst(GetElementPtrInst &GEP) { return nullptr; if (GEP.getNumIndices() == 1) { - // We can only preserve inbounds if the original gep is inbounds, the add - // is nsw, and the add operands are non-negative. - auto CanPreserveInBounds = [&](bool AddIsNSW, Value *Idx1, Value *Idx2) { + auto CanPreserveNoWrapFlags = [&](bool AddIsNSW, bool AddIsNUW, Value *Idx1, + Value *Idx2) { + // Preserve "inbounds nuw" if the original gep is "inbounds nuw", + // and the add is "nuw". + if (GEP.isInBounds() && GEP.hasNoUnsignedWrap() && AddIsNUW) + return GEPNoWrapFlags::inBounds() | GEPNoWrapFlags::noUnsignedWrap(); ---------------- nikic wrote:
```suggestion if (GEP.hasNoUnsignedWrap() && AddIsNUW) return GEP.getNoWrapFlags(); ``` Would this work to subsume both this case and the only nuw one below? https://github.com/llvm/llvm-project/pull/135155 _______________________________________________ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits