diff --git a/llvm/lib/Target/X86/X86MCInstLower.cpp b/llvm/lib/Target/X86/X86MCInstLower.cpp --- a/llvm/lib/Target/X86/X86MCInstLower.cpp +++ b/llvm/lib/Target/X86/X86MCInstLower.cpp @@ -1337,10 +1337,10 @@ // The default C calling convention will place two arguments into %rcx and // %rdx -- so we only work with those. - unsigned DestRegs[] = {X86::RDI, X86::RSI}; + const Register DestRegs[] = {X86::RDI, X86::RSI}; bool UsedMask[] = {false, false}; // Filled out in loop. - unsigned SrcRegs[] = {0, 0}; + Register SrcRegs[] = {0, 0}; // Then we put the operands in the %rdi and %rsi registers. We spill the // values in the register before we clobber them, and mark them as used in @@ -1350,7 +1350,7 @@ for (unsigned I = 0; I < MI.getNumOperands(); ++I) if (auto Op = MCIL.LowerMachineOperand(&MI, MI.getOperand(I))) { assert(Op->isReg() && "Only support arguments in registers"); - SrcRegs[I] = Op->getReg(); + SrcRegs[I] = getX86SubSuperRegister(Op->getReg(), 64); if (SrcRegs[I] != DestRegs[I]) { UsedMask[I] = true; EmitAndCountInstruction( @@ -1361,6 +1361,9 @@ } // Now that the register values are stashed, mov arguments into place. + // FIXME: This doesn't work if one of the later SrcRegs is equal to an + // earlier DestReg. We will have already overwritten over the register before + // we can copy from it. for (unsigned I = 0; I < MI.getNumOperands(); ++I) if (SrcRegs[I] != DestRegs[I]) EmitAndCountInstruction( @@ -1429,11 +1432,11 @@ // An x86-64 convention may place three arguments into %rcx, %rdx, and R8, // so we'll work with those. Or we may be called via SystemV, in which case // we don't have to do any translation. - unsigned DestRegs[] = {X86::RDI, X86::RSI, X86::RDX}; + const Register DestRegs[] = {X86::RDI, X86::RSI, X86::RDX}; bool UsedMask[] = {false, false, false}; // Will fill out src regs in the loop. - unsigned SrcRegs[] = {0, 0, 0}; + Register SrcRegs[] = {0, 0, 0}; // Then we put the operands in the SystemV registers. We spill the values in // the registers before we clobber them, and mark them as used in UsedMask. @@ -1443,7 +1446,7 @@ if (auto Op = MCIL.LowerMachineOperand(&MI, MI.getOperand(I))) { // TODO: Is register only support adequate? assert(Op->isReg() && "Only supports arguments in registers"); - SrcRegs[I] = Op->getReg(); + SrcRegs[I] = getX86SubSuperRegister(Op->getReg(), 64); if (SrcRegs[I] != DestRegs[I]) { UsedMask[I] = true; EmitAndCountInstruction( @@ -1459,6 +1462,9 @@ // is clobbers. We've already added nops to account for the size of mov and // push if the register is in the right place, so we only have to worry about // emitting movs. + // FIXME: This doesn't work if one of the later SrcRegs is equal to an + // earlier DestReg. We will have already overwritten over the register before + // we can copy from it. for (unsigned I = 0; I < MI.getNumOperands(); ++I) if (UsedMask[I]) EmitAndCountInstruction( diff --git a/llvm/test/CodeGen/X86/xray-custom-log.ll b/llvm/test/CodeGen/X86/xray-custom-log.ll --- a/llvm/test/CodeGen/X86/xray-custom-log.ll +++ b/llvm/test/CodeGen/X86/xray-custom-log.ll @@ -13,7 +13,7 @@ ; CHECK-NEXT: pushq %rdi ; CHECK-NEXT: pushq %rsi ; CHECK-NEXT: movq %rcx, %rdi - ; CHECK-NEXT: movq %eax, %rsi + ; CHECK-NEXT: movq %rax, %rsi ; CHECK-NEXT: callq __xray_CustomEvent ; CHECK-NEXT: popq %rsi ; CHECK-NEXT: popq %rdi @@ -23,7 +23,7 @@ ; PIC-NEXT: pushq %rdi ; PIC-NEXT: pushq %rsi ; PIC-NEXT: movq %rcx, %rdi - ; PIC-NEXT: movq %eax, %rsi + ; PIC-NEXT: movq %rax, %rsi ; PIC-NEXT: callq __xray_CustomEvent@PLT ; PIC-NEXT: popq %rsi ; PIC-NEXT: popq %rdi diff --git a/llvm/test/CodeGen/X86/xray-typed-event-log.ll b/llvm/test/CodeGen/X86/xray-typed-event-log.ll --- a/llvm/test/CodeGen/X86/xray-typed-event-log.ll +++ b/llvm/test/CodeGen/X86/xray-typed-event-log.ll @@ -16,9 +16,9 @@ ; CHECK-NEXT: pushq %rdi ; CHECK-NEXT: pushq %rsi ; CHECK-NEXT: pushq %rdx - ; CHECK-NEXT: movq %dx, %rdi + ; CHECK-NEXT: movq %rdx, %rdi ; CHECK-NEXT: movq %rcx, %rsi - ; CHECK-NEXT: movq %eax, %rdx + ; CHECK-NEXT: movq %rax, %rdx ; CHECK-NEXT: callq __xray_TypedEvent ; CHECK-NEXT: popq %rdx ; CHECK-NEXT: popq %rsi @@ -29,9 +29,9 @@ ; PIC-NEXT: pushq %rdi ; PIC-NEXT: pushq %rsi ; PIC-NEXT: pushq %rdx - ; PIC-NEXT: movq %dx, %rdi + ; PIC-NEXT: movq %rdx, %rdi ; PIC-NEXT: movq %rcx, %rsi - ; PIC-NEXT: movq %eax, %rdx + ; PIC-NEXT: movq %rax, %rdx ; PIC-NEXT: callq __xray_TypedEvent@PLT ; PIC-NEXT: popq %rdx ; PIC-NEXT: popq %rsi