Duncan Sands | ad20681 | 2011-05-03 19:53:10 +0000 | [diff] [blame] | 1 | ; RUN: opt < %s -instsimplify -S | FileCheck %s |
| 2 | |
| 3 | define i1 @max1(i32 %x, i32 %y) { |
| 4 | ; CHECK: @max1 |
| 5 | %c = icmp sgt i32 %x, %y |
| 6 | %m = select i1 %c, i32 %x, i32 %y |
| 7 | %r = icmp slt i32 %m, %x |
| 8 | ret i1 %r |
| 9 | ; CHECK: ret i1 false |
| 10 | } |
| 11 | |
| 12 | define i1 @max2(i32 %x, i32 %y) { |
| 13 | ; CHECK: @max2 |
| 14 | %c = icmp sge i32 %x, %y |
| 15 | %m = select i1 %c, i32 %x, i32 %y |
| 16 | %r = icmp sge i32 %m, %x |
| 17 | ret i1 %r |
| 18 | ; CHECK: ret i1 true |
| 19 | } |
| 20 | |
| 21 | define i1 @max3(i32 %x, i32 %y) { |
| 22 | ; CHECK: @max3 |
| 23 | %c = icmp ugt i32 %x, %y |
| 24 | %m = select i1 %c, i32 %x, i32 %y |
| 25 | %r = icmp ult i32 %m, %x |
| 26 | ret i1 %r |
| 27 | ; CHECK: ret i1 false |
| 28 | } |
| 29 | |
| 30 | define i1 @max4(i32 %x, i32 %y) { |
| 31 | ; CHECK: @max4 |
| 32 | %c = icmp uge i32 %x, %y |
| 33 | %m = select i1 %c, i32 %x, i32 %y |
| 34 | %r = icmp uge i32 %m, %x |
| 35 | ret i1 %r |
| 36 | ; CHECK: ret i1 true |
| 37 | } |
| 38 | |
| 39 | define i1 @max5(i32 %x, i32 %y) { |
| 40 | ; CHECK: @max5 |
| 41 | %c = icmp sgt i32 %x, %y |
| 42 | %m = select i1 %c, i32 %x, i32 %y |
| 43 | %r = icmp sgt i32 %x, %m |
| 44 | ret i1 %r |
| 45 | ; CHECK: ret i1 false |
| 46 | } |
| 47 | |
| 48 | define i1 @max6(i32 %x, i32 %y) { |
| 49 | ; CHECK: @max6 |
| 50 | %c = icmp sge i32 %x, %y |
| 51 | %m = select i1 %c, i32 %x, i32 %y |
| 52 | %r = icmp sle i32 %x, %m |
| 53 | ret i1 %r |
| 54 | ; CHECK: ret i1 true |
| 55 | } |
| 56 | |
| 57 | define i1 @max7(i32 %x, i32 %y) { |
| 58 | ; CHECK: @max7 |
| 59 | %c = icmp ugt i32 %x, %y |
| 60 | %m = select i1 %c, i32 %x, i32 %y |
| 61 | %r = icmp ugt i32 %x, %m |
| 62 | ret i1 %r |
| 63 | ; CHECK: ret i1 false |
| 64 | } |
| 65 | |
| 66 | define i1 @max8(i32 %x, i32 %y) { |
| 67 | ; CHECK: @max8 |
| 68 | %c = icmp uge i32 %x, %y |
| 69 | %m = select i1 %c, i32 %x, i32 %y |
| 70 | %r = icmp ule i32 %x, %m |
| 71 | ret i1 %r |
| 72 | ; CHECK: ret i1 true |
| 73 | } |
| 74 | |
| 75 | define i1 @min1(i32 %x, i32 %y) { |
| 76 | ; CHECK: @min1 |
| 77 | %c = icmp sgt i32 %x, %y |
| 78 | %m = select i1 %c, i32 %y, i32 %x |
| 79 | %r = icmp sgt i32 %m, %x |
| 80 | ret i1 %r |
| 81 | ; CHECK: ret i1 false |
| 82 | } |
| 83 | |
| 84 | define i1 @min2(i32 %x, i32 %y) { |
| 85 | ; CHECK: @min2 |
| 86 | %c = icmp sge i32 %x, %y |
| 87 | %m = select i1 %c, i32 %y, i32 %x |
| 88 | %r = icmp sle i32 %m, %x |
| 89 | ret i1 %r |
| 90 | ; CHECK: ret i1 true |
| 91 | } |
| 92 | |
| 93 | define i1 @min3(i32 %x, i32 %y) { |
| 94 | ; CHECK: @min3 |
| 95 | %c = icmp ugt i32 %x, %y |
| 96 | %m = select i1 %c, i32 %y, i32 %x |
| 97 | %r = icmp ugt i32 %m, %x |
| 98 | ret i1 %r |
| 99 | ; CHECK: ret i1 false |
| 100 | } |
| 101 | |
| 102 | define i1 @min4(i32 %x, i32 %y) { |
| 103 | ; CHECK: @min4 |
| 104 | %c = icmp uge i32 %x, %y |
| 105 | %m = select i1 %c, i32 %y, i32 %x |
| 106 | %r = icmp ule i32 %m, %x |
| 107 | ret i1 %r |
| 108 | ; CHECK: ret i1 true |
| 109 | } |
| 110 | |
| 111 | define i1 @min5(i32 %x, i32 %y) { |
| 112 | ; CHECK: @min5 |
| 113 | %c = icmp sgt i32 %x, %y |
| 114 | %m = select i1 %c, i32 %y, i32 %x |
| 115 | %r = icmp slt i32 %x, %m |
| 116 | ret i1 %r |
| 117 | ; CHECK: ret i1 false |
| 118 | } |
| 119 | |
| 120 | define i1 @min6(i32 %x, i32 %y) { |
| 121 | ; CHECK: @min6 |
| 122 | %c = icmp sge i32 %x, %y |
| 123 | %m = select i1 %c, i32 %y, i32 %x |
| 124 | %r = icmp sge i32 %x, %m |
| 125 | ret i1 %r |
| 126 | ; CHECK: ret i1 true |
| 127 | } |
| 128 | |
| 129 | define i1 @min7(i32 %x, i32 %y) { |
| 130 | ; CHECK: @min7 |
| 131 | %c = icmp ugt i32 %x, %y |
| 132 | %m = select i1 %c, i32 %y, i32 %x |
| 133 | %r = icmp ult i32 %x, %m |
| 134 | ret i1 %r |
| 135 | ; CHECK: ret i1 false |
| 136 | } |
| 137 | |
| 138 | define i1 @min8(i32 %x, i32 %y) { |
| 139 | ; CHECK: @min8 |
| 140 | %c = icmp uge i32 %x, %y |
| 141 | %m = select i1 %c, i32 %y, i32 %x |
| 142 | %r = icmp uge i32 %x, %m |
| 143 | ret i1 %r |
| 144 | ; CHECK: ret i1 true |
| 145 | } |
Duncan Sands | 8140ad3 | 2011-05-04 16:05:05 +0000 | [diff] [blame] | 146 | |
| 147 | define i1 @maxmin1(i32 %x, i32 %y, i32 %z) { |
| 148 | ; CHECK: @maxmin1 |
| 149 | %c1 = icmp sge i32 %x, %y |
| 150 | %max = select i1 %c1, i32 %x, i32 %y |
| 151 | %c2 = icmp sge i32 %x, %z |
| 152 | %min = select i1 %c2, i32 %z, i32 %x |
| 153 | %c = icmp sge i32 %max, %min |
| 154 | ret i1 %c |
| 155 | ; CHECK: ret i1 true |
| 156 | } |
| 157 | |
| 158 | define i1 @maxmin2(i32 %x, i32 %y, i32 %z) { |
| 159 | ; CHECK: @maxmin2 |
| 160 | %c1 = icmp sge i32 %x, %y |
| 161 | %max = select i1 %c1, i32 %x, i32 %y |
| 162 | %c2 = icmp sge i32 %x, %z |
| 163 | %min = select i1 %c2, i32 %z, i32 %x |
| 164 | %c = icmp sgt i32 %min, %max |
| 165 | ret i1 %c |
| 166 | ; CHECK: ret i1 false |
| 167 | } |
| 168 | |
| 169 | define i1 @maxmin3(i32 %x, i32 %y, i32 %z) { |
| 170 | ; CHECK: @maxmin3 |
| 171 | %c1 = icmp sge i32 %x, %y |
| 172 | %max = select i1 %c1, i32 %x, i32 %y |
| 173 | %c2 = icmp sge i32 %x, %z |
| 174 | %min = select i1 %c2, i32 %z, i32 %x |
| 175 | %c = icmp sle i32 %min, %max |
| 176 | ret i1 %c |
| 177 | ; CHECK: ret i1 true |
| 178 | } |
| 179 | |
| 180 | define i1 @maxmin4(i32 %x, i32 %y, i32 %z) { |
| 181 | ; CHECK: @maxmin4 |
| 182 | %c1 = icmp sge i32 %x, %y |
| 183 | %max = select i1 %c1, i32 %x, i32 %y |
| 184 | %c2 = icmp sge i32 %x, %z |
| 185 | %min = select i1 %c2, i32 %z, i32 %x |
| 186 | %c = icmp slt i32 %max, %min |
| 187 | ret i1 %c |
| 188 | ; CHECK: ret i1 false |
| 189 | } |
| 190 | |
| 191 | define i1 @maxmin5(i32 %x, i32 %y, i32 %z) { |
| 192 | ; CHECK: @maxmin5 |
| 193 | %c1 = icmp uge i32 %x, %y |
| 194 | %max = select i1 %c1, i32 %x, i32 %y |
| 195 | %c2 = icmp uge i32 %x, %z |
| 196 | %min = select i1 %c2, i32 %z, i32 %x |
| 197 | %c = icmp uge i32 %max, %min |
| 198 | ret i1 %c |
| 199 | ; CHECK: ret i1 true |
| 200 | } |
| 201 | |
| 202 | define i1 @maxmin6(i32 %x, i32 %y, i32 %z) { |
| 203 | ; CHECK: @maxmin6 |
| 204 | %c1 = icmp uge i32 %x, %y |
| 205 | %max = select i1 %c1, i32 %x, i32 %y |
| 206 | %c2 = icmp uge i32 %x, %z |
| 207 | %min = select i1 %c2, i32 %z, i32 %x |
| 208 | %c = icmp ugt i32 %min, %max |
| 209 | ret i1 %c |
| 210 | ; CHECK: ret i1 false |
| 211 | } |
| 212 | |
| 213 | define i1 @maxmin7(i32 %x, i32 %y, i32 %z) { |
| 214 | ; CHECK: @maxmin7 |
| 215 | %c1 = icmp uge i32 %x, %y |
| 216 | %max = select i1 %c1, i32 %x, i32 %y |
| 217 | %c2 = icmp uge i32 %x, %z |
| 218 | %min = select i1 %c2, i32 %z, i32 %x |
| 219 | %c = icmp ule i32 %min, %max |
| 220 | ret i1 %c |
| 221 | ; CHECK: ret i1 true |
| 222 | } |
| 223 | |
| 224 | define i1 @maxmin8(i32 %x, i32 %y, i32 %z) { |
| 225 | ; CHECK: @maxmin8 |
| 226 | %c1 = icmp uge i32 %x, %y |
| 227 | %max = select i1 %c1, i32 %x, i32 %y |
| 228 | %c2 = icmp uge i32 %x, %z |
| 229 | %min = select i1 %c2, i32 %z, i32 %x |
| 230 | %c = icmp ult i32 %max, %min |
| 231 | ret i1 %c |
| 232 | ; CHECK: ret i1 false |
| 233 | } |
Duncan Sands | e864b5b | 2011-05-07 16:56:49 +0000 | [diff] [blame] | 234 | |
| 235 | define i1 @eqcmp1(i32 %x, i32 %y) { |
| 236 | ; CHECK: @eqcmp1 |
| 237 | %c = icmp sge i32 %x, %y |
| 238 | %max = select i1 %c, i32 %x, i32 %y |
| 239 | %r = icmp eq i32 %max, %x |
| 240 | ret i1 %r |
| 241 | ; CHECK: ret i1 %c |
| 242 | } |
| 243 | |
| 244 | define i1 @eqcmp2(i32 %x, i32 %y) { |
| 245 | ; CHECK: @eqcmp2 |
| 246 | %c = icmp sge i32 %x, %y |
| 247 | %max = select i1 %c, i32 %x, i32 %y |
| 248 | %r = icmp eq i32 %x, %max |
| 249 | ret i1 %r |
| 250 | ; CHECK: ret i1 %c |
| 251 | } |
| 252 | |
| 253 | define i1 @eqcmp3(i32 %x, i32 %y) { |
| 254 | ; CHECK: @eqcmp3 |
| 255 | %c = icmp uge i32 %x, %y |
| 256 | %max = select i1 %c, i32 %x, i32 %y |
| 257 | %r = icmp eq i32 %max, %x |
| 258 | ret i1 %r |
| 259 | ; CHECK: ret i1 %c |
| 260 | } |
| 261 | |
| 262 | define i1 @eqcmp4(i32 %x, i32 %y) { |
| 263 | ; CHECK: @eqcmp4 |
| 264 | %c = icmp uge i32 %x, %y |
| 265 | %max = select i1 %c, i32 %x, i32 %y |
| 266 | %r = icmp eq i32 %x, %max |
| 267 | ret i1 %r |
| 268 | ; CHECK: ret i1 %c |
| 269 | } |