<div dir="ltr">On Thu, Apr 23, 2015 at 2:14 PM David Chisnall <<a href="mailto:David.Chisnall@cl.cam.ac.uk">David.Chisnall@cl.cam.ac.uk</a>> wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
The constant folding in IRBuilder is always a trade between the cost of checking for the special cases vs the cost of creating instructions that are later going to be deleted.  I’d imagine that add of 0 is something that is sufficiently rare that the cost (in terms of both run time and code size, as IRBuilder’s CreateAdd is often inlined) would be more than the cost of very rarely creating these instructions and having a later pass delete them.<br>
<br>
That said, the Folder is a template parameter.  For some front ends (particularly those used with source-to-source transforms), it might be significantly more common to have nop expressions and having an AggressiveFolder or similar might be beneficial.<br></blockquote><div><br></div><div>Replacing default Folder with some other will not allow you to remove "no-op" instructions. Folder is triggered only if both operands are constant, what is not the case i.e. in `add %a, 0`. To allow that "optimization" IRBuilder redesign is needed.<br></div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Profiling is likely to be needed to determine whether it’s a real win.<br>
<br>
David
<br>
</blockquote></div></div>