1 ; RUN: opt < %s -instsimplify -S | FileCheck %s
3 define i32 @test1(i32 %x) {
5 %cmp = icmp eq i32 %and, 0
7 %and1.x = select i1 %cmp, i32 %and1, i32 %x
13 define i32 @test2(i32 %x) {
15 %cmp = icmp ne i32 %and, 0
16 %and1 = and i32 %x, -2
17 %and1.x = select i1 %cmp, i32 %x, i32 %and1
19 ; CHECK-LABEL: @test2(
23 define i32 @test3(i32 %x) {
25 %cmp = icmp ne i32 %and, 0
26 %and1 = and i32 %x, -2
27 %and1.x = select i1 %cmp, i32 %and1, i32 %x
29 ; CHECK-LABEL: @test3(
30 ; CHECK: %[[and:.*]] = and i32 %x, -2
31 ; CHECK: ret i32 %[[and]]
34 define i32 @test4(i32 %X) {
35 %cmp = icmp slt i32 %X, 0
36 %or = or i32 %X, -2147483648
37 %cond = select i1 %cmp, i32 %X, i32 %or
40 ; CHECK: %[[or:.*]] = or i32 %X, -2147483648
41 ; CHECK: ret i32 %[[or]]
44 define i32 @test5(i32 %X) {
45 %cmp = icmp slt i32 %X, 0
46 %or = or i32 %X, -2147483648
47 %cond = select i1 %cmp, i32 %or, i32 %X
53 define i32 @test6(i32 %X) {
54 %cmp = icmp slt i32 %X, 0
55 %and = and i32 %X, 2147483647
56 %cond = select i1 %cmp, i32 %and, i32 %X
59 ; CHECK: %[[and:.*]] = and i32 %X, 2147483647
60 ; CHECK: ret i32 %[[and]]
63 define i32 @test7(i32 %X) {
64 %cmp = icmp slt i32 %X, 0
65 %and = and i32 %X, 2147483647
66 %cond = select i1 %cmp, i32 %X, i32 %and
72 define i32 @test8(i32 %X) {
73 %cmp = icmp sgt i32 %X, -1
74 %or = or i32 %X, -2147483648
75 %cond = select i1 %cmp, i32 %X, i32 %or
81 define i32 @test9(i32 %X) {
82 %cmp = icmp sgt i32 %X, -1
83 %or = or i32 %X, -2147483648
84 %cond = select i1 %cmp, i32 %or, i32 %X
87 ; CHECK: %[[or:.*]] = or i32 %X, -2147483648
88 ; CHECK: ret i32 %[[or]]
91 define i32 @test10(i32 %X) {
92 %cmp = icmp sgt i32 %X, -1
93 %and = and i32 %X, 2147483647
94 %cond = select i1 %cmp, i32 %and, i32 %X
96 ; CHECK-LABEL: @test10
100 define i32 @test11(i32 %X) {
101 %cmp = icmp sgt i32 %X, -1
102 %and = and i32 %X, 2147483647
103 %cond = select i1 %cmp, i32 %X, i32 %and
105 ; CHECK-LABEL: @test11
106 ; CHECK: %[[and:.*]] = and i32 %X, 2147483647
107 ; CHECK: ret i32 %[[and]]
110 ; CHECK-LABEL: @select_icmp_and_8_eq_0_or_8(
111 ; CHECK-NEXT: [[OR:%[a-z0-9]+]] = or i32 %x, 8
112 ; CHECK-NEXT: ret i32 [[OR]]
113 define i32 @select_icmp_and_8_eq_0_or_8(i32 %x) {
115 %cmp = icmp eq i32 %and, 0
117 %or.x = select i1 %cmp, i32 %or, i32 %x
121 ; CHECK-LABEL: @select_icmp_and_8_ne_0_and_not_8(
122 ; CHECK-NEXT: [[AND:%[a-z0-9]+]] = and i32 %x, -9
123 ; CHECK-NEXT: ret i32 [[AND]]
124 define i32 @select_icmp_and_8_ne_0_and_not_8(i32 %x) {
126 %cmp = icmp eq i32 %and, 0
127 %and1 = and i32 %x, -9
128 %x.and1 = select i1 %cmp, i32 %x, i32 %and1
132 ; CHECK-LABEL: @select_icmp_and_8_eq_0_and_not_8(
133 ; CHECK-NEXT: ret i32 %x
134 define i32 @select_icmp_and_8_eq_0_and_not_8(i32 %x) {
136 %cmp = icmp eq i32 %and, 0
137 %and1 = and i32 %x, -9
138 %and1.x = select i1 %cmp, i32 %and1, i32 %x
142 ; CHECK-LABEL: @select_icmp_x_and_8_eq_0_y_and_not_8(
143 ; CHECK: select i1 %cmp, i64 %y, i64 %and1
144 define i64 @select_icmp_x_and_8_eq_0_y_and_not_8(i32 %x, i64 %y) {
146 %cmp = icmp eq i32 %and, 0
147 %and1 = and i64 %y, -9
148 %y.and1 = select i1 %cmp, i64 %y, i64 %and1
152 ; CHECK-LABEL: @select_icmp_x_and_8_ne_0_y_and_not_8(
153 ; CHECK: select i1 %cmp, i64 %and1, i64 %y
154 define i64 @select_icmp_x_and_8_ne_0_y_and_not_8(i32 %x, i64 %y) {
156 %cmp = icmp eq i32 %and, 0
157 %and1 = and i64 %y, -9
158 %and1.y = select i1 %cmp, i64 %and1, i64 %y