1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -passes=instsimplify -S | FileCheck %s
4 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
6 ; (ctpop(X) == N) || (X != 0) --> X != 0
9 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11 declare i32 @llvm.ctpop.i32(i32)
13 define 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]]
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
25 declare <2 x i32> @llvm.ctpop.v2i32(<2 x i32>)
27 define <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]]
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
39 ; Negative test - wrong predicate
41 define i1 @eq_or_non_0_wrong_pred1(i32 %x) {
42 ; CHECK-LABEL: @eq_or_non_0_wrong_pred1(
43 ; CHECK-NEXT: ret i1 true
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
52 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
54 ; (ctpop(X) != N) && (X == 0) --> X == 0
57 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
59 define 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]]
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
71 define <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]]
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
83 ; Negative test - wrong predicate
85 define 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]]
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