[clang] [clang] Emit nuw GEPs for array subscript expressions (PR #103088)
Hari Limaye via cfe-commits
cfe-commits at lists.llvm.org
Wed Aug 21 14:55:31 PDT 2024
hazzlim wrote:
> > adding nuw is also valid for signed indices here
>
> I don't understand how you think this would work; a-1 and a+-1 are required to produce the same result.
The thinking here RE signed indices was that in this special case, where the base address of the GEP is the start of an array, the index cannot be negative without violating the `inbounds` attribute (alternatively the requirement of a pointer arithmetic expression to evaluate to an element of the array or one past the end, in C/C++ standard terms). Therefore we could prove `nuw` via `inbounds` + `nneg`.
I wonder if others agree that this is valid or can see an issue with this?
https://github.com/llvm/llvm-project/pull/103088
More information about the cfe-commits
mailing list