mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-02-09 13:33:17 +00:00
Replace inferred getCast(V,Ty) calls with more strict variants.
Rename getZeroExtend and getSignExtend to getZExt and getSExt to match the the casting mnemonics in the rest of LLVM. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@32514 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
ebc0922eeb
commit
d977d8651a
@ -514,18 +514,18 @@ public:
|
||||
|
||||
/// Cast constant expr
|
||||
///
|
||||
static Constant *getTrunc (Constant *C, const Type *Ty);
|
||||
static Constant *getSignExtend (Constant *C, const Type *Ty);
|
||||
static Constant *getZeroExtend (Constant *C, const Type *Ty);
|
||||
static Constant *getFPTrunc (Constant *C, const Type *Ty);
|
||||
static Constant *getFPExtend (Constant *C, const Type *Ty);
|
||||
static Constant *getUIToFP (Constant *C, const Type *Ty);
|
||||
static Constant *getSIToFP (Constant *C, const Type *Ty);
|
||||
static Constant *getFPToUI (Constant *C, const Type *Ty);
|
||||
static Constant *getFPToSI (Constant *C, const Type *Ty);
|
||||
static Constant *getPtrToInt (Constant *C, const Type *Ty);
|
||||
static Constant *getIntToPtr (Constant *C, const Type *Ty);
|
||||
static Constant *getBitCast (Constant *C, const Type *Ty);
|
||||
static Constant *getTrunc (Constant *C, const Type *Ty);
|
||||
static Constant *getSExt (Constant *C, const Type *Ty);
|
||||
static Constant *getZExt (Constant *C, const Type *Ty);
|
||||
static Constant *getFPTrunc (Constant *C, const Type *Ty);
|
||||
static Constant *getFPExtend(Constant *C, const Type *Ty);
|
||||
static Constant *getUIToFP (Constant *C, const Type *Ty);
|
||||
static Constant *getSIToFP (Constant *C, const Type *Ty);
|
||||
static Constant *getFPToUI (Constant *C, const Type *Ty);
|
||||
static Constant *getFPToSI (Constant *C, const Type *Ty);
|
||||
static Constant *getPtrToInt(Constant *C, const Type *Ty);
|
||||
static Constant *getIntToPtr(Constant *C, const Type *Ty);
|
||||
static Constant *getBitCast (Constant *C, const Type *Ty);
|
||||
|
||||
// @brief Convenience function for getting one of the casting operations
|
||||
// using a CastOps opcode.
|
||||
|
@ -459,11 +459,11 @@ static bool IndexOperandsEqual(Value *V1, Value *V2) {
|
||||
if (Constant *C2 = dyn_cast<Constant>(V2)) {
|
||||
// Sign extend the constants to long types, if necessary
|
||||
if (C1->getType()->getPrimitiveSizeInBits() < 64)
|
||||
C1 = ConstantExpr::getSignExtend(C1, Type::LongTy);
|
||||
C1 = ConstantExpr::getSExt(C1, Type::LongTy);
|
||||
else if (C1->getType() == Type::ULongTy)
|
||||
C1 = ConstantExpr::getBitCast(C1, Type::LongTy);
|
||||
if (C2->getType()->getPrimitiveSizeInBits() < 64)
|
||||
C2 = ConstantExpr::getSignExtend(C2, Type::LongTy);
|
||||
C2 = ConstantExpr::getSExt(C2, Type::LongTy);
|
||||
else if (C2->getType() == Type::ULongTy)
|
||||
C2 = ConstantExpr::getBitCast(C2, Type::LongTy);
|
||||
return C1 == C2;
|
||||
@ -555,11 +555,11 @@ BasicAliasAnalysis::CheckGEPInstructions(
|
||||
if (G1OC->getType() != G2OC->getType()) {
|
||||
// Sign extend both operands to long.
|
||||
if (G1OC->getType()->getPrimitiveSizeInBits() < 64)
|
||||
G1OC = ConstantExpr::getSignExtend(G1OC, Type::LongTy);
|
||||
G1OC = ConstantExpr::getSExt(G1OC, Type::LongTy);
|
||||
else if (G1OC->getType() == Type::ULongTy)
|
||||
G1OC = ConstantExpr::getBitCast(G1OC, Type::LongTy);
|
||||
if (G2OC->getType()->getPrimitiveSizeInBits() < 64)
|
||||
G2OC = ConstantExpr::getSignExtend(G2OC, Type::LongTy);
|
||||
G2OC = ConstantExpr::getSExt(G2OC, Type::LongTy);
|
||||
else if (G2OC->getType() == Type::ULongTy)
|
||||
G2OC = ConstantExpr::getBitCast(G2OC, Type::LongTy);
|
||||
GEP1Ops[FirstConstantOper] = G1OC;
|
||||
|
@ -340,8 +340,8 @@ ConstantRange ConstantRange::zeroExtend(const Type *Ty) const {
|
||||
Constant *Lower = getLower();
|
||||
Constant *Upper = getUpper();
|
||||
|
||||
return ConstantRange(ConstantExpr::getCast(Instruction::ZExt, Lower, Ty),
|
||||
ConstantExpr::getCast(Instruction::ZExt, Upper, Ty));
|
||||
return ConstantRange(ConstantExpr::getZExt(Lower, Ty),
|
||||
ConstantExpr::getZExt(Upper, Ty));
|
||||
}
|
||||
|
||||
/// truncate - Return a new range in the specified integer type, which must be
|
||||
@ -356,8 +356,8 @@ ConstantRange ConstantRange::truncate(const Type *Ty) const {
|
||||
return ConstantRange(getType());
|
||||
|
||||
return ConstantRange(
|
||||
ConstantExpr::getCast(Instruction::Trunc, getLower(), Ty),
|
||||
ConstantExpr::getCast(Instruction::Trunc, getUpper(), Ty));
|
||||
ConstantExpr::getTrunc(getLower(), Ty),
|
||||
ConstantExpr::getTrunc(getUpper(), Ty));
|
||||
}
|
||||
|
||||
|
||||
|
@ -584,7 +584,7 @@ SCEVHandle SCEVTruncateExpr::get(const SCEVHandle &Op, const Type *Ty) {
|
||||
SCEVHandle SCEVZeroExtendExpr::get(const SCEVHandle &Op, const Type *Ty) {
|
||||
if (SCEVConstant *SC = dyn_cast<SCEVConstant>(Op))
|
||||
return SCEVUnknown::get(
|
||||
ConstantExpr::getZeroExtend(SC->getValue(), Ty));
|
||||
ConstantExpr::getZExt(SC->getValue(), Ty));
|
||||
|
||||
// FIXME: If the input value is a chrec scev, and we can prove that the value
|
||||
// did not overflow the old, smaller, value, we can zero extend all of the
|
||||
@ -2000,11 +2000,14 @@ SCEVHandle ScalarEvolutionsImpl::getSCEVAtScope(SCEV *V, const Loop *L) {
|
||||
} else {
|
||||
SCEVHandle OpV = getSCEVAtScope(getSCEV(Op), L);
|
||||
if (SCEVConstant *SC = dyn_cast<SCEVConstant>(OpV))
|
||||
Operands.push_back(ConstantExpr::getCast(SC->getValue(),
|
||||
Op->getType()));
|
||||
Operands.push_back(ConstantExpr::getIntegerCast(SC->getValue(),
|
||||
Op->getType(),
|
||||
false));
|
||||
else if (SCEVUnknown *SU = dyn_cast<SCEVUnknown>(OpV)) {
|
||||
if (Constant *C = dyn_cast<Constant>(SU->getValue()))
|
||||
Operands.push_back(ConstantExpr::getCast(C, Op->getType()));
|
||||
Operands.push_back(ConstantExpr::getIntegerCast(C,
|
||||
Op->getType(),
|
||||
false));
|
||||
else
|
||||
return V;
|
||||
} else {
|
||||
@ -2122,7 +2125,7 @@ SolveQuadraticEquation(const SCEVAddRecExpr *AddRec) {
|
||||
|
||||
// Compute floor(sqrt(B^2-4ac))
|
||||
ConstantInt *SqrtVal =
|
||||
cast<ConstantInt>(ConstantExpr::getCast(SqrtTerm,
|
||||
cast<ConstantInt>(ConstantExpr::getBitCast(SqrtTerm,
|
||||
SqrtTerm->getType()->getUnsignedVersion()));
|
||||
uint64_t SqrtValV = SqrtVal->getZExtValue();
|
||||
uint64_t SqrtValV2 = (uint64_t)sqrt((double)SqrtValV);
|
||||
@ -2135,16 +2138,16 @@ SolveQuadraticEquation(const SCEVAddRecExpr *AddRec) {
|
||||
}
|
||||
|
||||
SqrtVal = ConstantInt::get(Type::ULongTy, SqrtValV2);
|
||||
SqrtTerm = ConstantExpr::getCast(SqrtVal, SqrtTerm->getType());
|
||||
SqrtTerm = ConstantExpr::getTruncOrBitCast(SqrtVal, SqrtTerm->getType());
|
||||
|
||||
Constant *NegB = ConstantExpr::getNeg(B);
|
||||
Constant *TwoA = ConstantExpr::getMul(A, Two);
|
||||
|
||||
// The divisions must be performed as signed divisions.
|
||||
const Type *SignedTy = NegB->getType()->getSignedVersion();
|
||||
NegB = ConstantExpr::getCast(NegB, SignedTy);
|
||||
TwoA = ConstantExpr::getCast(TwoA, SignedTy);
|
||||
SqrtTerm = ConstantExpr::getCast(SqrtTerm, SignedTy);
|
||||
NegB = ConstantExpr::getBitCast(NegB, SignedTy);
|
||||
TwoA = ConstantExpr::getBitCast(TwoA, SignedTy);
|
||||
SqrtTerm = ConstantExpr::getBitCast(SqrtTerm, SignedTy);
|
||||
|
||||
Constant *Solution1 =
|
||||
ConstantExpr::getSDiv(ConstantExpr::getAdd(NegB, SqrtTerm), TwoA);
|
||||
|
@ -20,9 +20,27 @@ using namespace llvm;
|
||||
/// InsertCastOfTo - Insert a cast of V to the specified type, doing what
|
||||
/// we can to share the casts.
|
||||
Value *SCEVExpander::InsertCastOfTo(Value *V, const Type *Ty) {
|
||||
// Compute the Cast opcode to use
|
||||
Instruction::CastOps opcode = Instruction::BitCast;
|
||||
if (Ty->isIntegral()) {
|
||||
if (V->getType()->getTypeID() == Type::PointerTyID)
|
||||
opcode = Instruction::PtrToInt;
|
||||
else {
|
||||
unsigned SrcBits = V->getType()->getPrimitiveSizeInBits();
|
||||
unsigned DstBits = Ty->getPrimitiveSizeInBits();
|
||||
opcode = (SrcBits > DstBits ? Instruction::Trunc :
|
||||
(SrcBits == DstBits ? Instruction::BitCast :
|
||||
(V->getType()->isSigned() ? Instruction::SExt :
|
||||
Instruction::ZExt)));
|
||||
}
|
||||
} else if (Ty->isFloatingPoint())
|
||||
opcode = Instruction::UIToFP;
|
||||
else if (Ty->getTypeID() == Type::PointerTyID && V->getType()->isIntegral())
|
||||
opcode = Instruction::IntToPtr;
|
||||
|
||||
// FIXME: keep track of the cast instruction.
|
||||
if (Constant *C = dyn_cast<Constant>(V))
|
||||
return ConstantExpr::getCast(C, Ty);
|
||||
return ConstantExpr::getCast(opcode, C, Ty);
|
||||
|
||||
if (Argument *A = dyn_cast<Argument>(V)) {
|
||||
// Check to see if there is already a cast!
|
||||
@ -38,8 +56,8 @@ Value *SCEVExpander::InsertCastOfTo(Value *V, const Type *Ty) {
|
||||
return CI;
|
||||
}
|
||||
}
|
||||
return CastInst::createInferredCast(
|
||||
V, Ty, V->getName(), A->getParent()->getEntryBlock().begin());
|
||||
return CastInst::create(opcode, V, Ty, V->getName(),
|
||||
A->getParent()->getEntryBlock().begin());
|
||||
}
|
||||
|
||||
Instruction *I = cast<Instruction>(V);
|
||||
@ -64,7 +82,7 @@ Value *SCEVExpander::InsertCastOfTo(Value *V, const Type *Ty) {
|
||||
if (InvokeInst *II = dyn_cast<InvokeInst>(I))
|
||||
IP = II->getNormalDest()->begin();
|
||||
while (isa<PHINode>(IP)) ++IP;
|
||||
return CastInst::createInferredCast(V, Ty, V->getName(), IP);
|
||||
return CastInst::create(opcode, V, Ty, V->getName(), IP);
|
||||
}
|
||||
|
||||
Value *SCEVExpander::visitMulExpr(SCEVMulExpr *S) {
|
||||
|
@ -340,8 +340,8 @@ ConstantRange ConstantRange::zeroExtend(const Type *Ty) const {
|
||||
Constant *Lower = getLower();
|
||||
Constant *Upper = getUpper();
|
||||
|
||||
return ConstantRange(ConstantExpr::getCast(Instruction::ZExt, Lower, Ty),
|
||||
ConstantExpr::getCast(Instruction::ZExt, Upper, Ty));
|
||||
return ConstantRange(ConstantExpr::getZExt(Lower, Ty),
|
||||
ConstantExpr::getZExt(Upper, Ty));
|
||||
}
|
||||
|
||||
/// truncate - Return a new range in the specified integer type, which must be
|
||||
@ -356,8 +356,8 @@ ConstantRange ConstantRange::truncate(const Type *Ty) const {
|
||||
return ConstantRange(getType());
|
||||
|
||||
return ConstantRange(
|
||||
ConstantExpr::getCast(Instruction::Trunc, getLower(), Ty),
|
||||
ConstantExpr::getCast(Instruction::Trunc, getUpper(), Ty));
|
||||
ConstantExpr::getTrunc(getLower(), Ty),
|
||||
ConstantExpr::getTrunc(getUpper(), Ty));
|
||||
}
|
||||
|
||||
|
||||
|
@ -708,8 +708,8 @@ static GlobalVariable *OptimizeGlobalAddressOfMalloc(GlobalVariable *GV,
|
||||
|
||||
Constant *RepValue = NewGV;
|
||||
if (NewGV->getType() != GV->getType()->getElementType())
|
||||
RepValue = ConstantExpr::getCast(Instruction::BitCast,
|
||||
RepValue, GV->getType()->getElementType());
|
||||
RepValue = ConstantExpr::getBitCast(RepValue,
|
||||
GV->getType()->getElementType());
|
||||
|
||||
// If there is a comparison against null, we will insert a global bool to
|
||||
// keep track of whether the global was initialized yet or not.
|
||||
@ -1058,8 +1058,7 @@ static bool OptimizeOnceStoredGlobal(GlobalVariable *GV, Value *StoredOnceVal,
|
||||
GV->getInitializer()->isNullValue()) {
|
||||
if (Constant *SOVC = dyn_cast<Constant>(StoredOnceVal)) {
|
||||
if (GV->getInitializer()->getType() != SOVC->getType())
|
||||
SOVC = ConstantExpr::getCast(Instruction::BitCast,
|
||||
SOVC, GV->getInitializer()->getType());
|
||||
SOVC = ConstantExpr::getBitCast(SOVC, GV->getInitializer()->getType());
|
||||
|
||||
// Optimize away any trapping uses of the loaded value.
|
||||
if (OptimizeAwayTrappingUsesOfLoads(GV, SOVC))
|
||||
@ -1510,7 +1509,7 @@ static GlobalVariable *InstallGlobalCtors(GlobalVariable *GCL,
|
||||
if (!GCL->use_empty()) {
|
||||
Constant *V = NGV;
|
||||
if (V->getType() != GCL->getType())
|
||||
V = ConstantExpr::getCast(Instruction::BitCast, V, GCL->getType());
|
||||
V = ConstantExpr::getBitCast(V, GCL->getType());
|
||||
GCL->replaceAllUsesWith(V);
|
||||
}
|
||||
GCL->eraseFromParent();
|
||||
|
@ -1792,8 +1792,7 @@ FoundSExt:
|
||||
case 8: MiddleType = Type::SByteTy; break;
|
||||
}
|
||||
if (MiddleType) {
|
||||
Instruction *NewTrunc =
|
||||
CastInst::createInferredCast(XorLHS, MiddleType, "sext");
|
||||
Instruction *NewTrunc = new TruncInst(XorLHS, MiddleType, "sext");
|
||||
InsertNewInstBefore(NewTrunc, I);
|
||||
return new SExtInst(NewTrunc, I.getType());
|
||||
}
|
||||
@ -3097,16 +3096,12 @@ Instruction *InstCombiner::visitAnd(BinaryOperator &I) {
|
||||
// into : and (cast X to T), trunc_or_bitcast(C1)&C2
|
||||
// This will fold the two constants together, which may allow
|
||||
// other simplifications.
|
||||
Instruction *NewCast =
|
||||
CastInst::createInferredCast(CastOp->getOperand(0), I.getType(),
|
||||
CastOp->getName()+".shrunk");
|
||||
Instruction *NewCast = CastInst::createTruncOrBitCast(
|
||||
CastOp->getOperand(0), I.getType(),
|
||||
CastOp->getName()+".shrunk");
|
||||
NewCast = InsertNewInstBefore(NewCast, I);
|
||||
// trunc_or_bitcast(C1)&C2
|
||||
Instruction::CastOps opc = (
|
||||
AndCI->getType()->getPrimitiveSizeInBits() ==
|
||||
I.getType()->getPrimitiveSizeInBits() ?
|
||||
Instruction::BitCast : Instruction::Trunc);
|
||||
Constant *C3 = ConstantExpr::getCast(opc, AndCI, I.getType());
|
||||
Constant *C3 = ConstantExpr::getTruncOrBitCast(AndCI,I.getType());
|
||||
C3 = ConstantExpr::getAnd(C3, AndRHS);
|
||||
return BinaryOperator::createAnd(NewCast, C3);
|
||||
} else if (CastOp->getOpcode() == Instruction::Or) {
|
||||
@ -3286,7 +3281,8 @@ Instruction *InstCombiner::visitAnd(BinaryOperator &I) {
|
||||
Op1C->getOperand(0),
|
||||
I.getName());
|
||||
InsertNewInstBefore(NewOp, I);
|
||||
return CastInst::createInferredCast(NewOp, I.getType());
|
||||
return CastInst::createIntegerCast(NewOp, I.getType(),
|
||||
SrcTy->isSigned());
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -3690,7 +3686,8 @@ Instruction *InstCombiner::visitOr(BinaryOperator &I) {
|
||||
Op1C->getOperand(0),
|
||||
I.getName());
|
||||
InsertNewInstBefore(NewOp, I);
|
||||
return CastInst::createInferredCast(NewOp, I.getType());
|
||||
return CastInst::createIntegerCast(NewOp, I.getType(),
|
||||
SrcTy->isSigned());
|
||||
}
|
||||
}
|
||||
|
||||
@ -3871,7 +3868,8 @@ Instruction *InstCombiner::visitXor(BinaryOperator &I) {
|
||||
Op1C->getOperand(0),
|
||||
I.getName());
|
||||
InsertNewInstBefore(NewOp, I);
|
||||
return CastInst::createInferredCast(NewOp, I.getType());
|
||||
return CastInst::createIntegerCast(NewOp, I.getType(),
|
||||
SrcTy->isSigned());
|
||||
}
|
||||
}
|
||||
|
||||
@ -3947,7 +3945,7 @@ static Value *EmitGEPOffset(User *GEP, Instruction &I, InstCombiner &IC) {
|
||||
}
|
||||
} else {
|
||||
// Convert to correct type.
|
||||
Op = IC.InsertNewInstBefore(CastInst::createInferredCast(Op, SIntPtrTy,
|
||||
Op = IC.InsertNewInstBefore(CastInst::createSExtOrBitCast(Op, SIntPtrTy,
|
||||
Op->getName()+".c"), I);
|
||||
if (Size != 1)
|
||||
// We'll let instcombine(mul) convert this to a shl if possible.
|
||||
@ -4944,8 +4942,7 @@ Instruction *InstCombiner::visitSetCondInst(SetCondInst &I) {
|
||||
// If Op1 is a constant, we can fold the cast into the constant.
|
||||
if (Op1->getType() != Op0->getType())
|
||||
if (Constant *Op1C = dyn_cast<Constant>(Op1)) {
|
||||
Op1 = ConstantExpr::getCast(Instruction::BitCast, Op1C,
|
||||
Op0->getType());
|
||||
Op1 = ConstantExpr::getBitCast(Op1C, Op0->getType());
|
||||
} else {
|
||||
// Otherwise, cast the RHS right before the setcc
|
||||
Op1 = InsertCastBefore(Instruction::BitCast, Op1, Op0->getType(), I);
|
||||
@ -5392,8 +5389,7 @@ Instruction *InstCombiner::FoldShiftByConstant(Value *Op0, ConstantInt *Op1,
|
||||
|
||||
Value *Op = ShiftOp->getOperand(0);
|
||||
if (isShiftOfSignedShift != isSignedShift)
|
||||
Op = InsertNewInstBefore(
|
||||
CastInst::createInferredCast(Op, I.getType(), "tmp"), I);
|
||||
Op = InsertNewInstBefore(new BitCastInst(Op, I.getType(), "tmp"), I);
|
||||
ShiftInst *ShiftResult = new ShiftInst(I.getOpcode(), Op,
|
||||
ConstantInt::get(Type::UByteTy, Amt));
|
||||
if (I.getType() == ShiftResult->getType())
|
||||
@ -5681,7 +5677,7 @@ static bool CanEvaluateInDifferentType(Value *V, const Type *Ty,
|
||||
/// evaluate the expression.
|
||||
Value *InstCombiner::EvaluateInDifferentType(Value *V, const Type *Ty) {
|
||||
if (Constant *C = dyn_cast<Constant>(V))
|
||||
return ConstantExpr::getCast(C, Ty);
|
||||
return ConstantExpr::getIntegerCast(C, Ty, C->getType()->isSigned());
|
||||
|
||||
// Otherwise, it must be an instruction.
|
||||
Instruction *I = cast<Instruction>(V);
|
||||
@ -5990,7 +5986,7 @@ Instruction *InstCombiner::commonIntCastTransforms(CastInst &CI) {
|
||||
// (X&4) == 2 --> false
|
||||
// (X&4) != 2 --> true
|
||||
Constant *Res = ConstantBool::get(isSetNE);
|
||||
Res = ConstantExpr::getZeroExtend(Res, CI.getType());
|
||||
Res = ConstantExpr::getZExt(Res, CI.getType());
|
||||
return ReplaceInstUsesWith(CI, Res);
|
||||
}
|
||||
|
||||
@ -6014,7 +6010,7 @@ Instruction *InstCombiner::commonIntCastTransforms(CastInst &CI) {
|
||||
if (CI.getType() == In->getType())
|
||||
return ReplaceInstUsesWith(CI, In);
|
||||
else
|
||||
return CastInst::createInferredCast(In, CI.getType());
|
||||
return CastInst::createIntegerCast(In, CI.getType(), false/*ZExt*/);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -6090,9 +6086,6 @@ Instruction *InstCombiner::visitZExt(CastInst &CI) {
|
||||
|
||||
// If this is a cast of a cast
|
||||
if (CastInst *CSrc = dyn_cast<CastInst>(Src)) { // A->B->C cast
|
||||
// If the operand of the ZEXT is a TRUNC then we are dealing with integral
|
||||
// types and we can convert this to a logical AND if the sizes are just
|
||||
// right. This will be much cheaper than the pair of casts.
|
||||
// If this is a TRUNC followed by a ZEXT then we are dealing with integral
|
||||
// types and if the sizes are just right we can convert this into a logical
|
||||
// 'and' which will be much cheaper than the pair of casts.
|
||||
@ -6113,7 +6106,7 @@ Instruction *InstCombiner::visitZExt(CastInst &CI) {
|
||||
if (And->getType() != CI.getType()) {
|
||||
And->setName(CSrc->getName()+".mask");
|
||||
InsertNewInstBefore(And, CI);
|
||||
And = CastInst::createInferredCast(And, CI.getType());
|
||||
And = CastInst::createIntegerCast(And, CI.getType(), false/*ZExt*/);
|
||||
}
|
||||
return And;
|
||||
}
|
||||
@ -7770,7 +7763,7 @@ static Instruction *InstCombineLoadCast(InstCombiner &IC, LoadInst &LI) {
|
||||
CI->getName(),
|
||||
LI.isVolatile()),LI);
|
||||
// Now cast the result of the load.
|
||||
return CastInst::createInferredCast(NewLoad, LI.getType());
|
||||
return new BitCastInst(NewLoad, LI.getType());
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -7950,13 +7943,20 @@ static Instruction *InstCombineStoreToCast(InstCombiner &IC, StoreInst &SI) {
|
||||
// the same size. Instead of casting the pointer before the store, cast
|
||||
// the value to be stored.
|
||||
Value *NewCast;
|
||||
if (Constant *C = dyn_cast<Constant>(SI.getOperand(0)))
|
||||
NewCast = ConstantExpr::getCast(C, SrcPTy);
|
||||
Instruction::CastOps opcode = Instruction::BitCast;
|
||||
Value *SIOp0 = SI.getOperand(0);
|
||||
if (SrcPTy->getTypeID() == Type::PointerTyID) {
|
||||
if (SIOp0->getType()->isIntegral())
|
||||
opcode = Instruction::IntToPtr;
|
||||
} else if (SrcPTy->isIntegral()) {
|
||||
if (SIOp0->getType()->getTypeID() == Type::PointerTyID)
|
||||
opcode = Instruction::PtrToInt;
|
||||
}
|
||||
if (Constant *C = dyn_cast<Constant>(SIOp0))
|
||||
NewCast = ConstantExpr::getCast(opcode, C, SrcPTy);
|
||||
else
|
||||
NewCast = IC.InsertNewInstBefore(
|
||||
CastInst::createInferredCast(SI.getOperand(0), SrcPTy,
|
||||
SI.getOperand(0)->getName()+".c"), SI);
|
||||
|
||||
CastInst::create(opcode, SIOp0, SrcPTy, SIOp0->getName()+".c"), SI);
|
||||
return new StoreInst(NewCast, CastOp);
|
||||
}
|
||||
}
|
||||
|
@ -743,8 +743,7 @@ static Constant *CastConstantPacked(ConstantPacked *CP,
|
||||
(SrcEltTy->isFloatingPoint() && DstEltTy->isFloatingPoint())) {
|
||||
for (unsigned i = 0; i != SrcNumElts; ++i)
|
||||
Result.push_back(
|
||||
ConstantExpr::getCast(Instruction::BitCast, CP->getOperand(i),
|
||||
DstEltTy));
|
||||
ConstantExpr::getBitCast(CP->getOperand(i), DstEltTy));
|
||||
return ConstantPacked::get(Result);
|
||||
}
|
||||
|
||||
@ -1148,11 +1147,11 @@ static int IdxCompare(Constant *C1, Constant *C2, const Type *ElTy) {
|
||||
// Ok, we have two differing integer indices. Sign extend them to be the same
|
||||
// type. Long is always big enough, so we use it.
|
||||
if (C1->getType() != Type::LongTy && C1->getType() != Type::ULongTy)
|
||||
C1 = ConstantExpr::getSignExtend(C1, Type::LongTy);
|
||||
C1 = ConstantExpr::getSExt(C1, Type::LongTy);
|
||||
else
|
||||
C1 = ConstantExpr::getBitCast(C1, Type::LongTy);
|
||||
if (C2->getType() != Type::LongTy && C1->getType() != Type::ULongTy)
|
||||
C2 = ConstantExpr::getSignExtend(C2, Type::LongTy);
|
||||
C2 = ConstantExpr::getSExt(C2, Type::LongTy);
|
||||
else
|
||||
C2 = ConstantExpr::getBitCast(C2, Type::LongTy);
|
||||
|
||||
@ -1672,7 +1671,7 @@ Constant *llvm::ConstantFoldGetElementPtr(const Constant *C,
|
||||
R = ConstantExpr::getSExtOrBitCast(R, Idx0->getType());
|
||||
R = ConstantExpr::getMul(R, Idx0); // signed multiply
|
||||
// R is a signed integer, C is the GEP pointer so -> IntToPtr
|
||||
return ConstantExpr::getCast(Instruction::IntToPtr, R, C->getType());
|
||||
return ConstantExpr::getIntToPtr(R, C->getType());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1391,8 +1391,8 @@ namespace llvm {
|
||||
case Instruction::PtrToInt:
|
||||
case Instruction::IntToPtr:
|
||||
case Instruction::BitCast:
|
||||
New = ConstantExpr::getCast(
|
||||
OldC->getOpcode(), OldC->getOperand(0), NewTy);
|
||||
New = ConstantExpr::getCast(OldC->getOpcode(), OldC->getOperand(0),
|
||||
NewTy);
|
||||
break;
|
||||
case Instruction::Select:
|
||||
New = ConstantExpr::getSelectTy(NewTy, OldC->getOperand(0),
|
||||
@ -1464,8 +1464,8 @@ Constant *ConstantExpr::getCast(unsigned oc, Constant *C, const Type *Ty) {
|
||||
assert(0 && "Invalid cast opcode");
|
||||
break;
|
||||
case Instruction::Trunc: return getTrunc(C, Ty);
|
||||
case Instruction::ZExt: return getZeroExtend(C, Ty);
|
||||
case Instruction::SExt: return getSignExtend(C, Ty);
|
||||
case Instruction::ZExt: return getZExt(C, Ty);
|
||||
case Instruction::SExt: return getSExt(C, Ty);
|
||||
case Instruction::FPTrunc: return getFPTrunc(C, Ty);
|
||||
case Instruction::FPExt: return getFPExtend(C, Ty);
|
||||
case Instruction::UIToFP: return getUIToFP(C, Ty);
|
||||
@ -1547,7 +1547,7 @@ Constant *ConstantExpr::getTrunc(Constant *C, const Type *Ty) {
|
||||
return getFoldedCast(Instruction::Trunc, C, Ty);
|
||||
}
|
||||
|
||||
Constant *ConstantExpr::getSignExtend(Constant *C, const Type *Ty) {
|
||||
Constant *ConstantExpr::getSExt(Constant *C, const Type *Ty) {
|
||||
assert(C->getType()->isIntegral() && "SEXt operand must be integral");
|
||||
assert(Ty->isInteger() && "SExt produces only integer");
|
||||
assert(C->getType()->getPrimitiveSizeInBits() < Ty->getPrimitiveSizeInBits()&&
|
||||
@ -1556,7 +1556,7 @@ Constant *ConstantExpr::getSignExtend(Constant *C, const Type *Ty) {
|
||||
return getFoldedCast(Instruction::SExt, C, Ty);
|
||||
}
|
||||
|
||||
Constant *ConstantExpr::getZeroExtend(Constant *C, const Type *Ty) {
|
||||
Constant *ConstantExpr::getZExt(Constant *C, const Type *Ty) {
|
||||
assert(C->getType()->isIntegral() && "ZEXt operand must be integral");
|
||||
assert(Ty->isInteger() && "ZExt produces only integer");
|
||||
assert(C->getType()->getPrimitiveSizeInBits() < Ty->getPrimitiveSizeInBits()&&
|
||||
|
Loading…
x
Reference in New Issue
Block a user