diff options
| author | Dimitry Andric <dim@FreeBSD.org> | 2017-12-24 01:04:58 +0000 | 
|---|---|---|
| committer | Dimitry Andric <dim@FreeBSD.org> | 2017-12-24 01:04:58 +0000 | 
| commit | da09e106efc76da569f2bad3d59b6b19b503bf39 (patch) | |
| tree | 3dc7690165275d86df8841532970801b0dc1230d /contrib/llvm/lib/Target/PowerPC/PPCMIPeephole.cpp | |
| parent | fb142d88715c407bebf777730d5bd6cbf73e2bc7 (diff) | |
| parent | c7dac04c3480f3c20487f912f77343139fce2d99 (diff) | |
Notes
Diffstat (limited to 'contrib/llvm/lib/Target/PowerPC/PPCMIPeephole.cpp')
| -rw-r--r-- | contrib/llvm/lib/Target/PowerPC/PPCMIPeephole.cpp | 18 | 
1 files changed, 13 insertions, 5 deletions
| diff --git a/contrib/llvm/lib/Target/PowerPC/PPCMIPeephole.cpp b/contrib/llvm/lib/Target/PowerPC/PPCMIPeephole.cpp index a2640727f813..474661aaaee8 100644 --- a/contrib/llvm/lib/Target/PowerPC/PPCMIPeephole.cpp +++ b/contrib/llvm/lib/Target/PowerPC/PPCMIPeephole.cpp @@ -1025,9 +1025,6 @@ bool PPCMIPeephole::eliminateRedundantTOCSaves(  //   bge    0, .LBB0_4  bool PPCMIPeephole::eliminateRedundantCompare(void) { -  // FIXME: this transformation is causing miscompiles. Disabling it for now -  // until we can resolve the issue. -  return false;    bool Simplified = false;    for (MachineBasicBlock &MBB2 : *MF) { @@ -1087,10 +1084,21 @@ bool PPCMIPeephole::eliminateRedundantCompare(void) {        // we replace it with a signed comparison if the comparison        // to be merged is a signed comparison.        // In other cases of opcode mismatch, we cannot optimize this. -      if (isEqOrNe(BI2) && + +      // We cannot change opcode when comparing against an immediate +      // if the most significant bit of the immediate is one +      // due to the difference in sign extension. +      auto CmpAgainstImmWithSignBit = [](MachineInstr *I) { +        if (!I->getOperand(2).isImm()) +          return false; +        int16_t Imm = (int16_t)I->getOperand(2).getImm(); +        return Imm < 0; +      }; + +      if (isEqOrNe(BI2) && !CmpAgainstImmWithSignBit(CMPI2) &&            CMPI1->getOpcode() == getSignedCmpOpCode(CMPI2->getOpcode()))          NewOpCode = CMPI1->getOpcode(); -      else if (isEqOrNe(BI1) && +      else if (isEqOrNe(BI1) && !CmpAgainstImmWithSignBit(CMPI1) &&                 getSignedCmpOpCode(CMPI1->getOpcode()) == CMPI2->getOpcode())          NewOpCode = CMPI2->getOpcode();        else continue; | 
