@@ -3651,26 +3651,26 @@ tryToMatchAndCreateMulAccumulateReduction(VPReductionRecipe *Red,
36513651 auto ExtendAndReplaceConstantOp = [&Ctx](VPWidenCastRecipe *ExtA,
36523652 VPWidenCastRecipe *&ExtB,
36533653 VPValue *&ValB, VPWidenRecipe *Mul) {
3654- if (ExtA && ! ExtB && ValB->isLiveIn ()) {
3655- Type *NarrowTy = Ctx. Types . inferScalarType (ExtA-> getOperand ( 0 )) ;
3656- Instruction::CastOps ExtOpc = ExtA->getOpcode ( );
3657- const APInt *Const ;
3658- if (! match (ValB, m_APInt ( Const)) ||
3659- ! llvm::canConstantBeExtended (
3660- Const, NarrowTy, TTI::getPartialReductionExtendKind (ExtOpc)))
3661- return ;
3662- // The truncate ensures that the type of each extended operand is the
3663- // same, and it's been proven that the constant can be extended from
3664- // NarrowTy safely. Necessary since ExtA 's extended operand would be
3665- // e.g. an i8, while the const will likely be an i32. This will be
3666- // elided by later optimisations.
3667- VPBuilder Builder (Mul);
3668- auto *Trunc =
3669- Builder. createWidenCast (Instruction::CastOps:: Trunc, ValB, NarrowTy);
3670- Type *WideTy = Ctx. Types . inferScalarType (ExtA );
3671- ValB = ExtB = Builder. createWidenCast (ExtOpc, Trunc, WideTy );
3672- Mul-> setOperand ( 1 , ExtB );
3673- }
3654+ if (! ExtA || ExtB || ! ValB->isLiveIn ())
3655+ return ;
3656+ Type *NarrowTy = Ctx. Types . inferScalarType ( ExtA->getOperand ( 0 ) );
3657+ Instruction::CastOps ExtOpc = ExtA-> getOpcode () ;
3658+ const APInt * Const;
3659+ if (! match (ValB, m_APInt (Const)) ||
3660+ ! llvm::canConstantBeExtended (
3661+ Const, NarrowTy, TTI::getPartialReductionExtendKind (ExtOpc)))
3662+ return ;
3663+ // The truncate ensures that the type of each extended operand is the
3664+ // same, and it 's been proven that the constant can be extended from
3665+ // NarrowTy safely. Necessary since ExtA's extended operand would be
3666+ // e.g. an i8, while the const will likely be an i32. This will be
3667+ // elided by later optimisations.
3668+ VPBuilder Builder (Mul);
3669+ auto * Trunc =
3670+ Builder. createWidenCast (Instruction::CastOps::Trunc, ValB, NarrowTy );
3671+ Type *WideTy = Ctx. Types . inferScalarType (ExtA );
3672+ ValB = ExtB = Builder. createWidenCast (ExtOpc, Trunc, WideTy );
3673+ Mul-> setOperand ( 1 , ExtB);
36743674 };
36753675
36763676 // Try to match reduce.add(mul(...)).
@@ -3709,8 +3709,8 @@ tryToMatchAndCreateMulAccumulateReduction(VPReductionRecipe *Red,
37093709 auto *Ext0 = dyn_cast_if_present<VPWidenCastRecipe>(A->getDefiningRecipe ());
37103710 auto *Ext1 = dyn_cast_if_present<VPWidenCastRecipe>(B->getDefiningRecipe ());
37113711
3712- // Convert reduce.add(ext(mul(ext, const))) to reduce.add(ext(mul(ext,
3713- // ext(const))))
3712+ // reduce.add(ext(mul(ext, const)))
3713+ // -> reduce.add(ext(mul(ext, ext(const))))
37143714 ExtendAndReplaceConstantOp (Ext0, Ext1, B, Mul);
37153715
37163716 // Match reduce.add(ext(mul(ext(A), ext(B))))
0 commit comments