[LLVMdev] IRBuilder and "ad hoc" optimizations

David Chisnall David.Chisnall at cl.cam.ac.uk
Thu Apr 23 05:14:50 PDT 2015


On 23 Apr 2015, at 09:50, Paweł Bylica <chfast at gmail.com> wrote:
> 
> IRBuilder can fold constants (that behaviour can be controlled by Folder type). What do you think about optionally allow IRBuilder to eliminate no-op instructions like `add %a, 0` or `memcpy(%a, %b, 0)`?

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.

Profiling is likely to be needed to determine whether it’s a real win.

David





More information about the llvm-dev mailing list