From c686a9ab3742c72093070aea7eface4f4b2bc31b Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Mon, 1 Mar 2004 02:34:08 +0000 Subject: [PATCH] Fix a minor code-quality issue. When passing 8 and 16-bit integer constants to function calls, we would emit dead code, like this: int Y(int, short, double); int X() { Y(4, 123, 4); } --- Old X: sub %ESP, 20 mov %EAX, 4 mov DWORD PTR [%ESP], %EAX *** mov %AX, 123 mov %AX, 123 movsx %EAX, %AX mov DWORD PTR [%ESP + 4], %EAX fld QWORD PTR [.CPIX_0] fstp QWORD PTR [%ESP + 8] call Y mov %EAX, 0 # IMPLICIT_USE %EAX %ESP add %ESP, 20 ret Now we emit: X: sub %ESP, 20 mov %EAX, 4 mov DWORD PTR [%ESP], %EAX mov %AX, 123 movsx %EAX, %AX mov DWORD PTR [%ESP + 4], %EAX fld QWORD PTR [.CPIX_0] fstp QWORD PTR [%ESP + 8] call Y mov %EAX, 0 # IMPLICIT_USE %EAX %ESP add %ESP, 20 ret Next up, eliminate the mov AX and movsx entirely! llvm-svn: 12026 --- lib/Target/X86/InstSelectSimple.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/Target/X86/InstSelectSimple.cpp b/lib/Target/X86/InstSelectSimple.cpp index 0aa4ef98da6..b7796647d33 100644 --- a/lib/Target/X86/InstSelectSimple.cpp +++ b/lib/Target/X86/InstSelectSimple.cpp @@ -1098,7 +1098,7 @@ void ISel::doCall(const ValueRecord &Ret, MachineInstr *CallMI, // Arguments go on the stack in reverse order, as specified by the ABI. unsigned ArgOffset = 0; for (unsigned i = 0, e = Args.size(); i != e; ++i) { - unsigned ArgReg = Args[i].Val ? getReg(Args[i].Val) : Args[i].Reg; + unsigned ArgReg; switch (getClassB(Args[i].Ty)) { case cByte: case cShort: { @@ -1110,10 +1110,12 @@ void ISel::doCall(const ValueRecord &Ret, MachineInstr *CallMI, break; } case cInt: + ArgReg = Args[i].Val ? getReg(Args[i].Val) : Args[i].Reg; addRegOffset(BuildMI(BB, X86::MOV32mr, 5), X86::ESP, ArgOffset).addReg(ArgReg); break; case cLong: + ArgReg = Args[i].Val ? getReg(Args[i].Val) : Args[i].Reg; addRegOffset(BuildMI(BB, X86::MOV32mr, 5), X86::ESP, ArgOffset).addReg(ArgReg); addRegOffset(BuildMI(BB, X86::MOV32mr, 5), @@ -1122,6 +1124,7 @@ void ISel::doCall(const ValueRecord &Ret, MachineInstr *CallMI, break; case cFP: + ArgReg = Args[i].Val ? getReg(Args[i].Val) : Args[i].Reg; if (Args[i].Ty == Type::FloatTy) { addRegOffset(BuildMI(BB, X86::FST32m, 5), X86::ESP, ArgOffset).addReg(ArgReg);