case Instruction::FCmp:
return ConstantExpr::getCompare(cast<CmpInst>(I)->getPredicate(), Ops[0],
Ops[1]);
+ case Instruction::PtrToInt:
+ // If the input is a inttoptr, eliminate the pair. This requires knowing
+ // the width of a pointer, so it can't be done in ConstantExpr::getCast.
+ if (ConstantExpr *CE = dyn_cast<ConstantExpr>(Ops[0])) {
+ if (TD && CE->getOpcode() == Instruction::IntToPtr) {
+ Constant *Input = CE->getOperand(0);
+ unsigned InWidth = Input->getType()->getPrimitiveSizeInBits();
+ Constant *Mask =
+ ConstantInt::get(APInt::getLowBitsSet(InWidth,
+ TD->getPointerSizeInBits()));
+ Input = ConstantExpr::getAnd(Input, Mask);
+ // Do a zext or trunc to get to the dest size.
+ return ConstantExpr::getIntegerCast(Input, I->getType(), false);
+ }
+ }
+ // FALL THROUGH.
+ case Instruction::IntToPtr:
case Instruction::Trunc:
case Instruction::ZExt:
case Instruction::SExt:
case Instruction::SIToFP:
case Instruction::FPToUI:
case Instruction::FPToSI:
- case Instruction::PtrToInt:
- case Instruction::IntToPtr:
case Instruction::BitCast:
return ConstantExpr::getCast(Opc, Ops[0], DestTy);
case Instruction::Select:
}
const ValueName *NameVal = F->getValueName();
+ if (NameVal == 0) return false;
const char *Str = NameVal->getKeyData();
unsigned Len = NameVal->getKeyLength();
- if (Len == 0) return false;
// In these cases, the check of the length is required. We don't want to
// return true for a name like "cos\0blah" which strcmp would return equal to
Constant *
llvm::ConstantFoldCall(Function *F, Constant** Operands, unsigned NumOperands) {
const ValueName *NameVal = F->getValueName();
+ if (NameVal == 0) return 0;
const char *Str = NameVal->getKeyData();
unsigned Len = NameVal->getKeyLength();