[NFC][InstCombine] Add unary FNeg tests to fabs.ll

llvm-svn: 362238
This commit is contained in:
Cameron McInally 2019-05-31 16:17:04 +00:00
parent c3a24e93d5
commit 8ff009a461
1 changed files with 76 additions and 0 deletions

View File

@ -327,6 +327,17 @@ define double @select_fcmp_nnan_nsz_olt_zero(double %x) {
ret double %fabs ret double %fabs
} }
define double @select_fcmp_nnan_nsz_olt_zero_unary_fneg(double %x) {
; CHECK-LABEL: @select_fcmp_nnan_nsz_olt_zero_unary_fneg(
; CHECK-NEXT: [[TMP1:%.*]] = call nnan nsz double @llvm.fabs.f64(double [[X:%.*]])
; CHECK-NEXT: ret double [[TMP1]]
;
%ltzero = fcmp nnan nsz olt double %x, 0.0
%negx = fneg double %x
%fabs = select i1 %ltzero, double %negx, double %x
ret double %fabs
}
; X < -0.0 ? -X : X --> fabs(X) ; X < -0.0 ? -X : X --> fabs(X)
define float @select_fcmp_nnan_nsz_olt_negzero(float %x) { define float @select_fcmp_nnan_nsz_olt_negzero(float %x) {
@ -340,6 +351,17 @@ define float @select_fcmp_nnan_nsz_olt_negzero(float %x) {
ret float %fabs ret float %fabs
} }
define float @select_fcmp_nnan_nsz_olt_negzero_unary_fneg(float %x) {
; CHECK-LABEL: @select_fcmp_nnan_nsz_olt_negzero_unary_fneg(
; CHECK-NEXT: [[TMP1:%.*]] = call nnan ninf nsz float @llvm.fabs.f32(float [[X:%.*]])
; CHECK-NEXT: ret float [[TMP1]]
;
%ltzero = fcmp nnan nsz ninf olt float %x, -0.0
%negx = fneg float %x
%fabs = select i1 %ltzero, float %negx, float %x
ret float %fabs
}
; X <= 0.0 ? -X : X --> fabs(X) ; X <= 0.0 ? -X : X --> fabs(X)
define double @select_fcmp_nnan_nsz_ole_zero(double %x) { define double @select_fcmp_nnan_nsz_ole_zero(double %x) {
@ -353,6 +375,17 @@ define double @select_fcmp_nnan_nsz_ole_zero(double %x) {
ret double %fabs ret double %fabs
} }
define double @select_fcmp_nnan_nsz_ole_zero_unary_fneg(double %x) {
; CHECK-LABEL: @select_fcmp_nnan_nsz_ole_zero_unary_fneg(
; CHECK-NEXT: [[TMP1:%.*]] = call fast double @llvm.fabs.f64(double [[X:%.*]])
; CHECK-NEXT: ret double [[TMP1]]
;
%lezero = fcmp fast ole double %x, 0.0
%negx = fneg double %x
%fabs = select i1 %lezero, double %negx, double %x
ret double %fabs
}
; X <= -0.0 ? -X : X --> fabs(X) ; X <= -0.0 ? -X : X --> fabs(X)
define float @select_fcmp_nnan_nsz_ole_negzero(float %x) { define float @select_fcmp_nnan_nsz_ole_negzero(float %x) {
@ -366,6 +399,17 @@ define float @select_fcmp_nnan_nsz_ole_negzero(float %x) {
ret float %fabs ret float %fabs
} }
define float @select_fcmp_nnan_nsz_ole_negzero_unary_fneg(float %x) {
; CHECK-LABEL: @select_fcmp_nnan_nsz_ole_negzero_unary_fneg(
; CHECK-NEXT: [[TMP1:%.*]] = call nnan nsz float @llvm.fabs.f32(float [[X:%.*]])
; CHECK-NEXT: ret float [[TMP1]]
;
%lezero = fcmp nnan nsz ole float %x, -0.0
%negx = fneg float %x
%fabs = select i1 %lezero, float %negx, float %x
ret float %fabs
}
; X > 0.0 ? X : (0.0 - X) --> fabs(X) ; X > 0.0 ? X : (0.0 - X) --> fabs(X)
define <2 x float> @select_fcmp_nnan_nsz_ogt_zero(<2 x float> %x) { define <2 x float> @select_fcmp_nnan_nsz_ogt_zero(<2 x float> %x) {
@ -379,6 +423,17 @@ define <2 x float> @select_fcmp_nnan_nsz_ogt_zero(<2 x float> %x) {
ret <2 x float> %fabs ret <2 x float> %fabs
} }
define <2 x float> @select_fcmp_nnan_nsz_ogt_zero_unary_fneg(<2 x float> %x) {
; CHECK-LABEL: @select_fcmp_nnan_nsz_ogt_zero_unary_fneg(
; CHECK-NEXT: [[TMP1:%.*]] = call nnan nsz arcp <2 x float> @llvm.fabs.v2f32(<2 x float> [[X:%.*]])
; CHECK-NEXT: ret <2 x float> [[TMP1]]
;
%gtzero = fcmp nnan nsz arcp ogt <2 x float> %x, zeroinitializer
%negx = fneg <2 x float> %x
%fabs = select <2 x i1> %gtzero, <2 x float> %x, <2 x float> %negx
ret <2 x float> %fabs
}
; X > -0.0 ? X : (0.0 - X) --> fabs(X) ; X > -0.0 ? X : (0.0 - X) --> fabs(X)
define half @select_fcmp_nnan_nsz_ogt_negzero(half %x) { define half @select_fcmp_nnan_nsz_ogt_negzero(half %x) {
@ -405,6 +460,17 @@ define <2 x double> @select_fcmp_nnan_nsz_oge_zero(<2 x double> %x) {
ret <2 x double> %fabs ret <2 x double> %fabs
} }
define <2 x double> @select_fcmp_nnan_nsz_oge_zero_unary_fneg(<2 x double> %x) {
; CHECK-LABEL: @select_fcmp_nnan_nsz_oge_zero_unary_fneg(
; CHECK-NEXT: [[TMP1:%.*]] = call reassoc nnan nsz <2 x double> @llvm.fabs.v2f64(<2 x double> [[X:%.*]])
; CHECK-NEXT: ret <2 x double> [[TMP1]]
;
%gezero = fcmp nnan nsz reassoc oge <2 x double> %x, zeroinitializer
%negx = fneg <2 x double> %x
%fabs = select <2 x i1> %gezero, <2 x double> %x, <2 x double> %negx
ret <2 x double> %fabs
}
; X > -0.0 ? X : (0.0 - X) --> fabs(X) ; X > -0.0 ? X : (0.0 - X) --> fabs(X)
define half @select_fcmp_nnan_nsz_oge_negzero(half %x) { define half @select_fcmp_nnan_nsz_oge_negzero(half %x) {
@ -418,3 +484,13 @@ define half @select_fcmp_nnan_nsz_oge_negzero(half %x) {
ret half %fabs ret half %fabs
} }
define half @select_fcmp_nnan_nsz_oge_negzero_unary_fneg(half %x) {
; CHECK-LABEL: @select_fcmp_nnan_nsz_oge_negzero_unary_fneg(
; CHECK-NEXT: [[TMP1:%.*]] = call nnan nsz half @llvm.fabs.f16(half [[X:%.*]])
; CHECK-NEXT: ret half [[TMP1]]
;
%gezero = fcmp nnan nsz oge half %x, -0.0
%negx = fneg half %x
%fabs = select i1 %gezero, half %x, half %negx
ret half %fabs
}