aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Analysis/ConstantFolding.cpp
diff options
context:
space:
mode:
authorPaul Walker <paul.walker@arm.com>2024-10-08 13:28:44 +0100
committerGitHub <noreply@github.com>2024-10-08 13:28:44 +0100
commit87cdc8328d6c79da6dcce85eb318296bc5b42e82 (patch)
tree1207c7a8d57afa4e25de7ff9c7aba3fa3abf4ec9 /llvm/lib/Analysis/ConstantFolding.cpp
parente06e4932521b0ba578d34495186cde522de8eaec (diff)
downloadllvm-87cdc8328d6c79da6dcce85eb318296bc5b42e82.zip
llvm-87cdc8328d6c79da6dcce85eb318296bc5b42e82.tar.gz
llvm-87cdc8328d6c79da6dcce85eb318296bc5b42e82.tar.bz2
[LLVM][ConstFolds] Verify a scalar src before attempting scalar->vector bitcast transformation. (#111149)
It was previously safe to assume isa<Constant{Int,FP}> meant a scalar value. This is not true when use-constant-##-for-###-splat are enabled.
Diffstat (limited to 'llvm/lib/Analysis/ConstantFolding.cpp')
-rw-r--r--llvm/lib/Analysis/ConstantFolding.cpp3
1 files changed, 2 insertions, 1 deletions
diff --git a/llvm/lib/Analysis/ConstantFolding.cpp b/llvm/lib/Analysis/ConstantFolding.cpp
index a7a6de3..a6ef271 100644
--- a/llvm/lib/Analysis/ConstantFolding.cpp
+++ b/llvm/lib/Analysis/ConstantFolding.cpp
@@ -145,7 +145,8 @@ Constant *FoldBitCast(Constant *C, Type *DestTy, const DataLayout &DL) {
// If this is a scalar -> vector cast, convert the input into a <1 x scalar>
// vector so the code below can handle it uniformly.
- if (isa<ConstantFP>(C) || isa<ConstantInt>(C)) {
+ if (!isa<VectorType>(C->getType()) &&
+ (isa<ConstantFP>(C) || isa<ConstantInt>(C))) {
Constant *Ops = C; // don't take the address of C!
return FoldBitCast(ConstantVector::get(Ops), DestTy, DL);
}