diff options
| author | Craig Topper <craig.topper@intel.com> | 2017-11-23 19:25:45 +0000 |
|---|---|---|
| committer | Craig Topper <craig.topper@intel.com> | 2017-11-23 19:25:45 +0000 |
| commit | 40a1edc30787340350de0c4d5a008a266ec6b06d (patch) | |
| tree | 964156397280e7f2c5891902171244f61bb5ad73 /llvm/lib/Target/X86/X86InstrInfo.cpp | |
| parent | f31b0b850bb03bf53c9fd60c929bcf7462554526 (diff) | |
| download | bcm5719-llvm-40a1edc30787340350de0c4d5a008a266ec6b06d.tar.gz bcm5719-llvm-40a1edc30787340350de0c4d5a008a266ec6b06d.zip | |
[X86] Don't invert NewCC variable while processing the jcc/setcc/cmovcc instructions in optimizeCompareInstr.
The NewCC variable is calculated outside of the loop that processes jcc/setcc/cmovcc instructions. If we invert it during the loop it can cause an incorrect value to be used by a later iteration. Instead only read it during the loop and use a new variable to store the possibly inverted value.
Fixes PR35399.
llvm-svn: 318934
Diffstat (limited to 'llvm/lib/Target/X86/X86InstrInfo.cpp')
| -rw-r--r-- | llvm/lib/Target/X86/X86InstrInfo.cpp | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/llvm/lib/Target/X86/X86InstrInfo.cpp b/llvm/lib/Target/X86/X86InstrInfo.cpp index 68f964cc866..bd8d447fb88 100644 --- a/llvm/lib/Target/X86/X86InstrInfo.cpp +++ b/llvm/lib/Target/X86/X86InstrInfo.cpp @@ -7475,6 +7475,7 @@ bool X86InstrInfo::optimizeCompareInstr(MachineInstr &CmpInstr, unsigned SrcReg, } if (OldCC == X86::COND_INVALID) return false; } + X86::CondCode ReplacementCC = X86::COND_INVALID; if (IsCmpZero) { switch (OldCC) { default: break; @@ -7494,31 +7495,32 @@ bool X86InstrInfo::optimizeCompareInstr(MachineInstr &CmpInstr, unsigned SrcReg, default: return false; case X86::COND_E: + ReplacementCC = NewCC; break; case X86::COND_NE: - NewCC = GetOppositeBranchCondition(NewCC); + ReplacementCC = GetOppositeBranchCondition(NewCC); break; } } else if (IsSwapped) { // If we have SUB(r1, r2) and CMP(r2, r1), the condition code needs // to be changed from r2 > r1 to r1 < r2, from r2 < r1 to r1 > r2, etc. // We swap the condition code and synthesize the new opcode. - NewCC = getSwappedCondition(OldCC); - if (NewCC == X86::COND_INVALID) return false; + ReplacementCC = getSwappedCondition(OldCC); + if (ReplacementCC == X86::COND_INVALID) return false; } - if ((ShouldUpdateCC || IsSwapped) && NewCC != OldCC) { + if ((ShouldUpdateCC || IsSwapped) && ReplacementCC != OldCC) { // Synthesize the new opcode. bool HasMemoryOperand = Instr.hasOneMemOperand(); unsigned NewOpc; if (Instr.isBranch()) - NewOpc = GetCondBranchFromCond(NewCC); + NewOpc = GetCondBranchFromCond(ReplacementCC); else if(OpcIsSET) - NewOpc = getSETFromCond(NewCC, HasMemoryOperand); + NewOpc = getSETFromCond(ReplacementCC, HasMemoryOperand); else { unsigned DstReg = Instr.getOperand(0).getReg(); const TargetRegisterClass *DstRC = MRI->getRegClass(DstReg); - NewOpc = getCMovFromCond(NewCC, TRI->getRegSizeInBits(*DstRC)/8, + NewOpc = getCMovFromCond(ReplacementCC, TRI->getRegSizeInBits(*DstRC)/8, HasMemoryOperand); } |

