-
Notifications
You must be signed in to change notification settings - Fork 13.5k
LoongArch: Set FMAXNUM and FMINNUM as Legal #139010
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Now we define FMAXNUM and FMINNUM as IEEE754-2008 with +0.0>-0.0. LoongArch's fmax/fmin just follow this rules full. FMAXNUM_IEEE and FMINNUM_IEEE will be removed in future once: Fixes FMAXNUM/FMINNUM for all targets The use of FMAXNUM_IEEE/FMINNUM_IEEE are not used by middle end anymore.
@llvm/pr-subscribers-backend-loongarch Author: YunQiang Su (wzssyqa) ChangesNow we define FMAXNUM and FMINNUM as IEEE754-2008 with +0.0>-0.0. LoongArch's fmax/fmin just follow this rules full. FMAXNUM_IEEE and FMINNUM_IEEE will be removed in future once: Fixes FMAXNUM/FMINNUM for all targets Full diff: https://github.com/llvm/llvm-project/pull/139010.diff 4 Files Affected:
diff --git a/llvm/lib/Target/LoongArch/LoongArchFloat32InstrInfo.td b/llvm/lib/Target/LoongArch/LoongArchFloat32InstrInfo.td
index 65802d660432d..d5a5f17348e4b 100644
--- a/llvm/lib/Target/LoongArch/LoongArchFloat32InstrInfo.td
+++ b/llvm/lib/Target/LoongArch/LoongArchFloat32InstrInfo.td
@@ -172,7 +172,9 @@ def : PatFprFpr<fmul, FMUL_S, FPR32>;
def : PatFprFpr<fdiv, FDIV_S, FPR32>;
def : PatFprFpr<fcopysign, FCOPYSIGN_S, FPR32>;
def : PatFprFpr<fmaxnum_ieee, FMAX_S, FPR32>;
+def : PatFprFpr<fmaxnum, FMAX_S, FPR32>;
def : PatFprFpr<fminnum_ieee, FMIN_S, FPR32>;
+def : PatFprFpr<fminnum, FMIN_S, FPR32>;
def : PatFpr<fneg, FNEG_S, FPR32>;
def : PatFpr<fabs, FABS_S, FPR32>;
def : PatFpr<fsqrt, FSQRT_S, FPR32>;
diff --git a/llvm/lib/Target/LoongArch/LoongArchFloat64InstrInfo.td b/llvm/lib/Target/LoongArch/LoongArchFloat64InstrInfo.td
index b98025643903a..c5d176596d8c6 100644
--- a/llvm/lib/Target/LoongArch/LoongArchFloat64InstrInfo.td
+++ b/llvm/lib/Target/LoongArch/LoongArchFloat64InstrInfo.td
@@ -140,7 +140,9 @@ def : PatFprFpr<fmul, FMUL_D, FPR64>;
def : PatFprFpr<fdiv, FDIV_D, FPR64>;
def : PatFprFpr<fcopysign, FCOPYSIGN_D, FPR64>;
def : PatFprFpr<fmaxnum_ieee, FMAX_D, FPR64>;
+def : PatFprFpr<fmaxnum, FMAX_D, FPR64>;
def : PatFprFpr<fminnum_ieee, FMIN_D, FPR64>;
+def : PatFprFpr<fminnum, FMIN_D, FPR64>;
def : PatFpr<fneg, FNEG_D, FPR64>;
def : PatFpr<fabs, FABS_D, FPR64>;
def : PatFpr<fsqrt, FSQRT_D, FPR64>;
diff --git a/llvm/lib/Target/LoongArch/LoongArchISelLowering.cpp b/llvm/lib/Target/LoongArch/LoongArchISelLowering.cpp
index 1f66a02311274..ed3ac30a3f8c6 100644
--- a/llvm/lib/Target/LoongArch/LoongArchISelLowering.cpp
+++ b/llvm/lib/Target/LoongArch/LoongArchISelLowering.cpp
@@ -176,7 +176,9 @@ LoongArchTargetLowering::LoongArchTargetLowering(const TargetMachine &TM,
setOperationAction(ISD::BR_CC, MVT::f32, Expand);
setOperationAction(ISD::FMA, MVT::f32, Legal);
setOperationAction(ISD::FMINNUM_IEEE, MVT::f32, Legal);
+ setOperationAction(ISD::FMINNUM, MVT::f32, Legal);
setOperationAction(ISD::FMAXNUM_IEEE, MVT::f32, Legal);
+ setOperationAction(ISD::FMAXNUM, MVT::f32, Legal);
setOperationAction(ISD::STRICT_FSETCCS, MVT::f32, Legal);
setOperationAction(ISD::STRICT_FSETCC, MVT::f32, Legal);
setOperationAction(ISD::IS_FPCLASS, MVT::f32, Legal);
@@ -215,7 +217,9 @@ LoongArchTargetLowering::LoongArchTargetLowering(const TargetMachine &TM,
setOperationAction(ISD::STRICT_FSETCC, MVT::f64, Legal);
setOperationAction(ISD::FMA, MVT::f64, Legal);
setOperationAction(ISD::FMINNUM_IEEE, MVT::f64, Legal);
+ setOperationAction(ISD::FMINNUM, MVT::f64, Legal);
setOperationAction(ISD::FMAXNUM_IEEE, MVT::f64, Legal);
+ setOperationAction(ISD::FMAXNUM, MVT::f64, Legal);
setOperationAction(ISD::IS_FPCLASS, MVT::f64, Legal);
setOperationAction(ISD::FSIN, MVT::f64, Expand);
setOperationAction(ISD::FCOS, MVT::f64, Expand);
diff --git a/llvm/test/CodeGen/LoongArch/fp-max-min.ll b/llvm/test/CodeGen/LoongArch/fp-max-min.ll
index 1adf4273b3158..b967ea74ab30b 100644
--- a/llvm/test/CodeGen/LoongArch/fp-max-min.ll
+++ b/llvm/test/CodeGen/LoongArch/fp-max-min.ll
@@ -12,29 +12,21 @@ declare double @llvm.minnum.f64(double, double)
define float @maxnum_float(float %x, float %y) {
; LA32F-LABEL: maxnum_float:
; LA32F: # %bb.0:
-; LA32F-NEXT: fmax.s $fa1, $fa1, $fa1
-; LA32F-NEXT: fmax.s $fa0, $fa0, $fa0
; LA32F-NEXT: fmax.s $fa0, $fa0, $fa1
; LA32F-NEXT: ret
;
; LA32D-LABEL: maxnum_float:
; LA32D: # %bb.0:
-; LA32D-NEXT: fmax.s $fa1, $fa1, $fa1
-; LA32D-NEXT: fmax.s $fa0, $fa0, $fa0
; LA32D-NEXT: fmax.s $fa0, $fa0, $fa1
; LA32D-NEXT: ret
;
; LA64F-LABEL: maxnum_float:
; LA64F: # %bb.0:
-; LA64F-NEXT: fmax.s $fa1, $fa1, $fa1
-; LA64F-NEXT: fmax.s $fa0, $fa0, $fa0
; LA64F-NEXT: fmax.s $fa0, $fa0, $fa1
; LA64F-NEXT: ret
;
; LA64D-LABEL: maxnum_float:
; LA64D: # %bb.0:
-; LA64D-NEXT: fmax.s $fa1, $fa1, $fa1
-; LA64D-NEXT: fmax.s $fa0, $fa0, $fa0
; LA64D-NEXT: fmax.s $fa0, $fa0, $fa1
; LA64D-NEXT: ret
%z = call float @llvm.maxnum.f32(float %x, float %y)
@@ -55,8 +47,6 @@ define double @maxnum_double(double %x, double %y) {
;
; LA32D-LABEL: maxnum_double:
; LA32D: # %bb.0:
-; LA32D-NEXT: fmax.d $fa1, $fa1, $fa1
-; LA32D-NEXT: fmax.d $fa0, $fa0, $fa0
; LA32D-NEXT: fmax.d $fa0, $fa0, $fa1
; LA32D-NEXT: ret
;
@@ -74,8 +64,6 @@ define double @maxnum_double(double %x, double %y) {
;
; LA64D-LABEL: maxnum_double:
; LA64D: # %bb.0:
-; LA64D-NEXT: fmax.d $fa1, $fa1, $fa1
-; LA64D-NEXT: fmax.d $fa0, $fa0, $fa0
; LA64D-NEXT: fmax.d $fa0, $fa0, $fa1
; LA64D-NEXT: ret
%z = call double @llvm.maxnum.f64(double %x, double %y)
@@ -85,29 +73,21 @@ define double @maxnum_double(double %x, double %y) {
define float @minnum_float(float %x, float %y) {
; LA32F-LABEL: minnum_float:
; LA32F: # %bb.0:
-; LA32F-NEXT: fmax.s $fa1, $fa1, $fa1
-; LA32F-NEXT: fmax.s $fa0, $fa0, $fa0
; LA32F-NEXT: fmin.s $fa0, $fa0, $fa1
; LA32F-NEXT: ret
;
; LA32D-LABEL: minnum_float:
; LA32D: # %bb.0:
-; LA32D-NEXT: fmax.s $fa1, $fa1, $fa1
-; LA32D-NEXT: fmax.s $fa0, $fa0, $fa0
; LA32D-NEXT: fmin.s $fa0, $fa0, $fa1
; LA32D-NEXT: ret
;
; LA64F-LABEL: minnum_float:
; LA64F: # %bb.0:
-; LA64F-NEXT: fmax.s $fa1, $fa1, $fa1
-; LA64F-NEXT: fmax.s $fa0, $fa0, $fa0
; LA64F-NEXT: fmin.s $fa0, $fa0, $fa1
; LA64F-NEXT: ret
;
; LA64D-LABEL: minnum_float:
; LA64D: # %bb.0:
-; LA64D-NEXT: fmax.s $fa1, $fa1, $fa1
-; LA64D-NEXT: fmax.s $fa0, $fa0, $fa0
; LA64D-NEXT: fmin.s $fa0, $fa0, $fa1
; LA64D-NEXT: ret
%z = call float @llvm.minnum.f32(float %x, float %y)
@@ -128,8 +108,6 @@ define double @minnum_double(double %x, double %y) {
;
; LA32D-LABEL: minnum_double:
; LA32D: # %bb.0:
-; LA32D-NEXT: fmax.d $fa1, $fa1, $fa1
-; LA32D-NEXT: fmax.d $fa0, $fa0, $fa0
; LA32D-NEXT: fmin.d $fa0, $fa0, $fa1
; LA32D-NEXT: ret
;
@@ -147,8 +125,6 @@ define double @minnum_double(double %x, double %y) {
;
; LA64D-LABEL: minnum_double:
; LA64D: # %bb.0:
-; LA64D-NEXT: fmax.d $fa1, $fa1, $fa1
-; LA64D-NEXT: fmax.d $fa0, $fa0, $fa0
; LA64D-NEXT: fmin.d $fa0, $fa0, $fa1
; LA64D-NEXT: ret
%z = call double @llvm.minnum.f64(double %x, double %y)
|
ping |
Files optimized on llvm-test-suite after this pr can be found here |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Now we define FMAXNUM and FMINNUM as IEEE754-2008 with +0.0>-0.0. LoongArch's fmax/fmin just follow this rules full. FMAXNUM_IEEE and FMINNUM_IEEE will be removed in future once: Fixes FMAXNUM/FMINNUM for all targets The use of FMAXNUM_IEEE/FMINNUM_IEEE are not used by middle end anymore.
Now we define FMAXNUM and FMINNUM as IEEE754-2008 with +0.0>-0.0. LoongArch's fmax/fmin just follow this rules full.
FMAXNUM_IEEE and FMINNUM_IEEE will be removed in future once:
Fixes FMAXNUM/FMINNUM for all targets
The use of FMAXNUM_IEEE/FMINNUM_IEEE are not used by middle end anymore.