Duncan Sands | 8fb2c38 | 2011-01-20 13:21:55 +0000 | [diff] [blame] | 1 | ; RUN: opt < %s -instsimplify -S | FileCheck %s |
| 2 | target datalayout = "p:32:32" |
| 3 | |
| 4 | define i1 @ptrtoint() { |
Stephen Lin | c1c7a13 | 2013-07-14 01:42:54 +0000 | [diff] [blame] | 5 | ; CHECK-LABEL: @ptrtoint( |
Duncan Sands | 8fb2c38 | 2011-01-20 13:21:55 +0000 | [diff] [blame] | 6 | %a = alloca i8 |
| 7 | %tmp = ptrtoint i8* %a to i32 |
| 8 | %r = icmp eq i32 %tmp, 0 |
| 9 | ret i1 %r |
| 10 | ; CHECK: ret i1 false |
| 11 | } |
| 12 | |
Benjamin Kramer | ea51f62 | 2012-02-16 13:49:39 +0000 | [diff] [blame] | 13 | define i1 @bitcast() { |
Stephen Lin | c1c7a13 | 2013-07-14 01:42:54 +0000 | [diff] [blame] | 14 | ; CHECK-LABEL: @bitcast( |
Benjamin Kramer | ea51f62 | 2012-02-16 13:49:39 +0000 | [diff] [blame] | 15 | %a = alloca i32 |
| 16 | %b = alloca i64 |
| 17 | %x = bitcast i32* %a to i8* |
| 18 | %y = bitcast i64* %b to i8* |
| 19 | %cmp = icmp eq i8* %x, %y |
| 20 | ret i1 %cmp |
| 21 | ; CHECK-NEXT: ret i1 false |
| 22 | } |
| 23 | |
| 24 | define i1 @gep() { |
Stephen Lin | c1c7a13 | 2013-07-14 01:42:54 +0000 | [diff] [blame] | 25 | ; CHECK-LABEL: @gep( |
Benjamin Kramer | ea51f62 | 2012-02-16 13:49:39 +0000 | [diff] [blame] | 26 | %a = alloca [3 x i8], align 8 |
David Blaikie | 79e6c74 | 2015-02-27 19:29:02 +0000 | [diff] [blame] | 27 | %x = getelementptr inbounds [3 x i8], [3 x i8]* %a, i32 0, i32 0 |
Benjamin Kramer | ea51f62 | 2012-02-16 13:49:39 +0000 | [diff] [blame] | 28 | %cmp = icmp eq i8* %x, null |
| 29 | ret i1 %cmp |
| 30 | ; CHECK-NEXT: ret i1 false |
| 31 | } |
| 32 | |
Eli Friedman | 952d1f9 | 2012-02-18 03:29:25 +0000 | [diff] [blame] | 33 | define i1 @gep2() { |
Stephen Lin | c1c7a13 | 2013-07-14 01:42:54 +0000 | [diff] [blame] | 34 | ; CHECK-LABEL: @gep2( |
Eli Friedman | 952d1f9 | 2012-02-18 03:29:25 +0000 | [diff] [blame] | 35 | %a = alloca [3 x i8], align 8 |
David Blaikie | 79e6c74 | 2015-02-27 19:29:02 +0000 | [diff] [blame] | 36 | %x = getelementptr inbounds [3 x i8], [3 x i8]* %a, i32 0, i32 0 |
| 37 | %y = getelementptr inbounds [3 x i8], [3 x i8]* %a, i32 0, i32 0 |
Eli Friedman | 952d1f9 | 2012-02-18 03:29:25 +0000 | [diff] [blame] | 38 | %cmp = icmp eq i8* %x, %y |
| 39 | ret i1 %cmp |
| 40 | ; CHECK-NEXT: ret i1 true |
| 41 | } |
| 42 | |
Nick Lewycky | 3db143e | 2012-02-26 02:09:49 +0000 | [diff] [blame] | 43 | ; PR11238 |
| 44 | %gept = type { i32, i32 } |
| 45 | @gepy = global %gept zeroinitializer, align 8 |
| 46 | @gepz = extern_weak global %gept |
| 47 | |
| 48 | define i1 @gep3() { |
Stephen Lin | c1c7a13 | 2013-07-14 01:42:54 +0000 | [diff] [blame] | 49 | ; CHECK-LABEL: @gep3( |
Nick Lewycky | 3db143e | 2012-02-26 02:09:49 +0000 | [diff] [blame] | 50 | %x = alloca %gept, align 8 |
David Blaikie | 79e6c74 | 2015-02-27 19:29:02 +0000 | [diff] [blame] | 51 | %a = getelementptr %gept, %gept* %x, i64 0, i32 0 |
| 52 | %b = getelementptr %gept, %gept* %x, i64 0, i32 1 |
Nick Lewycky | 3db143e | 2012-02-26 02:09:49 +0000 | [diff] [blame] | 53 | %equal = icmp eq i32* %a, %b |
| 54 | ret i1 %equal |
| 55 | ; CHECK-NEXT: ret i1 false |
| 56 | } |
| 57 | |
| 58 | define i1 @gep4() { |
Stephen Lin | c1c7a13 | 2013-07-14 01:42:54 +0000 | [diff] [blame] | 59 | ; CHECK-LABEL: @gep4( |
Nick Lewycky | 3db143e | 2012-02-26 02:09:49 +0000 | [diff] [blame] | 60 | %x = alloca %gept, align 8 |
David Blaikie | 79e6c74 | 2015-02-27 19:29:02 +0000 | [diff] [blame] | 61 | %a = getelementptr %gept, %gept* @gepy, i64 0, i32 0 |
| 62 | %b = getelementptr %gept, %gept* @gepy, i64 0, i32 1 |
Nick Lewycky | 3db143e | 2012-02-26 02:09:49 +0000 | [diff] [blame] | 63 | %equal = icmp eq i32* %a, %b |
| 64 | ret i1 %equal |
| 65 | ; CHECK-NEXT: ret i1 false |
| 66 | } |
| 67 | |
Sanjay Patel | 81ed349 | 2016-12-11 20:07:02 +0000 | [diff] [blame] | 68 | @a = common global [1 x i32] zeroinitializer, align 4 |
| 69 | |
| 70 | define i1 @PR31262() { |
| 71 | ; CHECK-LABEL: @PR31262( |
Joey Gouly | 61eaa63 | 2017-06-06 10:17:14 +0000 | [diff] [blame] | 72 | ; CHECK-NEXT: ret i1 icmp uge (i32* getelementptr ([1 x i32], [1 x i32]* @a, i32 0, i32 undef), i32* getelementptr inbounds ([1 x i32], [1 x i32]* @a, i32 0, i32 0)) |
Sanjay Patel | 81ed349 | 2016-12-11 20:07:02 +0000 | [diff] [blame] | 73 | ; |
| 74 | %idx = getelementptr inbounds [1 x i32], [1 x i32]* @a, i64 0, i64 undef |
| 75 | %cmp = icmp uge i32* %idx, getelementptr inbounds ([1 x i32], [1 x i32]* @a, i32 0, i32 0) |
| 76 | ret i1 %cmp |
| 77 | } |
| 78 | |
Nick Lewycky | 3db143e | 2012-02-26 02:09:49 +0000 | [diff] [blame] | 79 | define i1 @gep5() { |
Stephen Lin | c1c7a13 | 2013-07-14 01:42:54 +0000 | [diff] [blame] | 80 | ; CHECK-LABEL: @gep5( |
Nick Lewycky | 3db143e | 2012-02-26 02:09:49 +0000 | [diff] [blame] | 81 | %x = alloca %gept, align 8 |
David Blaikie | 79e6c74 | 2015-02-27 19:29:02 +0000 | [diff] [blame] | 82 | %a = getelementptr inbounds %gept, %gept* %x, i64 0, i32 1 |
| 83 | %b = getelementptr %gept, %gept* @gepy, i64 0, i32 0 |
Nick Lewycky | 3db143e | 2012-02-26 02:09:49 +0000 | [diff] [blame] | 84 | %equal = icmp eq i32* %a, %b |
| 85 | ret i1 %equal |
| 86 | ; CHECK-NEXT: ret i1 false |
| 87 | } |
| 88 | |
| 89 | define i1 @gep6(%gept* %x) { |
| 90 | ; Same as @gep3 but potentially null. |
Stephen Lin | c1c7a13 | 2013-07-14 01:42:54 +0000 | [diff] [blame] | 91 | ; CHECK-LABEL: @gep6( |
David Blaikie | 79e6c74 | 2015-02-27 19:29:02 +0000 | [diff] [blame] | 92 | %a = getelementptr %gept, %gept* %x, i64 0, i32 0 |
| 93 | %b = getelementptr %gept, %gept* %x, i64 0, i32 1 |
Nick Lewycky | 3db143e | 2012-02-26 02:09:49 +0000 | [diff] [blame] | 94 | %equal = icmp eq i32* %a, %b |
| 95 | ret i1 %equal |
| 96 | ; CHECK-NEXT: ret i1 false |
| 97 | } |
| 98 | |
| 99 | define i1 @gep7(%gept* %x) { |
Stephen Lin | c1c7a13 | 2013-07-14 01:42:54 +0000 | [diff] [blame] | 100 | ; CHECK-LABEL: @gep7( |
David Blaikie | 79e6c74 | 2015-02-27 19:29:02 +0000 | [diff] [blame] | 101 | %a = getelementptr %gept, %gept* %x, i64 0, i32 0 |
| 102 | %b = getelementptr %gept, %gept* @gepz, i64 0, i32 0 |
Nick Lewycky | 3db143e | 2012-02-26 02:09:49 +0000 | [diff] [blame] | 103 | %equal = icmp eq i32* %a, %b |
| 104 | ret i1 %equal |
| 105 | ; CHECK: ret i1 %equal |
| 106 | } |
| 107 | |
| 108 | define i1 @gep8(%gept* %x) { |
Stephen Lin | c1c7a13 | 2013-07-14 01:42:54 +0000 | [diff] [blame] | 109 | ; CHECK-LABEL: @gep8( |
David Blaikie | 79e6c74 | 2015-02-27 19:29:02 +0000 | [diff] [blame] | 110 | %a = getelementptr %gept, %gept* %x, i32 1 |
| 111 | %b = getelementptr %gept, %gept* %x, i32 -1 |
Nick Lewycky | 3db143e | 2012-02-26 02:09:49 +0000 | [diff] [blame] | 112 | %equal = icmp ugt %gept* %a, %b |
| 113 | ret i1 %equal |
| 114 | ; CHECK: ret i1 %equal |
| 115 | } |
| 116 | |
Chandler Carruth | 8059c84 | 2012-03-25 21:28:14 +0000 | [diff] [blame] | 117 | define i1 @gep9(i8* %ptr) { |
Stephen Lin | c1c7a13 | 2013-07-14 01:42:54 +0000 | [diff] [blame] | 118 | ; CHECK-LABEL: @gep9( |
Chandler Carruth | 8059c84 | 2012-03-25 21:28:14 +0000 | [diff] [blame] | 119 | ; CHECK-NOT: ret |
| 120 | ; CHECK: ret i1 true |
| 121 | |
| 122 | entry: |
David Blaikie | 79e6c74 | 2015-02-27 19:29:02 +0000 | [diff] [blame] | 123 | %first1 = getelementptr inbounds i8, i8* %ptr, i32 0 |
| 124 | %first2 = getelementptr inbounds i8, i8* %first1, i32 1 |
| 125 | %first3 = getelementptr inbounds i8, i8* %first2, i32 2 |
| 126 | %first4 = getelementptr inbounds i8, i8* %first3, i32 4 |
| 127 | %last1 = getelementptr inbounds i8, i8* %first2, i32 48 |
| 128 | %last2 = getelementptr inbounds i8, i8* %last1, i32 8 |
| 129 | %last3 = getelementptr inbounds i8, i8* %last2, i32 -4 |
| 130 | %last4 = getelementptr inbounds i8, i8* %last3, i32 -4 |
Chandler Carruth | 8059c84 | 2012-03-25 21:28:14 +0000 | [diff] [blame] | 131 | %first.int = ptrtoint i8* %first4 to i32 |
| 132 | %last.int = ptrtoint i8* %last4 to i32 |
| 133 | %cmp = icmp ne i32 %last.int, %first.int |
| 134 | ret i1 %cmp |
| 135 | } |
| 136 | |
| 137 | define i1 @gep10(i8* %ptr) { |
Stephen Lin | c1c7a13 | 2013-07-14 01:42:54 +0000 | [diff] [blame] | 138 | ; CHECK-LABEL: @gep10( |
Chandler Carruth | 8059c84 | 2012-03-25 21:28:14 +0000 | [diff] [blame] | 139 | ; CHECK-NOT: ret |
| 140 | ; CHECK: ret i1 true |
| 141 | |
| 142 | entry: |
David Blaikie | 79e6c74 | 2015-02-27 19:29:02 +0000 | [diff] [blame] | 143 | %first1 = getelementptr inbounds i8, i8* %ptr, i32 -2 |
| 144 | %first2 = getelementptr inbounds i8, i8* %first1, i32 44 |
| 145 | %last1 = getelementptr inbounds i8, i8* %ptr, i32 48 |
| 146 | %last2 = getelementptr inbounds i8, i8* %last1, i32 -6 |
Chandler Carruth | 8059c84 | 2012-03-25 21:28:14 +0000 | [diff] [blame] | 147 | %first.int = ptrtoint i8* %first2 to i32 |
| 148 | %last.int = ptrtoint i8* %last2 to i32 |
| 149 | %cmp = icmp eq i32 %last.int, %first.int |
| 150 | ret i1 %cmp |
| 151 | } |
| 152 | |
| 153 | define i1 @gep11(i8* %ptr) { |
Stephen Lin | c1c7a13 | 2013-07-14 01:42:54 +0000 | [diff] [blame] | 154 | ; CHECK-LABEL: @gep11( |
Chandler Carruth | 8059c84 | 2012-03-25 21:28:14 +0000 | [diff] [blame] | 155 | ; CHECK-NOT: ret |
| 156 | ; CHECK: ret i1 true |
| 157 | |
| 158 | entry: |
David Blaikie | 79e6c74 | 2015-02-27 19:29:02 +0000 | [diff] [blame] | 159 | %first1 = getelementptr inbounds i8, i8* %ptr, i32 -2 |
| 160 | %last1 = getelementptr inbounds i8, i8* %ptr, i32 48 |
| 161 | %last2 = getelementptr inbounds i8, i8* %last1, i32 -6 |
Chandler Carruth | 8059c84 | 2012-03-25 21:28:14 +0000 | [diff] [blame] | 162 | %cmp = icmp ult i8* %first1, %last2 |
| 163 | ret i1 %cmp |
| 164 | } |
| 165 | |
| 166 | define i1 @gep12(i8* %ptr) { |
Stephen Lin | c1c7a13 | 2013-07-14 01:42:54 +0000 | [diff] [blame] | 167 | ; CHECK-LABEL: @gep12( |
Chandler Carruth | 8059c84 | 2012-03-25 21:28:14 +0000 | [diff] [blame] | 168 | ; CHECK-NOT: ret |
| 169 | ; CHECK: ret i1 %cmp |
| 170 | |
| 171 | entry: |
David Blaikie | 79e6c74 | 2015-02-27 19:29:02 +0000 | [diff] [blame] | 172 | %first1 = getelementptr inbounds i8, i8* %ptr, i32 -2 |
| 173 | %last1 = getelementptr inbounds i8, i8* %ptr, i32 48 |
| 174 | %last2 = getelementptr inbounds i8, i8* %last1, i32 -6 |
Chandler Carruth | 8059c84 | 2012-03-25 21:28:14 +0000 | [diff] [blame] | 175 | %cmp = icmp slt i8* %first1, %last2 |
| 176 | ret i1 %cmp |
| 177 | } |
| 178 | |
Chandler Carruth | 80d3e56 | 2012-12-07 02:08:58 +0000 | [diff] [blame] | 179 | define i1 @gep13(i8* %ptr) { |
Stephen Lin | c1c7a13 | 2013-07-14 01:42:54 +0000 | [diff] [blame] | 180 | ; CHECK-LABEL: @gep13( |
Chandler Carruth | 80d3e56 | 2012-12-07 02:08:58 +0000 | [diff] [blame] | 181 | ; We can prove this GEP is non-null because it is inbounds. |
David Blaikie | 79e6c74 | 2015-02-27 19:29:02 +0000 | [diff] [blame] | 182 | %x = getelementptr inbounds i8, i8* %ptr, i32 1 |
Chandler Carruth | 80d3e56 | 2012-12-07 02:08:58 +0000 | [diff] [blame] | 183 | %cmp = icmp eq i8* %x, null |
| 184 | ret i1 %cmp |
| 185 | ; CHECK-NEXT: ret i1 false |
| 186 | } |
| 187 | |
| 188 | define i1 @gep14({ {}, i8 }* %ptr) { |
Stephen Lin | c1c7a13 | 2013-07-14 01:42:54 +0000 | [diff] [blame] | 189 | ; CHECK-LABEL: @gep14( |
Chandler Carruth | 80d3e56 | 2012-12-07 02:08:58 +0000 | [diff] [blame] | 190 | ; We can't simplify this because the offset of one in the GEP actually doesn't |
| 191 | ; move the pointer. |
David Blaikie | 79e6c74 | 2015-02-27 19:29:02 +0000 | [diff] [blame] | 192 | %x = getelementptr inbounds { {}, i8 }, { {}, i8 }* %ptr, i32 0, i32 1 |
Chandler Carruth | 80d3e56 | 2012-12-07 02:08:58 +0000 | [diff] [blame] | 193 | %cmp = icmp eq i8* %x, null |
| 194 | ret i1 %cmp |
| 195 | ; CHECK-NOT: ret i1 false |
| 196 | } |
| 197 | |
| 198 | define i1 @gep15({ {}, [4 x {i8, i8}]}* %ptr, i32 %y) { |
Stephen Lin | c1c7a13 | 2013-07-14 01:42:54 +0000 | [diff] [blame] | 199 | ; CHECK-LABEL: @gep15( |
Chandler Carruth | 80d3e56 | 2012-12-07 02:08:58 +0000 | [diff] [blame] | 200 | ; We can prove this GEP is non-null even though there is a user value, as we |
| 201 | ; would necessarily violate inbounds on one side or the other. |
David Blaikie | 79e6c74 | 2015-02-27 19:29:02 +0000 | [diff] [blame] | 202 | %x = getelementptr inbounds { {}, [4 x {i8, i8}]}, { {}, [4 x {i8, i8}]}* %ptr, i32 0, i32 1, i32 %y, i32 1 |
Chandler Carruth | 80d3e56 | 2012-12-07 02:08:58 +0000 | [diff] [blame] | 203 | %cmp = icmp eq i8* %x, null |
| 204 | ret i1 %cmp |
| 205 | ; CHECK-NEXT: ret i1 false |
| 206 | } |
| 207 | |
| 208 | define i1 @gep16(i8* %ptr, i32 %a) { |
Stephen Lin | c1c7a13 | 2013-07-14 01:42:54 +0000 | [diff] [blame] | 209 | ; CHECK-LABEL: @gep16( |
Chandler Carruth | 80d3e56 | 2012-12-07 02:08:58 +0000 | [diff] [blame] | 210 | ; We can prove this GEP is non-null because it is inbounds and because we know |
| 211 | ; %b is non-zero even though we don't know its value. |
| 212 | %b = or i32 %a, 1 |
David Blaikie | 79e6c74 | 2015-02-27 19:29:02 +0000 | [diff] [blame] | 213 | %x = getelementptr inbounds i8, i8* %ptr, i32 %b |
Chandler Carruth | 80d3e56 | 2012-12-07 02:08:58 +0000 | [diff] [blame] | 214 | %cmp = icmp eq i8* %x, null |
| 215 | ret i1 %cmp |
| 216 | ; CHECK-NEXT: ret i1 false |
| 217 | } |
| 218 | |
David Majnemer | dc8767a | 2016-08-07 07:58:10 +0000 | [diff] [blame] | 219 | define i1 @gep17() { |
| 220 | ; CHECK-LABEL: @gep17( |
| 221 | %alloca = alloca i32, align 4 |
| 222 | %bc = bitcast i32* %alloca to [4 x i8]* |
| 223 | %gep1 = getelementptr inbounds i32, i32* %alloca, i32 1 |
| 224 | %pti1 = ptrtoint i32* %gep1 to i32 |
| 225 | %gep2 = getelementptr inbounds [4 x i8], [4 x i8]* %bc, i32 0, i32 1 |
| 226 | %pti2 = ptrtoint i8* %gep2 to i32 |
| 227 | %cmp = icmp ugt i32 %pti1, %pti2 |
| 228 | ret i1 %cmp |
| 229 | ; CHECK-NEXT: ret i1 true |
| 230 | } |
| 231 | |
Duncan Sands | 8fb2c38 | 2011-01-20 13:21:55 +0000 | [diff] [blame] | 232 | define i1 @zext(i32 %x) { |
Stephen Lin | c1c7a13 | 2013-07-14 01:42:54 +0000 | [diff] [blame] | 233 | ; CHECK-LABEL: @zext( |
Duncan Sands | 8fb2c38 | 2011-01-20 13:21:55 +0000 | [diff] [blame] | 234 | %e1 = zext i32 %x to i64 |
| 235 | %e2 = zext i32 %x to i64 |
| 236 | %r = icmp eq i64 %e1, %e2 |
| 237 | ret i1 %r |
| 238 | ; CHECK: ret i1 true |
| 239 | } |
| 240 | |
| 241 | define i1 @zext2(i1 %x) { |
Stephen Lin | c1c7a13 | 2013-07-14 01:42:54 +0000 | [diff] [blame] | 242 | ; CHECK-LABEL: @zext2( |
Duncan Sands | 8fb2c38 | 2011-01-20 13:21:55 +0000 | [diff] [blame] | 243 | %e = zext i1 %x to i32 |
| 244 | %c = icmp ne i32 %e, 0 |
| 245 | ret i1 %c |
| 246 | ; CHECK: ret i1 %x |
| 247 | } |
| 248 | |
Duncan Sands | d395108 | 2011-01-25 09:38:29 +0000 | [diff] [blame] | 249 | define i1 @zext3() { |
Stephen Lin | c1c7a13 | 2013-07-14 01:42:54 +0000 | [diff] [blame] | 250 | ; CHECK-LABEL: @zext3( |
Duncan Sands | d395108 | 2011-01-25 09:38:29 +0000 | [diff] [blame] | 251 | %e = zext i1 1 to i32 |
| 252 | %c = icmp ne i32 %e, 0 |
| 253 | ret i1 %c |
| 254 | ; CHECK: ret i1 true |
| 255 | } |
| 256 | |
Duncan Sands | 8fb2c38 | 2011-01-20 13:21:55 +0000 | [diff] [blame] | 257 | define i1 @sext(i32 %x) { |
Stephen Lin | c1c7a13 | 2013-07-14 01:42:54 +0000 | [diff] [blame] | 258 | ; CHECK-LABEL: @sext( |
Duncan Sands | 8fb2c38 | 2011-01-20 13:21:55 +0000 | [diff] [blame] | 259 | %e1 = sext i32 %x to i64 |
| 260 | %e2 = sext i32 %x to i64 |
| 261 | %r = icmp eq i64 %e1, %e2 |
| 262 | ret i1 %r |
| 263 | ; CHECK: ret i1 true |
| 264 | } |
| 265 | |
| 266 | define i1 @sext2(i1 %x) { |
Stephen Lin | c1c7a13 | 2013-07-14 01:42:54 +0000 | [diff] [blame] | 267 | ; CHECK-LABEL: @sext2( |
Duncan Sands | 8fb2c38 | 2011-01-20 13:21:55 +0000 | [diff] [blame] | 268 | %e = sext i1 %x to i32 |
| 269 | %c = icmp ne i32 %e, 0 |
| 270 | ret i1 %c |
| 271 | ; CHECK: ret i1 %x |
| 272 | } |
Duncan Sands | d395108 | 2011-01-25 09:38:29 +0000 | [diff] [blame] | 273 | |
| 274 | define i1 @sext3() { |
Stephen Lin | c1c7a13 | 2013-07-14 01:42:54 +0000 | [diff] [blame] | 275 | ; CHECK-LABEL: @sext3( |
Duncan Sands | d395108 | 2011-01-25 09:38:29 +0000 | [diff] [blame] | 276 | %e = sext i1 1 to i32 |
| 277 | %c = icmp ne i32 %e, 0 |
| 278 | ret i1 %c |
| 279 | ; CHECK: ret i1 true |
| 280 | } |
| 281 | |
| 282 | define i1 @add(i32 %x, i32 %y) { |
Stephen Lin | c1c7a13 | 2013-07-14 01:42:54 +0000 | [diff] [blame] | 283 | ; CHECK-LABEL: @add( |
Duncan Sands | d395108 | 2011-01-25 09:38:29 +0000 | [diff] [blame] | 284 | %l = lshr i32 %x, 1 |
Duncan Sands | 9e9d5b2 | 2011-01-25 15:14:15 +0000 | [diff] [blame] | 285 | %q = lshr i32 %y, 1 |
| 286 | %r = or i32 %q, 1 |
Duncan Sands | d395108 | 2011-01-25 09:38:29 +0000 | [diff] [blame] | 287 | %s = add i32 %l, %r |
| 288 | %c = icmp eq i32 %s, 0 |
| 289 | ret i1 %c |
Duncan Sands | 9e9d5b2 | 2011-01-25 15:14:15 +0000 | [diff] [blame] | 290 | ; CHECK: ret i1 false |
Duncan Sands | d395108 | 2011-01-25 09:38:29 +0000 | [diff] [blame] | 291 | } |
| 292 | |
| 293 | define i1 @add2(i8 %x, i8 %y) { |
Stephen Lin | c1c7a13 | 2013-07-14 01:42:54 +0000 | [diff] [blame] | 294 | ; CHECK-LABEL: @add2( |
Duncan Sands | d395108 | 2011-01-25 09:38:29 +0000 | [diff] [blame] | 295 | %l = or i8 %x, 128 |
| 296 | %r = or i8 %y, 129 |
| 297 | %s = add i8 %l, %r |
| 298 | %c = icmp eq i8 %s, 0 |
| 299 | ret i1 %c |
| 300 | ; CHECK: ret i1 false |
| 301 | } |
| 302 | |
Duncan Sands | 9e9d5b2 | 2011-01-25 15:14:15 +0000 | [diff] [blame] | 303 | define i1 @add3(i8 %x, i8 %y) { |
Stephen Lin | c1c7a13 | 2013-07-14 01:42:54 +0000 | [diff] [blame] | 304 | ; CHECK-LABEL: @add3( |
Duncan Sands | 9e9d5b2 | 2011-01-25 15:14:15 +0000 | [diff] [blame] | 305 | %l = zext i8 %x to i32 |
| 306 | %r = zext i8 %y to i32 |
| 307 | %s = add i32 %l, %r |
| 308 | %c = icmp eq i32 %s, 0 |
| 309 | ret i1 %c |
| 310 | ; CHECK: ret i1 %c |
| 311 | } |
| 312 | |
Duncan Sands | d114ab3 | 2011-02-13 17:15:40 +0000 | [diff] [blame] | 313 | define i1 @add4(i32 %x, i32 %y) { |
Stephen Lin | c1c7a13 | 2013-07-14 01:42:54 +0000 | [diff] [blame] | 314 | ; CHECK-LABEL: @add4( |
Duncan Sands | d114ab3 | 2011-02-13 17:15:40 +0000 | [diff] [blame] | 315 | %z = add nsw i32 %y, 1 |
| 316 | %s1 = add nsw i32 %x, %y |
| 317 | %s2 = add nsw i32 %x, %z |
| 318 | %c = icmp slt i32 %s1, %s2 |
| 319 | ret i1 %c |
| 320 | ; CHECK: ret i1 true |
| 321 | } |
| 322 | |
| 323 | define i1 @add5(i32 %x, i32 %y) { |
Stephen Lin | c1c7a13 | 2013-07-14 01:42:54 +0000 | [diff] [blame] | 324 | ; CHECK-LABEL: @add5( |
Duncan Sands | d114ab3 | 2011-02-13 17:15:40 +0000 | [diff] [blame] | 325 | %z = add nuw i32 %y, 1 |
| 326 | %s1 = add nuw i32 %x, %z |
| 327 | %s2 = add nuw i32 %x, %y |
| 328 | %c = icmp ugt i32 %s1, %s2 |
| 329 | ret i1 %c |
| 330 | ; CHECK: ret i1 true |
| 331 | } |
| 332 | |
Duncan Sands | c41076c | 2012-11-16 19:41:26 +0000 | [diff] [blame] | 333 | define i1 @add6(i64 %A, i64 %B) { |
Stephen Lin | c1c7a13 | 2013-07-14 01:42:54 +0000 | [diff] [blame] | 334 | ; CHECK-LABEL: @add6( |
Duncan Sands | c41076c | 2012-11-16 19:41:26 +0000 | [diff] [blame] | 335 | %s1 = add i64 %A, %B |
| 336 | %s2 = add i64 %B, %A |
| 337 | %cmp = icmp eq i64 %s1, %s2 |
| 338 | ret i1 %cmp |
| 339 | ; CHECK: ret i1 true |
| 340 | } |
| 341 | |
Duncan Sands | d395108 | 2011-01-25 09:38:29 +0000 | [diff] [blame] | 342 | define i1 @addpowtwo(i32 %x, i32 %y) { |
Stephen Lin | c1c7a13 | 2013-07-14 01:42:54 +0000 | [diff] [blame] | 343 | ; CHECK-LABEL: @addpowtwo( |
Duncan Sands | d395108 | 2011-01-25 09:38:29 +0000 | [diff] [blame] | 344 | %l = lshr i32 %x, 1 |
| 345 | %r = shl i32 1, %y |
| 346 | %s = add i32 %l, %r |
| 347 | %c = icmp eq i32 %s, 0 |
| 348 | ret i1 %c |
| 349 | ; CHECK: ret i1 false |
| 350 | } |
| 351 | |
| 352 | define i1 @or(i32 %x) { |
Stephen Lin | c1c7a13 | 2013-07-14 01:42:54 +0000 | [diff] [blame] | 353 | ; CHECK-LABEL: @or( |
Duncan Sands | d395108 | 2011-01-25 09:38:29 +0000 | [diff] [blame] | 354 | %o = or i32 %x, 1 |
| 355 | %c = icmp eq i32 %o, 0 |
| 356 | ret i1 %c |
| 357 | ; CHECK: ret i1 false |
| 358 | } |
Duncan Sands | 2e9e4f1 | 2011-01-29 13:27:00 +0000 | [diff] [blame] | 359 | |
Jun Bum Lim | cd197cf | 2016-02-11 17:11:49 +0000 | [diff] [blame] | 360 | ; Do not simplify if we cannot guarantee that the ConstantExpr is a non-zero |
| 361 | ; constant. |
| 362 | @GV = common global i32* null |
| 363 | define i1 @or_constexp(i32 %x) { |
| 364 | ; CHECK-LABEL: @or_constexp( |
| 365 | entry: |
| 366 | %0 = and i32 ptrtoint (i32** @GV to i32), 32 |
| 367 | %o = or i32 %x, %0 |
| 368 | %c = icmp eq i32 %o, 0 |
| 369 | ret i1 %c |
| 370 | ; CHECK: or |
| 371 | ; CHECK-NEXT: icmp eq |
| 372 | ; CHECK-NOT: ret i1 false |
| 373 | } |
| 374 | |
David Majnemer | 76d06bc | 2014-08-28 03:34:28 +0000 | [diff] [blame] | 375 | define i1 @shl1(i32 %x) { |
| 376 | ; CHECK-LABEL: @shl1( |
Duncan Sands | 2e9e4f1 | 2011-01-29 13:27:00 +0000 | [diff] [blame] | 377 | %s = shl i32 1, %x |
| 378 | %c = icmp eq i32 %s, 0 |
| 379 | ret i1 %c |
| 380 | ; CHECK: ret i1 false |
| 381 | } |
| 382 | |
David Majnemer | 76d06bc | 2014-08-28 03:34:28 +0000 | [diff] [blame] | 383 | define i1 @shl3(i32 %X) { |
| 384 | ; CHECK: @shl3 |
| 385 | %sub = shl nuw i32 4, %X |
| 386 | %cmp = icmp eq i32 %sub, 31 |
| 387 | ret i1 %cmp |
| 388 | ; CHECK-NEXT: ret i1 false |
| 389 | } |
| 390 | |
Nick Lewycky | 3cec6f5 | 2011-03-04 07:00:57 +0000 | [diff] [blame] | 391 | define i1 @lshr1(i32 %x) { |
Stephen Lin | c1c7a13 | 2013-07-14 01:42:54 +0000 | [diff] [blame] | 392 | ; CHECK-LABEL: @lshr1( |
Duncan Sands | 2e9e4f1 | 2011-01-29 13:27:00 +0000 | [diff] [blame] | 393 | %s = lshr i32 -1, %x |
| 394 | %c = icmp eq i32 %s, 0 |
| 395 | ret i1 %c |
| 396 | ; CHECK: ret i1 false |
| 397 | } |
| 398 | |
David Majnemer | a80fed7 | 2013-07-09 22:01:22 +0000 | [diff] [blame] | 399 | define i1 @lshr3(i32 %x) { |
Stephen Lin | c1c7a13 | 2013-07-14 01:42:54 +0000 | [diff] [blame] | 400 | ; CHECK-LABEL: @lshr3( |
David Majnemer | a80fed7 | 2013-07-09 22:01:22 +0000 | [diff] [blame] | 401 | %s = lshr i32 %x, %x |
| 402 | %c = icmp eq i32 %s, 0 |
| 403 | ret i1 %c |
| 404 | ; CHECK: ret i1 true |
| 405 | } |
| 406 | |
David Majnemer | 3af5bf3 | 2016-01-21 18:55:54 +0000 | [diff] [blame] | 407 | define i1 @lshr4(i32 %X, i32 %Y) { |
| 408 | ; CHECK-LABEL: @lshr4( |
| 409 | %A = lshr i32 %X, %Y |
| 410 | %C = icmp ule i32 %A, %X |
| 411 | ret i1 %C |
| 412 | ; CHECK: ret i1 true |
| 413 | } |
| 414 | |
| 415 | define i1 @lshr5(i32 %X, i32 %Y) { |
| 416 | ; CHECK-LABEL: @lshr5( |
| 417 | %A = lshr i32 %X, %Y |
| 418 | %C = icmp ugt i32 %A, %X |
| 419 | ret i1 %C |
| 420 | ; CHECK: ret i1 false |
| 421 | } |
| 422 | |
Sanjoy Das | 0196921 | 2016-10-26 19:18:43 +0000 | [diff] [blame] | 423 | define i1 @lshr6(i32 %X, i32 %Y) { |
| 424 | ; CHECK-LABEL: @lshr6( |
| 425 | %A = lshr i32 %X, %Y |
| 426 | %C = icmp ult i32 %X, %A |
| 427 | ret i1 %C |
| 428 | ; CHECK: ret i1 false |
| 429 | } |
| 430 | |
| 431 | define i1 @lshr7(i32 %X, i32 %Y) { |
| 432 | ; CHECK-LABEL: @lshr7( |
| 433 | %A = lshr i32 %X, %Y |
| 434 | %C = icmp uge i32 %X, %A |
| 435 | ret i1 %C |
| 436 | ; CHECK: ret i1 true |
| 437 | } |
| 438 | |
Nick Lewycky | 3cec6f5 | 2011-03-04 07:00:57 +0000 | [diff] [blame] | 439 | define i1 @ashr1(i32 %x) { |
Stephen Lin | c1c7a13 | 2013-07-14 01:42:54 +0000 | [diff] [blame] | 440 | ; CHECK-LABEL: @ashr1( |
Duncan Sands | 2e9e4f1 | 2011-01-29 13:27:00 +0000 | [diff] [blame] | 441 | %s = ashr i32 -1, %x |
| 442 | %c = icmp eq i32 %s, 0 |
| 443 | ret i1 %c |
| 444 | ; CHECK: ret i1 false |
| 445 | } |
Duncan Sands | 0650402 | 2011-02-03 09:37:39 +0000 | [diff] [blame] | 446 | |
David Majnemer | a80fed7 | 2013-07-09 22:01:22 +0000 | [diff] [blame] | 447 | define i1 @ashr3(i32 %x) { |
Stephen Lin | c1c7a13 | 2013-07-14 01:42:54 +0000 | [diff] [blame] | 448 | ; CHECK-LABEL: @ashr3( |
David Majnemer | a80fed7 | 2013-07-09 22:01:22 +0000 | [diff] [blame] | 449 | %s = ashr i32 %x, %x |
| 450 | %c = icmp eq i32 %s, 0 |
| 451 | ret i1 %c |
| 452 | ; CHECK: ret i1 true |
| 453 | } |
| 454 | |
Duncan Sands | 0650402 | 2011-02-03 09:37:39 +0000 | [diff] [blame] | 455 | define i1 @select1(i1 %cond) { |
Stephen Lin | c1c7a13 | 2013-07-14 01:42:54 +0000 | [diff] [blame] | 456 | ; CHECK-LABEL: @select1( |
Duncan Sands | 0650402 | 2011-02-03 09:37:39 +0000 | [diff] [blame] | 457 | %s = select i1 %cond, i32 1, i32 0 |
| 458 | %c = icmp eq i32 %s, 1 |
| 459 | ret i1 %c |
| 460 | ; CHECK: ret i1 %cond |
| 461 | } |
| 462 | |
| 463 | define i1 @select2(i1 %cond) { |
Stephen Lin | c1c7a13 | 2013-07-14 01:42:54 +0000 | [diff] [blame] | 464 | ; CHECK-LABEL: @select2( |
Duncan Sands | 0650402 | 2011-02-03 09:37:39 +0000 | [diff] [blame] | 465 | %x = zext i1 %cond to i32 |
| 466 | %s = select i1 %cond, i32 %x, i32 0 |
| 467 | %c = icmp ne i32 %s, 0 |
| 468 | ret i1 %c |
| 469 | ; CHECK: ret i1 %cond |
| 470 | } |
| 471 | |
| 472 | define i1 @select3(i1 %cond) { |
Stephen Lin | c1c7a13 | 2013-07-14 01:42:54 +0000 | [diff] [blame] | 473 | ; CHECK-LABEL: @select3( |
Duncan Sands | 0650402 | 2011-02-03 09:37:39 +0000 | [diff] [blame] | 474 | %x = zext i1 %cond to i32 |
| 475 | %s = select i1 %cond, i32 1, i32 %x |
| 476 | %c = icmp ne i32 %s, 0 |
| 477 | ret i1 %c |
| 478 | ; CHECK: ret i1 %cond |
| 479 | } |
| 480 | |
| 481 | define i1 @select4(i1 %cond) { |
Stephen Lin | c1c7a13 | 2013-07-14 01:42:54 +0000 | [diff] [blame] | 482 | ; CHECK-LABEL: @select4( |
Duncan Sands | 0650402 | 2011-02-03 09:37:39 +0000 | [diff] [blame] | 483 | %invert = xor i1 %cond, 1 |
| 484 | %s = select i1 %invert, i32 0, i32 1 |
| 485 | %c = icmp ne i32 %s, 0 |
| 486 | ret i1 %c |
| 487 | ; CHECK: ret i1 %cond |
| 488 | } |
Nick Lewycky | c9d2006 | 2011-03-01 08:15:50 +0000 | [diff] [blame] | 489 | |
Duncan Sands | 3d5692a | 2011-10-30 19:56:36 +0000 | [diff] [blame] | 490 | define i1 @select5(i32 %x) { |
Stephen Lin | c1c7a13 | 2013-07-14 01:42:54 +0000 | [diff] [blame] | 491 | ; CHECK-LABEL: @select5( |
Duncan Sands | 3d5692a | 2011-10-30 19:56:36 +0000 | [diff] [blame] | 492 | %c = icmp eq i32 %x, 0 |
| 493 | %s = select i1 %c, i32 1, i32 %x |
| 494 | %c2 = icmp eq i32 %s, 0 |
| 495 | ret i1 %c2 |
| 496 | ; CHECK: ret i1 false |
| 497 | } |
| 498 | |
| 499 | define i1 @select6(i32 %x) { |
Stephen Lin | c1c7a13 | 2013-07-14 01:42:54 +0000 | [diff] [blame] | 500 | ; CHECK-LABEL: @select6( |
Duncan Sands | 3d5692a | 2011-10-30 19:56:36 +0000 | [diff] [blame] | 501 | %c = icmp sgt i32 %x, 0 |
| 502 | %s = select i1 %c, i32 %x, i32 4 |
| 503 | %c2 = icmp eq i32 %s, 0 |
| 504 | ret i1 %c2 |
| 505 | ; CHECK: ret i1 %c2 |
| 506 | } |
| 507 | |
Nick Lewycky | c9d2006 | 2011-03-01 08:15:50 +0000 | [diff] [blame] | 508 | define i1 @urem1(i32 %X, i32 %Y) { |
Stephen Lin | c1c7a13 | 2013-07-14 01:42:54 +0000 | [diff] [blame] | 509 | ; CHECK-LABEL: @urem1( |
Nick Lewycky | c9d2006 | 2011-03-01 08:15:50 +0000 | [diff] [blame] | 510 | %A = urem i32 %X, %Y |
| 511 | %B = icmp ult i32 %A, %Y |
| 512 | ret i1 %B |
| 513 | ; CHECK: ret i1 true |
| 514 | } |
| 515 | |
| 516 | define i1 @urem2(i32 %X, i32 %Y) { |
Stephen Lin | c1c7a13 | 2013-07-14 01:42:54 +0000 | [diff] [blame] | 517 | ; CHECK-LABEL: @urem2( |
Nick Lewycky | c9d2006 | 2011-03-01 08:15:50 +0000 | [diff] [blame] | 518 | %A = urem i32 %X, %Y |
| 519 | %B = icmp eq i32 %A, %Y |
| 520 | ret i1 %B |
Benjamin Kramer | 1885d21 | 2011-03-09 22:07:31 +0000 | [diff] [blame] | 521 | ; CHECK: ret i1 false |
Nick Lewycky | c9d2006 | 2011-03-01 08:15:50 +0000 | [diff] [blame] | 522 | } |
Nick Lewycky | 3cec6f5 | 2011-03-04 07:00:57 +0000 | [diff] [blame] | 523 | |
Nick Lewycky | 3cec6f5 | 2011-03-04 07:00:57 +0000 | [diff] [blame] | 524 | define i1 @urem4(i32 %X) { |
Stephen Lin | c1c7a13 | 2013-07-14 01:42:54 +0000 | [diff] [blame] | 525 | ; CHECK-LABEL: @urem4( |
Nick Lewycky | 3cec6f5 | 2011-03-04 07:00:57 +0000 | [diff] [blame] | 526 | %A = urem i32 %X, 15 |
| 527 | %B = icmp ult i32 %A, 10 |
| 528 | ret i1 %B |
| 529 | ; CHECK: ret i1 %B |
| 530 | } |
| 531 | |
Nick Lewycky | 8e3a79d | 2011-03-04 10:06:52 +0000 | [diff] [blame] | 532 | define i1 @urem5(i16 %X, i32 %Y) { |
Stephen Lin | c1c7a13 | 2013-07-14 01:42:54 +0000 | [diff] [blame] | 533 | ; CHECK-LABEL: @urem5( |
Nick Lewycky | 8e3a79d | 2011-03-04 10:06:52 +0000 | [diff] [blame] | 534 | %A = zext i16 %X to i32 |
| 535 | %B = urem i32 %A, %Y |
| 536 | %C = icmp slt i32 %B, %Y |
| 537 | ret i1 %C |
Nick Lewycky | 35aeea9 | 2013-07-12 23:42:57 +0000 | [diff] [blame] | 538 | ; CHECK-NOT: ret i1 true |
Nick Lewycky | 8e3a79d | 2011-03-04 10:06:52 +0000 | [diff] [blame] | 539 | } |
| 540 | |
Nick Lewycky | 980104d | 2011-03-09 06:26:03 +0000 | [diff] [blame] | 541 | define i1 @urem6(i32 %X, i32 %Y) { |
Stephen Lin | c1c7a13 | 2013-07-14 01:42:54 +0000 | [diff] [blame] | 542 | ; CHECK-LABEL: @urem6( |
Nick Lewycky | 980104d | 2011-03-09 06:26:03 +0000 | [diff] [blame] | 543 | %A = urem i32 %X, %Y |
| 544 | %B = icmp ugt i32 %Y, %A |
| 545 | ret i1 %B |
| 546 | ; CHECK: ret i1 true |
| 547 | } |
| 548 | |
Nick Lewycky | 35aeea9 | 2013-07-12 23:42:57 +0000 | [diff] [blame] | 549 | define i1 @urem7(i32 %X) { |
Stephen Lin | c1c7a13 | 2013-07-14 01:42:54 +0000 | [diff] [blame] | 550 | ; CHECK-LABEL: @urem7( |
Nick Lewycky | 35aeea9 | 2013-07-12 23:42:57 +0000 | [diff] [blame] | 551 | %A = urem i32 1, %X |
| 552 | %B = icmp sgt i32 %A, %X |
| 553 | ret i1 %B |
| 554 | ; CHECK-NOT: ret i1 false |
| 555 | } |
| 556 | |
Nick Lewycky | cc79973 | 2011-03-11 09:00:19 +0000 | [diff] [blame] | 557 | ; PR9343 #15 |
Stephen Lin | c1c7a13 | 2013-07-14 01:42:54 +0000 | [diff] [blame] | 558 | ; CHECK-LABEL: @srem2( |
Nick Lewycky | cc79973 | 2011-03-11 09:00:19 +0000 | [diff] [blame] | 559 | ; CHECK: ret i1 false |
| 560 | define i1 @srem2(i16 %X, i32 %Y) { |
| 561 | %A = zext i16 %X to i32 |
| 562 | %B = add nsw i32 %A, 1 |
| 563 | %C = srem i32 %B, %Y |
| 564 | %D = icmp slt i32 %C, 0 |
| 565 | ret i1 %D |
| 566 | } |
Benjamin Kramer | 5acc751 | 2011-03-12 17:18:11 +0000 | [diff] [blame] | 567 | |
Stephen Lin | c1c7a13 | 2013-07-14 01:42:54 +0000 | [diff] [blame] | 568 | ; CHECK-LABEL: @srem3( |
Benjamin Kramer | 5acc751 | 2011-03-12 17:18:11 +0000 | [diff] [blame] | 569 | ; CHECK-NEXT: ret i1 false |
| 570 | define i1 @srem3(i16 %X, i32 %Y) { |
| 571 | %A = zext i16 %X to i32 |
| 572 | %B = or i32 2147483648, %A |
| 573 | %C = sub nsw i32 1, %B |
| 574 | %D = srem i32 %C, %Y |
| 575 | %E = icmp slt i32 %D, 0 |
| 576 | ret i1 %E |
| 577 | } |
| 578 | |
Sanjay Patel | 390f1dc | 2017-05-07 18:19:13 +0000 | [diff] [blame] | 579 | define i1 @udiv2(i32 %Z) { |
Stephen Lin | c1c7a13 | 2013-07-14 01:42:54 +0000 | [diff] [blame] | 580 | ; CHECK-LABEL: @udiv2( |
Sanjay Patel | 390f1dc | 2017-05-07 18:19:13 +0000 | [diff] [blame] | 581 | ; CHECK-NEXT: ret i1 true |
| 582 | ; |
Nick Lewycky | 9719a71 | 2011-03-05 05:19:11 +0000 | [diff] [blame] | 583 | %A = udiv exact i32 10, %Z |
| 584 | %B = udiv exact i32 20, %Z |
| 585 | %C = icmp ult i32 %A, %B |
| 586 | ret i1 %C |
Sanjay Patel | 390f1dc | 2017-05-07 18:19:13 +0000 | [diff] [blame] | 587 | } |
| 588 | |
| 589 | ; Exact sdiv and equality preds can simplify. |
| 590 | |
| 591 | define i1 @sdiv_exact_equality(i32 %Z) { |
| 592 | ; CHECK-LABEL: @sdiv_exact_equality( |
| 593 | ; CHECK-NEXT: ret i1 false |
| 594 | ; |
| 595 | %A = sdiv exact i32 10, %Z |
| 596 | %B = sdiv exact i32 20, %Z |
| 597 | %C = icmp eq i32 %A, %B |
| 598 | ret i1 %C |
| 599 | } |
| 600 | |
Sanjay Patel | a23b141 | 2017-05-15 19:16:49 +0000 | [diff] [blame] | 601 | ; But not other preds: PR32949 - https://bugs.llvm.org/show_bug.cgi?id=32949 |
Sanjay Patel | 390f1dc | 2017-05-07 18:19:13 +0000 | [diff] [blame] | 602 | |
| 603 | define i1 @sdiv_exact_not_equality(i32 %Z) { |
| 604 | ; CHECK-LABEL: @sdiv_exact_not_equality( |
Sanjay Patel | a23b141 | 2017-05-15 19:16:49 +0000 | [diff] [blame] | 605 | ; CHECK-NEXT: [[A:%.*]] = sdiv exact i32 10, %Z |
| 606 | ; CHECK-NEXT: [[B:%.*]] = sdiv exact i32 20, %Z |
| 607 | ; CHECK-NEXT: [[C:%.*]] = icmp ult i32 [[A]], [[B]] |
| 608 | ; CHECK-NEXT: ret i1 [[C]] |
Sanjay Patel | 390f1dc | 2017-05-07 18:19:13 +0000 | [diff] [blame] | 609 | ; |
| 610 | %A = sdiv exact i32 10, %Z |
| 611 | %B = sdiv exact i32 20, %Z |
| 612 | %C = icmp ult i32 %A, %B |
| 613 | ret i1 %C |
Nick Lewycky | 9719a71 | 2011-03-05 05:19:11 +0000 | [diff] [blame] | 614 | } |
| 615 | |
Duncan Sands | 92af0a8 | 2011-10-28 18:17:44 +0000 | [diff] [blame] | 616 | define i1 @udiv3(i32 %X, i32 %Y) { |
Stephen Lin | c1c7a13 | 2013-07-14 01:42:54 +0000 | [diff] [blame] | 617 | ; CHECK-LABEL: @udiv3( |
Duncan Sands | 92af0a8 | 2011-10-28 18:17:44 +0000 | [diff] [blame] | 618 | %A = udiv i32 %X, %Y |
| 619 | %C = icmp ugt i32 %A, %X |
| 620 | ret i1 %C |
| 621 | ; CHECK: ret i1 false |
| 622 | } |
| 623 | |
| 624 | define i1 @udiv4(i32 %X, i32 %Y) { |
Stephen Lin | c1c7a13 | 2013-07-14 01:42:54 +0000 | [diff] [blame] | 625 | ; CHECK-LABEL: @udiv4( |
Duncan Sands | 92af0a8 | 2011-10-28 18:17:44 +0000 | [diff] [blame] | 626 | %A = udiv i32 %X, %Y |
| 627 | %C = icmp ule i32 %A, %X |
| 628 | ret i1 %C |
| 629 | ; CHECK: ret i1 true |
| 630 | } |
| 631 | |
Eli Friedman | 0bae8b2 | 2011-11-08 21:08:02 +0000 | [diff] [blame] | 632 | ; PR11340 |
| 633 | define i1 @udiv6(i32 %X) nounwind { |
Stephen Lin | c1c7a13 | 2013-07-14 01:42:54 +0000 | [diff] [blame] | 634 | ; CHECK-LABEL: @udiv6( |
Eli Friedman | 0bae8b2 | 2011-11-08 21:08:02 +0000 | [diff] [blame] | 635 | %A = udiv i32 1, %X |
| 636 | %C = icmp eq i32 %A, 0 |
| 637 | ret i1 %C |
| 638 | ; CHECK: ret i1 %C |
| 639 | } |
| 640 | |
Sanjoy Das | 0196921 | 2016-10-26 19:18:43 +0000 | [diff] [blame] | 641 | define i1 @udiv7(i32 %X, i32 %Y) { |
| 642 | ; CHECK-LABEL: @udiv7( |
| 643 | %A = udiv i32 %X, %Y |
| 644 | %C = icmp ult i32 %X, %A |
| 645 | ret i1 %C |
| 646 | ; CHECK: ret i1 false |
| 647 | } |
| 648 | |
| 649 | define i1 @udiv8(i32 %X, i32 %Y) { |
| 650 | ; CHECK-LABEL: @udiv8( |
| 651 | %A = udiv i32 %X, %Y |
| 652 | %C = icmp uge i32 %X, %A |
| 653 | ret i1 %C |
| 654 | ; CHECK: ret i1 true |
| 655 | } |
| 656 | |
Duncan Sands | 7cb61e5 | 2011-10-27 19:16:21 +0000 | [diff] [blame] | 657 | define i1 @mul1(i32 %X) { |
Stephen Lin | c1c7a13 | 2013-07-14 01:42:54 +0000 | [diff] [blame] | 658 | ; CHECK-LABEL: @mul1( |
Duncan Sands | 7cb61e5 | 2011-10-27 19:16:21 +0000 | [diff] [blame] | 659 | ; Square of a non-zero number is non-zero if there is no overflow. |
| 660 | %Y = or i32 %X, 1 |
| 661 | %M = mul nuw i32 %Y, %Y |
| 662 | %C = icmp eq i32 %M, 0 |
| 663 | ret i1 %C |
| 664 | ; CHECK: ret i1 false |
| 665 | } |
| 666 | |
| 667 | define i1 @mul2(i32 %X) { |
Stephen Lin | c1c7a13 | 2013-07-14 01:42:54 +0000 | [diff] [blame] | 668 | ; CHECK-LABEL: @mul2( |
Duncan Sands | 7cb61e5 | 2011-10-27 19:16:21 +0000 | [diff] [blame] | 669 | ; Square of a non-zero number is positive if there is no signed overflow. |
| 670 | %Y = or i32 %X, 1 |
| 671 | %M = mul nsw i32 %Y, %Y |
| 672 | %C = icmp sgt i32 %M, 0 |
| 673 | ret i1 %C |
| 674 | ; CHECK: ret i1 true |
| 675 | } |
| 676 | |
| 677 | define i1 @mul3(i32 %X, i32 %Y) { |
Stephen Lin | c1c7a13 | 2013-07-14 01:42:54 +0000 | [diff] [blame] | 678 | ; CHECK-LABEL: @mul3( |
Duncan Sands | 7cb61e5 | 2011-10-27 19:16:21 +0000 | [diff] [blame] | 679 | ; Product of non-negative numbers is non-negative if there is no signed overflow. |
| 680 | %XX = mul nsw i32 %X, %X |
| 681 | %YY = mul nsw i32 %Y, %Y |
| 682 | %M = mul nsw i32 %XX, %YY |
| 683 | %C = icmp sge i32 %M, 0 |
| 684 | ret i1 %C |
| 685 | ; CHECK: ret i1 true |
| 686 | } |
Duncan Sands | bf48ac6 | 2012-02-10 14:26:42 +0000 | [diff] [blame] | 687 | |
| 688 | define <2 x i1> @vectorselect1(<2 x i1> %cond) { |
Stephen Lin | c1c7a13 | 2013-07-14 01:42:54 +0000 | [diff] [blame] | 689 | ; CHECK-LABEL: @vectorselect1( |
Duncan Sands | bf48ac6 | 2012-02-10 14:26:42 +0000 | [diff] [blame] | 690 | %invert = xor <2 x i1> %cond, <i1 1, i1 1> |
| 691 | %s = select <2 x i1> %invert, <2 x i32> <i32 0, i32 0>, <2 x i32> <i32 1, i32 1> |
| 692 | %c = icmp ne <2 x i32> %s, <i32 0, i32 0> |
| 693 | ret <2 x i1> %c |
| 694 | ; CHECK: ret <2 x i1> %cond |
| 695 | } |
Duncan Sands | 26641d7 | 2012-02-10 14:31:24 +0000 | [diff] [blame] | 696 | |
Chris Lattner | 445d8c6 | 2012-02-20 00:42:49 +0000 | [diff] [blame] | 697 | ; PR11948 |
| 698 | define <2 x i1> @vectorselectcrash(i32 %arg1) { |
Duncan Sands | 26641d7 | 2012-02-10 14:31:24 +0000 | [diff] [blame] | 699 | %tobool40 = icmp ne i32 %arg1, 0 |
| 700 | %cond43 = select i1 %tobool40, <2 x i16> <i16 -5, i16 66>, <2 x i16> <i16 46, i16 1> |
| 701 | %cmp45 = icmp ugt <2 x i16> %cond43, <i16 73, i16 21> |
| 702 | ret <2 x i1> %cmp45 |
| 703 | } |
Chris Lattner | 445d8c6 | 2012-02-20 00:42:49 +0000 | [diff] [blame] | 704 | |
| 705 | ; PR12013 |
| 706 | define i1 @alloca_compare(i64 %idx) { |
| 707 | %sv = alloca { i32, i32, [124 x i32] } |
David Blaikie | 79e6c74 | 2015-02-27 19:29:02 +0000 | [diff] [blame] | 708 | %1 = getelementptr inbounds { i32, i32, [124 x i32] }, { i32, i32, [124 x i32] }* %sv, i32 0, i32 2, i64 %idx |
Chris Lattner | 445d8c6 | 2012-02-20 00:42:49 +0000 | [diff] [blame] | 709 | %2 = icmp eq i32* %1, null |
| 710 | ret i1 %2 |
| 711 | ; CHECK: alloca_compare |
| 712 | ; CHECK: ret i1 false |
| 713 | } |
Chris Lattner | 01990f0 | 2012-02-24 19:01:58 +0000 | [diff] [blame] | 714 | |
| 715 | ; PR12075 |
| 716 | define i1 @infinite_gep() { |
| 717 | ret i1 1 |
| 718 | |
| 719 | unreachableblock: |
David Blaikie | 79e6c74 | 2015-02-27 19:29:02 +0000 | [diff] [blame] | 720 | %X = getelementptr i32, i32 *%X, i32 1 |
Chris Lattner | 01990f0 | 2012-02-24 19:01:58 +0000 | [diff] [blame] | 721 | %Y = icmp eq i32* %X, null |
| 722 | ret i1 %Y |
| 723 | } |
Dan Gohman | 995d40e | 2013-01-31 23:49:33 +0000 | [diff] [blame] | 724 | |
| 725 | ; It's not valid to fold a comparison of an argument with an alloca, even though |
| 726 | ; that's tempting. An argument can't *alias* an alloca, however the aliasing rule |
| 727 | ; relies on restrictions against guessing an object's address and dereferencing. |
| 728 | ; There are no restrictions against guessing an object's address and comparing. |
| 729 | |
| 730 | define i1 @alloca_argument_compare(i64* %arg) { |
| 731 | %alloc = alloca i64 |
| 732 | %cmp = icmp eq i64* %arg, %alloc |
| 733 | ret i1 %cmp |
| 734 | ; CHECK: alloca_argument_compare |
| 735 | ; CHECK: ret i1 %cmp |
| 736 | } |
Dan Gohman | b3e2d3a | 2013-02-01 00:11:13 +0000 | [diff] [blame] | 737 | |
| 738 | ; As above, but with the operands reversed. |
| 739 | |
| 740 | define i1 @alloca_argument_compare_swapped(i64* %arg) { |
| 741 | %alloc = alloca i64 |
| 742 | %cmp = icmp eq i64* %alloc, %arg |
| 743 | ret i1 %cmp |
| 744 | ; CHECK: alloca_argument_compare_swapped |
| 745 | ; CHECK: ret i1 %cmp |
| 746 | } |
| 747 | |
| 748 | ; Don't assume that a noalias argument isn't equal to a global variable's |
| 749 | ; address. This is an example where AliasAnalysis' NoAlias concept is |
| 750 | ; different from actual pointer inequality. |
| 751 | |
| 752 | @y = external global i32 |
| 753 | define zeroext i1 @external_compare(i32* noalias %x) { |
| 754 | %cmp = icmp eq i32* %x, @y |
| 755 | ret i1 %cmp |
| 756 | ; CHECK: external_compare |
| 757 | ; CHECK: ret i1 %cmp |
| 758 | } |
Manman Ren | 1217112 | 2013-03-18 21:23:25 +0000 | [diff] [blame] | 759 | |
| 760 | define i1 @alloca_gep(i64 %a, i64 %b) { |
Stephen Lin | c1c7a13 | 2013-07-14 01:42:54 +0000 | [diff] [blame] | 761 | ; CHECK-LABEL: @alloca_gep( |
Manman Ren | 1217112 | 2013-03-18 21:23:25 +0000 | [diff] [blame] | 762 | ; We can prove this GEP is non-null because it is inbounds and the pointer |
| 763 | ; is non-null. |
| 764 | %strs = alloca [1000 x [1001 x i8]], align 16 |
David Blaikie | 79e6c74 | 2015-02-27 19:29:02 +0000 | [diff] [blame] | 765 | %x = getelementptr inbounds [1000 x [1001 x i8]], [1000 x [1001 x i8]]* %strs, i64 0, i64 %a, i64 %b |
Manman Ren | 1217112 | 2013-03-18 21:23:25 +0000 | [diff] [blame] | 766 | %cmp = icmp eq i8* %x, null |
| 767 | ret i1 %cmp |
| 768 | ; CHECK-NEXT: ret i1 false |
| 769 | } |
Benjamin Kramer | 942dfe6 | 2013-09-23 14:16:38 +0000 | [diff] [blame] | 770 | |
| 771 | define i1 @non_inbounds_gep_compare(i64* %a) { |
| 772 | ; CHECK-LABEL: @non_inbounds_gep_compare( |
| 773 | ; Equality compares with non-inbounds GEPs can be folded. |
David Blaikie | 79e6c74 | 2015-02-27 19:29:02 +0000 | [diff] [blame] | 774 | %x = getelementptr i64, i64* %a, i64 42 |
| 775 | %y = getelementptr inbounds i64, i64* %x, i64 -42 |
| 776 | %z = getelementptr i64, i64* %a, i64 -42 |
| 777 | %w = getelementptr inbounds i64, i64* %z, i64 42 |
Benjamin Kramer | b517194 | 2013-09-23 14:41:35 +0000 | [diff] [blame] | 778 | %cmp = icmp eq i64* %y, %w |
Benjamin Kramer | 942dfe6 | 2013-09-23 14:16:38 +0000 | [diff] [blame] | 779 | ret i1 %cmp |
Benjamin Kramer | b517194 | 2013-09-23 14:41:35 +0000 | [diff] [blame] | 780 | ; CHECK-NEXT: ret i1 true |
Benjamin Kramer | 942dfe6 | 2013-09-23 14:16:38 +0000 | [diff] [blame] | 781 | } |
Benjamin Kramer | d75c8eb | 2013-09-28 21:27:49 +0000 | [diff] [blame] | 782 | |
| 783 | define i1 @non_inbounds_gep_compare2(i64* %a) { |
| 784 | ; CHECK-LABEL: @non_inbounds_gep_compare2( |
| 785 | ; Equality compares with non-inbounds GEPs can be folded. |
David Blaikie | 79e6c74 | 2015-02-27 19:29:02 +0000 | [diff] [blame] | 786 | %x = getelementptr i64, i64* %a, i64 4294967297 |
| 787 | %y = getelementptr i64, i64* %a, i64 1 |
Benjamin Kramer | d75c8eb | 2013-09-28 21:27:49 +0000 | [diff] [blame] | 788 | %cmp = icmp eq i64* %y, %y |
| 789 | ret i1 %cmp |
| 790 | ; CHECK-NEXT: ret i1 true |
| 791 | } |
Benjamin Kramer | 5e1794e | 2014-01-24 17:09:53 +0000 | [diff] [blame] | 792 | |
David Majnemer | 2d6c023 | 2014-05-14 20:16:28 +0000 | [diff] [blame] | 793 | define i1 @compare_always_true_slt(i16 %a) { |
| 794 | %1 = zext i16 %a to i32 |
| 795 | %2 = sub nsw i32 0, %1 |
| 796 | %3 = icmp slt i32 %2, 1 |
| 797 | ret i1 %3 |
| 798 | |
| 799 | ; CHECK-LABEL: @compare_always_true_slt |
| 800 | ; CHECK-NEXT: ret i1 true |
| 801 | } |
| 802 | |
| 803 | define i1 @compare_always_true_sle(i16 %a) { |
| 804 | %1 = zext i16 %a to i32 |
| 805 | %2 = sub nsw i32 0, %1 |
| 806 | %3 = icmp sle i32 %2, 0 |
| 807 | ret i1 %3 |
| 808 | |
| 809 | ; CHECK-LABEL: @compare_always_true_sle |
| 810 | ; CHECK-NEXT: ret i1 true |
| 811 | } |
| 812 | |
| 813 | define i1 @compare_always_false_sgt(i16 %a) { |
| 814 | %1 = zext i16 %a to i32 |
| 815 | %2 = sub nsw i32 0, %1 |
| 816 | %3 = icmp sgt i32 %2, 0 |
| 817 | ret i1 %3 |
| 818 | |
| 819 | ; CHECK-LABEL: @compare_always_false_sgt |
| 820 | ; CHECK-NEXT: ret i1 false |
| 821 | } |
| 822 | |
| 823 | define i1 @compare_always_false_sge(i16 %a) { |
| 824 | %1 = zext i16 %a to i32 |
| 825 | %2 = sub nsw i32 0, %1 |
| 826 | %3 = icmp sge i32 %2, 1 |
| 827 | ret i1 %3 |
| 828 | |
| 829 | ; CHECK-LABEL: @compare_always_false_sge |
| 830 | ; CHECK-NEXT: ret i1 false |
| 831 | } |
| 832 | |
| 833 | define i1 @compare_always_false_eq(i16 %a) { |
| 834 | %1 = zext i16 %a to i32 |
| 835 | %2 = sub nsw i32 0, %1 |
| 836 | %3 = icmp eq i32 %2, 1 |
| 837 | ret i1 %3 |
| 838 | |
| 839 | ; CHECK-LABEL: @compare_always_false_eq |
| 840 | ; CHECK-NEXT: ret i1 false |
| 841 | } |
| 842 | |
| 843 | define i1 @compare_always_false_ne(i16 %a) { |
| 844 | %1 = zext i16 %a to i32 |
| 845 | %2 = sub nsw i32 0, %1 |
| 846 | %3 = icmp ne i32 %2, 1 |
| 847 | ret i1 %3 |
| 848 | |
| 849 | ; CHECK-LABEL: @compare_always_false_ne |
| 850 | ; CHECK-NEXT: ret i1 true |
| 851 | } |
David Majnemer | ea8d5db | 2014-05-16 16:57:04 +0000 | [diff] [blame] | 852 | |
David Majnemer | 78910fc | 2014-05-16 17:14:03 +0000 | [diff] [blame] | 853 | define i1 @lshr_ugt_false(i32 %a) { |
| 854 | %shr = lshr i32 1, %a |
| 855 | %cmp = icmp ugt i32 %shr, 1 |
| 856 | ret i1 %cmp |
| 857 | ; CHECK-LABEL: @lshr_ugt_false |
| 858 | ; CHECK-NEXT: ret i1 false |
| 859 | } |
| 860 | |
Nick Lewycky | ec37354 | 2014-05-20 05:13:21 +0000 | [diff] [blame] | 861 | define i1 @nonnull_arg(i32* nonnull %i) { |
| 862 | %cmp = icmp eq i32* %i, null |
| 863 | ret i1 %cmp |
| 864 | ; CHECK-LABEL: @nonnull_arg |
| 865 | ; CHECK: ret i1 false |
| 866 | } |
| 867 | |
Hal Finkel | b0407ba | 2014-07-18 15:51:28 +0000 | [diff] [blame] | 868 | define i1 @nonnull_deref_arg(i32* dereferenceable(4) %i) { |
| 869 | %cmp = icmp eq i32* %i, null |
| 870 | ret i1 %cmp |
| 871 | ; CHECK-LABEL: @nonnull_deref_arg |
| 872 | ; CHECK: ret i1 false |
| 873 | } |
| 874 | |
| 875 | define i1 @nonnull_deref_as_arg(i32 addrspace(1)* dereferenceable(4) %i) { |
| 876 | %cmp = icmp eq i32 addrspace(1)* %i, null |
| 877 | ret i1 %cmp |
| 878 | ; CHECK-LABEL: @nonnull_deref_as_arg |
| 879 | ; CHECK: icmp |
Ahmed Bougacha | 082c5c7 | 2015-03-14 01:43:57 +0000 | [diff] [blame] | 880 | ; CHECK: ret |
Hal Finkel | b0407ba | 2014-07-18 15:51:28 +0000 | [diff] [blame] | 881 | } |
| 882 | |
Nick Lewycky | ec37354 | 2014-05-20 05:13:21 +0000 | [diff] [blame] | 883 | declare nonnull i32* @returns_nonnull_helper() |
| 884 | define i1 @returns_nonnull() { |
| 885 | %call = call nonnull i32* @returns_nonnull_helper() |
| 886 | %cmp = icmp eq i32* %call, null |
| 887 | ret i1 %cmp |
| 888 | ; CHECK-LABEL: @returns_nonnull |
| 889 | ; CHECK: ret i1 false |
| 890 | } |
| 891 | |
Hal Finkel | b0407ba | 2014-07-18 15:51:28 +0000 | [diff] [blame] | 892 | declare dereferenceable(4) i32* @returns_nonnull_deref_helper() |
| 893 | define i1 @returns_nonnull_deref() { |
| 894 | %call = call dereferenceable(4) i32* @returns_nonnull_deref_helper() |
| 895 | %cmp = icmp eq i32* %call, null |
| 896 | ret i1 %cmp |
| 897 | ; CHECK-LABEL: @returns_nonnull_deref |
| 898 | ; CHECK: ret i1 false |
| 899 | } |
| 900 | |
| 901 | declare dereferenceable(4) i32 addrspace(1)* @returns_nonnull_deref_as_helper() |
| 902 | define i1 @returns_nonnull_as_deref() { |
| 903 | %call = call dereferenceable(4) i32 addrspace(1)* @returns_nonnull_deref_as_helper() |
| 904 | %cmp = icmp eq i32 addrspace(1)* %call, null |
| 905 | ret i1 %cmp |
| 906 | ; CHECK-LABEL: @returns_nonnull_as_deref |
| 907 | ; CHECK: icmp |
| 908 | ; CHECK: ret |
| 909 | } |
| 910 | |
Philip Reames | cdb72f3 | 2014-10-20 22:40:55 +0000 | [diff] [blame] | 911 | define i1 @nonnull_load(i32** %addr) { |
David Blaikie | a79ac14 | 2015-02-27 21:17:42 +0000 | [diff] [blame] | 912 | %ptr = load i32*, i32** %addr, !nonnull !{} |
Philip Reames | cdb72f3 | 2014-10-20 22:40:55 +0000 | [diff] [blame] | 913 | %cmp = icmp eq i32* %ptr, null |
| 914 | ret i1 %cmp |
| 915 | ; CHECK-LABEL: @nonnull_load |
| 916 | ; CHECK: ret i1 false |
| 917 | } |
| 918 | |
| 919 | define i1 @nonnull_load_as_outer(i32* addrspace(1)* %addr) { |
David Blaikie | a79ac14 | 2015-02-27 21:17:42 +0000 | [diff] [blame] | 920 | %ptr = load i32*, i32* addrspace(1)* %addr, !nonnull !{} |
Philip Reames | cdb72f3 | 2014-10-20 22:40:55 +0000 | [diff] [blame] | 921 | %cmp = icmp eq i32* %ptr, null |
| 922 | ret i1 %cmp |
| 923 | ; CHECK-LABEL: @nonnull_load_as_outer |
| 924 | ; CHECK: ret i1 false |
| 925 | } |
| 926 | define i1 @nonnull_load_as_inner(i32 addrspace(1)** %addr) { |
David Blaikie | a79ac14 | 2015-02-27 21:17:42 +0000 | [diff] [blame] | 927 | %ptr = load i32 addrspace(1)*, i32 addrspace(1)** %addr, !nonnull !{} |
Philip Reames | cdb72f3 | 2014-10-20 22:40:55 +0000 | [diff] [blame] | 928 | %cmp = icmp eq i32 addrspace(1)* %ptr, null |
| 929 | ret i1 %cmp |
| 930 | ; CHECK-LABEL: @nonnull_load_as_inner |
| 931 | ; CHECK: ret i1 false |
| 932 | } |
| 933 | |
Nick Lewycky | c961030 | 2014-06-19 03:35:49 +0000 | [diff] [blame] | 934 | ; If a bit is known to be zero for A and known to be one for B, |
| 935 | ; then A and B cannot be equal. |
Sanjay Patel | bf82f44 | 2016-08-04 16:48:30 +0000 | [diff] [blame] | 936 | define i1 @icmp_eq_const(i32 %a) { |
| 937 | ; CHECK-LABEL: @icmp_eq_const( |
| 938 | ; CHECK-NEXT: ret i1 false |
| 939 | ; |
Nick Lewycky | c961030 | 2014-06-19 03:35:49 +0000 | [diff] [blame] | 940 | %b = mul nsw i32 %a, -2 |
| 941 | %c = icmp eq i32 %b, 1 |
| 942 | ret i1 %c |
Nick Lewycky | c961030 | 2014-06-19 03:35:49 +0000 | [diff] [blame] | 943 | } |
| 944 | |
Sanjay Patel | bf82f44 | 2016-08-04 16:48:30 +0000 | [diff] [blame] | 945 | define <2 x i1> @icmp_eq_const_vec(<2 x i32> %a) { |
| 946 | ; CHECK-LABEL: @icmp_eq_const_vec( |
Sanjay Patel | bcaf6f3 | 2016-08-04 17:48:04 +0000 | [diff] [blame] | 947 | ; CHECK-NEXT: ret <2 x i1> zeroinitializer |
Sanjay Patel | bf82f44 | 2016-08-04 16:48:30 +0000 | [diff] [blame] | 948 | ; |
| 949 | %b = mul nsw <2 x i32> %a, <i32 -2, i32 -2> |
| 950 | %c = icmp eq <2 x i32> %b, <i32 1, i32 1> |
| 951 | ret <2 x i1> %c |
| 952 | } |
| 953 | |
| 954 | define i1 @icmp_ne_const(i32 %a) { |
| 955 | ; CHECK-LABEL: @icmp_ne_const( |
| 956 | ; CHECK-NEXT: ret i1 true |
| 957 | ; |
Nick Lewycky | c961030 | 2014-06-19 03:35:49 +0000 | [diff] [blame] | 958 | %b = mul nsw i32 %a, -2 |
| 959 | %c = icmp ne i32 %b, 1 |
| 960 | ret i1 %c |
Sanjay Patel | bf82f44 | 2016-08-04 16:48:30 +0000 | [diff] [blame] | 961 | } |
Nick Lewycky | c961030 | 2014-06-19 03:35:49 +0000 | [diff] [blame] | 962 | |
Sanjay Patel | bf82f44 | 2016-08-04 16:48:30 +0000 | [diff] [blame] | 963 | define <2 x i1> @icmp_ne_const_vec(<2 x i32> %a) { |
| 964 | ; CHECK-LABEL: @icmp_ne_const_vec( |
Sanjay Patel | bcaf6f3 | 2016-08-04 17:48:04 +0000 | [diff] [blame] | 965 | ; CHECK-NEXT: ret <2 x i1> <i1 true, i1 true> |
Sanjay Patel | bf82f44 | 2016-08-04 16:48:30 +0000 | [diff] [blame] | 966 | ; |
| 967 | %b = mul nsw <2 x i32> %a, <i32 -2, i32 -2> |
| 968 | %c = icmp ne <2 x i32> %b, <i32 1, i32 1> |
| 969 | ret <2 x i1> %c |
Nick Lewycky | c961030 | 2014-06-19 03:35:49 +0000 | [diff] [blame] | 970 | } |
David Majnemer | 651ed5e | 2014-07-04 00:23:39 +0000 | [diff] [blame] | 971 | |
| 972 | define i1 @icmp_sdiv_int_min(i32 %a) { |
| 973 | %div = sdiv i32 -2147483648, %a |
| 974 | %cmp = icmp ne i32 %div, -1073741824 |
| 975 | ret i1 %cmp |
| 976 | |
| 977 | ; CHECK-LABEL: @icmp_sdiv_int_min |
| 978 | ; CHECK-NEXT: [[DIV:%.*]] = sdiv i32 -2147483648, %a |
| 979 | ; CHECK-NEXT: [[CMP:%.*]] = icmp ne i32 [[DIV]], -1073741824 |
| 980 | ; CHECK-NEXT: ret i1 [[CMP]] |
| 981 | } |
David Majnemer | 5ea4fc0 | 2014-07-14 19:49:57 +0000 | [diff] [blame] | 982 | |
| 983 | define i1 @icmp_sdiv_pr20288(i64 %a) { |
| 984 | %div = sdiv i64 %a, -8589934592 |
| 985 | %cmp = icmp ne i64 %div, 1073741824 |
| 986 | ret i1 %cmp |
| 987 | |
| 988 | ; CHECK-LABEL: @icmp_sdiv_pr20288 |
| 989 | ; CHECK-NEXT: [[DIV:%.*]] = sdiv i64 %a, -8589934592 |
| 990 | ; CHECK-NEXT: [[CMP:%.*]] = icmp ne i64 [[DIV]], 1073741824 |
| 991 | ; CHECK-NEXT: ret i1 [[CMP]] |
| 992 | } |
David Majnemer | af9180f | 2014-07-14 20:38:45 +0000 | [diff] [blame] | 993 | |
| 994 | define i1 @icmp_sdiv_neg1(i64 %a) { |
David Majnemer | b8f435c | 2014-07-14 20:46:04 +0000 | [diff] [blame] | 995 | %div = sdiv i64 %a, -1 |
David Majnemer | af9180f | 2014-07-14 20:38:45 +0000 | [diff] [blame] | 996 | %cmp = icmp ne i64 %div, 1073741824 |
| 997 | ret i1 %cmp |
| 998 | |
| 999 | ; CHECK-LABEL: @icmp_sdiv_neg1 |
| 1000 | ; CHECK-NEXT: [[DIV:%.*]] = sdiv i64 %a, -1 |
| 1001 | ; CHECK-NEXT: [[CMP:%.*]] = icmp ne i64 [[DIV]], 1073741824 |
| 1002 | ; CHECK-NEXT: ret i1 [[CMP]] |
| 1003 | } |
David Majnemer | 97ddca3 | 2014-08-22 00:40:43 +0000 | [diff] [blame] | 1004 | |
| 1005 | define i1 @icmp_known_bits(i4 %x, i4 %y) { |
| 1006 | %and1 = and i4 %y, -7 |
| 1007 | %and2 = and i4 %x, -7 |
| 1008 | %or1 = or i4 %and1, 2 |
| 1009 | %or2 = or i4 %and2, 2 |
| 1010 | %add = add i4 %or1, %or2 |
| 1011 | %cmp = icmp eq i4 %add, 0 |
| 1012 | ret i1 %cmp |
| 1013 | |
| 1014 | ; CHECK-LABEL: @icmp_known_bits |
| 1015 | ; CHECK-NEXT: ret i1 false |
| 1016 | } |
David Majnemer | d6d1671 | 2014-08-27 18:03:46 +0000 | [diff] [blame] | 1017 | |
| 1018 | define i1 @icmp_shl_nuw_1(i64 %a) { |
| 1019 | %shl = shl nuw i64 1, %a |
| 1020 | %cmp = icmp ne i64 %shl, 0 |
| 1021 | ret i1 %cmp |
| 1022 | |
| 1023 | ; CHECK-LABEL: @icmp_shl_nuw_1 |
| 1024 | ; CHECK-NEXT: ret i1 true |
| 1025 | } |
| 1026 | |
David Majnemer | 76d06bc | 2014-08-28 03:34:28 +0000 | [diff] [blame] | 1027 | define i1 @icmp_shl_1_V_ugt_2147483648(i32 %V) { |
| 1028 | %shl = shl i32 1, %V |
| 1029 | %cmp = icmp ugt i32 %shl, 2147483648 |
| 1030 | ret i1 %cmp |
| 1031 | |
| 1032 | ; CHECK-LABEL: @icmp_shl_1_V_ugt_2147483648( |
| 1033 | ; CHECK-NEXT: ret i1 false |
| 1034 | } |
| 1035 | |
| 1036 | define i1 @icmp_shl_1_V_ule_2147483648(i32 %V) { |
| 1037 | %shl = shl i32 1, %V |
| 1038 | %cmp = icmp ule i32 %shl, 2147483648 |
| 1039 | ret i1 %cmp |
| 1040 | |
| 1041 | ; CHECK-LABEL: @icmp_shl_1_V_ule_2147483648( |
| 1042 | ; CHECK-NEXT: ret i1 true |
| 1043 | } |
| 1044 | |
| 1045 | define i1 @icmp_shl_1_V_eq_31(i32 %V) { |
| 1046 | %shl = shl i32 1, %V |
| 1047 | %cmp = icmp eq i32 %shl, 31 |
| 1048 | ret i1 %cmp |
| 1049 | |
| 1050 | ; CHECK-LABEL: @icmp_shl_1_V_eq_31( |
| 1051 | ; CHECK-NEXT: ret i1 false |
| 1052 | } |
| 1053 | |
| 1054 | define i1 @icmp_shl_1_V_ne_31(i32 %V) { |
| 1055 | %shl = shl i32 1, %V |
| 1056 | %cmp = icmp ne i32 %shl, 31 |
| 1057 | ret i1 %cmp |
| 1058 | |
| 1059 | ; CHECK-LABEL: @icmp_shl_1_V_ne_31( |
| 1060 | ; CHECK-NEXT: ret i1 true |
| 1061 | } |
David Majnemer | bd9ce4e | 2014-11-25 02:55:48 +0000 | [diff] [blame] | 1062 | |
| 1063 | define i1 @tautological1(i32 %A, i32 %B) { |
| 1064 | %C = and i32 %A, %B |
| 1065 | %D = icmp ugt i32 %C, %A |
| 1066 | ret i1 %D |
| 1067 | ; CHECK-LABEL: @tautological1( |
| 1068 | ; CHECK: ret i1 false |
| 1069 | } |
| 1070 | |
| 1071 | define i1 @tautological2(i32 %A, i32 %B) { |
| 1072 | %C = and i32 %A, %B |
| 1073 | %D = icmp ule i32 %C, %A |
| 1074 | ret i1 %D |
| 1075 | ; CHECK-LABEL: @tautological2( |
| 1076 | ; CHECK: ret i1 true |
| 1077 | } |
| 1078 | |
| 1079 | define i1 @tautological3(i32 %A, i32 %B) { |
| 1080 | %C = or i32 %A, %B |
| 1081 | %D = icmp ule i32 %A, %C |
| 1082 | ret i1 %D |
| 1083 | ; CHECK-LABEL: @tautological3( |
| 1084 | ; CHECK: ret i1 true |
| 1085 | } |
| 1086 | |
| 1087 | define i1 @tautological4(i32 %A, i32 %B) { |
| 1088 | %C = or i32 %A, %B |
| 1089 | %D = icmp ugt i32 %A, %C |
| 1090 | ret i1 %D |
| 1091 | ; CHECK-LABEL: @tautological4( |
| 1092 | ; CHECK: ret i1 false |
| 1093 | } |
| 1094 | |
| 1095 | define i1 @tautological5(i32 %A, i32 %B) { |
| 1096 | %C = or i32 %A, %B |
| 1097 | %D = icmp ult i32 %C, %A |
| 1098 | ret i1 %D |
| 1099 | ; CHECK-LABEL: @tautological5( |
| 1100 | ; CHECK: ret i1 false |
| 1101 | } |
| 1102 | |
| 1103 | define i1 @tautological6(i32 %A, i32 %B) { |
| 1104 | %C = or i32 %A, %B |
| 1105 | %D = icmp uge i32 %C, %A |
| 1106 | ret i1 %D |
| 1107 | ; CHECK-LABEL: @tautological6( |
| 1108 | ; CHECK: ret i1 true |
| 1109 | } |
| 1110 | |
| 1111 | define i1 @tautological7(i32 %A, i32 %B) { |
| 1112 | %C = and i32 %A, %B |
| 1113 | %D = icmp uge i32 %A, %C |
| 1114 | ret i1 %D |
| 1115 | ; CHECK-LABEL: @tautological7( |
| 1116 | ; CHECK: ret i1 true |
| 1117 | } |
| 1118 | |
| 1119 | define i1 @tautological8(i32 %A, i32 %B) { |
| 1120 | %C = and i32 %A, %B |
| 1121 | %D = icmp ult i32 %A, %C |
| 1122 | ret i1 %D |
| 1123 | ; CHECK-LABEL: @tautological8( |
| 1124 | ; CHECK: ret i1 false |
| 1125 | } |
David Majnemer | 2df38cd | 2015-08-20 23:01:41 +0000 | [diff] [blame] | 1126 | |
Nick Lewycky | 762f8a8 | 2016-04-21 00:53:14 +0000 | [diff] [blame] | 1127 | declare void @helper_i1(i1) |
| 1128 | ; Series of tests for icmp s[lt|ge] (or A, B), A and icmp s[gt|le] A, (or A, B) |
| 1129 | define void @icmp_slt_sge_or(i32 %Ax, i32 %Bx) { |
| 1130 | ; 'p' for positive, 'n' for negative, 'x' for potentially either. |
| 1131 | ; %D is 'icmp slt (or A, B), A' |
| 1132 | ; %E is 'icmp sge (or A, B), A' making it the not of %D |
| 1133 | ; %F is 'icmp sgt A, (or A, B)' making it the same as %D |
| 1134 | ; %G is 'icmp sle A, (or A, B)' making it the not of %D |
| 1135 | %Aneg = or i32 %Ax, 2147483648 |
| 1136 | %Apos = and i32 %Ax, 2147483647 |
| 1137 | %Bneg = or i32 %Bx, 2147483648 |
| 1138 | %Bpos = and i32 %Bx, 2147483647 |
| 1139 | |
| 1140 | %Cpp = or i32 %Apos, %Bpos |
| 1141 | %Dpp = icmp slt i32 %Cpp, %Apos |
| 1142 | %Epp = icmp sge i32 %Cpp, %Apos |
| 1143 | %Fpp = icmp sgt i32 %Apos, %Cpp |
| 1144 | %Gpp = icmp sle i32 %Apos, %Cpp |
| 1145 | %Cpx = or i32 %Apos, %Bx |
| 1146 | %Dpx = icmp slt i32 %Cpx, %Apos |
| 1147 | %Epx = icmp sge i32 %Cpx, %Apos |
| 1148 | %Fpx = icmp sgt i32 %Apos, %Cpx |
| 1149 | %Gpx = icmp sle i32 %Apos, %Cpx |
| 1150 | %Cpn = or i32 %Apos, %Bneg |
| 1151 | %Dpn = icmp slt i32 %Cpn, %Apos |
| 1152 | %Epn = icmp sge i32 %Cpn, %Apos |
| 1153 | %Fpn = icmp sgt i32 %Apos, %Cpn |
| 1154 | %Gpn = icmp sle i32 %Apos, %Cpn |
| 1155 | |
| 1156 | %Cxp = or i32 %Ax, %Bpos |
| 1157 | %Dxp = icmp slt i32 %Cxp, %Ax |
| 1158 | %Exp = icmp sge i32 %Cxp, %Ax |
| 1159 | %Fxp = icmp sgt i32 %Ax, %Cxp |
| 1160 | %Gxp = icmp sle i32 %Ax, %Cxp |
| 1161 | %Cxx = or i32 %Ax, %Bx |
| 1162 | %Dxx = icmp slt i32 %Cxx, %Ax |
| 1163 | %Exx = icmp sge i32 %Cxx, %Ax |
| 1164 | %Fxx = icmp sgt i32 %Ax, %Cxx |
| 1165 | %Gxx = icmp sle i32 %Ax, %Cxx |
| 1166 | %Cxn = or i32 %Ax, %Bneg |
| 1167 | %Dxn = icmp slt i32 %Cxn, %Ax |
| 1168 | %Exn = icmp sge i32 %Cxn, %Ax |
| 1169 | %Fxn = icmp sgt i32 %Ax, %Cxn |
| 1170 | %Gxn = icmp sle i32 %Ax, %Cxn |
| 1171 | |
| 1172 | %Cnp = or i32 %Aneg, %Bpos |
| 1173 | %Dnp = icmp slt i32 %Cnp, %Aneg |
| 1174 | %Enp = icmp sge i32 %Cnp, %Aneg |
| 1175 | %Fnp = icmp sgt i32 %Aneg, %Cnp |
| 1176 | %Gnp = icmp sle i32 %Aneg, %Cnp |
| 1177 | %Cnx = or i32 %Aneg, %Bx |
| 1178 | %Dnx = icmp slt i32 %Cnx, %Aneg |
| 1179 | %Enx = icmp sge i32 %Cnx, %Aneg |
| 1180 | %Fnx = icmp sgt i32 %Aneg, %Cnx |
| 1181 | %Gnx = icmp sle i32 %Aneg, %Cnx |
| 1182 | %Cnn = or i32 %Aneg, %Bneg |
| 1183 | %Dnn = icmp slt i32 %Cnn, %Aneg |
| 1184 | %Enn = icmp sge i32 %Cnn, %Aneg |
| 1185 | %Fnn = icmp sgt i32 %Aneg, %Cnn |
| 1186 | %Gnn = icmp sle i32 %Aneg, %Cnn |
| 1187 | |
| 1188 | call void @helper_i1(i1 %Dpp) |
| 1189 | call void @helper_i1(i1 %Epp) |
| 1190 | call void @helper_i1(i1 %Fpp) |
| 1191 | call void @helper_i1(i1 %Gpp) |
| 1192 | call void @helper_i1(i1 %Dpx) |
| 1193 | call void @helper_i1(i1 %Epx) |
| 1194 | call void @helper_i1(i1 %Fpx) |
| 1195 | call void @helper_i1(i1 %Gpx) |
| 1196 | call void @helper_i1(i1 %Dpn) |
| 1197 | call void @helper_i1(i1 %Epn) |
| 1198 | call void @helper_i1(i1 %Fpn) |
| 1199 | call void @helper_i1(i1 %Gpn) |
| 1200 | call void @helper_i1(i1 %Dxp) |
| 1201 | call void @helper_i1(i1 %Exp) |
| 1202 | call void @helper_i1(i1 %Fxp) |
| 1203 | call void @helper_i1(i1 %Gxp) |
| 1204 | call void @helper_i1(i1 %Dxx) |
| 1205 | call void @helper_i1(i1 %Exx) |
| 1206 | call void @helper_i1(i1 %Fxx) |
| 1207 | call void @helper_i1(i1 %Gxx) |
| 1208 | call void @helper_i1(i1 %Dxn) |
| 1209 | call void @helper_i1(i1 %Exn) |
| 1210 | call void @helper_i1(i1 %Fxn) |
| 1211 | call void @helper_i1(i1 %Gxn) |
| 1212 | call void @helper_i1(i1 %Dnp) |
| 1213 | call void @helper_i1(i1 %Enp) |
| 1214 | call void @helper_i1(i1 %Fnp) |
| 1215 | call void @helper_i1(i1 %Gnp) |
| 1216 | call void @helper_i1(i1 %Dnx) |
| 1217 | call void @helper_i1(i1 %Enx) |
| 1218 | call void @helper_i1(i1 %Fnx) |
| 1219 | call void @helper_i1(i1 %Gnx) |
| 1220 | call void @helper_i1(i1 %Dnn) |
| 1221 | call void @helper_i1(i1 %Enn) |
| 1222 | call void @helper_i1(i1 %Fnn) |
| 1223 | call void @helper_i1(i1 %Gnn) |
| 1224 | ; CHECK-LABEL: @icmp_slt_sge_or |
| 1225 | ; CHECK: call void @helper_i1(i1 false) |
| 1226 | ; CHECK: call void @helper_i1(i1 true) |
| 1227 | ; CHECK: call void @helper_i1(i1 false) |
| 1228 | ; CHECK: call void @helper_i1(i1 true) |
| 1229 | ; CHECK: call void @helper_i1(i1 %Dpx) |
| 1230 | ; CHECK: call void @helper_i1(i1 %Epx) |
| 1231 | ; CHECK: call void @helper_i1(i1 %Fpx) |
| 1232 | ; CHECK: call void @helper_i1(i1 %Gpx) |
| 1233 | ; CHECK: call void @helper_i1(i1 true) |
| 1234 | ; CHECK: call void @helper_i1(i1 false) |
| 1235 | ; CHECK: call void @helper_i1(i1 true) |
| 1236 | ; CHECK: call void @helper_i1(i1 false) |
| 1237 | ; CHECK: call void @helper_i1(i1 false) |
| 1238 | ; CHECK: call void @helper_i1(i1 true) |
| 1239 | ; CHECK: call void @helper_i1(i1 false) |
| 1240 | ; CHECK: call void @helper_i1(i1 true) |
| 1241 | ; CHECK: call void @helper_i1(i1 %Dxx) |
| 1242 | ; CHECK: call void @helper_i1(i1 %Exx) |
| 1243 | ; CHECK: call void @helper_i1(i1 %Fxx) |
| 1244 | ; CHECK: call void @helper_i1(i1 %Gxx) |
| 1245 | ; CHECK: call void @helper_i1(i1 %Dxn) |
| 1246 | ; CHECK: call void @helper_i1(i1 %Exn) |
| 1247 | ; CHECK: call void @helper_i1(i1 %Fxn) |
| 1248 | ; CHECK: call void @helper_i1(i1 %Gxn) |
| 1249 | ; CHECK: call void @helper_i1(i1 false) |
| 1250 | ; CHECK: call void @helper_i1(i1 true) |
| 1251 | ; CHECK: call void @helper_i1(i1 false) |
| 1252 | ; CHECK: call void @helper_i1(i1 true) |
| 1253 | ; CHECK: call void @helper_i1(i1 false) |
| 1254 | ; CHECK: call void @helper_i1(i1 true) |
| 1255 | ; CHECK: call void @helper_i1(i1 false) |
| 1256 | ; CHECK: call void @helper_i1(i1 true) |
| 1257 | ; CHECK: call void @helper_i1(i1 false) |
| 1258 | ; CHECK: call void @helper_i1(i1 true) |
| 1259 | ; CHECK: call void @helper_i1(i1 false) |
| 1260 | ; CHECK: call void @helper_i1(i1 true) |
| 1261 | ret void |
| 1262 | } |
Craig Topper | 5ea2d55 | 2017-06-01 21:20:07 +0000 | [diff] [blame] | 1263 | |
| 1264 | define i1 @constant_fold_inttoptr_null() { |
| 1265 | ; CHECK-LABEL: @constant_fold_inttoptr_null( |
| 1266 | ; CHECK-NEXT: ret i1 false |
| 1267 | ; |
| 1268 | %x = icmp eq i32* inttoptr (i64 32 to i32*), null |
| 1269 | ret i1 %x |
| 1270 | } |
| 1271 | |
| 1272 | define i1 @constant_fold_null_inttoptr() { |
| 1273 | ; CHECK-LABEL: @constant_fold_null_inttoptr( |
Craig Topper | b23e7c7 | 2017-06-02 16:17:32 +0000 | [diff] [blame] | 1274 | ; CHECK-NEXT: ret i1 false |
Craig Topper | 5ea2d55 | 2017-06-01 21:20:07 +0000 | [diff] [blame] | 1275 | ; |
| 1276 | %x = icmp eq i32* null, inttoptr (i64 32 to i32*) |
| 1277 | ret i1 %x |
| 1278 | } |