[llvm] [ConstantFold] Support byte values in `bitcast` constant folding (PR #188030)
Pedro Lobo via llvm-commits
llvm-commits at lists.llvm.org
Sat Apr 18 12:00:20 PDT 2026
================
@@ -68,26 +68,53 @@ static Constant *FoldBitCast(Constant *V, Type *DestTy) {
if (V->isAllOnesValue())
return Constant::getAllOnesValue(DestTy);
- // Handle ConstantInt -> ConstantFP
+ // Handle ConstantInt -> Constant{Byte, FP}
if (ConstantInt *CI = dyn_cast<ConstantInt>(V)) {
// Canonicalize scalar-to-vector bitcasts into vector-to-vector bitcasts
// This allows for other simplifications (although some of them
// can only be handled by Analysis/ConstantFolding.cpp).
if (isa<VectorType>(DestTy) && !isa<VectorType>(SrcTy))
return ConstantExpr::getBitCast(ConstantVector::get(V), DestTy);
+ if (DestTy->isByteTy() &&
+ DestTy->getScalarSizeInBits() == SrcTy->getScalarSizeInBits())
+ return ConstantByte::get(DestTy->getContext(), CI->getValue());
+
// Make sure dest type is compatible with the folded fp constant.
// See note below regarding the PPC_FP128 restriction.
- if (!DestTy->isFPOrFPVectorTy() || DestTy->isPPC_FP128Ty() ||
- DestTy->getScalarSizeInBits() != SrcTy->getScalarSizeInBits())
- return nullptr;
+ if (DestTy->isFloatingPointTy() && !DestTy->isPPC_FP128Ty() &&
----------------
pedroclobo wrote:
Changed the scalar checks back to vector checks.
https://github.com/llvm/llvm-project/pull/188030
More information about the llvm-commits
mailing list