Index: llvm/lib/CodeGen/TwoAddressInstructionPass.cpp =================================================================== --- llvm/lib/CodeGen/TwoAddressInstructionPass.cpp +++ llvm/lib/CodeGen/TwoAddressInstructionPass.cpp @@ -134,7 +134,7 @@ bool convertInstTo3Addr(MachineBasicBlock::iterator &mi, MachineBasicBlock::iterator &nmi, Register RegA, - Register RegB, unsigned Dist); + Register RegB, unsigned &Dist); bool isDefTooClose(Register Reg, unsigned Dist, MachineInstr *MI); @@ -146,7 +146,7 @@ bool tryInstructionTransform(MachineBasicBlock::iterator &mi, MachineBasicBlock::iterator &nmi, unsigned SrcIdx, unsigned DstIdx, - unsigned Dist, bool shouldOnlyCommute); + unsigned &Dist, bool shouldOnlyCommute); bool tryInstructionCommute(MachineInstr *MI, unsigned DstOpIdx, @@ -674,7 +674,7 @@ /// Return true if this transformation was successful. bool TwoAddressInstructionPass::convertInstTo3Addr( MachineBasicBlock::iterator &mi, MachineBasicBlock::iterator &nmi, - Register RegA, Register RegB, unsigned Dist) { + Register RegA, Register RegB, unsigned &Dist) { MachineInstrSpan MIS(mi, MBB); MachineInstr *NewMI = TII->convertToThreeAddress(*mi, LV); if (!NewMI) @@ -723,7 +723,9 @@ if (LIS && !SingleInst) LIS->repairIntervalsInRange(MBB, MIS.begin(), MIS.end(), OrigRegs); - DistanceMap.insert(std::make_pair(NewMI, Dist)); + for (MachineInstr &MI : MIS) + DistanceMap.insert(std::make_pair(&MI, Dist++)); + Dist--; mi = NewMI; nmi = std::next(mi); @@ -1226,7 +1228,7 @@ tryInstructionTransform(MachineBasicBlock::iterator &mi, MachineBasicBlock::iterator &nmi, unsigned SrcIdx, unsigned DstIdx, - unsigned Dist, bool shouldOnlyCommute) { + unsigned &Dist, bool shouldOnlyCommute) { if (OptLevel == CodeGenOpt::None) return false; Index: llvm/test/CodeGen/X86/addcarry.ll =================================================================== --- llvm/test/CodeGen/X86/addcarry.ll +++ llvm/test/CodeGen/X86/addcarry.ll @@ -179,7 +179,7 @@ ; CHECK-NEXT: leal (%rsi,%rcx), %edx ; CHECK-NEXT: addl %esi, %edx ; CHECK-NEXT: setb %al -; CHECK-NEXT: addl %esi, %ecx +; CHECK-NEXT: addl %ecx, %esi ; CHECK-NEXT: movl %edx, (%rdi) ; CHECK-NEXT: adcb $0, %al ; CHECK-NEXT: retq Index: llvm/test/CodeGen/X86/sadd_sat_plus.ll =================================================================== --- llvm/test/CodeGen/X86/sadd_sat_plus.ll +++ llvm/test/CodeGen/X86/sadd_sat_plus.ll @@ -95,8 +95,8 @@ ; X64-NEXT: cwtl ; X64-NEXT: sarl $15, %eax ; X64-NEXT: xorl $-32768, %eax # imm = 0x8000 -; X64-NEXT: addw %di, %si -; X64-NEXT: cmovnol %esi, %eax +; X64-NEXT: addw %si, %di +; X64-NEXT: cmovnol %edi, %eax ; X64-NEXT: # kill: def $ax killed $ax killed $eax ; X64-NEXT: retq %a = mul i16 %y, %z @@ -131,8 +131,8 @@ ; X64-NEXT: leal (%rdi,%rax), %ecx ; X64-NEXT: sarb $7, %cl ; X64-NEXT: xorb $-128, %cl -; X64-NEXT: addb %dil, %al -; X64-NEXT: movzbl %al, %edx +; X64-NEXT: addb %al, %dil +; X64-NEXT: movzbl %dil, %edx ; X64-NEXT: movzbl %cl, %eax ; X64-NEXT: cmovnol %edx, %eax ; X64-NEXT: # kill: def $al killed $al killed $eax Index: llvm/test/CodeGen/X86/sadd_sat_vec.ll =================================================================== --- llvm/test/CodeGen/X86/sadd_sat_vec.ll +++ llvm/test/CodeGen/X86/sadd_sat_vec.ll @@ -434,8 +434,8 @@ ; SSE-NEXT: leal (%rax,%rcx), %esi ; SSE-NEXT: sarb $7, %sil ; SSE-NEXT: xorb $-128, %sil -; SSE-NEXT: addb %al, %cl -; SSE-NEXT: movzbl %cl, %eax +; SSE-NEXT: addb %cl, %al +; SSE-NEXT: movzbl %al, %eax ; SSE-NEXT: movzbl %sil, %ecx ; SSE-NEXT: cmovnol %eax, %ecx ; SSE-NEXT: movb %cl, (%rdx) @@ -448,8 +448,8 @@ ; AVX-NEXT: leal (%rax,%rcx), %esi ; AVX-NEXT: sarb $7, %sil ; AVX-NEXT: xorb $-128, %sil -; AVX-NEXT: addb %al, %cl -; AVX-NEXT: movzbl %cl, %eax +; AVX-NEXT: addb %cl, %al +; AVX-NEXT: movzbl %al, %eax ; AVX-NEXT: movzbl %sil, %ecx ; AVX-NEXT: cmovnol %eax, %ecx ; AVX-NEXT: movb %cl, (%rdx) @@ -470,9 +470,9 @@ ; SSE-NEXT: movswl %si, %esi ; SSE-NEXT: sarl $15, %esi ; SSE-NEXT: xorl $-32768, %esi # imm = 0x8000 -; SSE-NEXT: addw %ax, %cx -; SSE-NEXT: cmovol %esi, %ecx -; SSE-NEXT: movw %cx, (%rdx) +; SSE-NEXT: addw %cx, %ax +; SSE-NEXT: cmovol %esi, %eax +; SSE-NEXT: movw %ax, (%rdx) ; SSE-NEXT: retq ; ; AVX-LABEL: v1i16: @@ -483,9 +483,9 @@ ; AVX-NEXT: movswl %si, %esi ; AVX-NEXT: sarl $15, %esi ; AVX-NEXT: xorl $-32768, %esi # imm = 0x8000 -; AVX-NEXT: addw %ax, %cx -; AVX-NEXT: cmovol %esi, %ecx -; AVX-NEXT: movw %cx, (%rdx) +; AVX-NEXT: addw %cx, %ax +; AVX-NEXT: cmovol %esi, %eax +; AVX-NEXT: movw %ax, (%rdx) ; AVX-NEXT: retq %x = load <1 x i16>, <1 x i16>* %px %y = load <1 x i16>, <1 x i16>* %py