[LLVMdev] IRBuilder and "ad hoc" optimizations

Paweł Bylica chfast at gmail.com
Thu Apr 23 05:30:40 PDT 2015


On Thu, Apr 23, 2015 at 2:14 PM David Chisnall <David.Chisnall at cl.cam.ac.uk>
wrote:

> 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.
>
> 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.
>

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.

Profiling is likely to be needed to determine whether it’s a real win.
>
> David
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20150423/08784e25/attachment.html>


More information about the llvm-dev mailing list