1 ; RUN: opt < %s -instcombine -S | FileCheck %s
3 ; Check simplification of
4 ; (icmp sgt x, -1) & (icmp sgt/sge n, x) --> icmp ugt/uge n, x
6 ; CHECK-LABEL: define i1 @test_and1
7 ; CHECK: [[R:%[0-9]+]] = icmp ugt i32 %nn, %x
9 define i1 @test_and1(i32 %x, i32 %n) {
10 %nn = and i32 %n, 2147483647
11 %a = icmp sge i32 %x, 0
12 %b = icmp slt i32 %x, %nn
17 ; CHECK-LABEL: define i1 @test_and2
18 ; CHECK: [[R:%[0-9]+]] = icmp uge i32 %nn, %x
20 define i1 @test_and2(i32 %x, i32 %n) {
21 %nn = and i32 %n, 2147483647
22 %a = icmp sgt i32 %x, -1
23 %b = icmp sle i32 %x, %nn
28 ; CHECK-LABEL: define i1 @test_and3
29 ; CHECK: [[R:%[0-9]+]] = icmp ugt i32 %nn, %x
31 define i1 @test_and3(i32 %x, i32 %n) {
32 %nn = and i32 %n, 2147483647
33 %a = icmp sgt i32 %nn, %x
34 %b = icmp sge i32 %x, 0
39 ; CHECK-LABEL: define i1 @test_and4
40 ; CHECK: [[R:%[0-9]+]] = icmp uge i32 %nn, %x
42 define i1 @test_and4(i32 %x, i32 %n) {
43 %nn = and i32 %n, 2147483647
44 %a = icmp sge i32 %nn, %x
45 %b = icmp sge i32 %x, 0
50 ; CHECK-LABEL: define i1 @test_or1
51 ; CHECK: [[R:%[0-9]+]] = icmp ule i32 %nn, %x
53 define i1 @test_or1(i32 %x, i32 %n) {
54 %nn = and i32 %n, 2147483647
55 %a = icmp slt i32 %x, 0
56 %b = icmp sge i32 %x, %nn
61 ; CHECK-LABEL: define i1 @test_or2
62 ; CHECK: [[R:%[0-9]+]] = icmp ult i32 %nn, %x
64 define i1 @test_or2(i32 %x, i32 %n) {
65 %nn = and i32 %n, 2147483647
66 %a = icmp sle i32 %x, -1
67 %b = icmp sgt i32 %x, %nn
72 ; CHECK-LABEL: define i1 @test_or3
73 ; CHECK: [[R:%[0-9]+]] = icmp ule i32 %nn, %x
75 define i1 @test_or3(i32 %x, i32 %n) {
76 %nn = and i32 %n, 2147483647
77 %a = icmp sle i32 %nn, %x
78 %b = icmp slt i32 %x, 0
83 ; CHECK-LABEL: define i1 @test_or4
84 ; CHECK: [[R:%[0-9]+]] = icmp ult i32 %nn, %x
86 define i1 @test_or4(i32 %x, i32 %n) {
87 %nn = and i32 %n, 2147483647
88 %a = icmp slt i32 %nn, %x
89 %b = icmp slt i32 %x, 0
96 ; CHECK-LABEL: define i1 @negative1
99 ; CHECK: %c = and i1 %a, %b
101 define i1 @negative1(i32 %x, i32 %n) {
102 %nn = and i32 %n, 2147483647
103 %a = icmp slt i32 %x, %nn
104 %b = icmp sgt i32 %x, 0 ; should be: icmp sge
109 ; CHECK-LABEL: define i1 @negative2
112 ; CHECK: %c = and i1 %a, %b
114 define i1 @negative2(i32 %x, i32 %n) {
115 %a = icmp slt i32 %x, %n ; n can be negative
116 %b = icmp sge i32 %x, 0
121 ; CHECK-LABEL: define i1 @negative3
124 ; CHECK: %c = and i1 %a, %b
126 define i1 @negative3(i32 %x, i32 %y, i32 %n) {
127 %nn = and i32 %n, 2147483647
128 %a = icmp slt i32 %x, %nn
129 %b = icmp sge i32 %y, 0 ; should compare %x and not %y
134 ; CHECK-LABEL: define i1 @negative4
137 ; CHECK: %c = and i1 %a, %b
139 define i1 @negative4(i32 %x, i32 %n) {
140 %nn = and i32 %n, 2147483647
141 %a = icmp ne i32 %x, %nn ; should be: icmp slt/sle
142 %b = icmp sge i32 %x, 0
147 ; CHECK-LABEL: define i1 @negative5
150 ; CHECK: %c = or i1 %a, %b
152 define i1 @negative5(i32 %x, i32 %n) {
153 %nn = and i32 %n, 2147483647
154 %a = icmp slt i32 %x, %nn
155 %b = icmp sge i32 %x, 0
156 %c = or i1 %a, %b ; should be: and