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:%.*]])
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:%.*]])
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) {
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:%.*]])
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:%.*]])
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) {
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
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) {
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) {
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
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) {
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
+}
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:%.*]])
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){
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:%.*]])
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:%.*]])
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>)
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){
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
+}