Skip to content

Commit 3d58c23

Browse files
committed
Fold poison for llvm trig
Some tests are duplicated in an effort to consolidate folding of poisons
1 parent 8e451a5 commit 3d58c23

File tree

6 files changed

+56
-83
lines changed

6 files changed

+56
-83
lines changed

llvm/lib/Analysis/ValueTracking.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7914,6 +7914,18 @@ bool llvm::intrinsicPropagatesPoison(Intrinsic::ID IID) {
79147914
case Intrinsic::smul_fix_sat:
79157915
case Intrinsic::pow:
79167916
case Intrinsic::powi:
7917+
case Intrinsic::sin:
7918+
case Intrinsic::sinh:
7919+
case Intrinsic::cos:
7920+
case Intrinsic::cosh:
7921+
case Intrinsic::sincos:
7922+
case Intrinsic::sincospi:
7923+
case Intrinsic::tan:
7924+
case Intrinsic::tanh:
7925+
case Intrinsic::asin:
7926+
case Intrinsic::acos:
7927+
case Intrinsic::atan:
7928+
case Intrinsic::atan2:
79177929
case Intrinsic::canonicalize:
79187930
case Intrinsic::sqrt:
79197931
return true;

llvm/test/Transforms/InstSimplify/ConstProp/atan-intrinsic.ll

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,7 @@ define double @test_atan_neg0() {
3535

3636
define double @test_atan_poison() {
3737
; CHECK-LABEL: define double @test_atan_poison() {
38-
; CHECK-NEXT: [[RES:%.*]] = call double @llvm.atan.f64(double poison)
39-
; CHECK-NEXT: ret double [[RES]]
38+
; CHECK-NEXT: ret double poison
4039
;
4140
%res = call double @llvm.atan.f64(double poison)
4241
ret double %res

llvm/test/Transforms/InstSimplify/ConstProp/sinh-cosh-intrinsics.ll

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,7 @@ define double @test_sinh_neg0() {
3535

3636
define double @test_sinh_poison() {
3737
; CHECK-LABEL: define double @test_sinh_poison() {
38-
; CHECK-NEXT: [[RES:%.*]] = call double @llvm.sinh.f64(double poison)
39-
; CHECK-NEXT: ret double [[RES]]
38+
; CHECK-NEXT: ret double poison
4039
;
4140
%res = call double @llvm.sinh.f64(double poison)
4241
ret double %res
@@ -121,8 +120,7 @@ define double @test_cosh_neg0() {
121120

122121
define double @test_cosh_poison() {
123122
; CHECK-LABEL: define double @test_cosh_poison() {
124-
; CHECK-NEXT: [[RES:%.*]] = call double @llvm.cosh.f64(double poison)
125-
; CHECK-NEXT: ret double [[RES]]
123+
; CHECK-NEXT: ret double poison
126124
;
127125
%res = call double @llvm.cosh.f64(double poison)
128126
ret double %res

llvm/test/Transforms/InstSimplify/fold-intrinsics.ll

Lines changed: 36 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -90,18 +90,12 @@ define void @pow_poison(i16 %arg_int,float %arg_flt, ptr %P) {
9090

9191
define void @sin_poison(ptr %P) {
9292
; CHECK-LABEL: @sin_poison(
93-
; CHECK-NEXT: [[SIN_F32:%.*]] = call float @llvm.sin.f32(float poison)
94-
; CHECK-NEXT: store volatile float [[SIN_F32]], ptr [[P:%.*]], align 4
95-
; CHECK-NEXT: [[SIN_2XF32:%.*]] = call <2 x float> @llvm.sin.v2f32(<2 x float> poison)
96-
; CHECK-NEXT: store volatile <2 x float> [[SIN_2XF32]], ptr [[P]], align 8
97-
; CHECK-NEXT: [[SIN_4XF64:%.*]] = call <4 x double> @llvm.sin.v4f64(<4 x double> poison)
98-
; CHECK-NEXT: store volatile <4 x double> [[SIN_4XF64]], ptr [[P]], align 32
99-
; CHECK-NEXT: [[ASIN_F32:%.*]] = call float @llvm.asin.f32(float poison)
100-
; CHECK-NEXT: store volatile float [[ASIN_F32]], ptr [[P]], align 4
101-
; CHECK-NEXT: [[ASIN_2XF32:%.*]] = call <2 x float> @llvm.asin.v2f32(<2 x float> poison)
102-
; CHECK-NEXT: store volatile <2 x float> [[ASIN_2XF32]], ptr [[P]], align 8
103-
; CHECK-NEXT: [[ASIN_4XF64:%.*]] = call <4 x double> @llvm.asin.v4f64(<4 x double> poison)
104-
; CHECK-NEXT: store volatile <4 x double> [[ASIN_4XF64]], ptr [[P]], align 32
93+
; CHECK-NEXT: store volatile float poison, ptr [[P:%.*]], align 4
94+
; CHECK-NEXT: store volatile <2 x float> poison, ptr [[P]], align 8
95+
; CHECK-NEXT: store volatile <4 x double> poison, ptr [[P]], align 32
96+
; CHECK-NEXT: store volatile float poison, ptr [[P]], align 4
97+
; CHECK-NEXT: store volatile <2 x float> poison, ptr [[P]], align 8
98+
; CHECK-NEXT: store volatile <4 x double> poison, ptr [[P]], align 32
10599
; CHECK-NEXT: ret void
106100
;
107101
%sin_f32 = call float @llvm.sin(float poison)
@@ -128,15 +122,12 @@ define void @sin_poison(ptr %P) {
128122

129123
define void @cos_poison(ptr %P) {
130124
; CHECK-LABEL: @cos_poison(
131-
; CHECK-NEXT: store volatile float 0.000000e+00, ptr [[P:%.*]], align 4
132-
; CHECK-NEXT: store volatile <2 x float> zeroinitializer, ptr [[P]], align 8
133-
; CHECK-NEXT: store volatile <4 x double> zeroinitializer, ptr [[P]], align 32
134-
; CHECK-NEXT: [[ACOS_F32:%.*]] = call float @llvm.acos.f32(float poison)
135-
; CHECK-NEXT: store volatile float [[ACOS_F32]], ptr [[P]], align 4
136-
; CHECK-NEXT: [[ACOS_2XF32:%.*]] = call <2 x float> @llvm.acos.v2f32(<2 x float> poison)
137-
; CHECK-NEXT: store volatile <2 x float> [[ACOS_2XF32]], ptr [[P]], align 8
138-
; CHECK-NEXT: [[ACOS_4XF64:%.*]] = call <4 x double> @llvm.acos.v4f64(<4 x double> poison)
139-
; CHECK-NEXT: store volatile <4 x double> [[ACOS_4XF64]], ptr [[P]], align 32
125+
; CHECK-NEXT: store volatile float poison, ptr [[P:%.*]], align 4
126+
; CHECK-NEXT: store volatile <2 x float> poison, ptr [[P]], align 8
127+
; CHECK-NEXT: store volatile <4 x double> poison, ptr [[P]], align 32
128+
; CHECK-NEXT: store volatile float poison, ptr [[P]], align 4
129+
; CHECK-NEXT: store volatile <2 x float> poison, ptr [[P]], align 8
130+
; CHECK-NEXT: store volatile <4 x double> poison, ptr [[P]], align 32
140131
; CHECK-NEXT: ret void
141132
;
142133
%cos_f32 = call float @llvm.cos(float poison)
@@ -163,24 +154,15 @@ define void @cos_poison(ptr %P) {
163154

164155
define void @tan_poison(ptr %P) {
165156
; CHECK-LABEL: @tan_poison(
166-
; CHECK-NEXT: [[TAN_F32:%.*]] = call float @llvm.tan.f32(float poison)
167-
; CHECK-NEXT: store volatile float [[TAN_F32]], ptr [[P:%.*]], align 4
168-
; CHECK-NEXT: [[TAN_2XF32:%.*]] = call <2 x float> @llvm.tan.v2f32(<2 x float> poison)
169-
; CHECK-NEXT: store volatile <2 x float> [[TAN_2XF32]], ptr [[P]], align 8
170-
; CHECK-NEXT: [[TAN_4XF64:%.*]] = call <4 x double> @llvm.tan.v4f64(<4 x double> poison)
171-
; CHECK-NEXT: store volatile <4 x double> [[TAN_4XF64]], ptr [[P]], align 32
172-
; CHECK-NEXT: [[ATAN_F32:%.*]] = call float @llvm.atan.f32(float poison)
173-
; CHECK-NEXT: store volatile float [[ATAN_F32]], ptr [[P]], align 4
174-
; CHECK-NEXT: [[ATAN_2XF32:%.*]] = call <2 x float> @llvm.atan.v2f32(<2 x float> poison)
175-
; CHECK-NEXT: store volatile <2 x float> [[ATAN_2XF32]], ptr [[P]], align 8
176-
; CHECK-NEXT: [[ATAN_4XF64:%.*]] = call <4 x double> @llvm.atan.v4f64(<4 x double> poison)
177-
; CHECK-NEXT: store volatile <4 x double> [[ATAN_4XF64]], ptr [[P]], align 32
178-
; CHECK-NEXT: [[ATAN2_F32:%.*]] = call float @llvm.atan2.f32(float poison, float poison)
179-
; CHECK-NEXT: store volatile float [[ATAN2_F32]], ptr [[P]], align 4
180-
; CHECK-NEXT: [[ATAN2_2XF32:%.*]] = call <2 x float> @llvm.atan2.v2f32(<2 x float> poison, <2 x float> poison)
181-
; CHECK-NEXT: store volatile <2 x float> [[ATAN2_2XF32]], ptr [[P]], align 8
182-
; CHECK-NEXT: [[ATAN2_4XF64:%.*]] = call <4 x double> @llvm.atan2.v4f64(<4 x double> poison, <4 x double> poison)
183-
; CHECK-NEXT: store volatile <4 x double> [[ATAN2_4XF64]], ptr [[P]], align 32
157+
; CHECK-NEXT: store volatile float poison, ptr [[P:%.*]], align 4
158+
; CHECK-NEXT: store volatile <2 x float> poison, ptr [[P]], align 8
159+
; CHECK-NEXT: store volatile <4 x double> poison, ptr [[P]], align 32
160+
; CHECK-NEXT: store volatile float poison, ptr [[P]], align 4
161+
; CHECK-NEXT: store volatile <2 x float> poison, ptr [[P]], align 8
162+
; CHECK-NEXT: store volatile <4 x double> poison, ptr [[P]], align 32
163+
; CHECK-NEXT: store volatile float poison, ptr [[P]], align 4
164+
; CHECK-NEXT: store volatile <2 x float> poison, ptr [[P]], align 8
165+
; CHECK-NEXT: store volatile <4 x double> poison, ptr [[P]], align 32
184166
; CHECK-NEXT: ret void
185167
;
186168
%tan_f32 = call float @llvm.tan(float poison)
@@ -216,18 +198,12 @@ define void @tan_poison(ptr %P) {
216198

217199
define void @sincos_poison(ptr %P) {
218200
; CHECK-LABEL: @sincos_poison(
219-
; CHECK-NEXT: [[SINCOS_F32:%.*]] = call { float, float } @llvm.sincos.f32(float poison)
220-
; CHECK-NEXT: store volatile { float, float } [[SINCOS_F32]], ptr [[P:%.*]], align 4
221-
; CHECK-NEXT: [[SINCOS_2XF32:%.*]] = call { <2 x float>, <2 x float> } @llvm.sincos.v2f32(<2 x float> poison)
222-
; CHECK-NEXT: store volatile { <2 x float>, <2 x float> } [[SINCOS_2XF32]], ptr [[P]], align 8
223-
; CHECK-NEXT: [[SINCOS_4XF64:%.*]] = call { <4 x double>, <4 x double> } @llvm.sincos.v4f64(<4 x double> poison)
224-
; CHECK-NEXT: store volatile { <4 x double>, <4 x double> } [[SINCOS_4XF64]], ptr [[P]], align 32
225-
; CHECK-NEXT: [[SINCOSPI_F32:%.*]] = call { float, float } @llvm.sincospi.f32(float poison)
226-
; CHECK-NEXT: store volatile { float, float } [[SINCOSPI_F32]], ptr [[P]], align 4
227-
; CHECK-NEXT: [[SINCOSPI_2XF32:%.*]] = call { <2 x float>, <2 x float> } @llvm.sincospi.v2f32(<2 x float> poison)
228-
; CHECK-NEXT: store volatile { <2 x float>, <2 x float> } [[SINCOSPI_2XF32]], ptr [[P]], align 8
229-
; CHECK-NEXT: [[SINCOSPI_4XF64:%.*]] = call { <4 x double>, <4 x double> } @llvm.sincospi.v4f64(<4 x double> poison)
230-
; CHECK-NEXT: store volatile { <4 x double>, <4 x double> } [[SINCOSPI_4XF64]], ptr [[P]], align 32
201+
; CHECK-NEXT: store volatile { float, float } poison, ptr [[P:%.*]], align 4
202+
; CHECK-NEXT: store volatile { <2 x float>, <2 x float> } poison, ptr [[P]], align 8
203+
; CHECK-NEXT: store volatile { <4 x double>, <4 x double> } poison, ptr [[P]], align 32
204+
; CHECK-NEXT: store volatile { float, float } poison, ptr [[P]], align 4
205+
; CHECK-NEXT: store volatile { <2 x float>, <2 x float> } poison, ptr [[P]], align 8
206+
; CHECK-NEXT: store volatile { <4 x double>, <4 x double> } poison, ptr [[P]], align 32
231207
; CHECK-NEXT: ret void
232208
;
233209
%sincos_f32 = call { float, float } @llvm.sincos(float poison)
@@ -254,12 +230,9 @@ define void @sincos_poison(ptr %P) {
254230

255231
define void @sinh_poison(ptr %P) {
256232
; CHECK-LABEL: @sinh_poison(
257-
; CHECK-NEXT: [[SINH_F32:%.*]] = call float @llvm.sinh.f32(float poison)
258-
; CHECK-NEXT: store volatile float [[SINH_F32]], ptr [[P:%.*]], align 4
259-
; CHECK-NEXT: [[SINH_2XF32:%.*]] = call <2 x float> @llvm.sinh.v2f32(<2 x float> poison)
260-
; CHECK-NEXT: store volatile <2 x float> [[SINH_2XF32]], ptr [[P]], align 8
261-
; CHECK-NEXT: [[SINH_4XF64:%.*]] = call <4 x double> @llvm.sinh.v4f64(<4 x double> poison)
262-
; CHECK-NEXT: store volatile <4 x double> [[SINH_4XF64]], ptr [[P]], align 32
233+
; CHECK-NEXT: store volatile float poison, ptr [[P:%.*]], align 4
234+
; CHECK-NEXT: store volatile <2 x float> poison, ptr [[P]], align 8
235+
; CHECK-NEXT: store volatile <4 x double> poison, ptr [[P]], align 32
263236
; CHECK-NEXT: ret void
264237
;
265238
%sinh_f32 = call float @llvm.sinh(float poison)
@@ -277,12 +250,9 @@ define void @sinh_poison(ptr %P) {
277250

278251
define void @cosh_poison(ptr %P) {
279252
; CHECK-LABEL: @cosh_poison(
280-
; CHECK-NEXT: [[COSH_F32:%.*]] = call float @llvm.cosh.f32(float poison)
281-
; CHECK-NEXT: store volatile float [[COSH_F32]], ptr [[P:%.*]], align 4
282-
; CHECK-NEXT: [[COSH_2XF32:%.*]] = call <2 x float> @llvm.cosh.v2f32(<2 x float> poison)
283-
; CHECK-NEXT: store volatile <2 x float> [[COSH_2XF32]], ptr [[P]], align 8
284-
; CHECK-NEXT: [[COSH_4XF64:%.*]] = call <4 x double> @llvm.cosh.v4f64(<4 x double> poison)
285-
; CHECK-NEXT: store volatile <4 x double> [[COSH_4XF64]], ptr [[P]], align 32
253+
; CHECK-NEXT: store volatile float poison, ptr [[P:%.*]], align 4
254+
; CHECK-NEXT: store volatile <2 x float> poison, ptr [[P]], align 8
255+
; CHECK-NEXT: store volatile <4 x double> poison, ptr [[P]], align 32
286256
; CHECK-NEXT: ret void
287257
;
288258
%cosh_f32 = call float @llvm.cosh(float poison)
@@ -300,12 +270,9 @@ define void @cosh_poison(ptr %P) {
300270

301271
define void @tanh_poison(ptr %P) {
302272
; CHECK-LABEL: @tanh_poison(
303-
; CHECK-NEXT: [[TANH_F32:%.*]] = call float @llvm.tanh.f32(float poison)
304-
; CHECK-NEXT: store volatile float [[TANH_F32]], ptr [[P:%.*]], align 4
305-
; CHECK-NEXT: [[TANH_2XF32:%.*]] = call <2 x float> @llvm.tanh.v2f32(<2 x float> poison)
306-
; CHECK-NEXT: store volatile <2 x float> [[TANH_2XF32]], ptr [[P]], align 8
307-
; CHECK-NEXT: [[TANH_4XF64:%.*]] = call <4 x double> @llvm.tanh.v4f64(<4 x double> poison)
308-
; CHECK-NEXT: store volatile <4 x double> [[TANH_4XF64]], ptr [[P]], align 32
273+
; CHECK-NEXT: store volatile float poison, ptr [[P:%.*]], align 4
274+
; CHECK-NEXT: store volatile <2 x float> poison, ptr [[P]], align 8
275+
; CHECK-NEXT: store volatile <4 x double> poison, ptr [[P]], align 32
309276
; CHECK-NEXT: ret void
310277
;
311278
%tanh_f32 = call float @llvm.tanh(float poison)

llvm/test/Transforms/InstSimplify/sincos.ll

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,26 +50,23 @@ define { <2 x float>, <2 x float> } @sincos_zero_vector() {
5050

5151
define { float, float } @sincos_poison() {
5252
; CHECK-LABEL: define { float, float } @sincos_poison() {
53-
; CHECK-NEXT: [[RET:%.*]] = call { float, float } @llvm.sincos.f32(float poison)
54-
; CHECK-NEXT: ret { float, float } [[RET]]
53+
; CHECK-NEXT: ret { float, float } poison
5554
;
5655
%ret = call { float, float } @llvm.sincos.f32(float poison)
5756
ret { float, float } %ret
5857
}
5958

6059
define { <2 x float>, <2 x float> } @sincos_poison_vector() {
6160
; CHECK-LABEL: define { <2 x float>, <2 x float> } @sincos_poison_vector() {
62-
; CHECK-NEXT: [[RET:%.*]] = call { <2 x float>, <2 x float> } @llvm.sincos.v2f32(<2 x float> poison)
63-
; CHECK-NEXT: ret { <2 x float>, <2 x float> } [[RET]]
61+
; CHECK-NEXT: ret { <2 x float>, <2 x float> } poison
6462
;
6563
%ret = call { <2 x float>, <2 x float> } @llvm.sincos.v2f32(<2 x float> poison)
6664
ret { <2 x float>, <2 x float> } %ret
6765
}
6866

6967
define { <vscale x 2 x float>, <vscale x 2 x float> } @sincos_poison_scalable_vector() {
7068
; CHECK-LABEL: define { <vscale x 2 x float>, <vscale x 2 x float> } @sincos_poison_scalable_vector() {
71-
; CHECK-NEXT: [[RET:%.*]] = call { <vscale x 2 x float>, <vscale x 2 x float> } @llvm.sincos.nxv2f32(<vscale x 2 x float> poison)
72-
; CHECK-NEXT: ret { <vscale x 2 x float>, <vscale x 2 x float> } [[RET]]
69+
; CHECK-NEXT: ret { <vscale x 2 x float>, <vscale x 2 x float> } poison
7370
;
7471
%ret = call { <vscale x 2 x float>, <vscale x 2 x float> } @llvm.sincos.nxv2f32(<vscale x 2 x float> poison)
7572
ret { <vscale x 2 x float>, <vscale x 2 x float> } %ret

llvm/unittests/Analysis/ValueTrackingTest.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -912,8 +912,8 @@ TEST(ValueTracking, propagatesPoison) {
912912
{false, "call i32 @llvm.fshr.i32(i32 %x, i32 %y, i32 %shamt)", 2},
913913
{true, "call float @llvm.sqrt.f32(float %fx)", 0},
914914
{true, "call float @llvm.powi.f32.i32(float %fx, i32 %x)", 0},
915-
{false, "call float @llvm.sin.f32(float %fx)", 0},
916-
{false, "call float @llvm.cos.f32(float %fx)", 0},
915+
{true, "call float @llvm.sin.f32(float %fx)", 0},
916+
{true, "call float @llvm.cos.f32(float %fx)", 0},
917917
{true, "call float @llvm.pow.f32(float %fx, float %fy)", 0},
918918
{false, "call float @llvm.exp.f32(float %fx)", 0},
919919
{false, "call float @llvm.exp2.f32(float %fx)", 0},

0 commit comments

Comments
 (0)