public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] LoongArch: Use UNSPEC for fmin/fmax RTL pattern [PR105414]
@ 2022-09-24 12:47 Xi Ruoyao
  2022-09-28  8:26 ` Lulu Cheng
  0 siblings, 1 reply; 2+ messages in thread
From: Xi Ruoyao @ 2022-09-24 12:47 UTC (permalink / raw)
  To: gcc-patches; +Cc: Lulu Cheng, Wang Xuerui, Chenghua Xu, Xi Ruoyao

I made a mistake defining fmin/fmax RTL patterns in r13-2085: I used
smin and smax in the definition mistakenly.  This causes the optimizer
to perform constant folding as if fmin/fmax was "really" smin/smax
operations even with -fsignaling-nans.  Then pr105414.c fails.

We don't have fmin/fmax RTL codes for now (PR107013) so we can only use
an UNSPEC for fmin and fmax patterns.

gcc/ChangeLog:

	PR tree-optimization/105414
	* config/loongarch/loongarch.md (UNSPEC_FMAX): New unspec.
	(UNSPEC_FMIN): Likewise.
	(fmax<mode>3): Use UNSPEC_FMAX instead of smax.
	(fmin<mode>3): Use UNSPEC_FMIN instead of smin.
---
 gcc/config/loongarch/loongarch.md | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/gcc/config/loongarch/loongarch.md b/gcc/config/loongarch/loongarch.md
index 3787fd8230f..214b14bddd3 100644
--- a/gcc/config/loongarch/loongarch.md
+++ b/gcc/config/loongarch/loongarch.md
@@ -35,6 +35,8 @@ (define_c_enum "unspec" [
   ;; Floating point unspecs.
   UNSPEC_FRINT
   UNSPEC_FCLASS
+  UNSPEC_FMAX
+  UNSPEC_FMIN
 
   ;; Override return address for exception handling.
   UNSPEC_EH_RETURN
@@ -1032,8 +1034,9 @@ (define_insn "smin<mode>3"
 
 (define_insn "fmax<mode>3"
   [(set (match_operand:ANYF 0 "register_operand" "=f")
-	(smax:ANYF (match_operand:ANYF 1 "register_operand" "f")
-		   (match_operand:ANYF 2 "register_operand" "f")))]
+	(unspec:ANYF [(use (match_operand:ANYF 1 "register_operand" "f"))
+		      (use (match_operand:ANYF 2 "register_operand" "f"))]
+		     UNSPEC_FMAX))]
   ""
   "fmax.<fmt>\t%0,%1,%2"
   [(set_attr "type" "fmove")
@@ -1041,8 +1044,9 @@ (define_insn "fmax<mode>3"
 
 (define_insn "fmin<mode>3"
   [(set (match_operand:ANYF 0 "register_operand" "=f")
-	(smin:ANYF (match_operand:ANYF 1 "register_operand" "f")
-		   (match_operand:ANYF 2 "register_operand" "f")))]
+	(unspec:ANYF [(use (match_operand:ANYF 1 "register_operand" "f"))
+		      (use (match_operand:ANYF 2 "register_operand" "f"))]
+		     UNSPEC_FMIN))]
   ""
   "fmin.<fmt>\t%0,%1,%2"
   [(set_attr "type" "fmove")
-- 
2.37.0


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] LoongArch: Use UNSPEC for fmin/fmax RTL pattern [PR105414]
  2022-09-24 12:47 [PATCH] LoongArch: Use UNSPEC for fmin/fmax RTL pattern [PR105414] Xi Ruoyao
@ 2022-09-28  8:26 ` Lulu Cheng
  0 siblings, 0 replies; 2+ messages in thread
From: Lulu Cheng @ 2022-09-28  8:26 UTC (permalink / raw)
  To: Xi Ruoyao, gcc-patches; +Cc: Wang Xuerui, Chenghua Xu

I have no problem.

Thanks.

在 2022/9/24 下午8:47, Xi Ruoyao 写道:
> I made a mistake defining fmin/fmax RTL patterns in r13-2085: I used
> smin and smax in the definition mistakenly.  This causes the optimizer
> to perform constant folding as if fmin/fmax was "really" smin/smax
> operations even with -fsignaling-nans.  Then pr105414.c fails.
>
> We don't have fmin/fmax RTL codes for now (PR107013) so we can only use
> an UNSPEC for fmin and fmax patterns.
>
> gcc/ChangeLog:
>
> 	PR tree-optimization/105414
> 	* config/loongarch/loongarch.md (UNSPEC_FMAX): New unspec.
> 	(UNSPEC_FMIN): Likewise.
> 	(fmax<mode>3): Use UNSPEC_FMAX instead of smax.
> 	(fmin<mode>3): Use UNSPEC_FMIN instead of smin.
> ---
>   gcc/config/loongarch/loongarch.md | 12 ++++++++----
>   1 file changed, 8 insertions(+), 4 deletions(-)
>
> diff --git a/gcc/config/loongarch/loongarch.md b/gcc/config/loongarch/loongarch.md
> index 3787fd8230f..214b14bddd3 100644
> --- a/gcc/config/loongarch/loongarch.md
> +++ b/gcc/config/loongarch/loongarch.md
> @@ -35,6 +35,8 @@ (define_c_enum "unspec" [
>     ;; Floating point unspecs.
>     UNSPEC_FRINT
>     UNSPEC_FCLASS
> +  UNSPEC_FMAX
> +  UNSPEC_FMIN
>   
>     ;; Override return address for exception handling.
>     UNSPEC_EH_RETURN
> @@ -1032,8 +1034,9 @@ (define_insn "smin<mode>3"
>   
>   (define_insn "fmax<mode>3"
>     [(set (match_operand:ANYF 0 "register_operand" "=f")
> -	(smax:ANYF (match_operand:ANYF 1 "register_operand" "f")
> -		   (match_operand:ANYF 2 "register_operand" "f")))]
> +	(unspec:ANYF [(use (match_operand:ANYF 1 "register_operand" "f"))
> +		      (use (match_operand:ANYF 2 "register_operand" "f"))]
> +		     UNSPEC_FMAX))]
>     ""
>     "fmax.<fmt>\t%0,%1,%2"
>     [(set_attr "type" "fmove")
> @@ -1041,8 +1044,9 @@ (define_insn "fmax<mode>3"
>   
>   (define_insn "fmin<mode>3"
>     [(set (match_operand:ANYF 0 "register_operand" "=f")
> -	(smin:ANYF (match_operand:ANYF 1 "register_operand" "f")
> -		   (match_operand:ANYF 2 "register_operand" "f")))]
> +	(unspec:ANYF [(use (match_operand:ANYF 1 "register_operand" "f"))
> +		      (use (match_operand:ANYF 2 "register_operand" "f"))]
> +		     UNSPEC_FMIN))]
>     ""
>     "fmin.<fmt>\t%0,%1,%2"
>     [(set_attr "type" "fmove")


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-09-28  8:27 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-24 12:47 [PATCH] LoongArch: Use UNSPEC for fmin/fmax RTL pattern [PR105414] Xi Ruoyao
2022-09-28  8:26 ` Lulu Cheng

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).