Hi LLVM, 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)`? - Paweł -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20150423/4f99a092/attachment.html>
On 4/23/2015 3:50 AM, Paweł Bylica wrote:> Hi LLVM, > > 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)`? > > - Paweł >You mean in cases when the builder is creating an instruction that is a no-op? The problem may be with handling cases like this: MachineInstr *MI = BuildMI(ADD, DstReg).addReg(SrcReg).addImm(0); if (C != 0) MI->getOperand(2).setImm(C); If the builder doesn't create the initial SrcReg+0, then this code will fail. -Krzysztof -- Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation
On 4/23/2015 6:57 AM, Krzysztof Parzyszek wrote:> > MachineInstr *MI = BuildMI(ADD, DstReg).addReg(SrcReg).addImm(0);Wrong builder. Please disregard. :) -K -- Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation
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
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>