<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<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);">
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>
</body>
</html>