[llvm] [SeparateConstOffsetFromGEP] Preserve inbounds flag based on ValueTracking (PR #130617)
Fabian Ritter via llvm-commits
llvm-commits at lists.llvm.org
Thu Mar 27 02:08:43 PDT 2025
================
@@ -1100,11 +1104,15 @@ bool SeparateConstOffsetFromGEP::splitGEP(GetElementPtrInst *GEP) {
// address with silently-wrapping two's complement arithmetic".
// Therefore, the final code will be a semantically equivalent.
//
- // TODO(jingyue): do some range analysis to keep as many inbounds as
- // possible. GEPs with inbounds are more friendly to alias analysis.
- // TODO(gep_nowrap): Preserve nuw at least.
- GEPNoWrapFlags NewGEPFlags = GEPNoWrapFlags::none();
- GEP->setNoWrapFlags(GEPNoWrapFlags::none());
+ // If the initial GEP was inbounds and all variable indices and the
+ // accumulated offsets are non-negative, they can be added in any order and
+ // the intermediate results are in bounds. So, we can preserve the inbounds
+ // flag for both GEPs. GEPs with inbounds are more friendly to alias analysis.
+ //
+ // TODO(gep_nowrap): Preserve nuw?
----------------
ritter-x2a wrote:
The most recent commit preserves more flags based on nuw. All test cases in the updated preserve-inbounds.ll were validated by alive2 (no timeouts or memouts were hit, with `-tv-smt-to=1500000 -tv-smt-max-mem=80000 --tv-disable-undef-input`).
https://github.com/llvm/llvm-project/pull/130617
More information about the llvm-commits
mailing list