AVX-512: fixed a compare pattern
[oota-llvm.git] / test / CodeGen / X86 / avx512-cmp.ll
1 ; RUN: llc < %s -mtriple=x86_64-apple-darwin -mcpu=knl --show-mc-encoding | FileCheck %s
2
3 ; CHECK-LABEL: test1
4 ; CHECK: vucomisd {{.*}}encoding: [0x62
5 define double @test1(double %a, double %b) nounwind {
6   %tobool = fcmp une double %a, %b
7   br i1 %tobool, label %l1, label %l2
8
9 l1:
10   %c = fsub double %a, %b
11   ret double %c
12 l2:
13   %c1 = fadd double %a, %b
14   ret double %c1
15 }
16
17 ; CHECK-LABEL: test2
18 ; CHECK: vucomiss {{.*}}encoding: [0x62
19 define float @test2(float %a, float %b) nounwind {
20   %tobool = fcmp olt float %a, %b
21   br i1 %tobool, label %l1, label %l2
22
23 l1:
24   %c = fsub float %a, %b
25   ret float %c
26 l2:
27   %c1 = fadd float %a, %b
28   ret float %c1
29 }
30
31 ; CHECK-LABEL: test3
32 ; CHECK: vcmpeqss
33 ; CHECK: kmov
34 ; CHECK: ret
35 define i32 @test3(float %a, float %b) {
36
37   %cmp10.i = fcmp oeq float %a, %b
38   %conv11.i = zext i1 %cmp10.i to i32
39   ret i32 %conv11.i
40 }
41
42 ; CHECK-LABEL: test4
43 ; CHECK: kortestw
44 ; CHECK: jne
45 ; CHECK: ret
46 declare i32 @llvm.x86.avx512.kortestz.w(i16, i16)
47
48 define i16 @test4(i16 %a, i16 %b) {
49   %kortz = call i32 @llvm.x86.avx512.kortestz.w(i16 %a, i16 %b)
50   %t1 = and i32 %kortz, 1
51   %res = icmp eq i32 %t1, 0
52   br i1 %res, label %A, label %B
53
54  A: ret i16 %a
55  B:
56  %b1 = add i16 %a, %b
57  ret i16 %b1
58
59 }
60
61 ; CHECK-LABEL: test5
62 ; CHECK: ret
63 define float @test5(float %p) #0 {
64 entry:
65   %cmp = fcmp oeq float %p, 0.000000e+00
66   br i1 %cmp, label %return, label %if.end
67
68 if.end:                                           ; preds = %entry
69   %cmp1 = fcmp ogt float %p, 0.000000e+00
70   %cond = select i1 %cmp1, float 1.000000e+00, float -1.000000e+00
71   br label %return
72
73 return:                                           ; preds = %if.end, %entry
74   %retval.0 = phi float [ %cond, %if.end ], [ %p, %entry ]
75   ret float %retval.0
76 }
77
78 ; CHECK-LABEL: test6
79 ; CHECK: cmpl
80 ; CHECK-NOT: kmov
81 ; CHECK: ret
82 define i32 @test6(i32 %a, i32 %b) {
83   %cmp = icmp eq i32 %a, %b
84   %res = zext i1 %cmp to i32
85   ret i32 %res
86 }
87
88 ; CHECK-LABEL: test7
89 ; CHECK: vucomisd
90 ; CHECK-NOT: kmov
91 ; CHECK: ret
92 define i32 @test7(double %x, double %y) #2 {
93 entry:
94   %0 = fcmp one double %x, %y
95   %or = zext i1 %0 to i32
96   ret i32 %or
97 }
98
99 define i32 @test8(i32 %a1, i32 %a2, i32 %a3) {
100   %tmp1 = icmp eq i32 %a1, -1
101   %tmp2 = icmp eq i32 %a2, -2147483648
102   %tmp3 = and i1 %tmp1, %tmp2
103   %tmp4 = icmp eq i32 %a3, 0
104   %tmp5 = or i1 %tmp3, %tmp4
105   %res = select i1 %tmp5, i32 1, i32 %a3
106   ret i32 %res
107   }