From 3654f1baa66f524c89e40ab24e18e594e56363e9 Mon Sep 17 00:00:00 2001 From: Paul Walker Date: Tue, 10 Dec 2024 15:42:05 +0000 Subject: [LLVM][IR] Add support for vector ConstantInt/FP to ConstandFolding:FoldBitCast. (#117163) --- llvm/lib/Analysis/ConstantFolding.cpp | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'llvm/lib/Analysis/ConstantFolding.cpp') 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(C->getType())) + return ConstantExpr::getBitCast(C, DestTy); + // If this is a bitcast from constant vector -> vector, fold it. - if (!isa(C) && !isa(C)) + if (!isa(C) && !isa(C) && + !isa(C) && !isa(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(C) && // FIXME: Remove ConstantVector. - !isa(C)) - return C; + assert((isa(C) || // FIXME: Remove ConstantVector. + isa(C) || isa(C)) && + "Constant folding cannot fail for plain fp->int bitcast!"); } // Now we know that the input and output vectors are both integer vectors -- cgit v1.1