diff options
author | Richard Sandiford <rsandifo@linux.vnet.ibm.com> | 2013-08-07 11:10:06 +0000 |
---|---|---|
committer | Richard Sandiford <rsandifo@linux.vnet.ibm.com> | 2013-08-07 11:10:06 +0000 |
commit | 29e873ddb6b21c4a934926a0cf7809e98ac1fff0 (patch) | |
tree | 62117d26b18e30c45cad7338dcc4e750b9918d7b /lib/Target/SystemZ/SystemZElimCompare.cpp | |
parent | e0bbf7288c00c377a97a9d4bf5fb0bf20c44cd1c (diff) | |
download | llvm-29e873ddb6b21c4a934926a0cf7809e98ac1fff0.tar.gz llvm-29e873ddb6b21c4a934926a0cf7809e98ac1fff0.tar.bz2 llvm-29e873ddb6b21c4a934926a0cf7809e98ac1fff0.tar.xz |
[SystemZ] Optimize floating-point comparisons with zero
This follows the same lines as the integer code. In the end it seemed
easier to have a second 4-bit mask in TSFlags to specify the compare-like
CC values. That eats one more TSFlags bit than adding a CCHasUnordered
would have done, but it feels more concise.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@187883 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Target/SystemZ/SystemZElimCompare.cpp')
-rw-r--r-- | lib/Target/SystemZ/SystemZElimCompare.cpp | 35 |
1 files changed, 25 insertions, 10 deletions
diff --git a/lib/Target/SystemZ/SystemZElimCompare.cpp b/lib/Target/SystemZ/SystemZElimCompare.cpp index 07afc86acb..b8a77db0f8 100644 --- a/lib/Target/SystemZ/SystemZElimCompare.cpp +++ b/lib/Target/SystemZ/SystemZElimCompare.cpp @@ -122,6 +122,12 @@ static bool resultTests(MachineInstr *MI, unsigned Reg, unsigned SubReg) { case SystemZ::LTR: case SystemZ::LTGR: case SystemZ::LTGFR: + case SystemZ::LER: + case SystemZ::LDR: + case SystemZ::LXR: + case SystemZ::LTEBR: + case SystemZ::LTDBR: + case SystemZ::LTXBR: if (MI->getOperand(1).getReg() == Reg && MI->getOperand(1).getSubReg() == SubReg) return true; @@ -230,15 +236,12 @@ adjustCCMasksForInstr(MachineInstr *MI, MachineInstr *Compare, unsigned MIFlags = Desc.TSFlags; // See which compare-style condition codes are available. - unsigned ReusableCCMask = 0; - if (MIFlags & SystemZII::CCHasZero) - ReusableCCMask |= SystemZ::CCMASK_CMP_EQ; + unsigned ReusableCCMask = SystemZII::getCompareZeroCCMask(MIFlags); // For unsigned comparisons with zero, only equality makes sense. unsigned CompareFlags = Compare->getDesc().TSFlags; - if (!(CompareFlags & SystemZII::IsLogical) && - (MIFlags & SystemZII::CCHasOrder)) - ReusableCCMask |= SystemZ::CCMASK_CMP_LT | SystemZ::CCMASK_CMP_GT; + if (CompareFlags & SystemZII::IsLogical) + ReusableCCMask &= SystemZ::CCMASK_CMP_EQ; if (ReusableCCMask == 0) return false; @@ -297,6 +300,21 @@ adjustCCMasksForInstr(MachineInstr *MI, MachineInstr *Compare, return true; } +// Return true if Compare is a comparison against zero. +static bool isCompareZero(MachineInstr *Compare) { + switch (Compare->getOpcode()) { + case SystemZ::LTEBRCompare: + case SystemZ::LTDBRCompare: + case SystemZ::LTXBRCompare: + return true; + + default: + return (Compare->getNumExplicitOperands() == 2 && + Compare->getOperand(1).isImm() && + Compare->getOperand(1).getImm() == 0); + } +} + // Try to optimize cases where comparison instruction Compare is testing // a value against zero. Return true on success and if Compare should be // deleted as dead. CCUsers is the list of instructions that use the CC @@ -304,10 +322,7 @@ adjustCCMasksForInstr(MachineInstr *MI, MachineInstr *Compare, bool SystemZElimCompare:: optimizeCompareZero(MachineInstr *Compare, SmallVectorImpl<MachineInstr *> &CCUsers) { - // Check whether this is a comparison against zero. - if (Compare->getNumExplicitOperands() != 2 || - !Compare->getOperand(1).isImm() || - Compare->getOperand(1).getImm() != 0) + if (!isCompareZero(Compare)) return false; // Search back for CC results that are based on the first operand. |