* Implement cast (long|ulong) to bool

* Fix cast of (short|ushort|int|uint) to bool to work right

llvm-svn: 6510
This commit is contained in:
Chris Lattner 2003-06-01 03:38:24 +00:00
parent bf37f7de1b
commit 4536fcd57b
1 changed files with 22 additions and 4 deletions

View File

@ -1552,10 +1552,28 @@ void ISel::emitCastOperation(MachineBasicBlock *BB,
// Implement casts to bool by using compare on the operand followed by set if
// not zero on the result.
if (DestTy == Type::BoolTy) {
if (SrcClass == cFP || SrcClass == cLong)
abort(); // FIXME: implement cast (long & FP) to bool
switch (SrcClass) {
case cByte:
BMI(BB, IP, X86::TESTrr8, 2).addReg(SrcReg).addReg(SrcReg);
break;
case cShort:
BMI(BB, IP, X86::TESTrr16, 2).addReg(SrcReg).addReg(SrcReg);
break;
case cInt:
BMI(BB, IP, X86::TESTrr32, 2).addReg(SrcReg).addReg(SrcReg);
break;
case cLong: {
unsigned TmpReg = makeAnotherReg(Type::IntTy);
BMI(BB, IP, X86::ORrr32, 2, TmpReg).addReg(SrcReg).addReg(SrcReg+1);
break;
}
case cFP:
assert(0 && "FIXME: implement cast FP to bool");
abort();
}
BMI(BB, IP, X86::CMPri8, 2).addReg(SrcReg).addZImm(0);
// If the zero flag is not set, then the value is true, set the byte to
// true.
BMI(BB, IP, X86::SETNEr, 1, DestReg);
return;
}