[llvm] Handle GEPs with negative offset and 'nuw' attribute (PR #117147)
via llvm-commits
llvm-commits at lists.llvm.org
Fri Nov 22 02:32:00 PST 2024
pkarveti wrote:
@nikic Consider a program where b is of type unsigned char* and i is an unsigned int. The program contains a for loop iterating from 0 to 4, and within the loop, we access b[2 - i]. Because both i and b are unsigned indices, the nuw (no unsigned wrap) attribute is added. The corresponding LLVM IR is:
**%sub = sub nsw i32 2, %i.11765, !dbg !570
%arrayidx418 = getelementptr inbounds nuw i8, ptr %b.0, i32 %sub**
After the loop is fully unrolled, when i becomes 3, the value accessed is -1, which corresponds to accessing b[-1]. The LLVM IR for this is:
**%arrayidx418.3 = getelementptr inbounds nuw i8, ptr %b.0, i32 -1**
Here, the offset is negative, yet the GEP (getelementptr) instruction still has the nuw attribute. I am trying to solve this problem**.
https://github.com/llvm/llvm-project/pull/117147
More information about the llvm-commits
mailing list