aboutsummaryrefslogtreecommitdiffstats
path: root/test/CodeGen/X86/cmovcmov.ll
blob: 982bc82c4c791393291300c56d63cc0de1798a14 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
; RUN: llc < %s -asm-verbose=false -mtriple=x86_64-unknown-linux | FileCheck %s --check-prefix=CHECK --check-prefix=CMOV
; RUN: llc < %s -asm-verbose=false -mtriple=i686-unknown-linux | FileCheck %s --check-prefix=CHECK --check-prefix=NOCMOV

target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"

; Test 2xCMOV patterns exposed after legalization.
; One way to do that is with (select (fcmp une/oeq)), which gets
; legalized to setp/setne.

; CHECK-LABEL: test_select_fcmp_oeq_i32:

; CMOV-NEXT: ucomiss  %xmm1, %xmm0
; CMOV-NEXT: cmovnel  %esi, %edi
; CMOV-NEXT: cmovpl  %esi, %edi
; CMOV-NEXT: movl  %edi, %eax
; CMOV-NEXT: retq

; NOCMOV-NEXT:  flds  8(%esp)
; NOCMOV-NEXT:  flds  4(%esp)
; NOCMOV-NEXT:  fucompp
; NOCMOV-NEXT:  fnstsw  %ax
; NOCMOV-NEXT:  sahf
; NOCMOV-NEXT:  leal  16(%esp), %eax
; NOCMOV-NEXT:  jne  [[TBB:.LBB[0-9_]+]]
; NOCMOV-NEXT:  jp  [[TBB]]
; NOCMOV-NEXT:  leal  12(%esp), %eax
; NOCMOV-NEXT:[[TBB]]:
; NOCMOV-NEXT:  movl  (%eax), %eax
; NOCMOV-NEXT:  retl
define i32 @test_select_fcmp_oeq_i32(float %a, float %b, i32 %c, i32 %d) #0 {
entry:
  %cmp = fcmp oeq float %a, %b
  %r = select i1 %cmp, i32 %c, i32 %d
  ret i32 %r
}

; CHECK-LABEL: test_select_fcmp_oeq_i64:

; CMOV-NEXT:   ucomiss  %xmm1, %xmm0
; CMOV-NEXT:   cmovneq  %rsi, %rdi
; CMOV-NEXT:   cmovpq  %rsi, %rdi
; CMOV-NEXT:   movq  %rdi, %rax
; CMOV-NEXT:   retq

; NOCMOV-NEXT:   flds  8(%esp)
; NOCMOV-NEXT:   flds  4(%esp)
; NOCMOV-NEXT:   fucompp
; NOCMOV-NEXT:   fnstsw  %ax
; NOCMOV-NEXT:   sahf
; NOCMOV-NEXT:   leal  20(%esp), %ecx
; NOCMOV-NEXT:   jne  [[TBB:.LBB[0-9_]+]]
; NOCMOV-NEXT:   jp  [[TBB]]
; NOCMOV-NEXT:   leal  12(%esp), %ecx
; NOCMOV-NEXT: [[TBB]]:
; NOCMOV-NEXT:   movl  (%ecx), %eax
; NOCMOV-NEXT:   orl  $4, %ecx
; NOCMOV-NEXT:   movl  (%ecx), %edx
; NOCMOV-NEXT:   retl
define i64 @test_select_fcmp_oeq_i64(float %a, float %b, i64 %c, i64 %d) #0 {
entry:
  %cmp = fcmp oeq float %a, %b
  %r = select i1 %cmp, i64 %c, i64 %d
  ret i64 %r
}

; CHECK-LABEL: test_select_fcmp_une_i64:

; CMOV-NEXT:   ucomiss  %xmm1, %xmm0
; CMOV-NEXT:   cmovneq  %rdi, %rsi
; CMOV-NEXT:   cmovpq  %rdi, %rsi
; CMOV-NEXT:   movq  %rsi, %rax
; CMOV-NEXT:   retq

