Skip to content

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

Merged
merged 2 commits into from
May 9, 2025

Conversation

wzssyqa
Copy link
Contributor

@wzssyqa wzssyqa commented May 8, 2025

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.
@llvmbot
Copy link
Member

llvmbot commented May 8, 2025

@llvm/pr-subscribers-backend-loongarch

Author: YunQiang Su (wzssyqa)

Changes

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.


Full diff: https://github.com/llvm/llvm-project/pull/139010.diff

4 Files Affected:

  • (modified) llvm/lib/Target/LoongArch/LoongArchFloat32InstrInfo.td (+2)
  • (modified) llvm/lib/Target/LoongArch/LoongArchFloat64InstrInfo.td (+2)
  • (modified) llvm/lib/Target/LoongArch/LoongArchISelLowering.cpp (+4)
  • (modified) llvm/test/CodeGen/LoongArch/fp-max-min.ll (-24)
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)

@wzssyqa
Copy link
Contributor Author

wzssyqa commented May 9, 2025

ping

@wzssyqa wzssyqa requested review from MaskRay, tangaac and leecheechen May 9, 2025 07:32
@tangaac
Copy link
Contributor

tangaac commented May 9, 2025

Files optimized on llvm-test-suite after this pr can be found here
tangaac/loong-opt-cov-ts@d98d5ee

Copy link
Contributor

@tangaac tangaac left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@wzssyqa wzssyqa merged commit 08b3617 into llvm:main May 9, 2025
11 checks passed
Dinistro pushed a commit that referenced this pull request May 9, 2025
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants