@@ -3383,15 +3383,71 @@ static SDValue TryMatchTrue(SDNode *N, EVT VecVT, SelectionDAG &DAG) {
33833383 return DAG.getZExtOrTrunc (Ret, DL, N->getValueType (0 ));
33843384}
33853385
3386+ static SDValue
3387+ combineVectorSizedSetCCEquality (SDNode *N, TargetLowering::DAGCombinerInfo &DCI,
3388+ const WebAssemblySubtarget *Subtarget) {
3389+
3390+ SDLoc DL (N);
3391+ SDValue X = N->getOperand (0 );
3392+ SDValue Y = N->getOperand (1 );
3393+ EVT VT = N->getValueType (0 );
3394+ EVT OpVT = X.getValueType ();
3395+
3396+ ISD::CondCode CC = cast<CondCodeSDNode>(N->getOperand (2 ))->get ();
3397+ SelectionDAG &DAG = DCI.DAG ;
3398+ // We're looking for an oversized integer equality comparison.
3399+ if (!OpVT.isScalarInteger () || !OpVT.isByteSized () || OpVT != MVT::i128 ||
3400+ !Subtarget->hasSIMD128 ())
3401+ return SDValue ();
3402+
3403+ // Don't perform this combine if constructing the vector will be expensive.
3404+ auto IsVectorBitCastCheap = [](SDValue X) {
3405+ X = peekThroughBitcasts (X);
3406+ return isa<ConstantSDNode>(X) || X.getOpcode () == ISD::LOAD;
3407+ };
3408+
3409+ if (!IsVectorBitCastCheap (X) || !IsVectorBitCastCheap (Y))
3410+ return SDValue ();
3411+
3412+ // TODO: Not sure what's the purpose of this? I'm keeping here since RISCV has
3413+ // it
3414+ if (DCI.DAG .getMachineFunction ().getFunction ().hasFnAttribute (
3415+ Attribute::NoImplicitFloat))
3416+ return SDValue ();
3417+
3418+ unsigned OpSize = OpVT.getSizeInBits ();
3419+ unsigned VecSize = OpSize / 8 ;
3420+
3421+ EVT VecVT = EVT::getVectorVT (*DCI.DAG .getContext (), MVT::i8 , VecSize);
3422+ EVT CmpVT = EVT::getVectorVT (*DCI.DAG .getContext (), MVT::i8 , VecSize);
3423+
3424+ SDValue VecX = DAG.getBitcast (VecVT, X);
3425+ SDValue VecY = DAG.getBitcast (VecVT, Y);
3426+
3427+ SDValue Cmp = DAG.getSetCC (DL, CmpVT, VecX, VecY, CC);
3428+
3429+ SDValue AllTrue = DAG.getZExtOrTrunc (
3430+ DAG.getNode (
3431+ ISD::INTRINSIC_WO_CHAIN, DL, MVT::i32 ,
3432+ {DAG.getConstant (Intrinsic::wasm_alltrue, DL, MVT::i32 ), Cmp}),
3433+ DL, MVT::i1);
3434+
3435+ return DAG.getSetCC (DL, VT, AllTrue, DAG.getConstant (0 , DL, MVT::i1), CC);
3436+ }
3437+
33863438static SDValue performSETCCCombine (SDNode *N,
3387- TargetLowering::DAGCombinerInfo &DCI) {
3439+ TargetLowering::DAGCombinerInfo &DCI,
3440+ const WebAssemblySubtarget *Subtarget) {
33883441 if (!DCI.isBeforeLegalize ())
33893442 return SDValue ();
33903443
33913444 EVT VT = N->getValueType (0 );
33923445 if (!VT.isScalarInteger ())
33933446 return SDValue ();
33943447
3448+ if (SDValue V = combineVectorSizedSetCCEquality (N, DCI, Subtarget))
3449+ return V;
3450+
33953451 SDValue LHS = N->getOperand (0 );
33963452 if (LHS->getOpcode () != ISD::BITCAST)
33973453 return SDValue ();
@@ -3532,7 +3588,7 @@ WebAssemblyTargetLowering::PerformDAGCombine(SDNode *N,
35323588 case ISD::BITCAST:
35333589 return performBitcastCombine (N, DCI);
35343590 case ISD::SETCC:
3535- return performSETCCCombine (N, DCI);
3591+ return performSETCCCombine (N, DCI, Subtarget );
35363592 case ISD::VECTOR_SHUFFLE:
35373593 return performVECTOR_SHUFFLECombine (N, DCI);
35383594 case ISD::SIGN_EXTEND:
0 commit comments