; NOCMOV-NEXT:   flds  8(%esp)
; NOCMOV-NEXT:   flds  4(%esp)
; NOCMOV-NEXT:   fucompp
; NOCMOV-NEXT:   fnstsw  %ax
; NOCMOV-NEXT:   sahf
; NOCMOV-NEXT:   leal  12(%esp), %ecx
; NOCMOV-NEXT:   jne  [[TBB:.LBB[0-9_]+]]
; NOCMOV-NEXT:   jp  [[TBB]]
; NOCMOV-NEXT:   leal  20(%esp), %ecx
; NOCMOV-NEXT: [[TBB]]:
; NOCMOV-NEXT:   movl  (%ecx), %eax
; NOCMOV-NEXT:   orl  $4, %ecx
; NOCMOV-NEXT:   movl  (%ecx), %edx
; NOCMOV-NEXT:   retl
define i64 @test_select_fcmp_une_i64(float %a, float %b, i64 %c, i64 %d) #0 {
entry:
  %cmp = fcmp une float %a, %b
  %r = select i1 %cmp, i64 %c, i64 %d
  ret i64 %r
}

; CHECK-LABEL: test_select_fcmp_oeq_f64:

; CMOV-NEXT:   ucomiss  %xmm1, %xmm0
; CMOV-NEXT:   jne  [[TBB:.LBB[0-9_]+]]
; CMOV-NEXT:   jp  [[TBB]]
; CMOV-NEXT:   movaps  %xmm2, %xmm3
; CMOV-NEXT: [[TBB]]:
; CMOV-NEXT:   movaps  %xmm3, %xmm0
; CMOV-NEXT:   retq

; NOCMOV-NEXT:   flds  8(%esp)
; NOCMOV-NEXT:   flds  4(%esp)
; NOCMOV-NEXT:   fucompp
; NOCMOV-NEXT:   fnstsw  %ax
; NOCMOV-NEXT:   sahf
; NOCMOV-NEXT:   leal  20(%esp), %eax
; NOCMOV-NEXT:   jne  [[TBB:.LBB[0-9_]+]]
; NOCMOV-NEXT:   jp  [[TBB]]
; NOCMOV-NEXT:   leal  12(%esp), %eax
; NOCMOV-NEXT: [[TBB]]:
; NOCMOV-NEXT:   fldl  (%eax)
; NOCMOV-NEXT:   retl
define double @test_select_fcmp_oeq_f64(float %a, float %b, double %c, double %d) #0 {
entry:
  %cmp = fcmp oeq float %a, %b
  %r = select i1 %cmp, double %c, double %d
  ret double %r
}

; CHECK-LABEL: test_select_fcmp_oeq_v4i32:

; CMOV-NEXT:   ucomiss  %xmm1, %xmm0
; CMOV-NEXT:   jne  [[TBB:.LBB[0-9_]+]]
; CMOV-NEXT:   jp  [[TBB]]
; CMOV-NEXT:   movaps  %xmm2, %xmm3
; CMOV-NEXT: [[TBB]]:
; CMOV-NEXT:   movaps  %xmm3, %xmm0
; CMOV-NEXT:   retq

