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


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@13558 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Chris Lattner 2004-05-13 15:26:48 +00:00
parent 9f1b531090
commit b7cb9ffd34
2 changed files with 24 additions and 6 deletions

View File

@ -1500,6 +1500,9 @@ void ISel::doCall(const ValueRecord &Ret, MachineInstr *CallMI,
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 @@ void ISel::visitStoreInst(StoreInst &I) {
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),

View File

@ -1500,6 +1500,9 @@ void ISel::doCall(const ValueRecord &Ret, MachineInstr *CallMI,
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 @@ void ISel::visitStoreInst(StoreInst &I) {
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),