@@ -870,38 +870,37 @@ bool VectorCombine::foldBitOpOfCastops(Instruction &I) {
870870 if (LHSSrc->getType () != RHSSrc->getType ())
871871 return false ;
872872
873- // Only handle vector types with integer elements
874- auto *SrcVecTy = dyn_cast<FixedVectorType>(LHSSrc->getType ());
875- auto *DstVecTy = dyn_cast<FixedVectorType>(I.getType ());
876- if (!SrcVecTy || !DstVecTy)
873+ auto *SrcTy = LHSSrc->getType ();
874+ auto *DstTy = I.getType ();
875+ // Only handle vector types with integer elements if the cast is not bitcast
876+ if (CastOpcode != Instruction::BitCast &&
877+ (!isa<FixedVectorType>(SrcTy) || !isa<FixedVectorType>(DstTy)))
877878 return false ;
878879
879- if (!SrcVecTy ->getScalarType ()->isIntegerTy () ||
880- !DstVecTy ->getScalarType ()->isIntegerTy ())
880+ if (!SrcTy ->getScalarType ()->isIntegerTy () ||
881+ !DstTy ->getScalarType ()->isIntegerTy ())
881882 return false ;
882883
883884 // Cost Check :
884885 // OldCost = bitlogic + 2*casts
885886 // NewCost = bitlogic + cast
886887
887888 // Calculate specific costs for each cast with instruction context
888- InstructionCost LHSCastCost =
889- TTI.getCastInstrCost (CastOpcode, DstVecTy, SrcVecTy,
890- TTI::CastContextHint::None, CostKind, LHSCast);
891- InstructionCost RHSCastCost =
892- TTI.getCastInstrCost (CastOpcode, DstVecTy, SrcVecTy,
893- TTI::CastContextHint::None, CostKind, RHSCast);
889+ InstructionCost LHSCastCost = TTI.getCastInstrCost (
890+ CastOpcode, DstTy, SrcTy, TTI::CastContextHint::None, CostKind, LHSCast);
891+ InstructionCost RHSCastCost = TTI.getCastInstrCost (
892+ CastOpcode, DstTy, SrcTy, TTI::CastContextHint::None, CostKind, RHSCast);
894893
895894 InstructionCost OldCost =
896- TTI.getArithmeticInstrCost (BinOp->getOpcode (), DstVecTy , CostKind) +
895+ TTI.getArithmeticInstrCost (BinOp->getOpcode (), DstTy , CostKind) +
897896 LHSCastCost + RHSCastCost;
898897
899898 // For new cost, we can't provide an instruction (it doesn't exist yet)
900899 InstructionCost GenericCastCost = TTI.getCastInstrCost (
901- CastOpcode, DstVecTy, SrcVecTy , TTI::CastContextHint::None, CostKind);
900+ CastOpcode, DstTy, SrcTy , TTI::CastContextHint::None, CostKind);
902901
903902 InstructionCost NewCost =
904- TTI.getArithmeticInstrCost (BinOp->getOpcode (), SrcVecTy , CostKind) +
903+ TTI.getArithmeticInstrCost (BinOp->getOpcode (), SrcTy , CostKind) +
905904 GenericCastCost;
906905
907906 // Account for multi-use casts using specific costs
0 commit comments