@@ -3383,15 +3383,71 @@ static SDValue TryMatchTrue(SDNode *N, EVT VecVT, SelectionDAG &DAG) {
3383
3383
return DAG.getZExtOrTrunc (Ret, DL, N->getValueType (0 ));
3384
3384
}
3385
3385
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
+
3386
3438
static SDValue performSETCCCombine (SDNode *N,
3387
- TargetLowering::DAGCombinerInfo &DCI) {
3439
+ TargetLowering::DAGCombinerInfo &DCI,
3440
+ const WebAssemblySubtarget *Subtarget) {
3388
3441
if (!DCI.isBeforeLegalize ())
3389
3442
return SDValue ();
3390
3443
3391
3444
EVT VT = N->getValueType (0 );
3392
3445
if (!VT.isScalarInteger ())
3393
3446
return SDValue ();
3394
3447
3448
+ if (SDValue V = combineVectorSizedSetCCEquality (N, DCI, Subtarget))
3449
+ return V;
3450
+
3395
3451
SDValue LHS = N->getOperand (0 );
3396
3452
if (LHS->getOpcode () != ISD::BITCAST)
3397
3453
return SDValue ();
@@ -3532,7 +3588,7 @@ WebAssemblyTargetLowering::PerformDAGCombine(SDNode *N,
3532
3588
case ISD::BITCAST:
3533
3589
return performBitcastCombine (N, DCI);
3534
3590
case ISD::SETCC:
3535
- return performSETCCCombine (N, DCI);
3591
+ return performSETCCCombine (N, DCI, Subtarget );
3536
3592
case ISD::VECTOR_SHUFFLE:
3537
3593
return performVECTOR_SHUFFLECombine (N, DCI);
3538
3594
case ISD::SIGN_EXTEND:
0 commit comments