diff options
| author | Jonas Paulsson <paulsson@linux.vnet.ibm.com> | 2018-06-07 05:59:07 +0000 |
|---|---|---|
| committer | Jonas Paulsson <paulsson@linux.vnet.ibm.com> | 2018-06-07 05:59:07 +0000 |
| commit | e80d405760f9c35d4d85b657701605baca8cb000 (patch) | |
| tree | 47921b3f7860482a9d49b0f1aee08dfac2e57591 | |
| parent | 8153628f6a42a148d2b75189e2e286d1652422a2 (diff) | |
| download | bcm5719-llvm-e80d405760f9c35d4d85b657701605baca8cb000.tar.gz bcm5719-llvm-e80d405760f9c35d4d85b657701605baca8cb000.zip | |
[SystemZ] Build Load And Test from scratch in convertToLoadAndTest.
This is needed to get CC operand in right place, as expected by the
SchedModel.
Review: Ulrich Weigand
https://reviews.llvm.org/D47820
llvm-svn: 334161
| -rw-r--r-- | llvm/lib/Target/SystemZ/SystemZElimCompare.cpp | 26 |
1 files changed, 16 insertions, 10 deletions
diff --git a/llvm/lib/Target/SystemZ/SystemZElimCompare.cpp b/llvm/lib/Target/SystemZ/SystemZElimCompare.cpp index 2df8985f85b..9edd1fc3640 100644 --- a/llvm/lib/Target/SystemZ/SystemZElimCompare.cpp +++ b/llvm/lib/Target/SystemZ/SystemZElimCompare.cpp @@ -293,9 +293,14 @@ bool SystemZElimCompare::convertToLoadAndTest( if (!Opcode || !adjustCCMasksForInstr(MI, Compare, CCUsers, Opcode)) return false; - MI.setDesc(TII->get(Opcode)); - MachineInstrBuilder(*MI.getParent()->getParent(), MI) - .addReg(SystemZ::CC, RegState::ImplicitDefine); + // Rebuild to get the CC operand in the right place. + MachineInstr *BuiltMI = + BuildMI(*MI.getParent(), MI, MI.getDebugLoc(), TII->get(Opcode)); + for (const auto &MO : MI.operands()) + BuiltMI->addOperand(MO); + BuiltMI->setMemRefs(MI.memoperands_begin(), MI.memoperands_end()); + MI.eraseFromParent(); + return true; } @@ -425,12 +430,12 @@ bool SystemZElimCompare::optimizeCompareZero( // Search back for CC results that are based on the first operand. unsigned SrcReg = getCompareSourceReg(Compare); MachineBasicBlock &MBB = *Compare.getParent(); - MachineBasicBlock::iterator MBBI = Compare, MBBE = MBB.begin(); Reference CCRefs; Reference SrcRefs; - while (MBBI != MBBE) { - --MBBI; - MachineInstr &MI = *MBBI; + for (MachineBasicBlock::reverse_iterator MBBI = + std::next(MachineBasicBlock::reverse_iterator(&Compare)), + MBBE = MBB.rend(); MBBI != MBBE;) { + MachineInstr &MI = *MBBI++; if (resultTests(MI, SrcReg)) { // Try to remove both MI and Compare by converting a branch to BRCT(G). // or a load-and-trap instruction. We don't care in this case whether @@ -463,9 +468,10 @@ bool SystemZElimCompare::optimizeCompareZero( // Also do a forward search to handle cases where an instruction after the // compare can be converted, like // LTEBRCompare %f0s, %f0s; %f2s = LER %f0s => LTEBRCompare %f2s, %f0s - MBBI = Compare, MBBE = MBB.end(); - while (++MBBI != MBBE) { - MachineInstr &MI = *MBBI; + for (MachineBasicBlock::iterator MBBI = + std::next(MachineBasicBlock::iterator(&Compare)), MBBE = MBB.end(); + MBBI != MBBE;) { + MachineInstr &MI = *MBBI++; if (preservesValueOf(MI, SrcReg)) { // Try to eliminate Compare by reusing a CC result from MI. if (convertToLoadAndTest(MI, Compare, CCUsers)) { |

