OLD | NEW |
1 //===-- ARMBaseInstrInfo.cpp - ARM Instruction Information ----------------===// | 1 //===-- ARMBaseInstrInfo.cpp - ARM 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 Base ARM implementation of the TargetInstrInfo class. | 10 // This file contains the Base ARM implementation of the TargetInstrInfo class. |
(...skipping 2376 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2387 // One is MI, the other is a SUB instruction. | 2387 // One is MI, the other is a SUB instruction. |
2388 // For CMPrr(r1,r2), we are looking for SUB(r1,r2) or SUB(r2,r1). | 2388 // For CMPrr(r1,r2), we are looking for SUB(r1,r2) or SUB(r2,r1). |
2389 // For CMPri(r1, CmpValue), we are looking for SUBri(r1, CmpValue). | 2389 // For CMPri(r1, CmpValue), we are looking for SUBri(r1, CmpValue). |
2390 MachineInstr *Sub = nullptr; | 2390 MachineInstr *Sub = nullptr; |
2391 if (SrcReg2 != 0) | 2391 if (SrcReg2 != 0) |
2392 // MI is not a candidate for CMPrr. | 2392 // MI is not a candidate for CMPrr. |
2393 MI = nullptr; | 2393 MI = nullptr; |
2394 else if (MI->getParent() != CmpInstr->getParent() || CmpValue != 0) { | 2394 else if (MI->getParent() != CmpInstr->getParent() || CmpValue != 0) { |
2395 // Conservatively refuse to convert an instruction which isn't in the same | 2395 // Conservatively refuse to convert an instruction which isn't in the same |
2396 // BB as the comparison. | 2396 // BB as the comparison. |
2397 // For CMPri, we need to check Sub, thus we can't return here. | 2397 // For CMPri w/ CmpValue != 0, a Sub may still be a candidate. |
| 2398 // Thus we cannot return here. |
2398 if (CmpInstr->getOpcode() == ARM::CMPri || | 2399 if (CmpInstr->getOpcode() == ARM::CMPri || |
2399 CmpInstr->getOpcode() == ARM::t2CMPri) | 2400 CmpInstr->getOpcode() == ARM::t2CMPri) |
2400 MI = nullptr; | 2401 MI = nullptr; |
2401 else | 2402 else |
2402 return false; | 2403 return false; |
2403 } | 2404 } |
2404 | 2405 |
2405 // Check that CPSR isn't set between the comparison instruction and the one we | 2406 // Check that CPSR isn't set between the comparison instruction and the one we |
2406 // want to change. At the same time, search for Sub. | 2407 // want to change. At the same time, search for Sub. |
2407 const TargetRegisterInfo *TRI = &getRegisterInfo(); | 2408 const TargetRegisterInfo *TRI = &getRegisterInfo(); |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2466 case ARM::t2ANDri: | 2467 case ARM::t2ANDri: |
2467 case ARM::ORRrr: | 2468 case ARM::ORRrr: |
2468 case ARM::ORRri: | 2469 case ARM::ORRri: |
2469 case ARM::t2ORRrr: | 2470 case ARM::t2ORRrr: |
2470 case ARM::t2ORRri: | 2471 case ARM::t2ORRri: |
2471 case ARM::EORrr: | 2472 case ARM::EORrr: |
2472 case ARM::EORri: | 2473 case ARM::EORri: |
2473 case ARM::t2EORrr: | 2474 case ARM::t2EORrr: |
2474 case ARM::t2EORri: { | 2475 case ARM::t2EORri: { |
2475 // Scan forward for the use of CPSR | 2476 // Scan forward for the use of CPSR |
2476 // When checking against MI: if it's a conditional code requires | 2477 // When checking against MI: if it's a conditional code that requires |
2477 // checking of V bit, then this is not safe to do. | 2478 // checking of the V bit or C bit, then this is not safe to do. |
2478 // It is safe to remove CmpInstr if CPSR is redefined or killed. | 2479 // It is safe to remove CmpInstr if CPSR is redefined or killed. |
2479 // If we are done with the basic block, we need to check whether CPSR is | 2480 // If we are done with the basic block, we need to check whether CPSR is |
2480 // live-out. | 2481 // live-out. |
2481 SmallVector<std::pair<MachineOperand*, ARMCC::CondCodes>, 4> | 2482 SmallVector<std::pair<MachineOperand*, ARMCC::CondCodes>, 4> |
2482 OperandsToUpdate; | 2483 OperandsToUpdate; |
2483 bool isSafe = false; | 2484 bool isSafe = false; |
2484 I = CmpInstr; | 2485 I = CmpInstr; |
2485 E = CmpInstr->getParent()->end(); | 2486 E = CmpInstr->getParent()->end(); |
2486 while (!isSafe && ++I != E) { | 2487 while (!isSafe && ++I != E) { |
2487 const MachineInstr &Instr = *I; | 2488 const MachineInstr &Instr = *I; |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2534 // If it is safe to remove CmpInstr, the condition code of these | 2535 // If it is safe to remove CmpInstr, the condition code of these |
2535 // operands will be modified. | 2536 // operands will be modified. |
2536 if (SrcReg2 != 0 && Sub->getOperand(1).getReg() == SrcReg2 && | 2537 if (SrcReg2 != 0 && Sub->getOperand(1).getReg() == SrcReg2 && |
2537 Sub->getOperand(2).getReg() == SrcReg) { | 2538 Sub->getOperand(2).getReg() == SrcReg) { |
2538 // VSel doesn't support condition code update. | 2539 // VSel doesn't support condition code update. |
2539 if (IsInstrVSel) | 2540 if (IsInstrVSel) |
2540 return false; | 2541 return false; |
2541 OperandsToUpdate.push_back( | 2542 OperandsToUpdate.push_back( |
2542 std::make_pair(&((*I).getOperand(IO - 1)), NewCC)); | 2543 std::make_pair(&((*I).getOperand(IO - 1)), NewCC)); |
2543 } | 2544 } |
2544 } else | 2545 } else { |
| 2546 // No Sub, so this is x = <op> y, z; cmp x, 0. |
2545 switch (CC) { | 2547 switch (CC) { |
2546 default: | 2548 case ARMCC::EQ: // Z |
| 2549 case ARMCC::NE: // Z |
| 2550 case ARMCC::MI: // N |
| 2551 case ARMCC::PL: // N |
| 2552 case ARMCC::AL: // none |
2547 // CPSR can be used multiple times, we should continue. | 2553 // CPSR can be used multiple times, we should continue. |
2548 break; | 2554 break; |
2549 case ARMCC::VS: | 2555 case ARMCC::HS: // C |
2550 case ARMCC::VC: | 2556 case ARMCC::LO: // C |
2551 case ARMCC::GE: | 2557 case ARMCC::VS: // V |
2552 case ARMCC::LT: | 2558 case ARMCC::VC: // V |
2553 case ARMCC::GT: | 2559 case ARMCC::HI: // C Z |
2554 case ARMCC::LE: | 2560 case ARMCC::LS: // C Z |
| 2561 case ARMCC::GE: // N V |
| 2562 case ARMCC::LT: // N V |
| 2563 case ARMCC::GT: // Z N V |
| 2564 case ARMCC::LE: // Z N V |
| 2565 // The instruction uses the V bit or C bit which is not safe. |
2555 return false; | 2566 return false; |
2556 } | 2567 } |
| 2568 } |
2557 } | 2569 } |
2558 } | 2570 } |
2559 | 2571 |
2560 // If CPSR is not killed nor re-defined, we should check whether it is | 2572 // If CPSR is not killed nor re-defined, we should check whether it is |
2561 // live-out. If it is live-out, do not optimize. | 2573 // live-out. If it is live-out, do not optimize. |
2562 if (!isSafe) { | 2574 if (!isSafe) { |
2563 MachineBasicBlock *MBB = CmpInstr->getParent(); | 2575 MachineBasicBlock *MBB = CmpInstr->getParent(); |
2564 for (MachineBasicBlock::succ_iterator SI = MBB->succ_begin(), | 2576 for (MachineBasicBlock::succ_iterator SI = MBB->succ_begin(), |
2565 SE = MBB->succ_end(); SI != SE; ++SI) | 2577 SE = MBB->succ_end(); SI != SE; ++SI) |
2566 if ((*SI)->isLiveIn(ARM::CPSR)) | 2578 if ((*SI)->isLiveIn(ARM::CPSR)) |
(...skipping 2003 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4570 BaseReg.Reg = MOBaseReg.getReg(); | 4582 BaseReg.Reg = MOBaseReg.getReg(); |
4571 BaseReg.SubReg = MOBaseReg.getSubReg(); | 4583 BaseReg.SubReg = MOBaseReg.getSubReg(); |
4572 | 4584 |
4573 InsertedReg.Reg = MOInsertedReg.getReg(); | 4585 InsertedReg.Reg = MOInsertedReg.getReg(); |
4574 InsertedReg.SubReg = MOInsertedReg.getSubReg(); | 4586 InsertedReg.SubReg = MOInsertedReg.getSubReg(); |
4575 InsertedReg.SubIdx = MOIndex.getImm() == 0 ? ARM::ssub_0 : ARM::ssub_1; | 4587 InsertedReg.SubIdx = MOIndex.getImm() == 0 ? ARM::ssub_0 : ARM::ssub_1; |
4576 return true; | 4588 return true; |
4577 } | 4589 } |
4578 llvm_unreachable("Target dependent opcode missing"); | 4590 llvm_unreachable("Target dependent opcode missing"); |
4579 } | 4591 } |
OLD | NEW |