1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -instcombine -S | FileCheck %s
8 ; iff y is free to invert and all uses of z can be freely updated.
10 declare void @use1(i1)
12 ; Most basic positive test
13 define i32 @t0(i1 %i0, i32 %v0, i32 %v1, i32 %v2, i32 %v3) {
15 ; CHECK-NEXT: [[I1:%.*]] = icmp ne i32 [[V0:%.*]], [[V1:%.*]]
16 ; CHECK-NEXT: [[TMP1:%.*]] = or i1 [[I1]], [[I0:%.*]]
17 ; CHECK-NEXT: [[I4:%.*]] = select i1 [[TMP1]], i32 [[V3:%.*]], i32 [[V2:%.*]]
18 ; CHECK-NEXT: ret i32 [[I4]]
20 %i1 = icmp eq i32 %v0, %v1
23 %i4 = select i1 %i3, i32 %v2, i32 %v3
26 define i32 @t1(i32 %v0, i32 %v1, i32 %v2, i32 %v3, i32 %v4, i32 %v5) {
28 ; CHECK-NEXT: [[I0:%.*]] = icmp eq i32 [[V0:%.*]], [[V1:%.*]]
29 ; CHECK-NEXT: [[I1:%.*]] = icmp ne i32 [[V2:%.*]], [[V3:%.*]]
30 ; CHECK-NEXT: call void @use1(i1 [[I0]])
31 ; CHECK-NEXT: [[TMP1:%.*]] = or i1 [[I0]], [[I1]]
32 ; CHECK-NEXT: [[I4:%.*]] = select i1 [[TMP1]], i32 [[V5:%.*]], i32 [[V4:%.*]]
33 ; CHECK-NEXT: ret i32 [[I4]]
35 %i0 = icmp eq i32 %v0, %v1
36 %i1 = icmp eq i32 %v2, %v3
37 call void @use1(i1 %i0)
40 %i4 = select i1 %i3, i32 %v4, i32 %v5
44 ; All users of %i3 must be invertible
45 define i1 @n2(i1 %i0, i32 %v0, i32 %v1, i32 %v2, i32 %v3) {
47 ; CHECK-NEXT: [[I1:%.*]] = icmp eq i32 [[V0:%.*]], [[V1:%.*]]
48 ; CHECK-NEXT: [[I2:%.*]] = xor i1 [[I0:%.*]], true
49 ; CHECK-NEXT: [[I3:%.*]] = and i1 [[I1]], [[I2]]
50 ; CHECK-NEXT: ret i1 [[I3]]
52 %i1 = icmp eq i32 %v0, %v1
55 ret i1 %i3 ; can not be inverted
58 ; %i1 must be invertible
59 define i32 @n3(i1 %i0, i32 %v0, i32 %v1, i32 %v2, i32 %v3) {
61 ; CHECK-NEXT: [[I1:%.*]] = icmp eq i32 [[V0:%.*]], [[V1:%.*]]
62 ; CHECK-NEXT: call void @use1(i1 [[I1]])
63 ; CHECK-NEXT: [[I2:%.*]] = xor i1 [[I0:%.*]], true
64 ; CHECK-NEXT: [[I3:%.*]] = and i1 [[I1]], [[I2]]
65 ; CHECK-NEXT: [[I4:%.*]] = select i1 [[I3]], i32 [[V2:%.*]], i32 [[V3:%.*]]
66 ; CHECK-NEXT: ret i32 [[I4]]
68 %i1 = icmp eq i32 %v0, %v1 ; has extra uninvertible use
69 call void @use1(i1 %i1) ; bad extra use
72 %i4 = select i1 %i3, i32 %v2, i32 %v3
76 ; FIXME: we could invert all uses of %i1 here
77 define i32 @n4(i1 %i0, i32 %v0, i32 %v1, i32 %v2, i32 %v3, i32 %v4, i32 %v5, i32* %dst) {
79 ; CHECK-NEXT: [[I1:%.*]] = icmp eq i32 [[V0:%.*]], [[V1:%.*]]
80 ; CHECK-NEXT: [[I2:%.*]] = select i1 [[I1]], i32 [[V2:%.*]], i32 [[V3:%.*]]
81 ; CHECK-NEXT: store i32 [[I2]], i32* [[DST:%.*]], align 4
82 ; CHECK-NEXT: [[I3:%.*]] = xor i1 [[I0:%.*]], true
83 ; CHECK-NEXT: [[I4:%.*]] = and i1 [[I1]], [[I3]]
84 ; CHECK-NEXT: [[I5:%.*]] = select i1 [[I4]], i32 [[V4:%.*]], i32 [[V5:%.*]]
85 ; CHECK-NEXT: ret i32 [[I5]]
87 %i1 = icmp eq i32 %v0, %v1 ; has extra invertible use
88 %i2 = select i1 %i1, i32 %v2, i32 %v3 ; invertible use
89 store i32 %i2, i32* %dst
92 %i5 = select i1 %i4, i32 %v4, i32 %v5