@@ -15928,17 +15928,32 @@ static SDValue getVectorBitwiseReduce(unsigned Opcode, SDValue Vec, EVT VT,
1592815928 return getVectorBitwiseReduce(Opcode, HalfVec, VT, DL, DAG);
1592915929 }
1593015930
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));
1593615943
1593715944 // any_ext doesn't work with umin/umax, so only use it for uadd.
1593815945 unsigned ExtendOp =
1593915946 ScalarOpcode == ISD::XOR ? ISD::ANY_EXTEND : ISD::SIGN_EXTEND;
1594015947 SDValue Extended = DAG.getNode(
1594115948 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+ }
1594215957 switch (ScalarOpcode) {
1594315958 case ISD::AND:
1594415959 Result = DAG.getNode(ISD::VECREDUCE_UMIN, DL, ExtendedVT, Extended);
0 commit comments