Mikael Holmén
2014-Aug-15 09:18 UTC
[LLVMdev] Physical register definition removed by MachineCSE
Hi, My target has a special configuration register that many instructions read implicitly, configuring for example if an add instruction should saturate at over/underflow or not. Now, I have a problem where the MachineCSE removes a setting of this configuration register in a basic block, because MachineCSE::isPhysDefTriviallyDead can't find any uses of it in the basic block where it's defined. Similar to other special physical registers, e.g the stack pointer, this configuration register is marked as "reserved". Is there anything else I need to do for the MachineCSE to leave this register and not remove it just because it can't find any uses in the current basic block? Best regards, Mikael Holmén
Tom Stellard
2014-Aug-15 14:15 UTC
[LLVMdev] Physical register definition removed by MachineCSE
On Fri, Aug 15, 2014 at 11:18:51AM +0200, Mikael Holmén wrote:> Hi, > > My target has a special configuration register that many > instructions read implicitly, configuring for example if an add > instruction should saturate at over/underflow or not. >> Now, I have a problem where the MachineCSE removes a setting of this > configuration register in a basic block, because > MachineCSE::isPhysDefTriviallyDead can't find any uses of it in the > basic block where it's defined. > > Similar to other special physical registers, e.g the stack pointer, > this configuration register is marked as "reserved". > > Is there anything else I need to do for the MachineCSE to leave this > register and not remove it just because it can't find any uses in > the current basic block?Have you added this register as an implicit use to the instructions like add whose behavior depends on its value? -Tom> > Best regards, > Mikael Holmén > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
Mikael Holmén
2014-Aug-18 07:07 UTC
[LLVMdev] Physical register definition removed by MachineCSE
Hi, On 08/15/14 16:15, Tom Stellard wrote:> On Fri, Aug 15, 2014 at 11:18:51AM +0200, Mikael Holmén wrote: >> Hi, >> >> My target has a special configuration register that many >> instructions read implicitly, configuring for example if an add >> instruction should saturate at over/underflow or not. >> > >> Now, I have a problem where the MachineCSE removes a setting of this >> configuration register in a basic block, because >> MachineCSE::isPhysDefTriviallyDead can't find any uses of it in the >> basic block where it's defined. >> >> Similar to other special physical registers, e.g the stack pointer, >> this configuration register is marked as "reserved". >> >> Is there anything else I need to do for the MachineCSE to leave this >> register and not remove it just because it can't find any uses in >> the current basic block? > > Have you added this register as an implicit use to the instructions > like add whose behavior depends on its value?Yes. So it's like BB1: ... def ConfReg ... <no uses of ConfReg> branch cond BB2 branch BB3 BB2: ... add ... <imp-use ConfReg> ... Since there are no uses of ConfReg after the ConfReg def in BB1, MachineCSE::isPhysDefTriviallyDead decides ConfReg is trivially dead, and removes the setting. Best Regards, Mikael> > -Tom> >> >> Best regards, >> Mikael Holmén >> _______________________________________________ >> LLVM Developers mailing list >> LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu >> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev > >
Jim Grosbach
2014-Aug-18 21:57 UTC
[LLVMdev] Physical register definition removed by MachineCSE
> On Aug 15, 2014, at 2:18 AM, Mikael Holmén <mikael.holmen at ericsson.com> wrote: > > Hi, > > My target has a special configuration register that many instructions read implicitly, configuring for example if an add instruction should saturate at over/underflow or not. > > Now, I have a problem where the MachineCSE removes a setting of this configuration register in a basic block, because MachineCSE::isPhysDefTriviallyDead can't find any uses of it in the basic block where it's defined. > > Similar to other special physical registers, e.g the stack pointer, this configuration register is marked as "reserved". > > Is there anything else I need to do for the MachineCSE to leave this register and not remove it just because it can't find any uses in the current basic block?The instructions which set this control register are distinct from normal reg-to-reg moves and such, I assume? The way that’s typically modeled is to mark those instructions as having side effects (hasSideEffects=1) in the .td file. Note that LLVM doesn’t have any more general notion of things like saturating arithmetic, so it is possible (likely even) that you’ll end up with some strange mis-optimizations when operations get optimized across one of those instructions. That’s a wholly separate issue, though. -Jim> > Best regards, > Mikael Holmén > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev