1; RUN: opt < %s -instcombine -S | FileCheck %s
2; PR3021
3
4; When inst combining an FCMP with the LHS coming from a uitofp instruction, we
5; can't lower it to signed ICMP instructions.
6
7; CHECK-LABEL: @test1(
8define i1 @test1(i32 %val) {
9  %1 = uitofp i32 %val to double
10  %2 = fcmp ole double %1, 0.000000e+00
11; CHECK: icmp eq i32 %val, 0
12  ret i1 %2
13}
14
15; CHECK-LABEL: @test2(
16define i1 @test2(i32 %val) {
17  %1 = uitofp i32 %val to double
18  %2 = fcmp olt double %1, 0.000000e+00
19  ret i1 %2
20; CHECK: ret i1 false
21}
22
23; CHECK-LABEL: @test3(
24define i1 @test3(i32 %val) {
25  %1 = uitofp i32 %val to double
26  %2 = fcmp oge double %1, 0.000000e+00
27  ret i1 %2
28; CHECK: ret i1 true
29}
30
31; CHECK-LABEL: @test4(
32define i1 @test4(i32 %val) {
33  %1 = uitofp i32 %val to double
34  %2 = fcmp ogt double %1, 0.000000e+00
35; CHECK: icmp ne i32 %val, 0
36  ret i1 %2
37}
38
39; CHECK-LABEL: @test5(
40define i1 @test5(i32 %val) {
41  %1 = uitofp i32 %val to double
42  %2 = fcmp ogt double %1, -4.400000e+00
43  ret i1 %2
44; CHECK: ret i1 true
45}
46
47; CHECK-LABEL: @test6(
48define i1 @test6(i32 %val) {
49  %1 = uitofp i32 %val to double
50  %2 = fcmp olt double %1, -4.400000e+00
51  ret i1 %2
52; CHECK: ret i1 false
53}
54
55; Check that optimizing unsigned >= comparisons correctly distinguishes
56; positive and negative constants.  <rdar://problem/12029145>
57; CHECK-LABEL: @test7(
58define i1 @test7(i32 %val) {
59  %1 = uitofp i32 %val to double
60  %2 = fcmp oge double %1, 3.200000e+00
61  ret i1 %2
62; CHECK: icmp ugt i32 %val, 3
63}
64