1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-10-19 19:12:56 +02:00

Instead of blindly looking past constantexpr casts, actually constant

fold them.  This correctly truncates constants that are too large for the
destination slot and makes the code easier to understand.  This fixes PR853
and Regression/CodeGen/X86/2006-07-28-AsmPrint-Long-As-Pointer.ll

llvm-svn: 29408
This commit is contained in:
Chris Lattner 2006-07-29 01:57:19 +00:00
parent a7ee908421
commit 557d3cacbe

View File

@ -385,23 +385,29 @@ void AsmPrinter::EmitConstantValueOnly(const Constant *CV) {
break; break;
} }
case Instruction::Cast: { case Instruction::Cast: {
// Support only non-converting or widening casts for now, that is, ones // Support only foldable casts to/from pointers that can be eliminated by
// that do not involve a change in value. This assertion is really gross, // changing the pointer to the appropriately sized integer type.
// and may not even be a complete check.
Constant *Op = CE->getOperand(0); Constant *Op = CE->getOperand(0);
const Type *OpTy = Op->getType(), *Ty = CE->getType(); const Type *OpTy = Op->getType(), *Ty = CE->getType();
// Remember, kids, pointers can be losslessly converted back and forth // Handle casts to pointers by changing them into casts to the appropriate
// into 32-bit or wider integers, regardless of signedness. :-P // integer type. This promotes constant folding and simplifies this code.
assert(((isa<PointerType>(OpTy) if (isa<PointerType>(Ty)) {
&& (Ty == Type::LongTy || Ty == Type::ULongTy const Type *IntPtrTy = TD->getIntPtrType();
|| Ty == Type::IntTy || Ty == Type::UIntTy)) Op = ConstantExpr::getCast(Op, IntPtrTy);
|| (isa<PointerType>(Ty) return EmitConstantValueOnly(Op);
&& (OpTy == Type::LongTy || OpTy == Type::ULongTy }
|| OpTy == Type::IntTy || OpTy == Type::UIntTy))
|| (((TD->getTypeSize(Ty) >= TD->getTypeSize(OpTy)) // We know the dest type is not a pointer. Is the src value a pointer or
&& OpTy->isLosslesslyConvertibleTo(Ty)))) // integral?
&& "FIXME: Don't yet support this kind of constant cast expr"); if (isa<PointerType>(OpTy) || OpTy->isIntegral()) {
// We can emit the pointer value into this slot if the slot is an
// integer slot greater or equal to the size of the pointer.
if (Ty->isIntegral() && TD->getTypeSize(Ty) >= TD->getTypeSize(OpTy))
return EmitConstantValueOnly(Op);
}
assert(0 && "FIXME: Don't yet support this kind of constant cast expr");
EmitConstantValueOnly(Op); EmitConstantValueOnly(Op);
break; break;
} }