[llvm-commits] CVS: llvm/lib/Target/X86/InstSelectSimple.cpp
Chris Lattner
lattner at cs.uiuc.edu
Thu May 13 10:26:02 PDT 2004
Changes in directory llvm/lib/Target/X86:
InstSelectSimple.cpp updated: 1.253 -> 1.254
---
Log message:
Two more improvements for null pointer handling: storing a null pointer
and passing a null pointer into a function.
For this testcase:
void %test(int** %X) {
store int* null, int** %X
call void %test(int** null)
ret void
}
we now generate this:
test:
sub %ESP, 12
mov %EAX, DWORD PTR [%ESP + 16]
mov DWORD PTR [%EAX], 0
mov DWORD PTR [%ESP], 0
call test
add %ESP, 12
ret
instead of this:
test:
sub %ESP, 12
mov %EAX, DWORD PTR [%ESP + 16]
mov %ECX, 0
mov DWORD PTR [%EAX], %ECX
mov %EAX, 0
mov DWORD PTR [%ESP], %EAX
call test
add %ESP, 12
ret
---
Diffs of the changes: (+12 -3)
Index: llvm/lib/Target/X86/InstSelectSimple.cpp
diff -u llvm/lib/Target/X86/InstSelectSimple.cpp:1.253 llvm/lib/Target/X86/InstSelectSimple.cpp:1.254
--- llvm/lib/Target/X86/InstSelectSimple.cpp:1.253 Thu May 13 10:12:43 2004
+++ llvm/lib/Target/X86/InstSelectSimple.cpp Thu May 13 10:26:48 2004
@@ -1500,6 +1500,9 @@
unsigned Val = cast<ConstantInt>(Args[i].Val)->getRawValue();
addRegOffset(BuildMI(BB, X86::MOV32mi, 5),
X86::ESP, ArgOffset).addImm(Val);
+ } else if (Args[i].Val && isa<ConstantPointerNull>(Args[i].Val)) {
+ addRegOffset(BuildMI(BB, X86::MOV32mi, 5),
+ X86::ESP, ArgOffset).addImm(0);
} else {
ArgReg = Args[i].Val ? getReg(Args[i].Val) : Args[i].Reg;
addRegOffset(BuildMI(BB, X86::MOV32mr, 5),
@@ -2984,13 +2987,19 @@
X86::MOV8mi, X86::MOV16mi, X86::MOV32mi
};
unsigned Opcode = Opcodes[Class];
- if (AllocaFrameIdx != ~0U) {
+ if (AllocaFrameIdx != ~0U)
addFrameReference(BuildMI(BB, Opcode, 5), AllocaFrameIdx).addImm(Val);
- } else {
+ else
addFullAddress(BuildMI(BB, Opcode, 5),
BaseReg, Scale, IndexReg, Disp).addImm(Val);
- }
}
+ } else if (isa<ConstantPointerNull>(I.getOperand(0))) {
+ if (AllocaFrameIdx != ~0U)
+ addFrameReference(BuildMI(BB, X86::MOV32mi, 5), AllocaFrameIdx).addImm(0);
+ else
+ addFullAddress(BuildMI(BB, X86::MOV32mi, 5),
+ BaseReg, Scale, IndexReg, Disp).addImm(0);
+
} else if (ConstantBool *CB = dyn_cast<ConstantBool>(I.getOperand(0))) {
if (AllocaFrameIdx != ~0U)
addFrameReference(BuildMI(BB, X86::MOV8mi, 5),
More information about the llvm-commits
mailing list