<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<style type="text/css" style="display:none;"> P {margin-top:0;margin-bottom:0;} </style>
</head>
<body dir="ltr">
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
I don't think you can safely assume an address or range for a global at compile-time and make decisions based on this. It's the linker's job to calculate an address for this, and the final physical address is another thing that depends on your platform, e.g
 a hosted environment, or a an embedded system with all sorts of different memories where you can place data. But I am always a bit out of my comfort zone with linkers, so others my have a better answer.</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
Cheers.<br>
</div>
<div id="appendonsend"></div>
<hr style="display:inline-block;width:98%" tabindex="-1">
<div id="divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" style="font-size:11pt" color="#000000"><b>From:</b> llvm-dev <llvm-dev-bounces@lists.llvm.org> on behalf of Sam Kvasov via llvm-dev <llvm-dev@lists.llvm.org><br>
<b>Sent:</b> 24 April 2020 01:17<br>
<b>To:</b> llvm-dev@lists.llvm.org <llvm-dev@lists.llvm.org><br>
<b>Subject:</b> [llvm-dev] Pointer comparison folding</font>
<div> </div>
</div>
<style type="text/css" style="display:none">
<!--
p
        {margin-top:0;
        margin-bottom:0}
-->
</style>
<div dir="ltr">
<div style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
Hi,</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<br>
</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
I am looking at some code that does address comparisons to check whether a given pointer is within a certain memory range. For example:</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<br>
</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
if (0xff00 <= &a[x] && &a[x] < 0xffff)</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<br>
</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
This results in IR like:</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<span></span><span>  %2 = getelementptr inbounds [100 x i32], [100 x i32]* @a, i32 0, i32 %0, !dbg !9<br>
</span>
<div>  %3 = icmp uge i32* %2, inttoptr (i32 65280 to i32*), !dbg !10<br>
</div>
<div>  %4 = icmp ult i32* %2, inttoptr (i32 65535 to i32*), !dbg !11<br>
</div>
<span></span>
<div><br>
</div>
<div>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?</div>
<div><br>
</div>
<div>Regards,</div>
<div><br>
Sam</div>
<span></span><br>
</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<br>
</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<br>
</div>
</div>
</body>
</html>