xref: /llvm-project/llvm/test/Transforms/InstSimplify/and-or-icmp-ctpop.ll (revision 060de415af335fdd82910f409e2be3b8457eaa43)
1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2; RUN: opt < %s -passes=instsimplify -S | FileCheck %s
3
4;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5;
6; (ctpop(X) == N) || (X != 0) --> X != 0
7; where N > 0
8;
9;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10
11declare i32 @llvm.ctpop.i32(i32)
12
13define i1 @eq_or_non_0(i32 %x) {
14; CHECK-LABEL: @eq_or_non_0(
15; CHECK-NEXT:    [[NOTZERO:%.*]] = icmp ne i32 [[X:%.*]], 0
16; CHECK-NEXT:    ret i1 [[NOTZERO]]
17;
18  %t0 = tail call i32 @llvm.ctpop.i32(i32 %x)
19  %cmp = icmp eq i32 %t0, 10
20  %notzero = icmp ne i32 %x, 0
21  %r = or i1 %notzero, %cmp
22  ret i1 %r
23}
24
25declare <2 x i32> @llvm.ctpop.v2i32(<2 x i32>)
26
27define <2 x i1> @eq_or_non_0_commute(<2 x i32> %x) {
28; CHECK-LABEL: @eq_or_non_0_commute(
29; CHECK-NEXT:    [[NOTZERO:%.*]] = icmp ne <2 x i32> [[X:%.*]], zeroinitializer
30; CHECK-NEXT:    ret <2 x i1> [[NOTZERO]]
31;
32  %t0 = tail call <2 x i32> @llvm.ctpop.v2i32(<2 x i32> %x)
33  %cmp = icmp eq <2 x i32> %t0, <i32 20, i32 20>
34  %notzero = icmp ne <2 x i32> %x, <i32 0, i32 0>
35  %r = or <2 x i1> %cmp, %notzero
36  ret <2 x i1> %r
37}
38
39; Negative test - wrong predicate
40
41define i1 @eq_or_non_0_wrong_pred1(i32 %x) {
42; CHECK-LABEL: @eq_or_non_0_wrong_pred1(
43; CHECK-NEXT:    ret i1 true
44;
45  %t0 = tail call i32 @llvm.ctpop.i32(i32 %x)
46  %cmp = icmp ne i32 %t0, 10
47  %notzero = icmp ne i32 %x, 0
48  %r = or i1 %notzero, %cmp
49  ret i1 %r
50}
51
52;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
53;
54; (ctpop(X) != N) && (X == 0) --> X == 0
55; where N > 0
56;
57;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
58
59define i1 @ne_and_is_0(i32 %x) {
60; CHECK-LABEL: @ne_and_is_0(
61; CHECK-NEXT:    [[ISZERO:%.*]] = icmp eq i32 [[X:%.*]], 0
62; CHECK-NEXT:    ret i1 [[ISZERO]]
63;
64  %t0 = tail call i32 @llvm.ctpop.i32(i32 %x)
65  %cmp = icmp ne i32 %t0, 10
66  %iszero = icmp eq i32 %x, 0
67  %r = and i1 %iszero, %cmp
68  ret i1 %r
69}
70
71define <2 x i1> @ne_and_is_0_commute(<2 x i32> %x) {
72; CHECK-LABEL: @ne_and_is_0_commute(
73; CHECK-NEXT:    [[ISZERO:%.*]] = icmp eq <2 x i32> [[X:%.*]], zeroinitializer
74; CHECK-NEXT:    ret <2 x i1> [[ISZERO]]
75;
76  %t0 = tail call <2 x i32> @llvm.ctpop.v2i32(<2 x i32> %x)
77  %cmp = icmp ne <2 x i32> %t0, <i32 20, i32 20>
78  %iszero = icmp eq <2 x i32> %x, <i32 0, i32 0>
79  %r = and <2 x i1> %cmp, %iszero
80  ret <2 x i1> %r
81}
82
83; Negative test - wrong predicate
84
85define i1 @ne_and_is_0_wrong_pred1(i32 %x) {
86; CHECK-LABEL: @ne_and_is_0_wrong_pred1(
87; CHECK-NEXT:    [[T0:%.*]] = tail call i32 @llvm.ctpop.i32(i32 [[X:%.*]])
88; CHECK-NEXT:    [[CMP:%.*]] = icmp ne i32 [[T0]], 10
89; CHECK-NEXT:    ret i1 [[CMP]]
90;
91  %t0 = tail call i32 @llvm.ctpop.i32(i32 %x)
92  %cmp = icmp ne i32 %t0, 10
93  %iszero = icmp eq i32 %x, 0
94  %r = or i1 %iszero, %cmp
95  ret i1 %r
96}
97