; NOCMOV-NEXT:   pushl  %edi
; NOCMOV-NEXT:   pushl  %esi
; NOCMOV-NEXT:   flds  20(%esp)
; NOCMOV-NEXT:   flds  16(%esp)
; NOCMOV-NEXT:   fucompp
; NOCMOV-NEXT:   fnstsw  %ax
; NOCMOV-NEXT:   sahf
; NOCMOV-NEXT:   leal  40(%esp), %eax
; NOCMOV-NEXT:   jne  [[TBB:.LBB[0-9_]+]]
; NOCMOV-NEXT:   jp  [[TBB]]
; NOCMOV-NEXT:   leal  24(%esp), %eax
; NOCMOV-NEXT: [[TBB]]:
; NOCMOV-NEXT:   movl  (%eax), %eax
; NOCMOV-NEXT:   leal  44(%esp), %ecx
; NOCMOV-NEXT:   jne  [[TBB:.LBB[0-9_]+]]
; NOCMOV-NEXT:   jp  [[TBB]]
; NOCMOV-NEXT:   leal  28(%esp), %ecx
; NOCMOV-NEXT: [[TBB]]:
; NOCMOV-NEXT:   movl  (%ecx), %ecx
; NOCMOV-NEXT:   leal  48(%esp), %esi
; NOCMOV-NEXT:   jne  [[TBB:.LBB[0-9_]+]]
; NOCMOV-NEXT:   jp  [[TBB]]
; NOCMOV-NEXT:   leal  32(%esp), %esi
; NOCMOV-NEXT: [[TBB]]:
; NOCMOV-NEXT:   movl  12(%esp), %edx
; NOCMOV-NEXT:   movl  (%esi), %esi
; NOCMOV-NEXT:   leal  52(%esp), %edi
; NOCMOV-NEXT:   jne  [[TBB:.LBB[0-9_]+]]
; NOCMOV-NEXT:   jp  [[TBB]]
; NOCMOV-NEXT:   leal  36(%esp), %edi
; NOCMOV-NEXT: [[TBB]]:
; NOCMOV-NEXT:   movl  (%edi), %edi
; NOCMOV-NEXT:   movl  %edi, 12(%edx)
; NOCMOV-NEXT:   movl  %esi, 8(%edx)
; NOCMOV-NEXT:   movl  %ecx, 4(%edx)
; NOCMOV-NEXT:   movl  %eax, (%edx)
; NOCMOV-NEXT:   popl  %esi
; NOCMOV-NEXT:   popl  %edi
; NOCMOV-NEXT:   retl  $4
define <4 x i32> @test_select_fcmp_oeq_v4i32(float %a, float %b, <4 x i32> %c, <4 x i32> %d) #0 {
entry:
  %cmp = fcmp oeq float %a, %b
  %r = select i1 %cmp, <4 x i32> %c, <4 x i32> %d
  ret <4 x i32> %r
}

; Also make sure we catch the original code-sequence of interest:

; CMOV: [[ONE_F32_LCPI:.LCPI.*]]:
; CMOV-NEXT:   .long  1065353216

; CHECK-LABEL: test_zext_fcmp_une:
; CMOV-NEXT:   ucomiss  %xmm1, %xmm0
; CMOV-NEXT:   movss  [[ONE_F32_LCPI]](%rip), %xmm0
; CMOV-NEXT:   jne  [[TBB:.LBB[0-9_]+]]
; CMOV-NEXT:   jp  [[TBB]]
; CMOV-NEXT:   xorps  %xmm0, %xmm0
; CMOV-NEXT: [[TBB]]:
; CMOV-NEXT:   retq

; NOCMOV:        jne
; NOCMOV-NEXT:   jp
define float @test_zext_fcmp_une(float %a, float %b) #0 {
entry:
  %cmp = fcmp une float %a, %b
  %conv1 = zext i1 %cmp to i32
  %conv2 = sitofp i32 %conv1 to float
  ret float %conv2
}

; CMOV: [[ONE_F32_LCPI:.LCPI.*]]:
; CMOV-NEXT:   .long  1065353216

; CHECK-LABEL: test_zext_fcmp_oeq:
; CMOV-NEXT:   ucomiss  %xmm1, %xmm0
; CMOV-NEXT:   xorps  %xmm0, %xmm0
; CMOV-NEXT:   jne  [[TBB:.LBB[0-9_]+]]
; CMOV-NEXT:   jp  [[TBB]]
; CMOV-NEXT:   movss  [[ONE_F32_LCPI]](%rip), %xmm0
; CMOV-NEXT: [[TBB]]:
; CMOV-NEXT:   retq

; NOCMOV:        jne
; NOCMOV-NEXT:   jp
define float @test_zext_fcmp_oeq(float %a, float %b) #0 {
entry:
  %cmp = fcmp oeq float %a, %b
  %conv1 = zext i1 %cmp to i32
  %conv2 = sitofp i32 %conv1 to float
  ret float %conv2
}

attributes #0 = { nounwind }