Skip to content

Commit 44481f5

Browse files
badumbatishRKSimon
andauthored
[DAGCombine] Change isBuildVectorAll* -> isConstantSplatVectorAll* for Vselect (#147305)
Change isBuildVectorAll* -> isConstantSplatVectorAll* in VSelect in case the fold happens after BuildVector has been canonically transformed to Splat or if the Splat is initially in vselect already - Fixes #73454 - Update related test cases, add extra tests in wasm --------- Co-authored-by: Simon Pilgrim <llvm-dev@redking.me.uk>
1 parent e608e3f commit 44481f5

File tree

3 files changed

+78
-12
lines changed

3 files changed

+78
-12
lines changed

llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13091,10 +13091,10 @@ static SDValue combineVSelectWithAllOnesOrZeros(SDValue Cond, SDValue TVal,
1309113091
EVT CondVT = Cond.getValueType();
1309213092
assert(CondVT.isVector() && "Vector select expects a vector selector!");
1309313093

13094-
bool IsTAllZero = ISD::isBuildVectorAllZeros(TVal.getNode());
13095-
bool IsTAllOne = ISD::isBuildVectorAllOnes(TVal.getNode());
13096-
bool IsFAllZero = ISD::isBuildVectorAllZeros(FVal.getNode());
13097-
bool IsFAllOne = ISD::isBuildVectorAllOnes(FVal.getNode());
13094+
bool IsTAllZero = ISD::isConstantSplatVectorAllZeros(TVal.getNode());
13095+
bool IsTAllOne = ISD::isConstantSplatVectorAllOnes(TVal.getNode());
13096+
bool IsFAllZero = ISD::isConstantSplatVectorAllZeros(FVal.getNode());
13097+
bool IsFAllOne = ISD::isConstantSplatVectorAllOnes(FVal.getNode());
1309813098

1309913099
// no vselect(cond, 0/-1, X) or vselect(cond, X, 0/-1), return
1310013100
if (!IsTAllZero && !IsTAllOne && !IsFAllZero && !IsFAllOne)

llvm/test/CodeGen/WebAssembly/fpclamptosat_vec.ll

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -107,11 +107,9 @@ define <2 x i32> @ustest_f64i32(<2 x double> %x) {
107107
; CHECK-NEXT: v128.bitselect
108108
; CHECK-NEXT: local.tee 0
109109
; CHECK-NEXT: v128.const 0, 0
110-
; CHECK-NEXT: local.tee 1
111-
; CHECK-NEXT: local.get 0
112-
; CHECK-NEXT: local.get 1
113110
; CHECK-NEXT: i64x2.gt_s
114-
; CHECK-NEXT: v128.bitselect
111+
; CHECK-NEXT: local.get 0
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
@@ -1558,11 +1556,9 @@ define <2 x i32> @ustest_f64i32_mm(<2 x double> %x) {
15581556
; CHECK-NEXT: v128.bitselect
15591557
; CHECK-NEXT: local.tee 0
15601558
; CHECK-NEXT: v128.const 0, 0
1561-
; CHECK-NEXT: local.tee 1
1562-
; CHECK-NEXT: local.get 0
1563-
; CHECK-NEXT: local.get 1
15641559
; CHECK-NEXT: i64x2.gt_s
1565-
; CHECK-NEXT: v128.bitselect
1560+
; CHECK-NEXT: local.get 0
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

llvm/test/CodeGen/WebAssembly/simd-select.ll

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -552,3 +552,73 @@ define <2 x double> @select_eq_v2f64(i32 %i, <2 x double> %x, <2 x double> %y) {
552552
%res = select i1 %c, <2 x double> %x, <2 x double> %y
553553
ret <2 x double> %res
554554
}
555+
556+
define <4 x i32> @select_splat_first_zero_and_icmp(<4 x i32> %x) {
557+
; CHECK-LABEL: select_splat_first_zero_and_icmp:
558+
; CHECK: .functype select_splat_first_zero_and_icmp (v128) -> (v128)
559+
; CHECK-NEXT: # %bb.0:
560+
; CHECK-NEXT: local.get 0
561+
; CHECK-NEXT: v128.const 2139095040, 2139095040, 2139095040, 2139095040
562+
; CHECK-NEXT: v128.and
563+
; CHECK-NEXT: v128.const 0, 0, 0, 0
564+
; CHECK-NEXT: i32x4.ne
565+
; CHECK-NEXT: local.get 0
566+
; CHECK-NEXT: v128.and
567+
; CHECK-NEXT: # fallthrough-return
568+
%a = and <4 x i32> %x, splat (i32 2139095040)
569+
%c = icmp eq <4 x i32> %a, zeroinitializer
570+
%res = select <4 x i1> %c, <4 x i32> zeroinitializer, <4 x i32> %x
571+
ret <4 x i32> %res
572+
}
573+
574+
define <4 x i32> @select_splat_second_zero_and_icmp(<4 x i32> %x) {
575+
; CHECK-LABEL: select_splat_second_zero_and_icmp:
576+
; CHECK: .functype select_splat_second_zero_and_icmp (v128) -> (v128)
577+
; CHECK-NEXT: # %bb.0:
578+
; CHECK-NEXT: local.get 0
579+
; CHECK-NEXT: v128.const 2139095040, 2139095040, 2139095040, 2139095040
580+
; CHECK-NEXT: v128.and
581+
; CHECK-NEXT: v128.const 0, 0, 0, 0
582+
; CHECK-NEXT: i32x4.eq
583+
; CHECK-NEXT: local.get 0
584+
; CHECK-NEXT: v128.and
585+
; CHECK-NEXT: # fallthrough-return
586+
%a = and <4 x i32> %x, splat (i32 2139095040)
587+
%c = icmp eq <4 x i32> %a, zeroinitializer
588+
%res = select <4 x i1> %c, <4 x i32> %x, <4 x i32> zeroinitializer
589+
ret <4 x i32> %res
590+
}
591+
592+
define <4 x i32> @select_splat_first_zero_cond_input(<4 x i1> %c, <4 x i32> %x) {
593+
; CHECK-LABEL: select_splat_first_zero_cond_input:
594+
; CHECK: .functype select_splat_first_zero_cond_input (v128, v128) -> (v128)
595+
; CHECK-NEXT: # %bb.0:
596+
; CHECK-NEXT: v128.const 0, 0, 0, 0
597+
; CHECK-NEXT: local.get 1
598+
; CHECK-NEXT: local.get 0
599+
; CHECK-NEXT: i32.const 31
600+
; CHECK-NEXT: i32x4.shl
601+
; CHECK-NEXT: i32.const 31
602+
; CHECK-NEXT: i32x4.shr_s
603+
; CHECK-NEXT: v128.bitselect
604+
; CHECK-NEXT: # fallthrough-return
605+
%res = select <4 x i1> %c, <4 x i32> zeroinitializer, <4 x i32> %x
606+
ret <4 x i32> %res
607+
}
608+
609+
define <4 x i32> @select_splat_second_zero_cond_input(<4 x i1> %c, <4 x i32> %x) {
610+
; CHECK-LABEL: select_splat_second_zero_cond_input:
611+
; CHECK: .functype select_splat_second_zero_cond_input (v128, v128) -> (v128)
612+
; CHECK-NEXT: # %bb.0:
613+
; CHECK-NEXT: local.get 0
614+
; CHECK-NEXT: i32.const 31
615+
; CHECK-NEXT: i32x4.shl
616+
; CHECK-NEXT: i32.const 31
617+
; CHECK-NEXT: i32x4.shr_s
618+
; CHECK-NEXT: local.get 1
619+
; CHECK-NEXT: v128.and
620+
; CHECK-NEXT: # fallthrough-return
621+
%res = select <4 x i1> %c, <4 x i32> %x, <4 x i32> zeroinitializer
622+
ret <4 x i32> %res
623+
}
624+

0 commit comments

Comments
 (0)