| OLD | NEW |
| 1 //===-- PPCInstrInfo.cpp - PowerPC Instruction Information ----------------===// | 1 //===-- PPCInstrInfo.cpp - PowerPC Instruction Information ----------------===// |
| 2 // | 2 // |
| 3 // The LLVM Compiler Infrastructure | 3 // The LLVM Compiler Infrastructure |
| 4 // | 4 // |
| 5 // This file is distributed under the University of Illinois Open Source | 5 // This file is distributed under the University of Illinois Open Source |
| 6 // License. See LICENSE.TXT for details. | 6 // License. See LICENSE.TXT for details. |
| 7 // | 7 // |
| 8 //===----------------------------------------------------------------------===// | 8 //===----------------------------------------------------------------------===// |
| 9 // | 9 // |
| 10 // This file contains the PowerPC implementation of the TargetInstrInfo class. | 10 // This file contains the PowerPC implementation of the TargetInstrInfo class. |
| (...skipping 1078 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1089 | 1089 |
| 1090 bool PPCInstrInfo::optimizeCompareInstr(MachineInstr *CmpInstr, | 1090 bool PPCInstrInfo::optimizeCompareInstr(MachineInstr *CmpInstr, |
| 1091 unsigned SrcReg, unsigned SrcReg2, | 1091 unsigned SrcReg, unsigned SrcReg2, |
| 1092 int Mask, int Value, | 1092 int Mask, int Value, |
| 1093 const MachineRegisterInfo *MRI) const { | 1093 const MachineRegisterInfo *MRI) const { |
| 1094 if (DisableCmpOpt) | 1094 if (DisableCmpOpt) |
| 1095 return false; | 1095 return false; |
| 1096 | 1096 |
| 1097 int OpC = CmpInstr->getOpcode(); | 1097 int OpC = CmpInstr->getOpcode(); |
| 1098 unsigned CRReg = CmpInstr->getOperand(0).getReg(); | 1098 unsigned CRReg = CmpInstr->getOperand(0).getReg(); |
| 1099 | 1099 bool isFP = OpC == PPC::FCMPUS || OpC == PPC::FCMPUD; |
| 1100 // FP record forms set CR1 based on the execption status bits, not a | 1100 unsigned CRRecReg = isFP ? PPC::CR1 : PPC::CR0; |
| 1101 // comparison with zero. | |
| 1102 if (OpC == PPC::FCMPUS || OpC == PPC::FCMPUD) | |
| 1103 return false; | |
| 1104 | 1101 |
| 1105 // The record forms set the condition register based on a signed comparison | 1102 // The record forms set the condition register based on a signed comparison |
| 1106 // with zero (so says the ISA manual). This is not as straightforward as it | 1103 // with zero (so says the ISA manual). This is not as straightforward as it |
| 1107 // seems, however, because this is always a 64-bit comparison on PPC64, even | 1104 // seems, however, because this is always a 64-bit comparison on PPC64, even |
| 1108 // for instructions that are 32-bit in nature (like slw for example). | 1105 // for instructions that are 32-bit in nature (like slw for example). |
| 1109 // So, on PPC32, for unsigned comparisons, we can use the record forms only | 1106 // So, on PPC32, for unsigned comparisons, we can use the record forms only |
| 1110 // for equality checks (as those don't depend on the sign). On PPC64, | 1107 // for equality checks (as those don't depend on the sign). On PPC64, |
| 1111 // we are restricted to equality for unsigned 64-bit comparisons and for | 1108 // we are restricted to equality for unsigned 64-bit comparisons and for |
| 1112 // signed 32-bit comparisons the applicability is more restricted. | 1109 // signed 32-bit comparisons the applicability is more restricted. |
| 1113 bool isPPC64 = TM.getSubtargetImpl()->isPPC64(); | 1110 bool isPPC64 = TM.getSubtargetImpl()->isPPC64(); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 1136 } else if (is32BitUnsignedCompare) { | 1133 } else if (is32BitUnsignedCompare) { |
| 1137 // We can perform this optimization, equality only, if MI is | 1134 // We can perform this optimization, equality only, if MI is |
| 1138 // zero-extending. | 1135 // zero-extending. |
| 1139 if (MIOpC == PPC::CNTLZW || MIOpC == PPC::CNTLZWo || | 1136 if (MIOpC == PPC::CNTLZW || MIOpC == PPC::CNTLZWo || |
| 1140 MIOpC == PPC::SLW || MIOpC == PPC::SLWo || | 1137 MIOpC == PPC::SLW || MIOpC == PPC::SLWo || |
| 1141 MIOpC == PPC::SRW || MIOpC == PPC::SRWo) { | 1138 MIOpC == PPC::SRW || MIOpC == PPC::SRWo) { |
| 1142 noSub = true; | 1139 noSub = true; |
| 1143 equalityOnly = true; | 1140 equalityOnly = true; |
| 1144 } else | 1141 } else |
| 1145 return false; | 1142 return false; |
| 1146 } else | 1143 } else if (!isFP) |
| 1147 equalityOnly = is64BitUnsignedCompare; | 1144 equalityOnly = is64BitUnsignedCompare; |
| 1148 } else | 1145 } else if (!isFP) |
| 1149 equalityOnly = is32BitUnsignedCompare; | 1146 equalityOnly = is32BitUnsignedCompare; |
| 1150 | 1147 |
| 1151 if (equalityOnly) { | 1148 if (equalityOnly) { |
| 1152 // We need to check the uses of the condition register in order to reject | 1149 // We need to check the uses of the condition register in order to reject |
| 1153 // non-equality comparisons. | 1150 // non-equality comparisons. |
| 1154 for (MachineRegisterInfo::use_iterator I = MRI->use_begin(CRReg), | 1151 for (MachineRegisterInfo::use_iterator I = MRI->use_begin(CRReg), |
| 1155 IE = MRI->use_end(); I != IE; ++I) { | 1152 IE = MRI->use_end(); I != IE; ++I) { |
| 1156 MachineInstr *UseMI = &*I; | 1153 MachineInstr *UseMI = &*I; |
| 1157 if (UseMI->getOpcode() == PPC::BCC) { | 1154 if (UseMI->getOpcode() == PPC::BCC) { |
| 1158 unsigned Pred = UseMI->getOperand(0).getImm(); | 1155 unsigned Pred = UseMI->getOperand(0).getImm(); |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1211 } | 1208 } |
| 1212 | 1209 |
| 1213 // Search for Sub. | 1210 // Search for Sub. |
| 1214 const TargetRegisterInfo *TRI = &getRegisterInfo(); | 1211 const TargetRegisterInfo *TRI = &getRegisterInfo(); |
| 1215 --I; | 1212 --I; |
| 1216 for (; I != E && !noSub; --I) { | 1213 for (; I != E && !noSub; --I) { |
| 1217 const MachineInstr &Instr = *I; | 1214 const MachineInstr &Instr = *I; |
| 1218 unsigned IOpC = Instr.getOpcode(); | 1215 unsigned IOpC = Instr.getOpcode(); |
| 1219 | 1216 |
| 1220 if (&*I != CmpInstr && ( | 1217 if (&*I != CmpInstr && ( |
| 1221 Instr.modifiesRegister(PPC::CR0, TRI) || | 1218 Instr.modifiesRegister(CRRecReg, TRI) || |
| 1222 Instr.readsRegister(PPC::CR0, TRI))) | 1219 Instr.readsRegister(CRRecReg, TRI))) |
| 1223 // This instruction modifies or uses the record condition register after | 1220 // This instruction modifies or uses the record condition register after |
| 1224 // the one we want to change. While we could do this transformation, it | 1221 // the one we want to change. While we could do this transformation, it |
| 1225 // would likely not be profitable. This transformation removes one | 1222 // would likely not be profitable. This transformation removes one |
| 1226 // instruction, and so even forcing RA to generate one move probably | 1223 // instruction, and so even forcing RA to generate one move probably |
| 1227 // makes it unprofitable. | 1224 // makes it unprofitable. |
| 1228 return false; | 1225 return false; |
| 1229 | 1226 |
| 1230 // Check whether CmpInstr can be made redundant by the current instruction. | 1227 // Check whether CmpInstr can be made redundant by the current instruction. |
| 1231 if ((OpC == PPC::CMPW || OpC == PPC::CMPLW || | 1228 if ((OpC == PPC::CMPW || OpC == PPC::CMPLW || |
| 1232 OpC == PPC::CMPD || OpC == PPC::CMPLD) && | 1229 OpC == PPC::CMPD || OpC == PPC::CMPLD) && |
| 1233 (IOpC == PPC::SUBF || IOpC == PPC::SUBF8) && | 1230 (IOpC == PPC::SUBF || IOpC == PPC::SUBF8) && |
| 1234 ((Instr.getOperand(1).getReg() == SrcReg && | 1231 ((Instr.getOperand(1).getReg() == SrcReg && |
| 1235 Instr.getOperand(2).getReg() == SrcReg2) || | 1232 Instr.getOperand(2).getReg() == SrcReg2) || |
| 1236 (Instr.getOperand(1).getReg() == SrcReg2 && | 1233 (Instr.getOperand(1).getReg() == SrcReg2 && |
| 1237 Instr.getOperand(2).getReg() == SrcReg))) { | 1234 Instr.getOperand(2).getReg() == SrcReg))) { |
| 1238 Sub = &*I; | 1235 Sub = &*I; |
| 1239 break; | 1236 break; |
| 1240 } | 1237 } |
| 1241 | 1238 |
| 1239 if (isFP && (IOpC == PPC::FSUB || IOpC == PPC::FSUBS) && |
| 1240 ((Instr.getOperand(1).getReg() == SrcReg && |
| 1241 Instr.getOperand(2).getReg() == SrcReg2) || |
| 1242 (Instr.getOperand(1).getReg() == SrcReg2 && |
| 1243 Instr.getOperand(2).getReg() == SrcReg))) { |
| 1244 Sub = &*I; |
| 1245 break; |
| 1246 } |
| 1247 |
| 1242 if (I == B) | 1248 if (I == B) |
| 1243 // The 'and' is below the comparison instruction. | 1249 // The 'and' is below the comparison instruction. |
| 1244 return false; | 1250 return false; |
| 1245 } | 1251 } |
| 1246 | 1252 |
| 1247 // Return false if no candidates exist. | 1253 // Return false if no candidates exist. |
| 1248 if (!MI && !Sub) | 1254 if (!MI && !Sub) |
| 1249 return false; | 1255 return false; |
| 1250 | 1256 |
| 1251 // The single candidate is called MI. | 1257 // The single candidate is called MI. |
| (...skipping 25 matching lines...) Expand all Loading... |
| 1277 // needs to be updated to be based on SUB. Push the condition code | 1283 // needs to be updated to be based on SUB. Push the condition code |
| 1278 // operands to OperandsToUpdate. If it is safe to remove CmpInstr, the | 1284 // operands to OperandsToUpdate. If it is safe to remove CmpInstr, the |
| 1279 // condition code of these operands will be modified. | 1285 // condition code of these operands will be modified. |
| 1280 bool ShouldSwap = false; | 1286 bool ShouldSwap = false; |
| 1281 if (Sub) { | 1287 if (Sub) { |
| 1282 ShouldSwap = SrcReg2 != 0 && Sub->getOperand(1).getReg() == SrcReg2 && | 1288 ShouldSwap = SrcReg2 != 0 && Sub->getOperand(1).getReg() == SrcReg2 && |
| 1283 Sub->getOperand(2).getReg() == SrcReg; | 1289 Sub->getOperand(2).getReg() == SrcReg; |
| 1284 | 1290 |
| 1285 // The operands to subf are the opposite of sub, so only in the fixed-point | 1291 // The operands to subf are the opposite of sub, so only in the fixed-point |
| 1286 // case, invert the order. | 1292 // case, invert the order. |
| 1287 ShouldSwap = !ShouldSwap; | 1293 if (!isFP) |
| 1294 ShouldSwap = !ShouldSwap; |
| 1288 } | 1295 } |
| 1289 | 1296 |
| 1290 if (ShouldSwap) | 1297 if (ShouldSwap) |
| 1291 for (MachineRegisterInfo::use_iterator I = MRI->use_begin(CRReg), | 1298 for (MachineRegisterInfo::use_iterator I = MRI->use_begin(CRReg), |
| 1292 IE = MRI->use_end(); I != IE; ++I) { | 1299 IE = MRI->use_end(); I != IE; ++I) { |
| 1293 MachineInstr *UseMI = &*I; | 1300 MachineInstr *UseMI = &*I; |
| 1294 if (UseMI->getOpcode() == PPC::BCC) { | 1301 if (UseMI->getOpcode() == PPC::BCC) { |
| 1295 PPC::Predicate Pred = (PPC::Predicate) UseMI->getOperand(0).getImm(); | 1302 PPC::Predicate Pred = (PPC::Predicate) UseMI->getOperand(0).getImm(); |
| 1296 assert((!equalityOnly || | 1303 assert((!equalityOnly || |
| 1297 Pred == PPC::PRED_EQ || Pred == PPC::PRED_NE) && | 1304 Pred == PPC::PRED_EQ || Pred == PPC::PRED_NE) && |
| (...skipping 18 matching lines...) Expand all Loading... |
| 1316 } | 1323 } |
| 1317 | 1324 |
| 1318 // Create a new virtual register to hold the value of the CR set by the | 1325 // Create a new virtual register to hold the value of the CR set by the |
| 1319 // record-form instruction. If the instruction was not previously in | 1326 // record-form instruction. If the instruction was not previously in |
| 1320 // record form, then set the kill flag on the CR. | 1327 // record form, then set the kill flag on the CR. |
| 1321 CmpInstr->eraseFromParent(); | 1328 CmpInstr->eraseFromParent(); |
| 1322 | 1329 |
| 1323 MachineBasicBlock::iterator MII = MI; | 1330 MachineBasicBlock::iterator MII = MI; |
| 1324 BuildMI(*MI->getParent(), llvm::next(MII), MI->getDebugLoc(), | 1331 BuildMI(*MI->getParent(), llvm::next(MII), MI->getDebugLoc(), |
| 1325 get(TargetOpcode::COPY), CRReg) | 1332 get(TargetOpcode::COPY), CRReg) |
| 1326 .addReg(PPC::CR0, MIOpC != NewOpC ? RegState::Kill : 0); | 1333 .addReg(CRRecReg, MIOpC != NewOpC ? RegState::Kill : 0); |
| 1327 | 1334 |
| 1328 if (MIOpC != NewOpC) { | 1335 if (MIOpC != NewOpC) { |
| 1329 // We need to be careful here: we're replacing one instruction with | 1336 // We need to be careful here: we're replacing one instruction with |
| 1330 // another, and we need to make sure that we get all of the right | 1337 // another, and we need to make sure that we get all of the right |
| 1331 // implicit uses and defs. On the other hand, the caller may be holding | 1338 // implicit uses and defs. On the other hand, the caller may be holding |
| 1332 // an iterator to this instruction, and so we can't delete it (this is | 1339 // an iterator to this instruction, and so we can't delete it (this is |
| 1333 // specifically the case if this is the instruction directly after the | 1340 // specifically the case if this is the instruction directly after the |
| 1334 // compare). | 1341 // compare). |
| 1335 | 1342 |
| 1336 const MCInstrDesc &NewDesc = get(NewOpC); | 1343 const MCInstrDesc &NewDesc = get(NewOpC); |
| (...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1526 }; | 1533 }; |
| 1527 } | 1534 } |
| 1528 | 1535 |
| 1529 INITIALIZE_PASS(PPCEarlyReturn, DEBUG_TYPE, | 1536 INITIALIZE_PASS(PPCEarlyReturn, DEBUG_TYPE, |
| 1530 "PowerPC Early-Return Creation", false, false) | 1537 "PowerPC Early-Return Creation", false, false) |
| 1531 | 1538 |
| 1532 char PPCEarlyReturn::ID = 0; | 1539 char PPCEarlyReturn::ID = 0; |
| 1533 FunctionPass* | 1540 FunctionPass* |
| 1534 llvm::createPPCEarlyReturnPass() { return new PPCEarlyReturn(); } | 1541 llvm::createPPCEarlyReturnPass() { return new PPCEarlyReturn(); } |
| 1535 | 1542 |
| OLD | NEW |