|
| 1 | +; NOTE: Assertions have been autogenerated by utils/update_test_checks.py |
| 2 | +; RUN: opt < %s -instcombine -S | FileCheck %s |
| 3 | + |
| 4 | +; Transform |
| 5 | +; z = (~x) & y |
| 6 | +; into: |
| 7 | +; z = ~(x | (~y)) |
| 8 | +; iff y is free to invert and all uses of z can be freely updated. |
| 9 | + |
| 10 | +declare void @use1(i1) |
| 11 | + |
| 12 | +; Most basic positive test |
| 13 | +define i32 @t0(i1 %i0, i32 %v0, i32 %v1, i32 %v2, i32 %v3) { |
| 14 | +; CHECK-LABEL: @t0( |
| 15 | +; CHECK-NEXT: [[I1:%.*]] = icmp eq i32 [[V0:%.*]], [[V1:%.*]] |
| 16 | +; CHECK-NEXT: [[I2:%.*]] = xor i1 [[I0:%.*]], true |
| 17 | +; CHECK-NEXT: [[I3:%.*]] = and i1 [[I1]], [[I2]] |
| 18 | +; CHECK-NEXT: [[I4:%.*]] = select i1 [[I3]], i32 [[V2:%.*]], i32 [[V3:%.*]] |
| 19 | +; CHECK-NEXT: ret i32 [[I4]] |
| 20 | +; |
| 21 | + %i1 = icmp eq i32 %v0, %v1 |
| 22 | + %i2 = xor i1 %i0, -1 |
| 23 | + %i3 = and i1 %i2, %i1 |
| 24 | + %i4 = select i1 %i3, i32 %v2, i32 %v3 |
| 25 | + ret i32 %i4 |
| 26 | +} |
| 27 | +define i32 @t1(i32 %v0, i32 %v1, i32 %v2, i32 %v3, i32 %v4, i32 %v5) { |
| 28 | +; CHECK-LABEL: @t1( |
| 29 | +; CHECK-NEXT: [[I0:%.*]] = icmp eq i32 [[V0:%.*]], [[V1:%.*]] |
| 30 | +; CHECK-NEXT: [[I1:%.*]] = icmp eq i32 [[V2:%.*]], [[V3:%.*]] |
| 31 | +; CHECK-NEXT: call void @use1(i1 [[I0]]) |
| 32 | +; CHECK-NEXT: [[I2:%.*]] = xor i1 [[I0]], true |
| 33 | +; CHECK-NEXT: [[I3:%.*]] = and i1 [[I1]], [[I2]] |
| 34 | +; CHECK-NEXT: [[I4:%.*]] = select i1 [[I3]], i32 [[V4:%.*]], i32 [[V5:%.*]] |
| 35 | +; CHECK-NEXT: ret i32 [[I4]] |
| 36 | +; |
| 37 | + %i0 = icmp eq i32 %v0, %v1 |
| 38 | + %i1 = icmp eq i32 %v2, %v3 |
| 39 | + call void @use1(i1 %i0) |
| 40 | + %i2 = xor i1 %i0, -1 |
| 41 | + %i3 = and i1 %i2, %i1 |
| 42 | + %i4 = select i1 %i3, i32 %v4, i32 %v5 |
| 43 | + ret i32 %i4 |
| 44 | +} |
| 45 | + |
| 46 | +; All users of %i3 must be invertible |
| 47 | +define i1 @n2(i1 %i0, i32 %v0, i32 %v1, i32 %v2, i32 %v3) { |
| 48 | +; CHECK-LABEL: @n2( |
| 49 | +; CHECK-NEXT: [[I1:%.*]] = icmp eq i32 [[V0:%.*]], [[V1:%.*]] |
| 50 | +; CHECK-NEXT: [[I2:%.*]] = xor i1 [[I0:%.*]], true |
| 51 | +; CHECK-NEXT: [[I3:%.*]] = and i1 [[I1]], [[I2]] |
| 52 | +; CHECK-NEXT: ret i1 [[I3]] |
| 53 | +; |
| 54 | + %i1 = icmp eq i32 %v0, %v1 |
| 55 | + %i2 = xor i1 %i0, -1 |
| 56 | + %i3 = and i1 %i2, %i1 |
| 57 | + ret i1 %i3 ; can not be inverted |
| 58 | +} |
| 59 | + |
| 60 | +; %i1 must be invertible |
| 61 | +define i32 @n3(i1 %i0, i32 %v0, i32 %v1, i32 %v2, i32 %v3) { |
| 62 | +; CHECK-LABEL: @n3( |
| 63 | +; CHECK-NEXT: [[I1:%.*]] = icmp eq i32 [[V0:%.*]], [[V1:%.*]] |
| 64 | +; CHECK-NEXT: call void @use1(i1 [[I1]]) |
| 65 | +; CHECK-NEXT: [[I2:%.*]] = xor i1 [[I0:%.*]], true |
| 66 | +; CHECK-NEXT: [[I3:%.*]] = and i1 [[I1]], [[I2]] |
| 67 | +; CHECK-NEXT: [[I4:%.*]] = select i1 [[I3]], i32 [[V2:%.*]], i32 [[V3:%.*]] |
| 68 | +; CHECK-NEXT: ret i32 [[I4]] |
| 69 | +; |
| 70 | + %i1 = icmp eq i32 %v0, %v1 ; has extra uninvertible use |
| 71 | + call void @use1(i1 %i1) ; bad extra use |
| 72 | + %i2 = xor i1 %i0, -1 |
| 73 | + %i3 = and i1 %i2, %i1 |
| 74 | + %i4 = select i1 %i3, i32 %v2, i32 %v3 |
| 75 | + ret i32 %i4 |
| 76 | +} |
| 77 | + |
| 78 | +; FIXME: we could invert all uses of %i1 here |
| 79 | +define i32 @n4(i1 %i0, i32 %v0, i32 %v1, i32 %v2, i32 %v3, i32 %v4, i32 %v5, i32* %dst) { |
| 80 | +; CHECK-LABEL: @n4( |
| 81 | +; CHECK-NEXT: [[I1:%.*]] = icmp eq i32 [[V0:%.*]], [[V1:%.*]] |
| 82 | +; CHECK-NEXT: [[I2:%.*]] = select i1 [[I1]], i32 [[V2:%.*]], i32 [[V3:%.*]] |
| 83 | +; CHECK-NEXT: store i32 [[I2]], i32* [[DST:%.*]], align 4 |
| 84 | +; CHECK-NEXT: [[I3:%.*]] = xor i1 [[I0:%.*]], true |
| 85 | +; CHECK-NEXT: [[I4:%.*]] = and i1 [[I1]], [[I3]] |
| 86 | +; CHECK-NEXT: [[I5:%.*]] = select i1 [[I4]], i32 [[V4:%.*]], i32 [[V5:%.*]] |
| 87 | +; CHECK-NEXT: ret i32 [[I5]] |
| 88 | +; |
| 89 | + %i1 = icmp eq i32 %v0, %v1 ; has extra invertible use |
| 90 | + %i2 = select i1 %i1, i32 %v2, i32 %v3 ; invertible use |
| 91 | + store i32 %i2, i32* %dst |
| 92 | + %i3 = xor i1 %i0, -1 |
| 93 | + %i4 = and i1 %i3, %i1 |
| 94 | + %i5 = select i1 %i4, i32 %v4, i32 %v5 |
| 95 | + ret i32 %i5 |
| 96 | +} |
0 commit comments