[llvm] r362253 - [NFC][InstCombine] Add unary FNeg to cos-1.ll cos-2.ll cos-sin-intrinsic.ll
Cameron McInally via llvm-commits
llvm-commits at lists.llvm.org
Fri May 31 11:54:44 PDT 2019
Author: mcinally
Date: Fri May 31 11:54:44 2019
New Revision: 362253
URL: http://llvm.org/viewvc/llvm-project?rev=362253&view=rev
Log:
[NFC][InstCombine] Add unary FNeg to cos-1.ll cos-2.ll cos-sin-intrinsic.ll
Modified:
llvm/trunk/test/Transforms/InstCombine/cos-1.ll
llvm/trunk/test/Transforms/InstCombine/cos-2.ll
llvm/trunk/test/Transforms/InstCombine/cos-sin-intrinsic.ll
Modified: llvm/trunk/test/Transforms/InstCombine/cos-1.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/cos-1.ll?rev=362253&r1=362252&r2=362253&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/cos-1.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/cos-1.ll Fri May 31 11:54:44 2019
@@ -29,6 +29,16 @@ define double @cos_negated_arg(double %x
ret double %r
}
+define double @cos_unary_negated_arg(double %x) {
+; ANY-LABEL: @cos_unary_negated_arg(
+; ANY-NEXT: [[COS:%.*]] = call double @cos(double [[X:%.*]])
+; ANY-NEXT: ret double [[COS]]
+;
+ %neg = fneg double %x
+ %r = call double @cos(double %neg)
+ ret double %r
+}
+
define float @cosf_negated_arg(float %x) {
; ANY-LABEL: @cosf_negated_arg(
; ANY-NEXT: [[COS:%.*]] = call float @cosf(float [[X:%.*]])
@@ -39,6 +49,16 @@ define float @cosf_negated_arg(float %x)
ret float %r
}
+define float @cosf_unary_negated_arg(float %x) {
+; ANY-LABEL: @cosf_unary_negated_arg(
+; ANY-NEXT: [[COS:%.*]] = call float @cosf(float [[X:%.*]])
+; ANY-NEXT: ret float [[COS]]
+;
+ %neg = fneg float %x
+ %r = call float @cosf(float %neg)
+ ret float %r
+}
+
define float @cosf_negated_arg_FMF(float %x) {
; ANY-LABEL: @cosf_negated_arg_FMF(
; ANY-NEXT: [[COS:%.*]] = call reassoc nnan float @cosf(float [[X:%.*]])
@@ -49,6 +69,16 @@ define float @cosf_negated_arg_FMF(float
ret float %r
}
+define float @cosf_unary_negated_arg_FMF(float %x) {
+; ANY-LABEL: @cosf_unary_negated_arg_FMF(
+; ANY-NEXT: [[COS:%.*]] = call reassoc nnan float @cosf(float [[X:%.*]])
+; ANY-NEXT: ret float [[COS]]
+;
+ %neg = fneg float %x
+ %r = call nnan reassoc float @cosf(float %neg)
+ ret float %r
+}
+
; sin(-x) -> -sin(x);
define double @sin_negated_arg(double %x) {
@@ -62,6 +92,17 @@ define double @sin_negated_arg(double %x
ret double %r
}
+define double @sin_unary_negated_arg(double %x) {
+; ANY-LABEL: @sin_unary_negated_arg(
+; ANY-NEXT: [[TMP1:%.*]] = call double @sin(double [[X:%.*]])
+; ANY-NEXT: [[TMP2:%.*]] = fsub double -0.000000e+00, [[TMP1]]
+; ANY-NEXT: ret double [[TMP2]]
+;
+ %neg = fneg double %x
+ %r = call double @sin(double %neg)
+ ret double %r
+}
+
define float @sinf_negated_arg(float %x) {
; ANY-LABEL: @sinf_negated_arg(
; ANY-NEXT: [[TMP1:%.*]] = call float @sinf(float [[X:%.*]])
@@ -73,6 +114,17 @@ define float @sinf_negated_arg(float %x)
ret float %r
}
+define float @sinf_unary_negated_arg(float %x) {
+; ANY-LABEL: @sinf_unary_negated_arg(
+; ANY-NEXT: [[TMP1:%.*]] = call float @sinf(float [[X:%.*]])
+; ANY-NEXT: [[TMP2:%.*]] = fsub float -0.000000e+00, [[TMP1]]
+; ANY-NEXT: ret float [[TMP2]]
+;
+ %neg = fneg float %x
+ %r = call float @sinf(float %neg)
+ ret float %r
+}
+
define float @sinf_negated_arg_FMF(float %x) {
; ANY-LABEL: @sinf_negated_arg_FMF(
; ANY-NEXT: [[TMP1:%.*]] = call nnan afn float @sinf(float [[X:%.*]])
@@ -84,6 +136,17 @@ define float @sinf_negated_arg_FMF(float
ret float %r
}
+define float @sinf_unary_negated_arg_FMF(float %x) {
+; ANY-LABEL: @sinf_unary_negated_arg_FMF(
+; ANY-NEXT: [[TMP1:%.*]] = call nnan afn float @sinf(float [[X:%.*]])
+; ANY-NEXT: [[TMP2:%.*]] = fsub nnan afn float -0.000000e+00, [[TMP1]]
+; ANY-NEXT: ret float [[TMP2]]
+;
+ %neg = fneg ninf float %x
+ %r = call afn nnan float @sinf(float %neg)
+ ret float %r
+}
+
declare void @use(double)
define double @sin_negated_arg_extra_use(double %x) {
@@ -99,6 +162,19 @@ define double @sin_negated_arg_extra_use
ret double %r
}
+define double @sin_unary_negated_arg_extra_use(double %x) {
+; ANY-LABEL: @sin_unary_negated_arg_extra_use(
+; ANY-NEXT: [[NEG:%.*]] = fneg double [[X:%.*]]
+; ANY-NEXT: [[R:%.*]] = call double @sin(double [[NEG]])
+; ANY-NEXT: call void @use(double [[NEG]])
+; ANY-NEXT: ret double [[R]]
+;
+ %neg = fneg double %x
+ %r = call double @sin(double %neg)
+ call void @use(double %neg)
+ ret double %r
+}
+
; -sin(-x) --> sin(x)
; PR38458: https://bugs.llvm.org/show_bug.cgi?id=38458
@@ -113,6 +189,39 @@ define double @neg_sin_negated_arg(doubl
ret double %rn
}
+define double @unary_neg_sin_unary_negated_arg(double %x) {
+; ANY-LABEL: @unary_neg_sin_unary_negated_arg(
+; ANY-NEXT: [[TMP1:%.*]] = call double @sin(double [[X:%.*]])
+; ANY-NEXT: ret double [[TMP1]]
+;
+ %neg = fneg double %x
+ %r = call double @sin(double %neg)
+ %rn = fneg double %r
+ ret double %rn
+}
+
+define double @neg_sin_unary_negated_arg(double %x) {
+; ANY-LABEL: @neg_sin_unary_negated_arg(
+; ANY-NEXT: [[TMP1:%.*]] = call double @sin(double [[X:%.*]])
+; ANY-NEXT: ret double [[TMP1]]
+;
+ %neg = fsub double -0.0, %x
+ %r = call double @sin(double %neg)
+ %rn = fneg double %r
+ ret double %rn
+}
+
+define double @unary_neg_sin_negated_arg(double %x) {
+; ANY-LABEL: @unary_neg_sin_negated_arg(
+; ANY-NEXT: [[TMP1:%.*]] = call double @sin(double [[X:%.*]])
+; ANY-NEXT: ret double [[TMP1]]
+;
+ %neg = fneg double %x
+ %r = call double @sin(double %neg)
+ %rn = fsub double -0.0, %r
+ ret double %rn
+}
+
; tan(-x) -> -tan(x);
define double @tan_negated_arg(double %x) {
@@ -126,6 +235,17 @@ define double @tan_negated_arg(double %x
ret double %r
}
+define double @tan_unary_negated_arg(double %x) {
+; ANY-LABEL: @tan_unary_negated_arg(
+; ANY-NEXT: [[TMP1:%.*]] = call double @tan(double [[X:%.*]])
+; ANY-NEXT: [[TMP2:%.*]] = fsub double -0.000000e+00, [[TMP1]]
+; ANY-NEXT: ret double [[TMP2]]
+;
+ %neg = fneg double %x
+ %r = call double @tan(double %neg)
+ ret double %r
+}
+
; tanl(-x) -> -tanl(x);
define fp128 @tanl_negated_arg(fp128 %x) {
@@ -139,6 +259,17 @@ define fp128 @tanl_negated_arg(fp128 %x)
ret fp128 %r
}
+define fp128 @tanl_unary_negated_arg(fp128 %x) {
+; ANY-LABEL: @tanl_unary_negated_arg(
+; ANY-NEXT: [[TMP1:%.*]] = call fp128 @tanl(fp128 [[X:%.*]])
+; ANY-NEXT: [[TMP2:%.*]] = fsub fp128 0xL00000000000000008000000000000000, [[TMP1]]
+; ANY-NEXT: ret fp128 [[TMP2]]
+;
+ %neg = fneg fp128 %x
+ %r = call fp128 @tanl(fp128 %neg)
+ ret fp128 %r
+}
+
define float @negated_and_shrinkable_libcall(float %f) {
; NO-FLOAT-SHRINK-LABEL: @negated_and_shrinkable_libcall(
; NO-FLOAT-SHRINK-NEXT: [[CONV1:%.*]] = fpext float [[F:%.*]] to double
@@ -157,6 +288,24 @@ define float @negated_and_shrinkable_lib
ret float %conv2
}
+define float @unary_negated_and_shrinkable_libcall(float %f) {
+; NO-FLOAT-SHRINK-LABEL: @unary_negated_and_shrinkable_libcall(
+; NO-FLOAT-SHRINK-NEXT: [[CONV1:%.*]] = fpext float [[F:%.*]] to double
+; NO-FLOAT-SHRINK-NEXT: [[COS1:%.*]] = call double @cos(double [[CONV1]])
+; NO-FLOAT-SHRINK-NEXT: [[CONV2:%.*]] = fptrunc double [[COS1]] to float
+; NO-FLOAT-SHRINK-NEXT: ret float [[CONV2]]
+;
+; DO-FLOAT-SHRINK-LABEL: @unary_negated_and_shrinkable_libcall(
+; DO-FLOAT-SHRINK-NEXT: [[COSF:%.*]] = call float @cosf(float [[F:%.*]])
+; DO-FLOAT-SHRINK-NEXT: ret float [[COSF]]
+;
+ %conv1 = fpext float %f to double
+ %neg = fneg double %conv1
+ %cos = call double @cos(double %neg)
+ %conv2 = fptrunc double %cos to float
+ ret float %conv2
+}
+
; TODO: It was ok to shrink the libcall, so the intrinsic should shrink too?
define float @negated_and_shrinkable_intrinsic(float %f) {
@@ -173,3 +322,16 @@ define float @negated_and_shrinkable_int
ret float %conv2
}
+define float @unary_negated_and_shrinkable_intrinsic(float %f) {
+; ANY-LABEL: @unary_negated_and_shrinkable_intrinsic(
+; ANY-NEXT: [[CONV1:%.*]] = fpext float [[F:%.*]] to double
+; ANY-NEXT: [[COS:%.*]] = call double @llvm.cos.f64(double [[CONV1]])
+; ANY-NEXT: [[CONV2:%.*]] = fptrunc double [[COS]] to float
+; ANY-NEXT: ret float [[CONV2]]
+;
+ %conv1 = fpext float %f to double
+ %neg = fneg double %conv1
+ %cos = call double @llvm.cos.f64(double %neg)
+ %conv2 = fptrunc double %cos to float
+ ret float %conv2
+}
Modified: llvm/trunk/test/Transforms/InstCombine/cos-2.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/cos-2.ll?rev=362253&r1=362252&r2=362253&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/cos-2.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/cos-2.ll Fri May 31 11:54:44 2019
@@ -15,6 +15,13 @@ define float @test_no_simplify1(double %
ret float %cos
}
+define float @test_no_simplify2(double %d) {
+; CHECK-LABEL: @test_no_simplify2(
+ %neg = fneg double %d
+ %cos = call float @cos(double %neg)
+; CHECK: call float @cos(double %neg)
+ ret float %cos
+}
define i8 @bogus_sqrt() {
%fake_sqrt = call signext i8 (...) @sqrt()
Modified: llvm/trunk/test/Transforms/InstCombine/cos-sin-intrinsic.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/cos-sin-intrinsic.ll?rev=362253&r1=362252&r2=362253&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/cos-sin-intrinsic.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/cos-sin-intrinsic.ll Fri May 31 11:54:44 2019
@@ -38,6 +38,16 @@ define float @fneg_f32(float %x) {
ret float %cos
}
+define float @unary_fneg_f32(float %x) {
+; CHECK-LABEL: @unary_fneg_f32(
+; CHECK-NEXT: [[COS:%.*]] = call float @llvm.cos.f32(float [[X:%.*]])
+; CHECK-NEXT: ret float [[COS]]
+;
+ %x.fneg = fneg float %x
+ %cos = call float @llvm.cos.f32(float %x.fneg)
+ ret float %cos
+}
+
define <2 x float> @fneg_v2f32(<2 x float> %x) {
; CHECK-LABEL: @fneg_v2f32(
; CHECK-NEXT: [[COS:%.*]] = call <2 x float> @llvm.cos.v2f32(<2 x float> [[X:%.*]])
@@ -48,6 +58,16 @@ define <2 x float> @fneg_v2f32(<2 x floa
ret <2 x float> %cos
}
+define <2 x float> @unary_fneg_v2f32(<2 x float> %x) {
+; CHECK-LABEL: @unary_fneg_v2f32(
+; CHECK-NEXT: [[COS:%.*]] = call <2 x float> @llvm.cos.v2f32(<2 x float> [[X:%.*]])
+; CHECK-NEXT: ret <2 x float> [[COS]]
+;
+ %x.fneg = fneg <2 x float> %x
+ %cos = call <2 x float> @llvm.cos.v2f32(<2 x float> %x.fneg)
+ ret <2 x float> %cos
+}
+
; FMF are not required, but they should propagate.
define <2 x float> @fneg_cos_fmf(<2 x float> %x){
@@ -60,6 +80,16 @@ define <2 x float> @fneg_cos_fmf(<2 x fl
ret <2 x float> %r
}
+define <2 x float> @unary_fneg_cos_fmf(<2 x float> %x){
+; CHECK-LABEL: @unary_fneg_cos_fmf(
+; CHECK-NEXT: [[R:%.*]] = call nnan afn <2 x float> @llvm.cos.v2f32(<2 x float> [[X:%.*]])
+; CHECK-NEXT: ret <2 x float> [[R]]
+;
+ %negx = fneg fast <2 x float> %x
+ %r = call nnan afn <2 x float> @llvm.cos.v2f32(<2 x float> %negx)
+ ret <2 x float> %r
+}
+
define float @fabs_f32(float %x) {
; CHECK-LABEL: @fabs_f32(
; CHECK-NEXT: [[COS:%.*]] = call float @llvm.cos.f32(float [[X:%.*]])
@@ -81,6 +111,17 @@ define float @fabs_fneg_f32(float %x) {
ret float %cos
}
+define float @fabs_unary_fneg_f32(float %x) {
+; CHECK-LABEL: @fabs_unary_fneg_f32(
+; CHECK-NEXT: [[COS:%.*]] = call float @llvm.cos.f32(float [[X:%.*]])
+; CHECK-NEXT: ret float [[COS]]
+;
+ %x.fabs = call float @llvm.fabs.f32(float %x)
+ %x.fabs.fneg = fneg float %x.fabs
+ %cos = call float @llvm.cos.f32(float %x.fabs.fneg)
+ ret float %cos
+}
+
define <2 x float> @fabs_fneg_v2f32(<2 x float> %x) {
; CHECK-LABEL: @fabs_fneg_v2f32(
; CHECK-NEXT: [[COS:%.*]] = call <2 x float> @llvm.cos.v2f32(<2 x float> [[X:%.*]])
@@ -92,6 +133,17 @@ define <2 x float> @fabs_fneg_v2f32(<2 x
ret <2 x float> %cos
}
+define <2 x float> @fabs_unary_fneg_v2f32(<2 x float> %x) {
+; CHECK-LABEL: @fabs_unary_fneg_v2f32(
+; CHECK-NEXT: [[COS:%.*]] = call <2 x float> @llvm.cos.v2f32(<2 x float> [[X:%.*]])
+; CHECK-NEXT: ret <2 x float> [[COS]]
+;
+ %x.fabs = call <2 x float> @llvm.fabs.v2f32(<2 x float> %x)
+ %x.fabs.fneg = fneg <2 x float> %x.fabs
+ %cos = call <2 x float> @llvm.cos.v2f32(<2 x float> %x.fabs.fneg)
+ ret <2 x float> %cos
+}
+
; Negate is canonicalized after sin.
declare <2 x float> @llvm.sin.v2f32(<2 x float>)
@@ -107,6 +159,17 @@ define <2 x float> @fneg_sin(<2 x float>
ret <2 x float> %r
}
+define <2 x float> @unary_fneg_sin(<2 x float> %x){
+; CHECK-LABEL: @unary_fneg_sin(
+; CHECK-NEXT: [[TMP1:%.*]] = call <2 x float> @llvm.sin.v2f32(<2 x float> [[X:%.*]])
+; CHECK-NEXT: [[R:%.*]] = fsub <2 x float> <float -0.000000e+00, float -0.000000e+00>, [[TMP1]]
+; CHECK-NEXT: ret <2 x float> [[R]]
+;
+ %negx = fneg <2 x float> %x
+ %r = call <2 x float> @llvm.sin.v2f32(<2 x float> %negx)
+ ret <2 x float> %r
+}
+
; FMF are not required, but they should propagate.
define <2 x float> @fneg_sin_fmf(<2 x float> %x){
@@ -120,3 +183,13 @@ define <2 x float> @fneg_sin_fmf(<2 x fl
ret <2 x float> %r
}
+define <2 x float> @unary_fneg_sin_fmf(<2 x float> %x){
+; CHECK-LABEL: @unary_fneg_sin_fmf(
+; CHECK-NEXT: [[TMP1:%.*]] = call nnan arcp afn <2 x float> @llvm.sin.v2f32(<2 x float> [[X:%.*]])
+; CHECK-NEXT: [[R:%.*]] = fsub nnan arcp afn <2 x float> <float -0.000000e+00, float -0.000000e+00>, [[TMP1]]
+; CHECK-NEXT: ret <2 x float> [[R]]
+;
+ %negx = fneg fast <2 x float> %x
+ %r = call nnan arcp afn <2 x float> @llvm.sin.v2f32(<2 x float> %negx)
+ ret <2 x float> %r
+}
More information about the llvm-commits
mailing list