aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/IR/Constants.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/lib/IR/Constants.cpp')
-rw-r--r--llvm/lib/IR/Constants.cpp11
1 files changed, 11 insertions, 0 deletions
diff --git a/llvm/lib/IR/Constants.cpp b/llvm/lib/IR/Constants.cpp
index 5dcf1ba..c182513 100644
--- a/llvm/lib/IR/Constants.cpp
+++ b/llvm/lib/IR/Constants.cpp
@@ -2068,6 +2068,17 @@ Constant *ConstantExpr::getTruncOrBitCast(Constant *C, Type *Ty) {
return getTrunc(C, Ty);
}
+Constant *ConstantExpr::getSExtOrTrunc(Constant *C, Type *Ty) {
+ assert(C->getType()->isIntOrIntVectorTy() && Ty->isIntOrIntVectorTy() &&
+ "Can only sign extend/truncate integers!");
+ Type *CTy = C->getType();
+ if (CTy->getScalarSizeInBits() < Ty->getScalarSizeInBits())
+ return getSExt(C, Ty);
+ if (CTy->getScalarSizeInBits() > Ty->getScalarSizeInBits())
+ return getTrunc(C, Ty);
+ return C;
+}
+
Constant *ConstantExpr::getPointerCast(Constant *S, Type *Ty) {
assert(S->getType()->isPtrOrPtrVectorTy() && "Invalid cast");
assert((Ty->isIntOrIntVectorTy() || Ty->isPtrOrPtrVectorTy()) &&