aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/IR/Constants.cpp
diff options
context:
space:
mode:
authorPaul Walker <paul.walker@arm.com>2024-11-13 12:33:56 +0000
committerGitHub <noreply@github.com>2024-11-13 12:33:56 +0000
commit97298853b4de70dbce9c0a140ac38e3ac179e02e (patch)
tree34f75e1e64d0b2282b82bf14d67697a4a6c8c4bb /llvm/lib/IR/Constants.cpp
parent8ae2a18736c15e0d0d9d0893b21bce4f3bf581c9 (diff)
downloadllvm-97298853b4de70dbce9c0a140ac38e3ac179e02e.zip
llvm-97298853b4de70dbce9c0a140ac38e3ac179e02e.tar.gz
llvm-97298853b4de70dbce9c0a140ac38e3ac179e02e.tar.bz2
[LLVM][IR] Teach constant integer binop folds about vector ConstantInts. (#115739)
The existing logic mostly works with the main changes being: * Use getScalarSizeInBits instead of IntegerType::getBitWidth * Use ConstantInt::get(Type* instead of ConstantInt::get(LLVMContext
Diffstat (limited to 'llvm/lib/IR/Constants.cpp')
-rw-r--r--llvm/lib/IR/Constants.cpp7
1 files changed, 7 insertions, 0 deletions
diff --git a/llvm/lib/IR/Constants.cpp b/llvm/lib/IR/Constants.cpp
index 7ae3978..3d6c4ad 100644
--- a/llvm/lib/IR/Constants.cpp
+++ b/llvm/lib/IR/Constants.cpp
@@ -441,6 +441,13 @@ Constant *Constant::getAggregateElement(unsigned Elt) const {
? CAZ->getElementValue(Elt)
: nullptr;
+ if (const auto *CI = dyn_cast<ConstantInt>(this))
+ return Elt < cast<VectorType>(getType())
+ ->getElementCount()
+ .getKnownMinValue()
+ ? ConstantInt::get(getContext(), CI->getValue())
+ : nullptr;
+
// FIXME: getNumElements() will fail for non-fixed vector types.
if (isa<ScalableVectorType>(getType()))
return nullptr;