|
| 1 | +; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 4 |
| 2 | +; RUN: opt < %s -passes=instsimplify -S | FileCheck %s |
| 3 | + |
| 4 | +; %or2 cannot be folded into %or1 because %or1 has disjoint. |
| 5 | +; TODO: Can we move the logic into InstCombine and drop the disjoint flag? |
| 6 | +define i64 @test(i1 %cond, i64 %x) { |
| 7 | +; CHECK-LABEL: define i64 @test( |
| 8 | +; CHECK-SAME: i1 [[COND:%.*]], i64 [[X:%.*]]) { |
| 9 | +; CHECK-NEXT: [[OR1:%.*]] = or disjoint i64 [[X]], 7 |
| 10 | +; CHECK-NEXT: [[SEL1:%.*]] = select i1 [[COND]], i64 [[OR1]], i64 [[X]] |
| 11 | +; CHECK-NEXT: [[OR2:%.*]] = or i64 [[SEL1]], 7 |
| 12 | +; CHECK-NEXT: ret i64 [[OR2]] |
| 13 | +; |
| 14 | + %or1 = or disjoint i64 %x, 7 |
| 15 | + %sel1 = select i1 %cond, i64 %or1, i64 %x |
| 16 | + %or2 = or i64 %sel1, 7 |
| 17 | + ret i64 %or2 |
| 18 | +} |
| 19 | + |
| 20 | +define i64 @pr87042(i64 %x) { |
| 21 | +; CHECK-LABEL: define i64 @pr87042( |
| 22 | +; CHECK-SAME: i64 [[X:%.*]]) { |
| 23 | +; CHECK-NEXT: [[AND1:%.*]] = and i64 [[X]], 65535 |
| 24 | +; CHECK-NEXT: [[CMP1:%.*]] = icmp eq i64 [[AND1]], 0 |
| 25 | +; CHECK-NEXT: [[OR1:%.*]] = or disjoint i64 [[X]], 7 |
| 26 | +; CHECK-NEXT: [[SEL1:%.*]] = select i1 [[CMP1]], i64 [[OR1]], i64 [[X]] |
| 27 | +; CHECK-NEXT: [[AND2:%.*]] = and i64 [[SEL1]], 16776960 |
| 28 | +; CHECK-NEXT: [[CMP2:%.*]] = icmp eq i64 [[AND2]], 0 |
| 29 | +; CHECK-NEXT: [[OR2:%.*]] = or i64 [[SEL1]], 7 |
| 30 | +; CHECK-NEXT: [[SEL2:%.*]] = select i1 [[CMP2]], i64 [[OR2]], i64 [[SEL1]] |
| 31 | +; CHECK-NEXT: ret i64 [[SEL2]] |
| 32 | +; |
| 33 | + %and1 = and i64 %x, 65535 |
| 34 | + %cmp1 = icmp eq i64 %and1, 0 |
| 35 | + %or1 = or disjoint i64 %x, 7 |
| 36 | + %sel1 = select i1 %cmp1, i64 %or1, i64 %x |
| 37 | + %and2 = and i64 %sel1, 16776960 |
| 38 | + %cmp2 = icmp eq i64 %and2, 0 |
| 39 | + %or2 = or i64 %sel1, 7 |
| 40 | + %sel2 = select i1 %cmp2, i64 %or2, i64 %sel1 |
| 41 | + ret i64 %sel2 |
| 42 | +} |
0 commit comments