@@ -15928,17 +15928,32 @@ static SDValue getVectorBitwiseReduce(unsigned Opcode, SDValue Vec, EVT VT,
15928
15928
return getVectorBitwiseReduce(Opcode, HalfVec, VT, DL, DAG);
15929
15929
}
15930
15930
15931
- // Vectors that are less than 64 bits get widened to neatly fit a 64 bit
15932
- // register, so e.g. <4 x i1> gets lowered to <4 x i16>. Sign extending to
15933
- // this element size leads to the best codegen, since e.g. setcc results
15934
- // might need to be truncated otherwise.
15935
- EVT ExtendedVT = MVT::getIntegerVT(std::max(64u / NumElems, 8u));
15931
+ // Results of setcc operations get widened to 128 bits if their input
15932
+ // operands are 128 bits wide, otherwise vectors that are less than 64 bits
15933
+ // get widened to neatly fit a 64 bit register, so e.g. <4 x i1> gets
15934
+ // lowered to either <4 x i16> or <4 x i32>. Sign extending to this element
15935
+ // size leads to the best codegen, since e.g. setcc results might need to be
15936
+ // truncated otherwise.
15937
+ unsigned ExtendedWidth = 64;
15938
+ if (Vec.getOpcode() == ISD::SETCC &&
15939
+ Vec.getOperand(0).getValueSizeInBits() >= 128) {
15940
+ ExtendedWidth = 128;
15941
+ }
15942
+ EVT ExtendedVT = MVT::getIntegerVT(std::max(ExtendedWidth / NumElems, 8u));
15936
15943
15937
15944
// any_ext doesn't work with umin/umax, so only use it for uadd.
15938
15945
unsigned ExtendOp =
15939
15946
ScalarOpcode == ISD::XOR ? ISD::ANY_EXTEND : ISD::SIGN_EXTEND;
15940
15947
SDValue Extended = DAG.getNode(
15941
15948
ExtendOp, DL, VecVT.changeVectorElementType(ExtendedVT), Vec);
15949
+ // The uminp/uminv and umaxp/umaxv instructions don't have .2d variants, so
15950
+ // in that case we bitcast the sign extended values from v2i64 to v4i32
15951
+ // before reduction for optimal code generation.
15952
+ if ((ScalarOpcode == ISD::AND || ScalarOpcode == ISD::OR) &&
15953
+ NumElems == 2 && ExtendedWidth == 128) {
15954
+ Extended = DAG.getBitcast(MVT::v4i32, Extended);
15955
+ ExtendedVT = MVT::i32;
15956
+ }
15942
15957
switch (ScalarOpcode) {
15943
15958
case ISD::AND:
15944
15959
Result = DAG.getNode(ISD::VECREDUCE_UMIN, DL, ExtendedVT, Extended);
0 commit comments