diff options
author | Paul Walker <paul.walker@arm.com> | 2024-12-10 15:42:05 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-12-10 15:42:05 +0000 |
commit | 3654f1baa66f524c89e40ab24e18e594e56363e9 (patch) | |
tree | f0eca87ce73718471fd7aa1959d151ede3c702a0 /llvm/lib/Analysis/ConstantFolding.cpp | |
parent | 7ea1fe773225fe88fd3ceb0aa17152eec496d135 (diff) | |
download | llvm-3654f1baa66f524c89e40ab24e18e594e56363e9.zip llvm-3654f1baa66f524c89e40ab24e18e594e56363e9.tar.gz llvm-3654f1baa66f524c89e40ab24e18e594e56363e9.tar.bz2 |
[LLVM][IR] Add support for vector ConstantInt/FP to ConstandFolding:FoldBitCast. (#117163)
Diffstat (limited to 'llvm/lib/Analysis/ConstantFolding.cpp')
-rw-r--r-- | llvm/lib/Analysis/ConstantFolding.cpp | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/llvm/lib/Analysis/ConstantFolding.cpp b/llvm/lib/Analysis/ConstantFolding.cpp index 836fa94..3d5022e 100644 --- a/llvm/lib/Analysis/ConstantFolding.cpp +++ b/llvm/lib/Analysis/ConstantFolding.cpp @@ -151,8 +151,14 @@ Constant *FoldBitCast(Constant *C, Type *DestTy, const DataLayout &DL) { return FoldBitCast(ConstantVector::get(Ops), DestTy, DL); } + // Some of what follows may extend to cover scalable vectors but the current + // implementation is fixed length specific. + if (!isa<FixedVectorType>(C->getType())) + return ConstantExpr::getBitCast(C, DestTy); + // If this is a bitcast from constant vector -> vector, fold it. - if (!isa<ConstantDataVector>(C) && !isa<ConstantVector>(C)) + if (!isa<ConstantDataVector>(C) && !isa<ConstantVector>(C) && + !isa<ConstantInt>(C) && !isa<ConstantFP>(C)) return ConstantExpr::getBitCast(C, DestTy); // If the element types match, IR can fold it. @@ -194,10 +200,9 @@ Constant *FoldBitCast(Constant *C, Type *DestTy, const DataLayout &DL) { IntegerType::get(C->getContext(), FPWidth), NumSrcElt); // Ask IR to do the conversion now that #elts line up. C = ConstantExpr::getBitCast(C, SrcIVTy); - // If IR wasn't able to fold it, bail out. - if (!isa<ConstantVector>(C) && // FIXME: Remove ConstantVector. - !isa<ConstantDataVector>(C)) - return C; + assert((isa<ConstantVector>(C) || // FIXME: Remove ConstantVector. + isa<ConstantDataVector>(C) || isa<ConstantInt>(C)) && + "Constant folding cannot fail for plain fp->int bitcast!"); } // Now we know that the input and output vectors are both integer vectors |