diff options
| author | Kyle Butt <kyle+llvm@iteratee.net> | 2016-02-03 01:41:09 +0000 |
|---|---|---|
| committer | Kyle Butt <kyle+llvm@iteratee.net> | 2016-02-03 01:41:09 +0000 |
| commit | d62d8b771d3cc51b0b9e095011c7a1a6f83ce477 (patch) | |
| tree | 0b4dcccce8ae6c9d0c00306bd34d23f91e92e3cc /llvm/lib/Target | |
| parent | 4a38201176fc8e8822fbdace03bb98ee75cac82a (diff) | |
| download | bcm5719-llvm-d62d8b771d3cc51b0b9e095011c7a1a6f83ce477.tar.gz bcm5719-llvm-d62d8b771d3cc51b0b9e095011c7a1a6f83ce477.zip | |
Codegen: [PPC] Fix PPCVSXFMAMutate to handle duplicates.
The purpose of PPCVSXFMAMutate is to elide copies by changing FMA forms
on PPC.
%vreg6<def> = COPY %vreg96
%vreg6<def,tied1> = XSMADDASP %vreg6<tied0>, %vreg5<kill>, %vreg7
;v6 = v6 + v5 * v7
is replaced by
%vreg5<def,tied1> = XSMADDMSP %vreg5<tied0>, %vreg7, %vreg96
;v5 = v5 * v7 + v96
This was broken in the case where the target register was also used as a
multiplicand. Fix this case by checking for it and replacing both uses
with the copied register.
%vreg6<def> = COPY %vreg96
%vreg6<def,tied1> = XSMADDASP %vreg6<tied0>, %vreg5<kill>, %vreg6
;v6 = v6 + v5 * v6
is replaced by
%vreg5<def,tied1> = XSMADDMSP %vreg5<tied0>, %vreg96, %vreg96
;v5 = v5 * v96 + v96
llvm-svn: 259617
Diffstat (limited to 'llvm/lib/Target')
| -rw-r--r-- | llvm/lib/Target/PowerPC/PPCVSXFMAMutate.cpp | 51 |
1 files changed, 32 insertions, 19 deletions
diff --git a/llvm/lib/Target/PowerPC/PPCVSXFMAMutate.cpp b/llvm/lib/Target/PowerPC/PPCVSXFMAMutate.cpp index 6b19a2f7118..e90dc971a9f 100644 --- a/llvm/lib/Target/PowerPC/PPCVSXFMAMutate.cpp +++ b/llvm/lib/Target/PowerPC/PPCVSXFMAMutate.cpp @@ -168,21 +168,32 @@ protected: if (OtherUsers || KillsAddendSrc) continue; - // Find one of the product operands that is killed by this instruction. + // The transformation doesn't work well with things like: + // %vreg5 = A-form-op %vreg5, %vreg11, %vreg5; + // unless vreg11 is also a kill, so skip when it is not, + // and check operand 3 to see it is also a kill to handle the case: + // %vreg5 = A-form-op %vreg5, %vreg5, %vreg11; + // where vreg5 and vreg11 are both kills. This case would be skipped + // otherwise. + unsigned OldFMAReg = MI->getOperand(0).getReg(); + + // Find one of the product operands that is killed by this instruction. unsigned KilledProdOp = 0, OtherProdOp = 0; - if (LIS->getInterval(MI->getOperand(2).getReg()) - .Query(FMAIdx).isKill()) { + unsigned Reg2 = MI->getOperand(2).getReg(); + unsigned Reg3 = MI->getOperand(3).getReg(); + if (LIS->getInterval(Reg2).Query(FMAIdx).isKill() + && Reg2 != OldFMAReg) { KilledProdOp = 2; OtherProdOp = 3; - } else if (LIS->getInterval(MI->getOperand(3).getReg()) - .Query(FMAIdx).isKill()) { + } else if (LIS->getInterval(Reg3).Query(FMAIdx).isKill() + && Reg3 != OldFMAReg) { KilledProdOp = 3; OtherProdOp = 2; } - // If there are no killed product operands, then this transformation is - // likely not profitable. + // If there are no usable killed product operands, then this + // transformation is likely not profitable. if (!KilledProdOp) continue; @@ -212,14 +223,6 @@ protected: bool KilledProdRegUndef = MI->getOperand(KilledProdOp).isUndef(); bool OtherProdRegUndef = MI->getOperand(OtherProdOp).isUndef(); - unsigned OldFMAReg = MI->getOperand(0).getReg(); - - // The transformation doesn't work well with things like: - // %vreg5 = A-form-op %vreg5, %vreg11, %vreg5; - // so leave such things alone. - if (OldFMAReg == KilledProdReg) - continue; - // If there isn't a class that fits, we can't perform the transform. // This is needed for correctness with a mixture of VSX and Altivec // instructions to make sure that a low VSX register is not assigned to @@ -236,23 +239,33 @@ protected: MI->getOperand(0).setReg(KilledProdReg); MI->getOperand(1).setReg(KilledProdReg); MI->getOperand(3).setReg(AddendSrcReg); - MI->getOperand(2).setReg(OtherProdReg); MI->getOperand(0).setSubReg(KilledProdSubReg); MI->getOperand(1).setSubReg(KilledProdSubReg); MI->getOperand(3).setSubReg(AddSubReg); - MI->getOperand(2).setSubReg(OtherProdSubReg); MI->getOperand(1).setIsKill(KilledProdRegKill); MI->getOperand(3).setIsKill(AddRegKill); - MI->getOperand(2).setIsKill(OtherProdRegKill); MI->getOperand(1).setIsUndef(KilledProdRegUndef); MI->getOperand(3).setIsUndef(AddRegUndef); - MI->getOperand(2).setIsUndef(OtherProdRegUndef); MI->setDesc(TII->get(AltOpc)); + // If the addend is also a multiplicand, replace it with the addend + // source in both places. + if (OtherProdReg == AddendMI->getOperand(0).getReg()) { + MI->getOperand(2).setReg(AddendSrcReg); + MI->getOperand(2).setSubReg(AddSubReg); + MI->getOperand(2).setIsKill(AddRegKill); + MI->getOperand(2).setIsUndef(AddRegUndef); + } else { + MI->getOperand(2).setReg(OtherProdReg); + MI->getOperand(2).setSubReg(OtherProdSubReg); + MI->getOperand(2).setIsKill(OtherProdRegKill); + MI->getOperand(2).setIsUndef(OtherProdRegUndef); + } + DEBUG(dbgs() << " -> " << *MI); // The killed product operand was killed here, so we can reuse it now |

