1
1
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2
2
; RUN: opt < %s -instcombine -S | FileCheck %s
3
3
4
- ; TODO: Narrow the select operands to eliminate the existing shuffles and replace a wide select with a narrow select.
4
+ ; Narrow the select operands to eliminate the existing shuffles and replace a wide select with a narrow select.
5
5
6
6
define <2 x i8 > @narrow_shuffle_of_select (<2 x i1 > %cmp , <4 x i8 > %x , <4 x i8 > %y ) {
7
7
; CHECK-LABEL: @narrow_shuffle_of_select(
8
- ; CHECK-NEXT: [[WIDECMP :%.*]] = shufflevector <2 x i1 > [[CMP :%.*]], <2 x i1 > undef, <4 x i32> <i32 0, i32 1, i32 undef, i32 undef >
9
- ; CHECK-NEXT: [[WIDESEL :%.*]] = select <4 x i1 > [[WIDECMP ]], <4 x i8> [[X:%.*]] , <4 x i8> [[Y:%.*]]
10
- ; CHECK-NEXT: [[R:%.*]] = shufflevector <4 x i8 > [[WIDESEL ]], <4 x i8> undef , <2 x i32> <i32 0, i32 1>
8
+ ; CHECK-NEXT: [[TMP1 :%.*]] = shufflevector <4 x i8 > [[X :%.*]], <4 x i8 > undef, <2 x i32> <i32 0, i32 1>
9
+ ; CHECK-NEXT: [[TMP2 :%.*]] = shufflevector <4 x i8 > [[Y:%.* ]], <4 x i8> undef , <2 x i32> <i32 0, i32 1>
10
+ ; CHECK-NEXT: [[R:%.*]] = select <2 x i1 > [[CMP:%.* ]], <2 x i8> [[TMP1]] , <2 x i8> [[TMP2]]
11
11
; CHECK-NEXT: ret <2 x i8> [[R]]
12
12
;
13
13
%widecmp = shufflevector <2 x i1 > %cmp , <2 x i1 > undef , <4 x i32 > <i32 0 , i32 1 , i32 undef , i32 undef >
@@ -31,13 +31,13 @@ define <2 x i8> @narrow_shuffle_of_select_overspecified_extend(<2 x i1> %cmp, <4
31
31
ret <2 x i8 > %r
32
32
}
33
33
34
- ; TODO: Verify that undef elements are acceptable for identity shuffle mask. Also check FP types.
34
+ ; Verify that undef elements are acceptable for identity shuffle mask. Also check FP types.
35
35
36
36
define <3 x float > @narrow_shuffle_of_select_undefs (<3 x i1 > %cmp , <4 x float > %x , <4 x float > %y ) {
37
37
; CHECK-LABEL: @narrow_shuffle_of_select_undefs(
38
- ; CHECK-NEXT: [[WIDECMP :%.*]] = shufflevector <3 x i1 > [[CMP :%.*]], <3 x i1 > undef, <4 x i32> <i32 undef , i32 1, i32 2 , i32 undef>
39
- ; CHECK-NEXT: [[WIDESEL :%.*]] = select <4 x i1 > [[WIDECMP ]], <4 x float> [[X:%.*]] , <4 x float> [[Y:%.*]]
40
- ; CHECK-NEXT: [[R:%.*]] = shufflevector <4 x float > [[WIDESEL ]], <4 x float> undef , <3 x i32> <i32 0, i32 1, i32 undef>
38
+ ; CHECK-NEXT: [[TMP1 :%.*]] = shufflevector <4 x float > [[X :%.*]], <4 x float > undef, <3 x i32> <i32 0 , i32 1, i32 undef>
39
+ ; CHECK-NEXT: [[TMP2 :%.*]] = shufflevector <4 x float > [[Y:%.* ]], <4 x float> undef , <3 x i32> <i32 0, i32 1, i32 undef>
40
+ ; CHECK-NEXT: [[R:%.*]] = select <3 x i1 > [[CMP:%.* ]], <3 x float> [[TMP1]] , <3 x float> [[TMP2]]
41
41
; CHECK-NEXT: ret <3 x float> [[R]]
42
42
;
43
43
%widecmp = shufflevector <3 x i1 > %cmp , <3 x i1 > undef , <4 x i32 > <i32 undef , i32 1 , i32 2 , i32 undef >
@@ -49,36 +49,42 @@ define <3 x float> @narrow_shuffle_of_select_undefs(<3 x i1> %cmp, <4 x float> %
49
49
declare void @use (<4 x i8 >)
50
50
declare void @use_cmp (<4 x i1 >)
51
51
52
+ ; Negative test - extra use would require more instructions than we started with.
53
+
52
54
define <2 x i8 > @narrow_shuffle_of_select_use1 (<2 x i1 > %cmp , <4 x i8 > %x , <4 x i8 > %y ) {
53
55
; CHECK-LABEL: @narrow_shuffle_of_select_use1(
54
56
; CHECK-NEXT: [[WIDECMP:%.*]] = shufflevector <2 x i1> [[CMP:%.*]], <2 x i1> undef, <4 x i32> <i32 0, i32 1, i32 undef, i32 undef>
55
57
; CHECK-NEXT: [[WIDESEL:%.*]] = select <4 x i1> [[WIDECMP]], <4 x i8> [[X:%.*]], <4 x i8> [[Y:%.*]]
56
- ; CHECK-NEXT: [[R:%.*]] = shufflevector <4 x i8> [[WIDESEL]], <4 x i8> undef, <2 x i32> <i32 0, i32 1>
57
58
; CHECK-NEXT: call void @use(<4 x i8> [[WIDESEL]])
59
+ ; CHECK-NEXT: [[R:%.*]] = shufflevector <4 x i8> [[WIDESEL]], <4 x i8> undef, <2 x i32> <i32 0, i32 1>
58
60
; CHECK-NEXT: ret <2 x i8> [[R]]
59
61
;
60
62
%widecmp = shufflevector <2 x i1 > %cmp , <2 x i1 > undef , <4 x i32 > <i32 0 , i32 1 , i32 undef , i32 undef >
61
63
%widesel = select <4 x i1 > %widecmp , <4 x i8 > %x , <4 x i8 > %y
62
- %r = shufflevector <4 x i8 > %widesel , <4 x i8 > undef , <2 x i32 > <i32 0 , i32 1 >
63
64
call void @use (<4 x i8 > %widesel )
65
+ %r = shufflevector <4 x i8 > %widesel , <4 x i8 > undef , <2 x i32 > <i32 0 , i32 1 >
64
66
ret <2 x i8 > %r
65
67
}
66
68
69
+ ; Negative test - extra use would require more instructions than we started with.
70
+
67
71
define <2 x i8 > @narrow_shuffle_of_select_use2 (<2 x i1 > %cmp , <4 x i8 > %x , <4 x i8 > %y ) {
68
72
; CHECK-LABEL: @narrow_shuffle_of_select_use2(
69
73
; CHECK-NEXT: [[WIDECMP:%.*]] = shufflevector <2 x i1> [[CMP:%.*]], <2 x i1> undef, <4 x i32> <i32 0, i32 1, i32 undef, i32 undef>
74
+ ; CHECK-NEXT: call void @use_cmp(<4 x i1> [[WIDECMP]])
70
75
; CHECK-NEXT: [[WIDESEL:%.*]] = select <4 x i1> [[WIDECMP]], <4 x i8> [[X:%.*]], <4 x i8> [[Y:%.*]]
71
76
; CHECK-NEXT: [[R:%.*]] = shufflevector <4 x i8> [[WIDESEL]], <4 x i8> undef, <2 x i32> <i32 0, i32 1>
72
- ; CHECK-NEXT: call void @use_cmp(<4 x i1> [[WIDECMP]])
73
77
; CHECK-NEXT: ret <2 x i8> [[R]]
74
78
;
75
79
%widecmp = shufflevector <2 x i1 > %cmp , <2 x i1 > undef , <4 x i32 > <i32 0 , i32 1 , i32 undef , i32 undef >
80
+ call void @use_cmp (<4 x i1 > %widecmp )
76
81
%widesel = select <4 x i1 > %widecmp , <4 x i8 > %x , <4 x i8 > %y
77
82
%r = shufflevector <4 x i8 > %widesel , <4 x i8 > undef , <2 x i32 > <i32 0 , i32 1 >
78
- call void @use_cmp (<4 x i1 > %widecmp )
79
83
ret <2 x i8 > %r
80
84
}
81
85
86
+ ; Negative test - mismatched types would require extra shuffling.
87
+
82
88
define <3 x i8 > @narrow_shuffle_of_select_mismatch_types1 (<2 x i1 > %cmp , <4 x i8 > %x , <4 x i8 > %y ) {
83
89
; CHECK-LABEL: @narrow_shuffle_of_select_mismatch_types1(
84
90
; CHECK-NEXT: [[WIDECMP:%.*]] = shufflevector <2 x i1> [[CMP:%.*]], <2 x i1> undef, <4 x i32> <i32 0, i32 1, i32 undef, i32 undef>
@@ -92,6 +98,8 @@ define <3 x i8> @narrow_shuffle_of_select_mismatch_types1(<2 x i1> %cmp, <4 x i8
92
98
ret <3 x i8 > %r
93
99
}
94
100
101
+ ; Negative test - mismatched types would require extra shuffling.
102
+
95
103
define <3 x i8 > @narrow_shuffle_of_select_mismatch_types2 (<4 x i1 > %cmp , <6 x i8 > %x , <6 x i8 > %y ) {
96
104
; CHECK-LABEL: @narrow_shuffle_of_select_mismatch_types2(
97
105
; CHECK-NEXT: [[WIDECMP:%.*]] = shufflevector <4 x i1> [[CMP:%.*]], <4 x i1> undef, <6 x i32> <i32 0, i32 1, i32 2, i32 3, i32 undef, i32 undef>
@@ -105,13 +113,11 @@ define <3 x i8> @narrow_shuffle_of_select_mismatch_types2(<4 x i1> %cmp, <6 x i8
105
113
ret <3 x i8 > %r
106
114
}
107
115
108
- ; TODO: Narrowing constants does not require creating new narrowing shuffle instructions.
116
+ ; Narrowing constants does not require creating new narrowing shuffle instructions.
109
117
110
118
define <2 x i8 > @narrow_shuffle_of_select_consts (<2 x i1 > %cmp ) {
111
119
; CHECK-LABEL: @narrow_shuffle_of_select_consts(
112
- ; CHECK-NEXT: [[WIDECMP:%.*]] = shufflevector <2 x i1> [[CMP:%.*]], <2 x i1> undef, <4 x i32> <i32 0, i32 1, i32 undef, i32 undef>
113
- ; CHECK-NEXT: [[WIDESEL:%.*]] = select <4 x i1> [[WIDECMP]], <4 x i8> <i8 -1, i8 -2, i8 undef, i8 undef>, <4 x i8> <i8 1, i8 2, i8 undef, i8 undef>
114
- ; CHECK-NEXT: [[R:%.*]] = shufflevector <4 x i8> [[WIDESEL]], <4 x i8> undef, <2 x i32> <i32 0, i32 1>
120
+ ; CHECK-NEXT: [[R:%.*]] = select <2 x i1> [[CMP:%.*]], <2 x i8> <i8 -1, i8 -2>, <2 x i8> <i8 1, i8 2>
115
121
; CHECK-NEXT: ret <2 x i8> [[R]]
116
122
;
117
123
%widecmp = shufflevector <2 x i1 > %cmp , <2 x i1 > undef , <4 x i32 > <i32 0 , i32 1 , i32 undef , i32 undef >
@@ -121,15 +127,11 @@ define <2 x i8> @narrow_shuffle_of_select_consts(<2 x i1> %cmp) {
121
127
}
122
128
123
129
; PR38691 - https://bugs.llvm.org/show_bug.cgi?id=38691
124
- ; TODO: If the operands are widened only to be narrowed back, then all of the shuffles are unnecessary.
130
+ ; If the operands are widened only to be narrowed back, then all of the shuffles are unnecessary.
125
131
126
132
define <2 x i8 > @narrow_shuffle_of_select_with_widened_ops (<2 x i1 > %cmp , <2 x i8 > %x , <2 x i8 > %y ) {
127
133
; CHECK-LABEL: @narrow_shuffle_of_select_with_widened_ops(
128
- ; CHECK-NEXT: [[WIDEX:%.*]] = shufflevector <2 x i8> [[X:%.*]], <2 x i8> undef, <4 x i32> <i32 0, i32 1, i32 undef, i32 undef>
129
- ; CHECK-NEXT: [[WIDEY:%.*]] = shufflevector <2 x i8> [[Y:%.*]], <2 x i8> undef, <4 x i32> <i32 0, i32 1, i32 undef, i32 undef>
130
- ; CHECK-NEXT: [[WIDECMP:%.*]] = shufflevector <2 x i1> [[CMP:%.*]], <2 x i1> undef, <4 x i32> <i32 0, i32 1, i32 undef, i32 undef>
131
- ; CHECK-NEXT: [[WIDESEL:%.*]] = select <4 x i1> [[WIDECMP]], <4 x i8> [[WIDEX]], <4 x i8> [[WIDEY]]
132
- ; CHECK-NEXT: [[R:%.*]] = shufflevector <4 x i8> [[WIDESEL]], <4 x i8> undef, <2 x i32> <i32 0, i32 1>
134
+ ; CHECK-NEXT: [[R:%.*]] = select <2 x i1> [[CMP:%.*]], <2 x i8> [[X:%.*]], <2 x i8> [[Y:%.*]]
133
135
; CHECK-NEXT: ret <2 x i8> [[R]]
134
136
;
135
137
%widex = shufflevector <2 x i8 > %x , <2 x i8 > undef , <4 x i32 > <i32 0 , i32 1 , i32 undef , i32 undef >
0 commit comments