@@ -2955,27 +2955,35 @@ bool RISCVDAGToDAGISel::selectVLOp(SDValue N, SDValue &VL) {
2955
2955
return true ;
2956
2956
}
2957
2957
2958
+ static SDValue findVSplat (SDValue N) {
2959
+ SDValue Splat = N;
2960
+ if (Splat.getOpcode () != RISCVISD::VMV_V_X_VL ||
2961
+ !Splat.getOperand (0 ).isUndef ())
2962
+ return SDValue ();
2963
+ assert (Splat.getNumOperands () == 3 && " Unexpected number of operands" );
2964
+ return Splat;
2965
+ }
2966
+
2958
2967
bool RISCVDAGToDAGISel::selectVSplat (SDValue N, SDValue &SplatVal) {
2959
- if (N.getOpcode () != RISCVISD::VMV_V_X_VL || !N.getOperand (0 ).isUndef ())
2968
+ SDValue Splat = findVSplat (N);
2969
+ if (!Splat)
2960
2970
return false ;
2961
- assert (N. getNumOperands () == 3 && " Unexpected number of operands " );
2962
- SplatVal = N .getOperand (1 );
2971
+
2972
+ SplatVal = Splat .getOperand (1 );
2963
2973
return true ;
2964
2974
}
2965
2975
2966
- using ValidateFn = bool (*)(int64_t );
2967
-
2968
- static bool selectVSplatSimmHelper (SDValue N, SDValue &SplatVal,
2969
- SelectionDAG &DAG,
2970
- const RISCVSubtarget &Subtarget,
2971
- ValidateFn ValidateImm) {
2972
- if (N.getOpcode () != RISCVISD::VMV_V_X_VL || !N.getOperand (0 ).isUndef () ||
2973
- !isa<ConstantSDNode>(N.getOperand (1 )))
2976
+ static bool selectVSplatImmHelper (SDValue N, SDValue &SplatVal,
2977
+ SelectionDAG &DAG,
2978
+ const RISCVSubtarget &Subtarget,
2979
+ std::function<bool (int64_t )> ValidateImm) {
2980
+ SDValue Splat = findVSplat (N);
2981
+ if (!Splat || !isa<ConstantSDNode>(Splat.getOperand (1 )))
2974
2982
return false ;
2975
- assert (N.getNumOperands () == 3 && " Unexpected number of operands" );
2976
2983
2977
- int64_t SplatImm =
2978
- cast<ConstantSDNode>(N.getOperand (1 ))->getSExtValue ();
2984
+ const unsigned SplatEltSize = Splat.getScalarValueSizeInBits ();
2985
+ assert (Subtarget.getXLenVT () == Splat.getOperand (1 ).getSimpleValueType () &&
2986
+ " Unexpected splat operand type" );
2979
2987
2980
2988
// The semantics of RISCVISD::VMV_V_X_VL is that when the operand
2981
2989
// type is wider than the resulting vector element type: an implicit
@@ -2984,55 +2992,41 @@ static bool selectVSplatSimmHelper(SDValue N, SDValue &SplatVal,
2984
2992
// any zero-extended immediate.
2985
2993
// For example, we wish to match (i8 -1) -> (XLenVT 255) as a simm5 by first
2986
2994
// sign-extending to (XLenVT -1).
2987
- MVT XLenVT = Subtarget.getXLenVT ();
2988
- assert (XLenVT == N.getOperand (1 ).getSimpleValueType () &&
2989
- " Unexpected splat operand type" );
2990
- MVT EltVT = N.getSimpleValueType ().getVectorElementType ();
2991
- if (EltVT.bitsLT (XLenVT))
2992
- SplatImm = SignExtend64 (SplatImm, EltVT.getSizeInBits ());
2995
+ APInt SplatConst = Splat.getConstantOperandAPInt (1 ).sextOrTrunc (SplatEltSize);
2996
+
2997
+ int64_t SplatImm = SplatConst.getSExtValue ();
2993
2998
2994
2999
if (!ValidateImm (SplatImm))
2995
3000
return false ;
2996
3001
2997
- SplatVal = DAG.getTargetConstant (SplatImm, SDLoc (N), XLenVT );
3002
+ SplatVal = DAG.getTargetConstant (SplatImm, SDLoc (N), Subtarget. getXLenVT () );
2998
3003
return true ;
2999
3004
}
3000
3005
3001
3006
bool RISCVDAGToDAGISel::selectVSplatSimm5 (SDValue N, SDValue &SplatVal) {
3002
- return selectVSplatSimmHelper (N, SplatVal, *CurDAG, *Subtarget,
3003
- [](int64_t Imm) { return isInt<5 >(Imm); });
3007
+ return selectVSplatImmHelper (N, SplatVal, *CurDAG, *Subtarget,
3008
+ [](int64_t Imm) { return isInt<5 >(Imm); });
3004
3009
}
3005
3010
3006
3011
bool RISCVDAGToDAGISel::selectVSplatSimm5Plus1 (SDValue N, SDValue &SplatVal) {
3007
- return selectVSplatSimmHelper (
3012
+ return selectVSplatImmHelper (
3008
3013
N, SplatVal, *CurDAG, *Subtarget,
3009
3014
[](int64_t Imm) { return (isInt<5 >(Imm) && Imm != -16 ) || Imm == 16 ; });
3010
3015
}
3011
3016
3012
3017
bool RISCVDAGToDAGISel::selectVSplatSimm5Plus1NonZero (SDValue N,
3013
3018
SDValue &SplatVal) {
3014
- return selectVSplatSimmHelper (
3019
+ return selectVSplatImmHelper (
3015
3020
N, SplatVal, *CurDAG, *Subtarget, [](int64_t Imm) {
3016
3021
return Imm != 0 && ((isInt<5 >(Imm) && Imm != -16 ) || Imm == 16 );
3017
3022
});
3018
3023
}
3019
3024
3020
3025
bool RISCVDAGToDAGISel::selectVSplatUimm (SDValue N, unsigned Bits,
3021
3026
SDValue &SplatVal) {
3022
- if (N.getOpcode () != RISCVISD::VMV_V_X_VL || !N.getOperand (0 ).isUndef () ||
3023
- !isa<ConstantSDNode>(N.getOperand (1 )))
3024
- return false ;
3025
-
3026
- int64_t SplatImm =
3027
- cast<ConstantSDNode>(N.getOperand (1 ))->getSExtValue ();
3028
-
3029
- if (!isUIntN (Bits, SplatImm))
3030
- return false ;
3031
-
3032
- SplatVal =
3033
- CurDAG->getTargetConstant (SplatImm, SDLoc (N), Subtarget->getXLenVT ());
3034
-
3035
- return true ;
3027
+ return selectVSplatImmHelper (
3028
+ N, SplatVal, *CurDAG, *Subtarget,
3029
+ [Bits](int64_t Imm) { return isUIntN (Bits, Imm); });
3036
3030
}
3037
3031
3038
3032
bool RISCVDAGToDAGISel::selectLow8BitsVSplat (SDValue N, SDValue &SplatVal) {
0 commit comments