[llvm-commits] CVS: llvm/lib/VMCore/ConstantFolding.cpp
Chris Lattner
clattner at apple.com
Mon Dec 4 11:13:14 PST 2006
> --- llvm/lib/VMCore/ConstantFolding.cpp:1.105 Fri Dec 1 13:50:54 2006
> +++ llvm/lib/VMCore/ConstantFolding.cpp Sun Dec 3 20:45:43 2006
> @@ -777,7 +777,8 @@
> uint64_t V =
> DoubleToBits(cast<ConstantFP>(CP->getOperand(i))-
> >getValue());
> 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);
> }
This is always a bitcast.
> @@ -786,7 +787,8 @@
> for (unsigned i = 0; i != SrcNumElts; ++i) {
> uint32_t V = FloatToBits(cast<ConstantFP>(CP->getOperand(i))-
> >getValue());
> 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);
> }
Likewise.
> @@ -853,6 +854,7 @@
> break;
> }
> if (isAllNull)
> + // This is casting one pointer type to another, always
> BitCast
> return ConstantExpr::getCast(CE->getOperand(0), DestTy);
> }
> }
If so, why not create a bitcast explicitly?
BTW, if you want to add ConstantExpr::getBitCast (and friends) to
make it easier to do this, go for it.
> @@ -1632,9 +1634,13 @@
> // gep null, C is equal to C*sizeof(nullty). If nullty is
> a known llvm
> // type, we can statically fold this.
> Constant *R = ConstantInt::get(Type::UIntTy, ElSize);
> - R = ConstantExpr::getCast(R, Idx0->getType());
> - R = ConstantExpr::getMul(R, Idx0);
> - return ConstantExpr::getCast(R, C->getType());
> + // We know R is unsigned, Idx0 is signed because it must
> be an index
> + // through a sequential type (gep pointer operand) which
> is always
> + // 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());
> }
> }
> }
Please consider using ConstantExpr::getZExtOrBitCast (as I just
emailed to llvm commits).
> @@ -1662,11 +1668,16 @@
> // Otherwise it must be an array.
> if (!Idx0->isNullValue()) {
> const Type *IdxTy = Combined->getType();
> - if (IdxTy != Idx0->getType()) IdxTy = Type::LongTy;
> - Combined =
> - ConstantExpr::get(Instruction::Add,
> - ConstantExpr::getCast(Idx0, IdxTy),
> - ConstantExpr::getCast(Combined,
> IdxTy));
> + 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);
Please use:
ConstantExpr::getSExtOrBitCast
-Chris
More information about the llvm-commits
mailing list