@@ -970,7 +970,7 @@ void VPWidenIntrinsicRecipe::execute(VPTransformState &State) {
970970 if (isVectorIntrinsicWithOverloadTypeAtArg (VectorIntrinsicID, -1 ))
971971 TysForDecl.push_back (VectorType::get (getResultType (), State.VF ));
972972 SmallVector<Value *, 4 > Args;
973- for (const auto &I : enumerate(operands ())) {
973+ for (const auto &I : enumerate(arg_operands ())) {
974974 // Some intrinsics have a scalar argument - don't replace it with a
975975 // vector.
976976 Value *Arg;
@@ -983,18 +983,33 @@ void VPWidenIntrinsicRecipe::execute(VPTransformState &State) {
983983 Args.push_back (Arg);
984984 }
985985
986- // Use vector version of the intrinsic.
987- Module *M = State.Builder .GetInsertBlock ()->getModule ();
988- Function *VectorF =
989- Intrinsic::getOrInsertDeclaration (M, VectorIntrinsicID, TysForDecl);
990- assert (VectorF && " Can't retrieve vector intrinsic." );
991-
986+ CallInst *V = nullptr ;
992987 auto *CI = cast_or_null<CallInst>(getUnderlyingValue ());
993988 SmallVector<OperandBundleDef, 1 > OpBundles;
994989 if (CI)
995990 CI->getOperandBundlesAsDefs (OpBundles);
996991
997- CallInst *V = State.Builder .CreateCall (VectorF, Args, OpBundles);
992+ if (VPIntrinsic::isVPIntrinsic (VectorIntrinsicID)) {
993+ // Use vector version of the vector predicate Intrinsic
994+ IRBuilderBase &BuilderIR = State.Builder ;
995+ VectorBuilder VBuilder (BuilderIR);
996+ Value *Mask = BuilderIR.CreateVectorSplat (State.VF , BuilderIR.getTrue ());
997+ VBuilder.setMask (Mask).setEVL (
998+ State.get (getOperand (getNumOperands () - 1 ), /* NeedsScalar=*/ true ));
999+ auto *TyReturn = VectorType::get (getResultType (), State.VF );
1000+ Value *VPInst = VBuilder.createSimpleIntrinsic (VectorIntrinsicID, TyReturn,
1001+ Args, " vp.call" );
1002+ if (VPInst) {
1003+ V = cast<CallInst>(VPInst);
1004+ }
1005+ } else {
1006+ // Use vector version of the intrinsic.
1007+ Module *M = State.Builder .GetInsertBlock ()->getModule ();
1008+ Function *VectorF =
1009+ Intrinsic::getOrInsertDeclaration (M, VectorIntrinsicID, TysForDecl);
1010+ assert (VectorF && " Can't retrieve vector intrinsic." );
1011+ V = State.Builder .CreateCall (VectorF, Args, OpBundles);
1012+ }
9981013
9991014 setFlags (V);
10001015
@@ -1013,7 +1028,7 @@ InstructionCost VPWidenIntrinsicRecipe::computeCost(ElementCount VF,
10131028 // clear Arguments.
10141029 // TODO: Rework TTI interface to be independent of concrete IR values.
10151030 SmallVector<const Value *> Arguments;
1016- for (const auto &[Idx, Op] : enumerate(operands ())) {
1031+ for (const auto &[Idx, Op] : enumerate(arg_operands ())) {
10171032 auto *V = Op->getUnderlyingValue ();
10181033 if (!V) {
10191034 if (auto *UI = dyn_cast_or_null<CallBase>(getUnderlyingValue ())) {
0 commit comments