xref: /llvm-project/llvm/test/Transforms/InstSimplify/ConstProp/smul-fix-sat.ll (revision b280ee1dd7e9b36ae7aaa3953556e4b7a7f31a29)
1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2; RUN: opt < %s -passes=instsimplify -S | FileCheck %s
3
4;-----------------------------------------------------------------------------
5; Simple test using scalar layout.
6;-----------------------------------------------------------------------------
7
8declare i32 @llvm.smul.fix.sat.i32(i32, i32, i32)
9
10define i32 @test_smul_fix_sat_i32_0() {
11; CHECK-LABEL: @test_smul_fix_sat_i32_0(
12; CHECK-NEXT:    ret i32 536870912
13;
14  %r = call i32 @llvm.smul.fix.sat.i32(i32 1073741824, i32 1073741824, i32 31) ; 0.5 * 0.5
15  ret i32 %r
16}
17
18define i32 @test_smul_fix_sat_i32_undef_x() {
19; CHECK-LABEL: @test_smul_fix_sat_i32_undef_x(
20; CHECK-NEXT:    ret i32 0
21;
22  %r = call i32 @llvm.smul.fix.sat.i32(i32 undef, i32 1073741824, i32 31)
23  ret i32 %r
24}
25
26define i32 @test_smul_fix_sat_i32_x_undef() {
27; CHECK-LABEL: @test_smul_fix_sat_i32_x_undef(
28; CHECK-NEXT:    ret i32 0
29;
30  %r = call i32 @llvm.smul.fix.sat.i32(i32 17, i32 undef, i32 31)
31  ret i32 %r
32}
33
34;-----------------------------------------------------------------------------
35; More extensive tests based on vectors (basically using the scalar fold
36; for each index).
37;-----------------------------------------------------------------------------
38
39declare <8 x i3> @llvm.smul.fix.sat.v8i3(<8 x i3>, <8 x i3>, i32)
40
41define <8 x i3> @test_smul_fix_sat_v8i3_0() {
42; CHECK-LABEL: @test_smul_fix_sat_v8i3_0(
43; CHECK-NEXT:    ret <8 x i3> <i3 3, i3 3, i3 3, i3 3, i3 0, i3 -4, i3 -4, i3 -4>
44;
45  %r = call <8 x i3> @llvm.smul.fix.sat.v8i3(
46  <8 x i3> <i3 -4, i3 -3, i3 -2, i3 -1, i3 0, i3 1, i3 2, i3 3>,
47  <8 x i3> <i3 -4, i3 -4, i3 -4, i3 -4, i3 -4, i3 -4, i3 -4, i3 -4>,
48  i32 0)
49  ret <8 x i3> %r
50}
51
52define <8 x i3> @test_smul_fix_sat_v8i3_1() {
53; CHECK-LABEL: @test_smul_fix_sat_v8i3_1(
54; CHECK-NEXT:    ret <8 x i3> <i3 3, i3 3, i3 3, i3 2, i3 0, i3 -2, i3 -4, i3 -4>
55;
56  %r = call <8 x i3> @llvm.smul.fix.sat.v8i3(
57  <8 x i3> <i3 -4, i3 -3, i3 -2, i3 -1, i3 0, i3 1, i3 2, i3 3>,
58  <8 x i3> <i3 -4, i3 -4, i3 -4, i3 -4, i3 -4, i3 -4, i3 -4, i3 -4>,
59  i32 1)
60  ret <8 x i3> %r
61}
62
63define <8 x i3> @test_smul_fix_sat_v8i3_2() {
64; CHECK-LABEL: @test_smul_fix_sat_v8i3_2(
65; CHECK-NEXT:    ret <8 x i3> <i3 3, i3 3, i3 2, i3 1, i3 0, i3 -1, i3 -2, i3 -3>
66;
67  %r = call <8 x i3> @llvm.smul.fix.sat.v8i3(
68  <8 x i3> <i3 -4, i3 -3, i3 -2, i3 -1, i3 0, i3 1, i3 2, i3 3>,
69  <8 x i3> <i3 -4, i3 -4, i3 -4, i3 -4, i3 -4, i3 -4, i3 -4, i3 -4>,
70  i32 2)
71  ret <8 x i3> %r
72}
73
74define <8 x i3> @test_smul_fix_sat_v8i3_3() {
75; CHECK-LABEL: @test_smul_fix_sat_v8i3_3(
76; CHECK-NEXT:    ret <8 x i3> <i3 3, i3 3, i3 2, i3 1, i3 0, i3 -1, i3 -2, i3 -3>
77;
78  %r = call <8 x i3> @llvm.smul.fix.sat.v8i3(
79  <8 x i3> <i3 -4, i3 -3, i3 -2, i3 -1, i3 0, i3 1, i3 2, i3 3>,
80  <8 x i3> <i3 -1, i3 -1, i3 -1, i3 -1, i3 -1, i3 -1, i3 -1, i3 -1>,
81  i32 0)
82  ret <8 x i3> %r
83}
84
85define <8 x i3> @test_smul_fix_sat_v8i3_4() {
86; CHECK-LABEL: @test_smul_fix_sat_v8i3_4(
87; CHECK-NEXT:    ret <8 x i3> <i3 2, i3 1, i3 1, i3 0, i3 0, i3 -1, i3 -1, i3 -2>
88;
89  %r = call <8 x i3> @llvm.smul.fix.sat.v8i3(
90  <8 x i3> <i3 -4, i3 -3, i3 -2, i3 -1, i3 0, i3 1, i3 2, i3 3>,
91  <8 x i3> <i3 -1, i3 -1, i3 -1, i3 -1, i3 -1, i3 -1, i3 -1, i3 -1>,
92  i32 1)
93  ret <8 x i3> %r
94}
95
96define <8 x i3> @test_smul_fix_sat_v8i3_5() {
97; CHECK-LABEL: @test_smul_fix_sat_v8i3_5(
98; CHECK-NEXT:    ret <8 x i3> <i3 1, i3 0, i3 0, i3 0, i3 0, i3 -1, i3 -1, i3 -1>
99;
100  %r = call <8 x i3> @llvm.smul.fix.sat.v8i3(
101  <8 x i3> <i3 -4, i3 -3, i3 -2, i3 -1, i3 0, i3 1, i3 2, i3 3>,
102  <8 x i3> <i3 -1, i3 -1, i3 -1, i3 -1, i3 -1, i3 -1, i3 -1, i3 -1>,
103  i32 2)
104  ret <8 x i3> %r
105}
106
107define <8 x i3> @test_smul_fix_sat_v8i3_6() {
108; CHECK-LABEL: @test_smul_fix_sat_v8i3_6(
109; CHECK-NEXT:    ret <8 x i3> <i3 -4, i3 -4, i3 -4, i3 -3, i3 0, i3 3, i3 3, i3 3>
110;
111  %r = call <8 x i3> @llvm.smul.fix.sat.v8i3(
112  <8 x i3> <i3 -4, i3 -3, i3 -2, i3 -1, i3 0, i3 1, i3 2, i3 3>,
113  <8 x i3> <i3 3, i3 3, i3 3, i3 3, i3 3, i3 3, i3 3, i3 3>,
114  i32 0)
115  ret <8 x i3> %r
116}
117
118define <8 x i3> @test_smul_fix_sat_v8i3_7() {
119; CHECK-LABEL: @test_smul_fix_sat_v8i3_7(
120; CHECK-NEXT:    ret <8 x i3> <i3 -4, i3 -4, i3 -3, i3 -2, i3 0, i3 1, i3 3, i3 3>
121;
122  %r = call <8 x i3> @llvm.smul.fix.sat.v8i3(
123  <8 x i3> <i3 -4, i3 -3, i3 -2, i3 -1, i3 0, i3 1, i3 2, i3 3>,
124  <8 x i3> <i3 3, i3 3, i3 3, i3 3, i3 3, i3 3, i3 3, i3 3>,
125  i32 1)
126  ret <8 x i3> %r
127}
128
129define <8 x i3> @test_smul_fix_sat_v8i3_8() {
130; CHECK-LABEL: @test_smul_fix_sat_v8i3_8(
131; CHECK-NEXT:    ret <8 x i3> <i3 -3, i3 -3, i3 -2, i3 -1, i3 0, i3 0, i3 1, i3 2>
132;
133  %r = call <8 x i3> @llvm.smul.fix.sat.v8i3(
134  <8 x i3> <i3 -4, i3 -3, i3 -2, i3 -1, i3 0, i3 1, i3 2, i3 3>,
135  <8 x i3> <i3 3, i3 3, i3 3, i3 3, i3 3, i3 3, i3 3, i3 3>,
136  i32 2)
137  ret <8 x i3> %r
138}
139
140define <8 x i3> @test_smul_fix_sat_v8i3_9() {
141; CHECK-LABEL: @test_smul_fix_sat_v8i3_9(
142; CHECK-NEXT:    ret <8 x i3> <i3 0, i3 0, i3 poison, i3 poison, i3 1, i3 1, i3 1, i3 1>
143;
144  %r = call <8 x i3> @llvm.smul.fix.sat.v8i3(
145  <8 x i3> <i3 2, i3 undef, i3 2, i3 poison, i3 2, i3 2, i3 2, i3 2>,
146  <8 x i3> <i3 undef, i3 2, i3 poison, i3 2, i3 2, i3 2, i3 2, i3 2>,
147  i32 2)
148  ret <8 x i3> %r
149}
150