xref: /llvm-project/llvm/test/Transforms/InstSimplify/vec-cmp.ll (revision 38fffa630ee80163dc65e759392ad29798905679)
1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2; RUN: opt < %s -passes=instsimplify -S | FileCheck %s
3
4define <2 x i1> @nonzero_vec_splat(<2 x i32> %x) {
5; CHECK-LABEL: @nonzero_vec_splat(
6; CHECK-NEXT:    ret <2 x i1> zeroinitializer
7;
8  %y = or <2 x i32> %x, <i32 1, i32 1>
9  %c = icmp eq <2 x i32> %y, zeroinitializer
10  ret <2 x i1> %c
11}
12
13define <2 x i1> @nonzero_vec_nonsplat(<2 x i32> %x) {
14; CHECK-LABEL: @nonzero_vec_nonsplat(
15; CHECK-NEXT:    ret <2 x i1> splat (i1 true)
16;
17  %y = or <2 x i32> %x, <i32 2, i32 1>
18  %c = icmp ne <2 x i32> %y, zeroinitializer
19  ret <2 x i1> %c
20}
21
22define <2 x i1> @nonzero_vec_undef_elt(<2 x i32> %x) {
23; CHECK-LABEL: @nonzero_vec_undef_elt(
24; CHECK-NEXT:    [[Y:%.*]] = or <2 x i32> [[X:%.*]], <i32 undef, i32 1>
25; CHECK-NEXT:    [[C:%.*]] = icmp eq <2 x i32> [[Y]], zeroinitializer
26; CHECK-NEXT:    ret <2 x i1> [[C]]
27;
28  %y = or <2 x i32> %x, <i32 undef, i32 1>
29  %c = icmp eq <2 x i32> %y, zeroinitializer
30  ret <2 x i1> %c
31}
32
33define <2 x i1> @nonzero_vec_poison_elt(<2 x i32> %x) {
34; CHECK-LABEL: @nonzero_vec_poison_elt(
35; CHECK-NEXT:    ret <2 x i1> zeroinitializer
36;
37  %y = or <2 x i32> %x, <i32 poison, i32 1>
38  %c = icmp eq <2 x i32> %y, zeroinitializer
39  ret <2 x i1> %c
40}
41
42define <2 x i1> @may_be_zero_vec(<2 x i32> %x) {
43; CHECK-LABEL: @may_be_zero_vec(
44; CHECK-NEXT:    [[Y:%.*]] = or <2 x i32> [[X:%.*]], <i32 0, i32 1>
45; CHECK-NEXT:    [[C:%.*]] = icmp ne <2 x i32> [[Y]], zeroinitializer
46; CHECK-NEXT:    ret <2 x i1> [[C]]
47;
48  %y = or <2 x i32> %x, <i32 0, i32 1>
49  %c = icmp ne <2 x i32> %y, zeroinitializer
50  ret <2 x i1> %c
51}
52
53; Multiplies of non-zero numbers are non-zero if there is no unsigned overflow.
54define <2 x i1> @nonzero_vec_mul_nuw(<2 x i32> %x, <2 x i32> %y) {
55; CHECK-LABEL: @nonzero_vec_mul_nuw(
56; CHECK-NEXT:    ret <2 x i1> zeroinitializer
57;
58  %xnz = or <2 x i32> %x, <i32 1, i32 2>
59  %ynz = or <2 x i32> %y, <i32 3, i32 poison>
60  %m = mul nuw <2 x i32> %xnz, %ynz
61  %c = icmp eq <2 x i32> %m, zeroinitializer
62  ret <2 x i1> %c
63}
64
65; Multiplies of non-zero numbers are non-zero if there is no signed overflow.
66define <2 x i1> @nonzero_vec_mul_nsw(<2 x i32> %x, <2 x i32> %y) {
67; CHECK-LABEL: @nonzero_vec_mul_nsw(
68; CHECK-NEXT:    ret <2 x i1> splat (i1 true)
69;
70  %xnz = or <2 x i32> %x, <i32 poison, i32 2>
71  %ynz = or <2 x i32> %y, <i32 3, i32 4>
72  %m = mul nsw <2 x i32> %xnz, %ynz
73  %c = icmp ne <2 x i32> %m, zeroinitializer
74  ret <2 x i1> %c
75}
76
77