diff mbox series

[v3,4/5] LoongArch: Remove lrint_allow_inexact

Message ID 20231120004728.205167-5-xry111@xry111.site
State New
Headers show
Series LoongArch: SIMD fixes and optimizations | expand

Commit Message

Xi Ruoyao Nov. 20, 2023, 12:47 a.m. UTC
No functional change, just a cleanup.

gcc/ChangeLog:

	* config/loongarch/loongarch.md (lrint_allow_inexact): Remove.
	(<lrint_pattern><ANYF:mode><ANYFI:mode>2): Check if <LRINT>
	== UNSPEC_FTINT instead of <lrint_allow_inexact>.
---
 gcc/config/loongarch/loongarch.md | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)

Comments

Lulu Cheng Nov. 23, 2023, 8:23 a.m. UTC | #1
I tested it and it was fine. I never knew this could be used like this.

Thank you!

在 2023/11/20 上午8:47, Xi Ruoyao 写道:
> No functional change, just a cleanup.
>
> gcc/ChangeLog:
>
> 	* config/loongarch/loongarch.md (lrint_allow_inexact): Remove.
> 	(<lrint_pattern><ANYF:mode><ANYFI:mode>2): Check if <LRINT>
> 	== UNSPEC_FTINT instead of <lrint_allow_inexact>.
> ---
>   gcc/config/loongarch/loongarch.md | 5 +----
>   1 file changed, 1 insertion(+), 4 deletions(-)
>
> diff --git a/gcc/config/loongarch/loongarch.md b/gcc/config/loongarch/loongarch.md
> index 78ed63f2132..1e019815451 100644
> --- a/gcc/config/loongarch/loongarch.md
> +++ b/gcc/config/loongarch/loongarch.md
> @@ -585,9 +585,6 @@ (define_int_attr lrint_pattern [(UNSPEC_FTINT "lrint")
>   (define_int_attr lrint_submenmonic [(UNSPEC_FTINT "")
>   				    (UNSPEC_FTINTRM "rm")
>   				    (UNSPEC_FTINTRP "rp")])
> -(define_int_attr lrint_allow_inexact [(UNSPEC_FTINT "1")
> -				      (UNSPEC_FTINTRM "0")
> -				      (UNSPEC_FTINTRP "0")])
>   
>   ;; Iterator and attributes for bytepick.d
>   (define_int_iterator bytepick_w_ashift_amount [8 16 24])
> @@ -2384,7 +2381,7 @@ (define_insn "<lrint_pattern><ANYF:mode><ANYFI:mode>2"
>   	(unspec:ANYFI [(match_operand:ANYF 1 "register_operand" "f")]
>   		      LRINT))]
>     "TARGET_HARD_FLOAT &&
> -   (<lrint_allow_inexact>
> +   (<LRINT> == UNSPEC_FTINT
>       || flag_fp_int_builtin_inexact
>       || !flag_trapping_math)"
>     "ftint<lrint_submenmonic>.<ANYFI:ifmt>.<ANYF:fmt> %0,%1"
Xi Ruoyao Nov. 23, 2023, 8:58 a.m. UTC | #2
On Thu, 2023-11-23 at 16:23 +0800, chenglulu wrote:
> I tested it and it was fine. I never knew this could be used like
> this.

I remember when I wrote r13-3920 I tried this but failed.  Maybe
something has been improved in machine description parser, or perhaps I
just did some stupid thing that time...

> Thank you!
> 
> 在 2023/11/20 上午8:47, Xi Ruoyao 写道:
> > No functional change, just a cleanup.
> > 
> > gcc/ChangeLog:
> > 
> > 	* config/loongarch/loongarch.md (lrint_allow_inexact):
> > Remove.
> > 	(<lrint_pattern><ANYF:mode><ANYFI:mode>2): Check if <LRINT>
> > 	== UNSPEC_FTINT instead of <lrint_allow_inexact>.
> > ---
> >   gcc/config/loongarch/loongarch.md | 5 +----
> >   1 file changed, 1 insertion(+), 4 deletions(-)
> > 
> > diff --git a/gcc/config/loongarch/loongarch.md
> > b/gcc/config/loongarch/loongarch.md
> > index 78ed63f2132..1e019815451 100644
> > --- a/gcc/config/loongarch/loongarch.md
> > +++ b/gcc/config/loongarch/loongarch.md
> > @@ -585,9 +585,6 @@ (define_int_attr lrint_pattern [(UNSPEC_FTINT
> > "lrint")
> >   (define_int_attr lrint_submenmonic [(UNSPEC_FTINT "")
> >   				    (UNSPEC_FTINTRM "rm")
> >   				    (UNSPEC_FTINTRP "rp")])
> > -(define_int_attr lrint_allow_inexact [(UNSPEC_FTINT "1")
> > -				      (UNSPEC_FTINTRM "0")
> > -				      (UNSPEC_FTINTRP "0")])
> >   
> >   ;; Iterator and attributes for bytepick.d
> >   (define_int_iterator bytepick_w_ashift_amount [8 16 24])
> > @@ -2384,7 +2381,7 @@ (define_insn
> > "<lrint_pattern><ANYF:mode><ANYFI:mode>2"
> >   	(unspec:ANYFI [(match_operand:ANYF 1 "register_operand"
> > "f")]
> >   		      LRINT))]
> >     "TARGET_HARD_FLOAT &&
> > -   (<lrint_allow_inexact>
> > +   (<LRINT> == UNSPEC_FTINT
> >       || flag_fp_int_builtin_inexact
> >       || !flag_trapping_math)"
> >     "ftint<lrint_submenmonic>.<ANYFI:ifmt>.<ANYF:fmt> %0,%1"
>
Lulu Cheng Nov. 23, 2023, 9:14 a.m. UTC | #3
在 2023/11/23 下午4:58, Xi Ruoyao 写道:
> On Thu, 2023-11-23 at 16:23 +0800, chenglulu wrote:
>> I tested it and it was fine. I never knew this could be used like
>> this.
> I remember when I wrote r13-3920 I tried this but failed.  Maybe
> something has been improved in machine description parser, or perhaps I
> just did some stupid thing that time...

But I think this is a really cool implementation!

When I look at this code and compare it to our scalar implementation, it 
seems

that our scalar implementation still lacks an "lround".

>
>> Thank you!
>>
>> 在 2023/11/20 上午8:47, Xi Ruoyao 写道:
>>> No functional change, just a cleanup.
>>>
>>> gcc/ChangeLog:
>>>
>>> 	* config/loongarch/loongarch.md (lrint_allow_inexact):
>>> Remove.
>>> 	(<lrint_pattern><ANYF:mode><ANYFI:mode>2): Check if <LRINT>
>>> 	== UNSPEC_FTINT instead of <lrint_allow_inexact>.
>>> ---
>>>    gcc/config/loongarch/loongarch.md | 5 +----
>>>    1 file changed, 1 insertion(+), 4 deletions(-)
>>>
>>> diff --git a/gcc/config/loongarch/loongarch.md
>>> b/gcc/config/loongarch/loongarch.md
>>> index 78ed63f2132..1e019815451 100644
>>> --- a/gcc/config/loongarch/loongarch.md
>>> +++ b/gcc/config/loongarch/loongarch.md
>>> @@ -585,9 +585,6 @@ (define_int_attr lrint_pattern [(UNSPEC_FTINT
>>> "lrint")
>>>    (define_int_attr lrint_submenmonic [(UNSPEC_FTINT "")
>>>    				    (UNSPEC_FTINTRM "rm")
>>>    				    (UNSPEC_FTINTRP "rp")])
>>> -(define_int_attr lrint_allow_inexact [(UNSPEC_FTINT "1")
>>> -				      (UNSPEC_FTINTRM "0")
>>> -				      (UNSPEC_FTINTRP "0")])
>>>    
>>>    ;; Iterator and attributes for bytepick.d
>>>    (define_int_iterator bytepick_w_ashift_amount [8 16 24])
>>> @@ -2384,7 +2381,7 @@ (define_insn
>>> "<lrint_pattern><ANYF:mode><ANYFI:mode>2"
>>>    	(unspec:ANYFI [(match_operand:ANYF 1 "register_operand"
>>> "f")]
>>>    		      LRINT))]
>>>      "TARGET_HARD_FLOAT &&
>>> -   (<lrint_allow_inexact>
>>> +   (<LRINT> == UNSPEC_FTINT
>>>        || flag_fp_int_builtin_inexact
>>>        || !flag_trapping_math)"
>>>      "ftint<lrint_submenmonic>.<ANYFI:ifmt>.<ANYF:fmt> %0,%1"
Xi Ruoyao Nov. 23, 2023, 12:24 p.m. UTC | #4
On Thu, 2023-11-23 at 17:14 +0800, chenglulu wrote:
> When I look at this code and compare it to our scalar implementation, it 
> seems
> 
> that our scalar implementation still lacks an "lround".

Should be "lroundeven".  We don't have an instruction for lround :(.

I tried this but it does not work:

-(define_int_iterator LRINT [UNSPEC_FTINT UNSPEC_FTINTRM UNSPEC_FTINTRP])
+(define_int_iterator LRINT
+  [UNSPEC_FTINT UNSPEC_FTINTRM UNSPEC_FTINTRP UNSPEC_FTINTRNE])
 (define_int_attr lrint_pattern [(UNSPEC_FTINT "lrint")
 				(UNSPEC_FTINTRM "lfloor")
-				(UNSPEC_FTINTRP "lceil")])
+				(UNSPEC_FTINTRP "lceil")
+				(UNSPEC_FTINTRNE "lroundeven")])
 (define_int_attr lrint_submenmonic [(UNSPEC_FTINT "")
 				    (UNSPEC_FTINTRM "rm")
-				    (UNSPEC_FTINTRP "rp")])
+				    (UNSPEC_FTINTRP "rp")
+				    (UNSPEC_FTINTRNE "rne")])

The problem is "lroundevenMN2" is not a standard pattern name.  The SIMD
version of ftintrne in patch 1 only works because we are expanding
"roundevenM2" (it's a standard pattern name) to UNSPEC_SIMD_FRINTRNE,
and then a define_insn can match (fix (UNSPEC_SIMD_FRINTRNE op)).  But
for non-SIMD we don't have roundevenM2.
Lulu Cheng Nov. 23, 2023, 2:39 p.m. UTC | #5
在 2023/11/23 下午8:24, Xi Ruoyao 写道:
> On Thu, 2023-11-23 at 17:14 +0800, chenglulu wrote:
>> When I look at this code and compare it to our scalar implementation, it
>> seems
>>
>> that our scalar implementation still lacks an "lround".
> Should be "lroundeven".  We don't have an instruction for lround :(.
>
> I tried this but it does not work:
>
> -(define_int_iterator LRINT [UNSPEC_FTINT UNSPEC_FTINTRM UNSPEC_FTINTRP])
> +(define_int_iterator LRINT
> +  [UNSPEC_FTINT UNSPEC_FTINTRM UNSPEC_FTINTRP UNSPEC_FTINTRNE])
>   (define_int_attr lrint_pattern [(UNSPEC_FTINT "lrint")
>   				(UNSPEC_FTINTRM "lfloor")
> -				(UNSPEC_FTINTRP "lceil")])
> +				(UNSPEC_FTINTRP "lceil")
> +				(UNSPEC_FTINTRNE "lroundeven")])
>   (define_int_attr lrint_submenmonic [(UNSPEC_FTINT "")
>   				    (UNSPEC_FTINTRM "rm")
> -				    (UNSPEC_FTINTRP "rp")])
> +				    (UNSPEC_FTINTRP "rp")
> +				    (UNSPEC_FTINTRNE "rne")])
>
> The problem is "lroundevenMN2" is not a standard pattern name.  The SIMD
> version of ftintrne in patch 1 only works because we are expanding
> "roundevenM2" (it's a standard pattern name) to UNSPEC_SIMD_FRINTRNE,
> and then a define_insn can match (fix (UNSPEC_SIMD_FRINTRNE op)).  But
> for non-SIMD we don't have roundevenM2.
>
Okay, I understand. I think this is a bit regretful.
diff mbox series

Patch

diff --git a/gcc/config/loongarch/loongarch.md b/gcc/config/loongarch/loongarch.md
index 78ed63f2132..1e019815451 100644
--- a/gcc/config/loongarch/loongarch.md
+++ b/gcc/config/loongarch/loongarch.md
@@ -585,9 +585,6 @@  (define_int_attr lrint_pattern [(UNSPEC_FTINT "lrint")
 (define_int_attr lrint_submenmonic [(UNSPEC_FTINT "")
 				    (UNSPEC_FTINTRM "rm")
 				    (UNSPEC_FTINTRP "rp")])
-(define_int_attr lrint_allow_inexact [(UNSPEC_FTINT "1")
-				      (UNSPEC_FTINTRM "0")
-				      (UNSPEC_FTINTRP "0")])
 
 ;; Iterator and attributes for bytepick.d
 (define_int_iterator bytepick_w_ashift_amount [8 16 24])
@@ -2384,7 +2381,7 @@  (define_insn "<lrint_pattern><ANYF:mode><ANYFI:mode>2"
 	(unspec:ANYFI [(match_operand:ANYF 1 "register_operand" "f")]
 		      LRINT))]
   "TARGET_HARD_FLOAT &&
-   (<lrint_allow_inexact>
+   (<LRINT> == UNSPEC_FTINT
     || flag_fp_int_builtin_inexact
     || !flag_trapping_math)"
   "ftint<lrint_submenmonic>.<ANYFI:ifmt>.<ANYF:fmt> %0,%1"