> <span style="color:rgb(31,73,125);font-family:Calibri,sans-serif;font-size:15px;background-color:rgb(255,255,255)">After thinking about this more, I’m not sure if this is applicable to SPIR itself. For you to have a constant GEP expression, you have to know the pointer size in order to correctly generate the expression. Since the pointer size itself is not known, I don’t yet see how you can generate a constant expression that is valid SPIR.</span><div>
<font color="#1f497d" face="Calibri, sans-serif"><span style="font-size:15px"><br></span></font></div><div><font color="#1f497d" face="Calibri, sans-serif"><span style="font-size:15px">GEP is defined relative to (indepenently of) pointer size.<br>
</span></font><br><div class="gmail_quote">On 1 October 2012 17:36, Villmow, Micah <span dir="ltr"><<a href="mailto:Micah.Villmow@amd.com" target="_blank">Micah.Villmow@amd.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">






<div lang="EN-US" link="blue" vlink="purple">
<div>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d">Maybe it would be easier to provide a bitcode example of this problem.<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d">After thinking about this more, I’m not sure if this is applicable to SPIR itself. For you to have a constant GEP expression, you have to know the pointer size
 in order to correctly generate the expression. Since the pointer size itself is not known, I don’t yet see how you can generate a constant expression that is valid SPIR.<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d">Micah<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"><u></u> <u></u></span></p>
<div style="border:none;border-left:solid blue 1.5pt;padding:0in 0in 0in 4.0pt">
<div>
<div style="border:none;border-top:solid #b5c4df 1.0pt;padding:3.0pt 0in 0in 0in">
<p class="MsoNormal"><b><span style="font-size:10.0pt;font-family:"Tahoma","sans-serif"">From:</span></b><span style="font-size:10.0pt;font-family:"Tahoma","sans-serif""> <a href="mailto:mankeyrabbit@gmail.com" target="_blank">mankeyrabbit@gmail.com</a> [mailto:<a href="mailto:mankeyrabbit@gmail.com" target="_blank">mankeyrabbit@gmail.com</a>]
<b>On Behalf Of </b>James Molloy<br>
<b>Sent:</b> Saturday, September 29, 2012 5:30 AM<br>
<b>To:</b> Owen Anderson<br>
<b>Cc:</b> Villmow, Micah; <a href="mailto:llvmdev@cs.uiuc.edu" target="_blank">llvmdev@cs.uiuc.edu</a>; <a href="mailto:pocl-devel@lists.sourceforge.net" target="_blank">pocl-devel@lists.sourceforge.net</a>; <a href="mailto:cfe-dev@cs.uiuc.edu" target="_blank">cfe-dev@cs.uiuc.edu</a><br>

<b>Subject:</b> Re: [LLVMdev] [pocl-devel] [cfe-dev] SPIR provisional specification is now available in the Khronos website<u></u><u></u></span></p>
</div>
</div><div><div class="h5">
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">Yes, it would.<u></u><u></u></p>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">But I was concerned Micah was just going to write it off as an implementation detail, so I felt that I should offer a "less correct but less work" option for him to consider.<u></u><u></u></p>

</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">Cheers,<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-bottom:12.0pt">James<u></u><u></u></p>
<div>
<p class="MsoNormal">On 29 September 2012 03:16, Owen Anderson <<a href="mailto:resistor@mac.com" target="_blank">resistor@mac.com</a>> wrote:<u></u><u></u></p>
<div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
<div>
<div>
<p class="MsoNormal">On Sep 28, 2012, at 9:45 AM, James Molloy <<a href="mailto:james@jamesmolloy.co.uk" target="_blank">james@jamesmolloy.co.uk</a>> wrote:<u></u><u></u></p>
</div>
<p class="MsoNormal"><br>
<br>
<u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:13.5pt;font-family:"Helvetica","sans-serif"">You can easily simplify this problem with a restriction in SPIR: disallow ConstantExpr casts - no ptrtoint constant expression. Because GlobalVariables have pointer type,
 if you disallow converting their type to non-pointer type in a constantexpr, the number of constantexpr subclasses you have to deal with is drastically reduced (to essentially just BitCast and GEP).</span><u></u><u></u></p>

</div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">Wouldn't an easier solution just be not to represent them as constants in the first place?  For instance, you could have a built-in function to get the address of local N, where N is taken as a parameter.  You can call the builtins at the
 beginning of the kernel, and then proceed to use them as you wish without having to worry about reversing a constant folding later.  Plus, if a given vendor's backend
<i>wants</i> the address to get constant folded, it's easy to do replaceAllUsesWith of the call with a global, and run an appropriate constant folding pass.<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><span style="color:#888888"><u></u> <u></u></span></p>
</div>
<div>
<p class="MsoNormal"><span style="color:#888888">--Owen<u></u><u></u></span></p>
</div>
</div>
</div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
</div></div></div>
</div>
</div>

</blockquote></div><br></div>