1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py 2; RUN: opt -constraint-elimination -S %s | FileCheck %s 3 4define i1 @test_eq_1(i8 %a, i8 %b) { 5; CHECK-LABEL: @test_eq_1( 6; CHECK-NEXT: entry: 7; CHECK-NEXT: [[CMP:%.*]] = icmp eq i8 [[A:%.*]], [[B:%.*]] 8; CHECK-NEXT: br i1 [[CMP]], label [[THEN:%.*]], label [[ELSE:%.*]] 9; CHECK: then: 10; CHECK-NEXT: [[T_1:%.*]] = icmp uge i8 [[A]], [[B]] 11; CHECK-NEXT: [[T_2:%.*]] = icmp ule i8 [[A]], [[B]] 12; CHECK-NEXT: [[RES_1:%.*]] = xor i1 true, true 13; CHECK-NEXT: [[T_3:%.*]] = icmp eq i8 [[A]], [[B]] 14; CHECK-NEXT: [[RES_2:%.*]] = xor i1 [[RES_1]], [[T_3]] 15; CHECK-NEXT: [[T_4:%.*]] = icmp eq i8 [[B]], [[A]] 16; CHECK-NEXT: [[RES_3:%.*]] = xor i1 [[RES_2]], [[T_4]] 17; CHECK-NEXT: [[F_1:%.*]] = icmp ugt i8 [[B]], [[A]] 18; CHECK-NEXT: [[RES_4:%.*]] = xor i1 [[RES_3]], false 19; CHECK-NEXT: [[F_2:%.*]] = icmp ult i8 [[B]], [[A]] 20; CHECK-NEXT: [[RES_5:%.*]] = xor i1 [[RES_4]], false 21; CHECK-NEXT: [[C_1:%.*]] = icmp ult i8 [[B]], 99 22; CHECK-NEXT: [[RES_6:%.*]] = xor i1 [[RES_5]], [[C_1]] 23; CHECK-NEXT: ret i1 [[RES_6]] 24; CHECK: else: 25; CHECK-NEXT: [[F_3:%.*]] = icmp eq i8 [[A]], [[B]] 26; CHECK-NEXT: [[F_4:%.*]] = icmp eq i8 [[B]], [[A]] 27; CHECK-NEXT: [[RES_7:%.*]] = xor i1 [[F_3]], [[F_4]] 28; CHECK-NEXT: [[C_2:%.*]] = icmp ult i8 [[B]], 99 29; CHECK-NEXT: [[RES_8:%.*]] = xor i1 [[RES_7]], [[C_2]] 30; CHECK-NEXT: [[C_3:%.*]] = icmp uge i8 [[A]], [[B]] 31; CHECK-NEXT: [[RES_9:%.*]] = xor i1 [[RES_8]], [[C_3]] 32; CHECK-NEXT: [[C_4:%.*]] = icmp ule i8 [[A]], [[B]] 33; CHECK-NEXT: [[RES_10:%.*]] = xor i1 [[RES_9]], [[C_4]] 34; CHECK-NEXT: [[C_5:%.*]] = icmp ugt i8 [[B]], [[A]] 35; CHECK-NEXT: [[RES_11:%.*]] = xor i1 [[RES_10]], [[C_5]] 36; CHECK-NEXT: [[C_6:%.*]] = icmp ult i8 [[B]], [[A]] 37; CHECK-NEXT: [[RES_12:%.*]] = xor i1 [[RES_11]], [[C_6]] 38; CHECK-NEXT: ret i1 [[RES_12]] 39; 40entry: 41 %cmp = icmp eq i8 %a, %b 42 br i1 %cmp, label %then, label %else 43 44then: 45 %t.1 = icmp uge i8 %a, %b 46 %t.2 = icmp ule i8 %a, %b 47 %res.1 = xor i1 %t.1, %t.2 48 49 %t.3 = icmp eq i8 %a, %b 50 %res.2 = xor i1 %res.1, %t.3 51 52 %t.4 = icmp eq i8 %b, %a 53 %res.3 = xor i1 %res.2, %t.4 54 55 %f.1 = icmp ugt i8 %b, %a 56 %res.4 = xor i1 %res.3, %f.1 57 58 %f.2 = icmp ult i8 %b, %a 59 %res.5 = xor i1 %res.4, %f.2 60 61 %c.1 = icmp ult i8 %b, 99 62 %res.6 = xor i1 %res.5, %c.1 63 ret i1 %res.6 64 65else: 66 %f.3 = icmp eq i8 %a, %b 67 %f.4 = icmp eq i8 %b, %a 68 %res.7 = xor i1 %f.3, %f.4 69 70 %c.2 = icmp ult i8 %b, 99 71 %res.8 = xor i1 %res.7, %c.2 72 73 %c.3 = icmp uge i8 %a, %b 74 %res.9 = xor i1 %res.8, %c.3 75 76 %c.4 = icmp ule i8 %a, %b 77 %res.10 = xor i1 %res.9, %c.4 78 79 %c.5 = icmp ugt i8 %b, %a 80 %res.11 = xor i1 %res.10, %c.5 81 82 %c.6 = icmp ult i8 %b, %a 83 %res.12 = xor i1 %res.11, %c.6 84 ret i1 %res.12 85} 86 87define i1 @test_eq_2(i8 %a, i8 %b) { 88; CHECK-LABEL: @test_eq_2( 89; CHECK-NEXT: entry: 90; CHECK-NEXT: [[PRE_1:%.*]] = icmp eq i8 [[A:%.*]], [[B:%.*]] 91; CHECK-NEXT: br i1 [[PRE_1]], label [[THEN:%.*]], label [[ELSE:%.*]] 92; CHECK: then: 93; CHECK-NEXT: [[PRE_3:%.*]] = icmp ult i8 [[B]], 100 94; CHECK-NEXT: br i1 [[PRE_3]], label [[THEN_THEN:%.*]], label [[THEN_ELSE:%.*]] 95; CHECK: then.then: 96; CHECK-NEXT: [[T_1:%.*]] = icmp ult i8 [[A]], 100 97; CHECK-NEXT: [[T_2:%.*]] = icmp ult i8 [[B]], 100 98; CHECK-NEXT: [[XOR_1:%.*]] = xor i1 true, true 99; CHECK-NEXT: [[F_1:%.*]] = icmp uge i8 [[A]], 100 100; CHECK-NEXT: [[XOR_2:%.*]] = xor i1 [[XOR_1]], false 101; CHECK-NEXT: [[F_2:%.*]] = icmp uge i8 [[B]], 100 102; CHECK-NEXT: [[XOR_3:%.*]] = xor i1 [[XOR_2]], false 103; CHECK-NEXT: [[F_3_1:%.*]] = icmp ugt i8 [[A]], 99 104; CHECK-NEXT: [[XOR_4:%.*]] = xor i1 [[XOR_3]], false 105; CHECK-NEXT: [[C_1:%.*]] = icmp ult i8 [[A]], 99 106; CHECK-NEXT: [[XOR_5:%.*]] = xor i1 [[XOR_4]], [[C_1]] 107; CHECK-NEXT: [[C_2:%.*]] = icmp ugt i8 [[A]], 98 108; CHECK-NEXT: [[XOR_6:%.*]] = xor i1 [[XOR_5]], [[C_1]] 109; CHECK-NEXT: ret i1 [[XOR_6]] 110; CHECK: then.else: 111; CHECK-NEXT: [[F_4:%.*]] = icmp ult i8 [[A]], 100 112; CHECK-NEXT: [[F_5:%.*]] = icmp ult i8 [[B]], 100 113; CHECK-NEXT: [[XOR_7:%.*]] = xor i1 false, false 114; CHECK-NEXT: [[T_3:%.*]] = icmp uge i8 [[A]], 100 115; CHECK-NEXT: [[XOR_8:%.*]] = xor i1 [[XOR_7]], true 116; CHECK-NEXT: [[T_4:%.*]] = icmp uge i8 [[B]], 100 117; CHECK-NEXT: [[XOR_9:%.*]] = xor i1 [[XOR_8]], true 118; CHECK-NEXT: [[T_5:%.*]] = icmp ugt i8 [[A]], 99 119; CHECK-NEXT: [[XOR_10:%.*]] = xor i1 [[XOR_9]], true 120; CHECK-NEXT: [[C_3:%.*]] = icmp ult i8 [[A]], 99 121; CHECK-NEXT: [[XOR_11:%.*]] = xor i1 [[XOR_10]], false 122; CHECK-NEXT: [[C_4:%.*]] = icmp ugt i8 [[A]], 98 123; CHECK-NEXT: [[XOR_12:%.*]] = xor i1 [[XOR_11]], true 124; CHECK-NEXT: ret i1 [[XOR_12]] 125; CHECK: else: 126; CHECK-NEXT: [[CMP_2:%.*]] = icmp ult i8 [[A]], 100 127; CHECK-NEXT: ret i1 [[CMP_2]] 128; 129entry: 130 %pre.1 = icmp eq i8 %a, %b 131 br i1 %pre.1, label %then, label %else 132 133then: 134 %pre.3 = icmp ult i8 %b, 100 135 br i1 %pre.3, label %then.then, label %then.else 136 137then.then: 138 %t.1 = icmp ult i8 %a, 100 139 %t.2 = icmp ult i8 %b, 100 140 %xor.1 = xor i1 %t.1, %t.2 141 142 %f.1 = icmp uge i8 %a, 100 143 %xor.2 = xor i1 %xor.1, %f.1 144 145 %f.2 = icmp uge i8 %b, 100 146 %xor.3 = xor i1 %xor.2, %f.2 147 148 %f.3.1 = icmp ugt i8 %a, 99 149 %xor.4 = xor i1 %xor.3, %f.3.1 150 151 %c.1 = icmp ult i8 %a, 99 152 %xor.5 = xor i1 %xor.4, %c.1 153 154 %c.2 = icmp ugt i8 %a, 98 155 %xor.6 = xor i1 %xor.5, %c.1 156 157 ret i1 %xor.6 158 159then.else: 160 %f.4 = icmp ult i8 %a, 100 161 %f.5 = icmp ult i8 %b, 100 162 %xor.7 = xor i1 %f.4, %f.5 163 164 %t.3 = icmp uge i8 %a, 100 165 %xor.8 = xor i1 %xor.7, %t.3 166 167 %t.4 = icmp uge i8 %b, 100 168 %xor.9 = xor i1 %xor.8, %t.4 169 170 %t.5 = icmp ugt i8 %a, 99 171 %xor.10 = xor i1 %xor.9, %t.5 172 173 %c.3 = icmp ult i8 %a, 99 174 %xor.11 = xor i1 %xor.10, %c.3 175 176 %c.4 = icmp ugt i8 %a, 98 177 %xor.12 = xor i1 %xor.11, %c.4 178 179 ret i1 %xor.12 180 181else: 182 %cmp.2 = icmp ult i8 %a, 100 183 ret i1 %cmp.2 184} 185 186; Test of explicitly using uge & ule instead of eq. 187define i1 @test_eq_as_uge_ule_(i8 %a, i8 %b) { 188; CHECK-LABEL: @test_eq_as_uge_ule_( 189; CHECK-NEXT: entry: 190; CHECK-NEXT: [[PRE_1:%.*]] = icmp uge i8 [[A:%.*]], [[B:%.*]] 191; CHECK-NEXT: [[PRE_2:%.*]] = icmp ule i8 [[A]], [[B]] 192; CHECK-NEXT: [[PRE_AND:%.*]] = and i1 [[PRE_1]], [[PRE_2]] 193; CHECK-NEXT: br i1 [[PRE_AND]], label [[THEN:%.*]], label [[ELSE:%.*]] 194; CHECK: then: 195; CHECK-NEXT: [[PRE_3:%.*]] = icmp ult i8 [[B]], 100 196; CHECK-NEXT: br i1 [[PRE_3]], label [[THEN_THEN:%.*]], label [[THEN_ELSE:%.*]] 197; CHECK: then.then: 198; CHECK-NEXT: [[T_1:%.*]] = icmp ult i8 [[A]], 100 199; CHECK-NEXT: [[T_2:%.*]] = icmp ult i8 [[B]], 100 200; CHECK-NEXT: [[XOR_1:%.*]] = xor i1 true, true 201; CHECK-NEXT: [[F_1:%.*]] = icmp uge i8 [[A]], 100 202; CHECK-NEXT: [[XOR_2:%.*]] = xor i1 [[XOR_1]], false 203; CHECK-NEXT: [[F_2:%.*]] = icmp uge i8 [[B]], 100 204; CHECK-NEXT: [[XOR_3:%.*]] = xor i1 [[XOR_2]], false 205; CHECK-NEXT: [[F_3_1:%.*]] = icmp ugt i8 [[A]], 99 206; CHECK-NEXT: [[XOR_4:%.*]] = xor i1 [[XOR_3]], false 207; CHECK-NEXT: [[C_1:%.*]] = icmp ult i8 [[A]], 99 208; CHECK-NEXT: [[XOR_5:%.*]] = xor i1 [[XOR_4]], [[C_1]] 209; CHECK-NEXT: [[C_2:%.*]] = icmp ugt i8 [[A]], 98 210; CHECK-NEXT: [[XOR_6:%.*]] = xor i1 [[XOR_5]], [[C_1]] 211; CHECK-NEXT: ret i1 [[XOR_6]] 212; CHECK: then.else: 213; CHECK-NEXT: [[F_4:%.*]] = icmp ult i8 [[A]], 100 214; CHECK-NEXT: [[F_5:%.*]] = icmp ult i8 [[B]], 100 215; CHECK-NEXT: [[XOR_7:%.*]] = xor i1 false, false 216; CHECK-NEXT: [[T_3:%.*]] = icmp uge i8 [[A]], 100 217; CHECK-NEXT: [[XOR_8:%.*]] = xor i1 [[XOR_7]], true 218; CHECK-NEXT: [[T_4:%.*]] = icmp uge i8 [[B]], 100 219; CHECK-NEXT: [[XOR_9:%.*]] = xor i1 [[XOR_8]], true 220; CHECK-NEXT: [[T_5:%.*]] = icmp ugt i8 [[A]], 99 221; CHECK-NEXT: [[XOR_10:%.*]] = xor i1 [[XOR_9]], true 222; CHECK-NEXT: [[C_3:%.*]] = icmp ult i8 [[A]], 99 223; CHECK-NEXT: [[XOR_11:%.*]] = xor i1 [[XOR_10]], false 224; CHECK-NEXT: [[C_4:%.*]] = icmp ugt i8 [[A]], 98 225; CHECK-NEXT: [[XOR_12:%.*]] = xor i1 [[XOR_11]], true 226; CHECK-NEXT: ret i1 [[XOR_12]] 227; CHECK: else: 228; CHECK-NEXT: [[CMP_2:%.*]] = icmp ult i8 [[A]], 100 229; CHECK-NEXT: ret i1 [[CMP_2]] 230; 231entry: 232 %pre.1 = icmp uge i8 %a, %b 233 %pre.2 = icmp ule i8 %a, %b 234 %pre.and = and i1 %pre.1, %pre.2 235 br i1 %pre.and, label %then, label %else 236 237then: 238 %pre.3 = icmp ult i8 %b, 100 239 br i1 %pre.3, label %then.then, label %then.else 240 241then.then: 242 %t.1 = icmp ult i8 %a, 100 243 %t.2 = icmp ult i8 %b, 100 244 %xor.1 = xor i1 %t.1, %t.2 245 246 %f.1 = icmp uge i8 %a, 100 247 %xor.2 = xor i1 %xor.1, %f.1 248 249 %f.2 = icmp uge i8 %b, 100 250 %xor.3 = xor i1 %xor.2, %f.2 251 252 %f.3.1 = icmp ugt i8 %a, 99 253 %xor.4 = xor i1 %xor.3, %f.3.1 254 255 %c.1 = icmp ult i8 %a, 99 256 %xor.5 = xor i1 %xor.4, %c.1 257 258 %c.2 = icmp ugt i8 %a, 98 259 %xor.6 = xor i1 %xor.5, %c.1 260 261 ret i1 %xor.6 262 263then.else: 264 %f.4 = icmp ult i8 %a, 100 265 %f.5 = icmp ult i8 %b, 100 266 %xor.7 = xor i1 %f.4, %f.5 267 268 %t.3 = icmp uge i8 %a, 100 269 %xor.8 = xor i1 %xor.7, %t.3 270 271 %t.4 = icmp uge i8 %b, 100 272 %xor.9 = xor i1 %xor.8, %t.4 273 274 %t.5 = icmp ugt i8 %a, 99 275 %xor.10 = xor i1 %xor.9, %t.5 276 277 %c.3 = icmp ult i8 %a, 99 278 %xor.11 = xor i1 %xor.10, %c.3 279 280 %c.4 = icmp ugt i8 %a, 98 281 %xor.12 = xor i1 %xor.11, %c.4 282 283 ret i1 %xor.12 284 285else: 286 %cmp.2 = icmp ult i8 %a, 100 287 ret i1 %cmp.2 288} 289 290 291define i1 @test_eq_ult_and(i8 %a, i8 %b) { 292; CHECK-LABEL: @test_eq_ult_and( 293; CHECK-NEXT: entry: 294; CHECK-NEXT: [[PRE_1:%.*]] = icmp eq i8 [[A:%.*]], [[B:%.*]] 295; CHECK-NEXT: [[PRE_2:%.*]] = icmp ult i8 [[B]], 100 296; CHECK-NEXT: [[PRE_AND:%.*]] = and i1 [[PRE_1]], [[PRE_2]] 297; CHECK-NEXT: br i1 [[PRE_AND]], label [[THEN:%.*]], label [[ELSE:%.*]] 298; CHECK: then: 299; CHECK-NEXT: [[T_1:%.*]] = icmp ult i8 [[A]], 100 300; CHECK-NEXT: [[T_2:%.*]] = icmp ult i8 [[B]], 100 301; CHECK-NEXT: [[XOR_1:%.*]] = xor i1 true, true 302; CHECK-NEXT: [[F_1:%.*]] = icmp uge i8 [[A]], 100 303; CHECK-NEXT: [[XOR_2:%.*]] = xor i1 [[XOR_1]], false 304; CHECK-NEXT: [[F_2:%.*]] = icmp uge i8 [[B]], 100 305; CHECK-NEXT: [[XOR_3:%.*]] = xor i1 [[XOR_2]], false 306; CHECK-NEXT: [[F_3_1:%.*]] = icmp ugt i8 [[A]], 99 307; CHECK-NEXT: [[XOR_4:%.*]] = xor i1 [[XOR_3]], false 308; CHECK-NEXT: [[C_1:%.*]] = icmp ult i8 [[A]], 99 309; CHECK-NEXT: [[XOR_5:%.*]] = xor i1 [[XOR_4]], [[C_1]] 310; CHECK-NEXT: [[C_2:%.*]] = icmp ugt i8 [[A]], 98 311; CHECK-NEXT: [[XOR_6:%.*]] = xor i1 [[XOR_5]], [[C_1]] 312; CHECK-NEXT: ret i1 [[XOR_6]] 313; CHECK: else: 314; CHECK-NEXT: [[F_4:%.*]] = icmp ult i8 [[A]], 100 315; CHECK-NEXT: [[F_5:%.*]] = icmp ult i8 [[B]], 100 316; CHECK-NEXT: [[XOR_7:%.*]] = xor i1 [[F_4]], [[F_5]] 317; CHECK-NEXT: [[T_3:%.*]] = icmp uge i8 [[A]], 100 318; CHECK-NEXT: [[XOR_8:%.*]] = xor i1 [[XOR_7]], [[T_3]] 319; CHECK-NEXT: [[T_4:%.*]] = icmp uge i8 [[B]], 100 320; CHECK-NEXT: [[XOR_9:%.*]] = xor i1 [[XOR_8]], [[T_4]] 321; CHECK-NEXT: [[T_5:%.*]] = icmp ugt i8 [[A]], 99 322; CHECK-NEXT: [[XOR_10:%.*]] = xor i1 [[XOR_9]], [[T_5]] 323; CHECK-NEXT: [[C_3:%.*]] = icmp ult i8 [[A]], 99 324; CHECK-NEXT: [[XOR_11:%.*]] = xor i1 [[XOR_10]], [[C_3]] 325; CHECK-NEXT: [[C_4:%.*]] = icmp ugt i8 [[A]], 98 326; CHECK-NEXT: [[XOR_12:%.*]] = xor i1 [[XOR_11]], [[C_4]] 327; CHECK-NEXT: ret i1 [[XOR_12]] 328; 329entry: 330 %pre.1 = icmp eq i8 %a, %b 331 %pre.2 = icmp ult i8 %b, 100 332 %pre.and = and i1 %pre.1, %pre.2 333 br i1 %pre.and, label %then, label %else 334 335then: 336 %t.1 = icmp ult i8 %a, 100 337 %t.2 = icmp ult i8 %b, 100 338 %xor.1 = xor i1 %t.1, %t.2 339 340 %f.1 = icmp uge i8 %a, 100 341 %xor.2 = xor i1 %xor.1, %f.1 342 343 %f.2 = icmp uge i8 %b, 100 344 %xor.3 = xor i1 %xor.2, %f.2 345 346 %f.3.1 = icmp ugt i8 %a, 99 347 %xor.4 = xor i1 %xor.3, %f.3.1 348 349 %c.1 = icmp ult i8 %a, 99 350 %xor.5 = xor i1 %xor.4, %c.1 351 352 %c.2 = icmp ugt i8 %a, 98 353 %xor.6 = xor i1 %xor.5, %c.1 354 355 ret i1 %xor.6 356 357else: 358 %f.4 = icmp ult i8 %a, 100 359 %f.5 = icmp ult i8 %b, 100 360 %xor.7 = xor i1 %f.4, %f.5 361 362 %t.3 = icmp uge i8 %a, 100 363 %xor.8 = xor i1 %xor.7, %t.3 364 365 %t.4 = icmp uge i8 %b, 100 366 %xor.9 = xor i1 %xor.8, %t.4 367 368 %t.5 = icmp ugt i8 %a, 99 369 %xor.10 = xor i1 %xor.9, %t.5 370 371 %c.3 = icmp ult i8 %a, 99 372 %xor.11 = xor i1 %xor.10, %c.3 373 374 %c.4 = icmp ugt i8 %a, 98 375 %xor.12 = xor i1 %xor.11, %c.4 376 377 ret i1 %xor.12 378} 379