summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Target/PowerPC
diff options
context:
space:
mode:
authorHiroshi Inoue <inouehrs@jp.ibm.com>2017-10-18 10:31:19 +0000
committerHiroshi Inoue <inouehrs@jp.ibm.com>2017-10-18 10:31:19 +0000
commit5388e66d3ab9985a80968fc71beb40cde170c44f (patch)
tree9afc639f330c34248016acb642f35e7f734dd25d /llvm/lib/Target/PowerPC
parent74c047eabb17b75cac6d6e9537b8e6e51e750880 (diff)
downloadbcm5719-llvm-5388e66d3ab9985a80968fc71beb40cde170c44f.tar.gz
bcm5719-llvm-5388e66d3ab9985a80968fc71beb40cde170c44f.zip
[PowerPC] Use helper functions to check sign-/zero-extended value
Helper functions to identify sign- and zero-extending machine instruction is introduced in rL315888. This patch makes PPCInstrInfo::optimizeCompareInstr use the helper functions. It simplifies the code and also makes possible more optimizations since the helper can do more analysis than the original check code; I observed about 5000 more compare instructions are eliminated while building LLVM. Also, this patch fixes a bug in helpers on ANDIo instruction handling due to the order of checks. This bug causes a failure in an existing test case for optimizeCompareInstr. Differential Revision: https://reviews.llvm.org/D38988 llvm-svn: 316071
Diffstat (limited to 'llvm/lib/Target/PowerPC')
-rw-r--r--llvm/lib/Target/PowerPC/PPCInstrInfo.cpp34
1 files changed, 11 insertions, 23 deletions
diff --git a/llvm/lib/Target/PowerPC/PPCInstrInfo.cpp b/llvm/lib/Target/PowerPC/PPCInstrInfo.cpp
index b4da2d65596..d12610d1eed 100644
--- a/llvm/lib/Target/PowerPC/PPCInstrInfo.cpp
+++ b/llvm/lib/Target/PowerPC/PPCInstrInfo.cpp
@@ -1634,37 +1634,20 @@ bool PPCInstrInfo::optimizeCompareInstr(MachineInstr &CmpInstr, unsigned SrcReg,
// Get the unique definition of SrcReg.
MachineInstr *MI = MRI->getUniqueVRegDef(SrcReg);
if (!MI) return false;
- int MIOpC = MI->getOpcode();
bool equalityOnly = false;
bool noSub = false;
if (isPPC64) {
if (is32BitSignedCompare) {
// We can perform this optimization only if MI is sign-extending.
- if (MIOpC == PPC::SRAW || MIOpC == PPC::SRAWo ||
- MIOpC == PPC::SRAWI || MIOpC == PPC::SRAWIo ||
- MIOpC == PPC::EXTSB || MIOpC == PPC::EXTSBo ||
- MIOpC == PPC::EXTSH || MIOpC == PPC::EXTSHo ||
- MIOpC == PPC::EXTSW || MIOpC == PPC::EXTSWo) {
+ if (isSignExtended(*MI))
noSub = true;
- } else
+ else
return false;
} else if (is32BitUnsignedCompare) {
- // 32-bit rotate and mask instructions are zero extending only if MB <= ME
- bool isZeroExtendingRotate =
- (MIOpC == PPC::RLWINM || MIOpC == PPC::RLWINMo ||
- MIOpC == PPC::RLWNM || MIOpC == PPC::RLWNMo)
- && MI->getOperand(3).getImm() <= MI->getOperand(4).getImm();
-
// We can perform this optimization, equality only, if MI is
// zero-extending.
- // FIXME: Other possible target instructions include ANDISo and
- // RLWINM aliases, such as ROTRWI, EXTLWI, SLWI and SRWI.
- if (MIOpC == PPC::CNTLZW || MIOpC == PPC::CNTLZWo ||
- MIOpC == PPC::SLW || MIOpC == PPC::SLWo ||
- MIOpC == PPC::SRW || MIOpC == PPC::SRWo ||
- MIOpC == PPC::ANDIo ||
- isZeroExtendingRotate) {
+ if (isZeroExtended(*MI)) {
noSub = true;
equalityOnly = true;
} else
@@ -1811,7 +1794,7 @@ bool PPCInstrInfo::optimizeCompareInstr(MachineInstr &CmpInstr, unsigned SrcReg,
if (!MI) MI = Sub;
int NewOpC = -1;
- MIOpC = MI->getOpcode();
+ int MIOpC = MI->getOpcode();
if (MIOpC == PPC::ANDIo || MIOpC == PPC::ANDIo8)
NewOpC = MIOpC;
else {
@@ -2223,6 +2206,12 @@ PPCInstrInfo::isSignOrZeroExtended(const MachineInstr &MI, bool SignExt,
const MachineFunction *MF = MI.getParent()->getParent();
const MachineRegisterInfo *MRI = &MF->getRegInfo();
+ // If we know this instruction returns sign- or zero-extended result,
+ // return true.
+ if (SignExt ? isSignExtendingOp(MI):
+ isZeroExtendingOp(MI))
+ return true;
+
switch (MI.getOpcode()) {
case PPC::COPY: {
unsigned SrcReg = MI.getOperand(1).getReg();
@@ -2339,8 +2328,7 @@ PPCInstrInfo::isSignOrZeroExtended(const MachineInstr &MI, bool SignExt,
}
default:
- return SignExt?isSignExtendingOp(MI):
- isZeroExtendingOp(MI);
+ break;
}
return false;
}
OpenPOWER on IntegriCloud