public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] xtensa: Add supplementary split pattern for "*addsubx"
       [not found] <1a0c62cd-27d3-40e3-b424-9b2056739a84.ref@yahoo.co.jp>
@ 2024-03-21 23:36 ` Takayuki 'January June' Suwa
  2024-03-23  1:14   ` Max Filippov
  0 siblings, 1 reply; 2+ messages in thread
From: Takayuki 'January June' Suwa @ 2024-03-21 23:36 UTC (permalink / raw)
  To: GCC Patches; +Cc: Max Filippov

int test(int a) {
   return a * 4 + 30000;
}

In the example above, since Xtensa has instructions to add register value
scaled by 2, 4 or 8 (and corresponding define_insns), we would expect them
to be used but not, because it is transformed before reaching the RTL
generation pass as below:

int test(int a) {
   return (a + 7500) * 4;
}

Fortunately, the RTL combination pass tries a splitting pattern that matches
the first example, so it is easy to solve by defining that pattern.

gcc/ChangeLog:

	* config/xtensa/xtensa.md: Add new split pattern described above.
---
 gcc/config/xtensa/xtensa.md | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/gcc/config/xtensa/xtensa.md b/gcc/config/xtensa/xtensa.md
index 5cdf4dffe70..fbe40ec671a 100644
--- a/gcc/config/xtensa/xtensa.md
+++ b/gcc/config/xtensa/xtensa.md
@@ -194,6 +194,20 @@
    (set_attr "mode"	"SI")
    (set_attr "length"	"3")])
 
+(define_split
+  [(set (match_operand:SI 0 "register_operand")
+	(plus:SI (ashift:SI (match_operand:SI 1 "register_operand")
+			    (match_operand:SI 3 "addsubx_operand"))
+		 (match_operand:SI 2 "const_int_operand")))]
+  "TARGET_ADDX && can_create_pseudo_p ()"
+  [(set (match_dup 0)
+	(plus:SI (ashift:SI (match_dup 1)
+			    (match_dup 3))
+		 (match_dup 2)))]
+{
+  operands[2] = force_reg (SImode, operands[2]);
+})
+
 (define_expand "adddi3"
   [(set (match_operand:DI 0 "register_operand")
 	(plus:DI (match_operand:DI 1 "register_operand")
-- 
2.39.2

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

* Re: [PATCH] xtensa: Add supplementary split pattern for "*addsubx"
  2024-03-21 23:36 ` [PATCH] xtensa: Add supplementary split pattern for "*addsubx" Takayuki 'January June' Suwa
@ 2024-03-23  1:14   ` Max Filippov
  0 siblings, 0 replies; 2+ messages in thread
From: Max Filippov @ 2024-03-23  1:14 UTC (permalink / raw)
  To: Takayuki 'January June' Suwa; +Cc: GCC Patches

On Thu, Mar 21, 2024 at 4:36 PM Takayuki 'January June' Suwa
<jjsuwa_sys3175@yahoo.co.jp> wrote:
>
> int test(int a) {
>    return a * 4 + 30000;
> }
>
> In the example above, since Xtensa has instructions to add register value
> scaled by 2, 4 or 8 (and corresponding define_insns), we would expect them
> to be used but not, because it is transformed before reaching the RTL
> generation pass as below:
>
> int test(int a) {
>    return (a + 7500) * 4;
> }
>
> Fortunately, the RTL combination pass tries a splitting pattern that matches
> the first example, so it is easy to solve by defining that pattern.
>
> gcc/ChangeLog:
>
>         * config/xtensa/xtensa.md: Add new split pattern described above.
> ---
>  gcc/config/xtensa/xtensa.md | 14 ++++++++++++++
>  1 file changed, 14 insertions(+)

Regtested for target=xtensa-linux-uclibc, no new regressions.
Committed to master.

-- 
Thanks.
-- Max

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

end of thread, other threads:[~2024-03-23  1:14 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <1a0c62cd-27d3-40e3-b424-9b2056739a84.ref@yahoo.co.jp>
2024-03-21 23:36 ` [PATCH] xtensa: Add supplementary split pattern for "*addsubx" Takayuki 'January June' Suwa
2024-03-23  1:14   ` Max Filippov

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).