[llvm-dev] Pointer comparison folding
Sam Kvasov via llvm-dev
llvm-dev at lists.llvm.org
Thu Apr 23 17:17:27 PDT 2020
Hi,
I am looking at some code that does address comparisons to check whether a given pointer is within a certain memory range. For example:
if (0xff00 <= &a[x] && &a[x] < 0xffff)
This results in IR like:
%2 = getelementptr inbounds [100 x i32], [100 x i32]* @a, i32 0, i32 %0, !dbg !9
%3 = icmp uge i32* %2, inttoptr (i32 65280 to i32*), !dbg !10
%4 = icmp ult i32* %2, inttoptr (i32 65535 to i32*), !dbg !11
Suppose that 'a' is a global and we know the range of addresses where it can be allocated. Is it a safe transformation to use that range and constant fold the icmps? Is so, is it still safe if the gep offset 'x' is unknown?
Regards,
Sam
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20200424/1aeacb6f/attachment-0001.html>
More information about the llvm-dev
mailing list