Skip to content

Commit ffb724a

Browse files
committed
Precommit missed optimization test for #129441
This shows that reduceand is not well-optimized in WebAssembly. The long chain of shuffle should be turned to all_true.
1 parent e6ee2c7 commit ffb724a

File tree

1 file changed

+77
-0
lines changed

1 file changed

+77
-0
lines changed
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 5
2+
; RUN: llc < %s -verify-machineinstrs -disable-wasm-fallthrough-return-opt -wasm-disable-explicit-locals -wasm-keep-registers -mattr=+simd128 | FileCheck %s
3+
target triple = "wasm64"
4+
5+
define i1 @reduce_and_to_all_true_16i8(<16 x i8> %0) {
6+
; CHECK-LABEL: reduce_and_to_all_true_16i8:
7+
; CHECK: .functype reduce_and_to_all_true_16i8 (v128) -> (i32)
8+
; CHECK-NEXT: # %bb.0:
9+
; CHECK-NEXT: v128.const $push0=, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
10+
; CHECK-NEXT: i8x16.ne $push10=, $0, $pop0
11+
; CHECK-NEXT: local.tee $push9=, $0=, $pop10
12+
; CHECK-NEXT: i8x16.shuffle $push1=, $0, $0, 8, 9, 10, 11, 12, 13, 14, 15, 0, 1, 2, 3, 0, 1, 2, 3
13+
; CHECK-NEXT: v128.and $push8=, $pop9, $pop1
14+
; CHECK-NEXT: local.tee $push7=, $0=, $pop8
15+
; CHECK-NEXT: i8x16.shuffle $push2=, $0, $0, 4, 5, 6, 7, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3
16+
; CHECK-NEXT: v128.and $push3=, $pop7, $pop2
17+
; CHECK-NEXT: i32x4.extract_lane $push4=, $pop3, 0
18+
; CHECK-NEXT: i32.const $push5=, 0
19+
; CHECK-NEXT: i32.ne $push6=, $pop4, $pop5
20+
; CHECK-NEXT: return $pop6
21+
%2 = icmp ne <16 x i8> %0, zeroinitializer
22+
%3 = sext <16 x i1> %2 to <16 x i8>
23+
%4 = bitcast <16 x i8> %3 to <4 x i32>
24+
%5 = tail call i32 @llvm.vector.reduce.and.v4i32(<4 x i32> %4)
25+
%6 = icmp ne i32 %5, 0
26+
ret i1 %6
27+
}
28+
29+
30+
define i1 @reduce_and_to_all_true_4i32(<4 x i32> %0) {
31+
; CHECK-LABEL: reduce_and_to_all_true_4i32:
32+
; CHECK: .functype reduce_and_to_all_true_4i32 (v128) -> (i32)
33+
; CHECK-NEXT: # %bb.0:
34+
; CHECK-NEXT: v128.const $push0=, 0, 0, 0, 0
35+
; CHECK-NEXT: i32x4.ne $push10=, $0, $pop0
36+
; CHECK-NEXT: local.tee $push9=, $0=, $pop10
37+
; CHECK-NEXT: i8x16.shuffle $push1=, $0, $0, 8, 9, 10, 11, 12, 13, 14, 15, 0, 1, 2, 3, 0, 1, 2, 3
38+
; CHECK-NEXT: v128.and $push8=, $pop9, $pop1
39+
; CHECK-NEXT: local.tee $push7=, $0=, $pop8
40+
; CHECK-NEXT: i8x16.shuffle $push2=, $0, $0, 4, 5, 6, 7, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3
41+
; CHECK-NEXT: v128.and $push3=, $pop7, $pop2
42+
; CHECK-NEXT: i32x4.extract_lane $push4=, $pop3, 0
43+
; CHECK-NEXT: i32.const $push5=, 0
44+
; CHECK-NEXT: i32.ne $push6=, $pop4, $pop5
45+
; CHECK-NEXT: return $pop6
46+
%2 = icmp ne <4 x i32> %0, zeroinitializer
47+
%3 = sext <4 x i1> %2 to <4 x i32>
48+
%4 = tail call i32 @llvm.vector.reduce.and.v4i32(<4 x i32> %3)
49+
%5 = icmp ne i32 %4, 0
50+
ret i1 %5
51+
}
52+
53+
54+
55+
define i1 @reduce_and_to_all_true_2i64(<2 x i64> %0) {
56+
; CHECK-LABEL: reduce_and_to_all_true_2i64:
57+
; CHECK: .functype reduce_and_to_all_true_2i64 (v128) -> (i32)
58+
; CHECK-NEXT: # %bb.0:
59+
; CHECK-NEXT: v128.const $push0=, 0, 0, 0, 0
60+
; CHECK-NEXT: i32x4.ne $push10=, $0, $pop0
61+
; CHECK-NEXT: local.tee $push9=, $0=, $pop10
62+
; CHECK-NEXT: i8x16.shuffle $push1=, $0, $0, 8, 9, 10, 11, 12, 13, 14, 15, 0, 1, 2, 3, 0, 1, 2, 3
63+
; CHECK-NEXT: v128.and $push8=, $pop9, $pop1
64+
; CHECK-NEXT: local.tee $push7=, $0=, $pop8
65+
; CHECK-NEXT: i8x16.shuffle $push2=, $0, $0, 4, 5, 6, 7, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3
66+
; CHECK-NEXT: v128.and $push3=, $pop7, $pop2
67+
; CHECK-NEXT: i32x4.extract_lane $push4=, $pop3, 0
68+
; CHECK-NEXT: i32.const $push5=, 0
69+
; CHECK-NEXT: i32.ne $push6=, $pop4, $pop5
70+
; CHECK-NEXT: return $pop6
71+
%2 = bitcast <2 x i64> %0 to <4 x i32>
72+
%3 = icmp ne <4 x i32> %2, zeroinitializer
73+
%4 = sext <4 x i1> %3 to <4 x i32>
74+
%5 = tail call i32 @llvm.vector.reduce.and.v4i32(<4 x i32> %4)
75+
%6 = icmp ne i32 %5, 0
76+
ret i1 %6
77+
}

0 commit comments

Comments
 (0)