================
@@ -6985,6 +6985,72 @@ static SDValue combineSelectAsExtAnd(SDValue Cond, SDValue T, SDValue F,
return DAG.getNode(ISD::AND, DL, OpVT, CondMask, T.getOperand(0));
}
+// Widden int vector is not power of 2 in length.
+static SDValue widdenIntVectorSelect(SDNode *N, SelectionDAG &DAG,
+ const TargetLowering &TLI, SDValue Cond,
+ SDValue TrueVal, SDValue FalseVal) {
+ EVT ResultVT = N->getValueType(0);
+ if (ResultVT.isSimple() || !ResultVT.isVector() ||
+ ResultVT.isPow2VectorType() ||
+ TLI.getTypeAction(*DAG.getContext(), ResultVT) !=
+ TargetLowering::TypeWidenVector)
+ return SDValue();
+
+ EVT EltVT = ResultVT.getVectorElementType();
+ if (!EltVT.isInteger() || ResultVT.getVectorElementCount().isScalar())
+ return SDValue();
+
+ SDValue WiddenTrue = DAG.WidenVector(TrueVal, SDLoc(TrueVal));
+ SDValue WiddenFalse = DAG.WidenVector(FalseVal, SDLoc(FalseVal));
+
+ EVT WiddenVT = WiddenTrue.getValueType();
+ SDValue WiddenSelect = DAG.getNode(ISD::SELECT, SDLoc(N), WiddenVT, Cond,
+ WiddenTrue, WiddenFalse);
+ return DAG.getExtractSubvector(SDLoc(N), ResultVT, WiddenSelect, 0);
+}
+
+// Try to convert vXiY into vPiQ with:
+// 1. vXiY is not legal type
+// 2. vPiQ is legal type
+// 3. X * Y = P * Q
+// This prevent promotion of integer vectors like v32i4 to v32i16
+// which can create extra operations on type casting.
+static SDValue castIntVectorSelect(SDNode *N, SelectionDAG &DAG,
+ const TargetLowering &TLI, SDValue Cond,
+ SDValue TrueVal, SDValue FalseVal) {
+ EVT ResultVT = N->getValueType(0);
+ if (!ResultVT.isVector() || ResultVT.isScalableVector() ||
+ TLI.getTypeAction(*DAG.getContext(), ResultVT) ==
+ TargetLowering::TypeLegal ||
+ !TLI.shouldCastIntVectorSelect(ResultVT))
----------------
arsenm wrote:
Should avoid shouldCastIntVectorSelect
https://github.com/llvm/llvm-project/pull/173328