mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-05-24 18:38:50 +00:00
Change inferred casts to explicit casts.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@32165 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
56667123b7
commit
575d95ce37
@ -115,12 +115,18 @@ namespace llvm {
|
|||||||
|
|
||||||
Value *visitTruncateExpr(SCEVTruncateExpr *S) {
|
Value *visitTruncateExpr(SCEVTruncateExpr *S) {
|
||||||
Value *V = expand(S->getOperand());
|
Value *V = expand(S->getOperand());
|
||||||
return CastInst::createInferredCast(V, S->getType(), "tmp.", InsertPt);
|
Instruction::CastOps Opcode = (V->getType()->getPrimitiveSizeInBits() ==
|
||||||
|
S->getType()->getPrimitiveSizeInBits()) ? Instruction::BitCast :
|
||||||
|
Instruction::Trunc;
|
||||||
|
return CastInst::create(Opcode, V, S->getType(), "tmp.", InsertPt);
|
||||||
}
|
}
|
||||||
|
|
||||||
Value *visitZeroExtendExpr(SCEVZeroExtendExpr *S) {
|
Value *visitZeroExtendExpr(SCEVZeroExtendExpr *S) {
|
||||||
Value *V = expandInTy(S->getOperand(),S->getType()->getUnsignedVersion());
|
Value *V = expandInTy(S->getOperand(),S->getType()->getUnsignedVersion());
|
||||||
return CastInst::createInferredCast(V, S->getType(), "tmp.", InsertPt);
|
Instruction::CastOps Opcode = (V->getType()->getPrimitiveSizeInBits() ==
|
||||||
|
S->getType()->getPrimitiveSizeInBits()) ? Instruction::BitCast :
|
||||||
|
Instruction::ZExt;
|
||||||
|
return CastInst::create(Opcode, V, S->getType(), "tmp.", InsertPt);
|
||||||
}
|
}
|
||||||
|
|
||||||
Value *visitAddExpr(SCEVAddExpr *S) {
|
Value *visitAddExpr(SCEVAddExpr *S) {
|
||||||
|
@ -293,14 +293,9 @@ ConstantRange ConstantRange::zeroExtend(const Type *Ty) const {
|
|||||||
|
|
||||||
Constant *Lower = getLower();
|
Constant *Lower = getLower();
|
||||||
Constant *Upper = getUpper();
|
Constant *Upper = getUpper();
|
||||||
if (Lower->getType()->isInteger() && !Lower->getType()->isUnsigned()) {
|
|
||||||
// Ensure we are doing a ZERO extension even if the input range is signed.
|
|
||||||
Lower = ConstantExpr::getCast(Lower, Ty->getUnsignedVersion());
|
|
||||||
Upper = ConstantExpr::getCast(Upper, Ty->getUnsignedVersion());
|
|
||||||
}
|
|
||||||
|
|
||||||
return ConstantRange(ConstantExpr::getCast(Lower, Ty),
|
return ConstantRange(ConstantExpr::getCast(Instruction::ZExt, Lower, Ty),
|
||||||
ConstantExpr::getCast(Upper, Ty));
|
ConstantExpr::getCast(Instruction::ZExt, Upper, Ty));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// truncate - Return a new range in the specified integer type, which must be
|
/// truncate - Return a new range in the specified integer type, which must be
|
||||||
@ -314,8 +309,9 @@ ConstantRange ConstantRange::truncate(const Type *Ty) const {
|
|||||||
if (isFullSet() || getSetSize() >= Size)
|
if (isFullSet() || getSetSize() >= Size)
|
||||||
return ConstantRange(getType());
|
return ConstantRange(getType());
|
||||||
|
|
||||||
return ConstantRange(ConstantExpr::getCast(getLower(), Ty),
|
return ConstantRange(
|
||||||
ConstantExpr::getCast(getUpper(), Ty));
|
ConstantExpr::getCast(Instruction::Trunc, getLower(), Ty),
|
||||||
|
ConstantExpr::getCast(Instruction::Trunc, getUpper(), Ty));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -293,14 +293,9 @@ ConstantRange ConstantRange::zeroExtend(const Type *Ty) const {
|
|||||||
|
|
||||||
Constant *Lower = getLower();
|
Constant *Lower = getLower();
|
||||||
Constant *Upper = getUpper();
|
Constant *Upper = getUpper();
|
||||||
if (Lower->getType()->isInteger() && !Lower->getType()->isUnsigned()) {
|
|
||||||
// Ensure we are doing a ZERO extension even if the input range is signed.
|
|
||||||
Lower = ConstantExpr::getCast(Lower, Ty->getUnsignedVersion());
|
|
||||||
Upper = ConstantExpr::getCast(Upper, Ty->getUnsignedVersion());
|
|
||||||
}
|
|
||||||
|
|
||||||
return ConstantRange(ConstantExpr::getCast(Lower, Ty),
|
return ConstantRange(ConstantExpr::getCast(Instruction::ZExt, Lower, Ty),
|
||||||
ConstantExpr::getCast(Upper, Ty));
|
ConstantExpr::getCast(Instruction::ZExt, Upper, Ty));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// truncate - Return a new range in the specified integer type, which must be
|
/// truncate - Return a new range in the specified integer type, which must be
|
||||||
@ -314,8 +309,9 @@ ConstantRange ConstantRange::truncate(const Type *Ty) const {
|
|||||||
if (isFullSet() || getSetSize() >= Size)
|
if (isFullSet() || getSetSize() >= Size)
|
||||||
return ConstantRange(getType());
|
return ConstantRange(getType());
|
||||||
|
|
||||||
return ConstantRange(ConstantExpr::getCast(getLower(), Ty),
|
return ConstantRange(
|
||||||
ConstantExpr::getCast(getUpper(), Ty));
|
ConstantExpr::getCast(Instruction::Trunc, getLower(), Ty),
|
||||||
|
ConstantExpr::getCast(Instruction::Trunc, getUpper(), Ty));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -777,7 +777,8 @@ static Constant *CastConstantPacked(ConstantPacked *CP,
|
|||||||
uint64_t V =
|
uint64_t V =
|
||||||
DoubleToBits(cast<ConstantFP>(CP->getOperand(i))->getValue());
|
DoubleToBits(cast<ConstantFP>(CP->getOperand(i))->getValue());
|
||||||
Constant *C = ConstantInt::get(Type::ULongTy, V);
|
Constant *C = ConstantInt::get(Type::ULongTy, V);
|
||||||
Result.push_back(ConstantExpr::getCast(C, DstEltTy));
|
Result.push_back(
|
||||||
|
ConstantExpr::getInferredCast(C, false, DstEltTy, false));
|
||||||
}
|
}
|
||||||
return ConstantPacked::get(Result);
|
return ConstantPacked::get(Result);
|
||||||
}
|
}
|
||||||
@ -786,7 +787,8 @@ static Constant *CastConstantPacked(ConstantPacked *CP,
|
|||||||
for (unsigned i = 0; i != SrcNumElts; ++i) {
|
for (unsigned i = 0; i != SrcNumElts; ++i) {
|
||||||
uint32_t V = FloatToBits(cast<ConstantFP>(CP->getOperand(i))->getValue());
|
uint32_t V = FloatToBits(cast<ConstantFP>(CP->getOperand(i))->getValue());
|
||||||
Constant *C = ConstantInt::get(Type::UIntTy, V);
|
Constant *C = ConstantInt::get(Type::UIntTy, V);
|
||||||
Result.push_back(ConstantExpr::getCast(C, DstEltTy));
|
Result.push_back(
|
||||||
|
ConstantExpr::getInferredCast(C, false, DstEltTy, false));
|
||||||
}
|
}
|
||||||
return ConstantPacked::get(Result);
|
return ConstantPacked::get(Result);
|
||||||
}
|
}
|
||||||
@ -839,8 +841,7 @@ Constant *llvm::ConstantFoldCastInstruction(unsigned opc, const Constant *V,
|
|||||||
// do to try to simplify it.
|
// do to try to simplify it.
|
||||||
if (const ConstantExpr *CE = dyn_cast<ConstantExpr>(V)) {
|
if (const ConstantExpr *CE = dyn_cast<ConstantExpr>(V)) {
|
||||||
if (CE->isCast()) {
|
if (CE->isCast()) {
|
||||||
// Try hard to fold cast of cast because they are almost always
|
// Try hard to fold cast of cast because they are often eliminable.
|
||||||
// eliminable.
|
|
||||||
if (unsigned newOpc = foldConstantCastPair(opc, CE, DestTy))
|
if (unsigned newOpc = foldConstantCastPair(opc, CE, DestTy))
|
||||||
return ConstantExpr::getCast(newOpc, CE->getOperand(0), DestTy);
|
return ConstantExpr::getCast(newOpc, CE->getOperand(0), DestTy);
|
||||||
} else if (CE->getOpcode() == Instruction::GetElementPtr) {
|
} else if (CE->getOpcode() == Instruction::GetElementPtr) {
|
||||||
@ -853,6 +854,7 @@ Constant *llvm::ConstantFoldCastInstruction(unsigned opc, const Constant *V,
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (isAllNull)
|
if (isAllNull)
|
||||||
|
// This is casting one pointer type to another, always BitCast
|
||||||
return ConstantExpr::getCast(CE->getOperand(0), DestTy);
|
return ConstantExpr::getCast(CE->getOperand(0), DestTy);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1632,9 +1634,13 @@ Constant *llvm::ConstantFoldGetElementPtr(const Constant *C,
|
|||||||
// gep null, C is equal to C*sizeof(nullty). If nullty is a known llvm
|
// gep null, C is equal to C*sizeof(nullty). If nullty is a known llvm
|
||||||
// type, we can statically fold this.
|
// type, we can statically fold this.
|
||||||
Constant *R = ConstantInt::get(Type::UIntTy, ElSize);
|
Constant *R = ConstantInt::get(Type::UIntTy, ElSize);
|
||||||
R = ConstantExpr::getCast(R, Idx0->getType());
|
// We know R is unsigned, Idx0 is signed because it must be an index
|
||||||
R = ConstantExpr::getMul(R, Idx0);
|
// through a sequential type (gep pointer operand) which is always
|
||||||
return ConstantExpr::getCast(R, C->getType());
|
// signed.
|
||||||
|
R = ConstantExpr::getInferredCast(R, false, Idx0->getType(), true);
|
||||||
|
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());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1662,11 +1668,16 @@ Constant *llvm::ConstantFoldGetElementPtr(const Constant *C,
|
|||||||
// Otherwise it must be an array.
|
// Otherwise it must be an array.
|
||||||
if (!Idx0->isNullValue()) {
|
if (!Idx0->isNullValue()) {
|
||||||
const Type *IdxTy = Combined->getType();
|
const Type *IdxTy = Combined->getType();
|
||||||
if (IdxTy != Idx0->getType()) IdxTy = Type::LongTy;
|
if (IdxTy != Idx0->getType()) {
|
||||||
|
Constant *C1 = ConstantExpr::getInferredCast(
|
||||||
|
Idx0, true, Type::LongTy, true);
|
||||||
|
Constant *C2 = ConstantExpr::getInferredCast(
|
||||||
|
Combined, true, Type::LongTy, true);
|
||||||
|
Combined = ConstantExpr::get(Instruction::Add, C1, C2);
|
||||||
|
} else {
|
||||||
Combined =
|
Combined =
|
||||||
ConstantExpr::get(Instruction::Add,
|
ConstantExpr::get(Instruction::Add, Idx0, Combined);
|
||||||
ConstantExpr::getCast(Idx0, IdxTy),
|
}
|
||||||
ConstantExpr::getCast(Combined, IdxTy));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
NewIndices.push_back(Combined);
|
NewIndices.push_back(Combined);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user