Skip to content

Commit ee0da14

Browse files
committed
[WASM] Remove redundant zero folding and fix test
- Remove redundant zero folding in performVSelectCombine() - Fix fpclamptosat_vec.ll test with pre-legalization folding of Vselect.
1 parent b00d0c5 commit ee0da14

File tree

2 files changed

+17
-29
lines changed

2 files changed

+17
-29
lines changed

llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3213,26 +3213,18 @@ static SDValue performTruncateCombine(SDNode *N,
32133213
return truncateVectorWithNARROW(OutVT, In, DL, DAG);
32143214
}
32153215

3216-
static SDValue performVSelectCombine(SDNode *N, SelectionDAG &DAG) {
3216+
static SDValue performVSelectCombine(SDNode *N,
3217+
TargetLowering::DAGCombinerInfo &DCI) {
32173218
// In the tablegen.td, vselect A B C -> bitselect B C A
32183219

3219-
// SCENARIO A
3220-
// vselect <0>, X, Y
3221-
// -> bitselect X, Y, <0>
3222-
// -> or (AND(X, <0>), AND(<Y>, !<0>))
3223-
// -> or (0, AND(<Y>, !<0>))
3224-
// -> AND(Y, !<0>)
3225-
// -> AND(Y, 1)
3226-
// -> Y
3227-
3228-
// SCENARIO B
3220+
// SCENARIO 1
32293221
// vselect Y, <0>, X
32303222
// -> bitselect <0>, X, Y
32313223
// -> or (AND(<0>, Y), AND(<X>, !<Y>))
32323224
// -> or (0, AND(<X>, !<Y>))
32333225
// -> AND(<X>, !<Y>)
32343226

3235-
// SCENARIO C
3227+
// SCENARIO 2
32363228
// vselect X, Y, <0>
32373229
// -> bitselect Y, <0>, X
32383230
// -> or (AND(Y, X), AND(<0>, !X))
@@ -3242,28 +3234,28 @@ static SDValue performVSelectCombine(SDNode *N, SelectionDAG &DAG) {
32423234
using namespace llvm::SDPatternMatch;
32433235
assert(N->getOpcode() == ISD::VSELECT);
32443236

3237+
// INFO: There is degradation in performance pre-legalization,
3238+
// fpclamptosat_vec.ll
3239+
if (DCI.isBeforeLegalize())
3240+
return SDValue();
3241+
32453242
SDLoc DL(N);
32463243

32473244
SDValue Cond = N->getOperand(0), LHS = N->getOperand(1),
32483245
RHS = N->getOperand(2);
32493246
EVT NVT = N->getValueType(0);
3250-
3247+
SelectionDAG &DAG = DCI.DAG;
32513248
APInt SplatValue;
32523249

3253-
// SCENARIO A
3254-
if (ISD::isConstantSplatVector(Cond.getNode(), SplatValue) &&
3255-
SplatValue.isZero())
3256-
return RHS;
3257-
3258-
// SCENARIO B
3250+
// SCENARIO 1
32593251
if (ISD::isConstantSplatVector(LHS.getNode(), SplatValue) &&
32603252
SplatValue.isZero())
32613253
return DAG.getNode(
32623254
ISD::AND, DL, NVT,
32633255
{RHS, DAG.getSExtOrTrunc(DAG.getNOT(DL, Cond, Cond.getValueType()), DL,
32643256
NVT)});
32653257

3266-
// SCENARIO C
3258+
// SCENARIO 2
32673259
if (ISD::isConstantSplatVector(RHS.getNode(), SplatValue) &&
32683260
SplatValue.isZero())
32693261
return DAG.getNode(ISD::AND, DL, NVT,
@@ -3567,7 +3559,7 @@ WebAssemblyTargetLowering::PerformDAGCombine(SDNode *N,
35673559
default:
35683560
return SDValue();
35693561
case ISD::VSELECT:
3570-
return performVSelectCombine(N, DCI.DAG);
3562+
return performVSelectCombine(N, DCI);
35713563
case ISD::BITCAST:
35723564
return performBitcastCombine(N, DCI);
35733565
case ISD::SETCC:

llvm/test/CodeGen/WebAssembly/fpclamptosat_vec.ll

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -106,12 +106,10 @@ define <2 x i32> @ustest_f64i32(<2 x double> %x) {
106106
; CHECK-NEXT: i64x2.lt_s
107107
; CHECK-NEXT: v128.bitselect
108108
; CHECK-NEXT: local.tee 0
109-
; CHECK-NEXT: v128.const 0, 0
110-
; CHECK-NEXT: local.tee 1
111109
; CHECK-NEXT: local.get 0
112-
; CHECK-NEXT: local.get 1
110+
; CHECK-NEXT: v128.const 0, 0
113111
; CHECK-NEXT: i64x2.gt_s
114-
; CHECK-NEXT: v128.bitselect
112+
; CHECK-NEXT: v128.and
115113
; CHECK-NEXT: local.get 0
116114
; CHECK-NEXT: i8x16.shuffle 0, 1, 2, 3, 8, 9, 10, 11, 0, 1, 2, 3, 0, 1, 2, 3
117115
; CHECK-NEXT: # fallthrough-return
@@ -1557,12 +1555,10 @@ define <2 x i32> @ustest_f64i32_mm(<2 x double> %x) {
15571555
; CHECK-NEXT: i64x2.lt_s
15581556
; CHECK-NEXT: v128.bitselect
15591557
; CHECK-NEXT: local.tee 0
1560-
; CHECK-NEXT: v128.const 0, 0
1561-
; CHECK-NEXT: local.tee 1
15621558
; CHECK-NEXT: local.get 0
1563-
; CHECK-NEXT: local.get 1
1559+
; CHECK-NEXT: v128.const 0, 0
15641560
; CHECK-NEXT: i64x2.gt_s
1565-
; CHECK-NEXT: v128.bitselect
1561+
; CHECK-NEXT: v128.and
15661562
; CHECK-NEXT: local.get 0
15671563
; CHECK-NEXT: i8x16.shuffle 0, 1, 2, 3, 8, 9, 10, 11, 0, 1, 2, 3, 0, 1, 2, 3
15681564
; CHECK-NEXT: # fallthrough-return

0 commit comments

Comments
 (0)