[2/2] xtensa: Implement new target hook: TARGET_CONSTANT_OK_FOR_CPROP_P

Message ID 1e87f131-93eb-0d37-d0f4-a9a69a5dc61f@yahoo.co.jp
State New, archived
Headers
Series [1/2] Add new target hook: constant_ok_for_cprop_p |

Commit Message

Takayuki 'January June' Suwa Sept. 11, 2022, 11:51 a.m. UTC
  This patch implements new target hook TARGET_CONSTANT_OK_FOR_CPROP_P in
order to exclude CONST_INTs that cannot fit into a MOVI machine instruction
from cprop.

gcc/ChangeLog:

	* config/xtensa/xtensa.c (TARGET_CONSTANT_OK_FOR_CPROP_P):
	New macro definition.
	(xtensa_constant_ok_for_cprop_p):
	Implement the hook as mentioned above.
---
 gcc/config/xtensa/xtensa.cc | 20 +++++++++++++++++---
 1 file changed, 17 insertions(+), 3 deletions(-)
  

Comments

Max Filippov Sept. 12, 2022, 7:34 p.m. UTC | #1
On Sun, Sep 11, 2022 at 1:50 PM Takayuki 'January June' Suwa
<jjsuwa_sys3175@yahoo.co.jp> wrote:
>
> This patch implements new target hook TARGET_CONSTANT_OK_FOR_CPROP_P in
> order to exclude CONST_INTs that cannot fit into a MOVI machine instruction
> from cprop.
>
> gcc/ChangeLog:
>
>         * config/xtensa/xtensa.c (TARGET_CONSTANT_OK_FOR_CPROP_P):
>         New macro definition.
>         (xtensa_constant_ok_for_cprop_p):
>         Implement the hook as mentioned above.
> ---
>  gcc/config/xtensa/xtensa.cc | 20 +++++++++++++++++---
>  1 file changed, 17 insertions(+), 3 deletions(-)

Regtested for target=xtensa-linux-uclibc, no new regressions.
Committed to master.
  
Takayuki 'January June' Suwa Sept. 13, 2022, 3 a.m. UTC | #2
On 2022/09/13 4:34, Max Filippov wrote:
Hi!

> On Sun, Sep 11, 2022 at 1:50 PM Takayuki 'January June' Suwa
> <jjsuwa_sys3175@yahoo.co.jp> wrote:
>>
>> This patch implements new target hook TARGET_CONSTANT_OK_FOR_CPROP_P in
>> order to exclude CONST_INTs that cannot fit into a MOVI machine instruction
>> from cprop.
>>
>> gcc/ChangeLog:
>>
>>         * config/xtensa/xtensa.c (TARGET_CONSTANT_OK_FOR_CPROP_P):
>>         New macro definition.
>>         (xtensa_constant_ok_for_cprop_p):
>>         Implement the hook as mentioned above.
>> ---
>>  gcc/config/xtensa/xtensa.cc | 20 +++++++++++++++++---
>>  1 file changed, 17 insertions(+), 3 deletions(-)
> 
> Regtested for target=xtensa-linux-uclibc, no new regressions.
> Committed to master.
> 

Oops, sorry, this patch doesn't have the prerequisite patch merged in, so please revert (that target hook isn't working yet).
  
Max Filippov Sept. 13, 2022, 11:30 a.m. UTC | #3
On Mon, Sep 12, 2022 at 8:00 PM Takayuki 'January June' Suwa
<jjsuwa_sys3175@yahoo.co.jp> wrote:
> On 2022/09/13 4:34, Max Filippov wrote:
> > On Sun, Sep 11, 2022 at 1:50 PM Takayuki 'January June' Suwa
> > <jjsuwa_sys3175@yahoo.co.jp> wrote:
> >>
> >> This patch implements new target hook TARGET_CONSTANT_OK_FOR_CPROP_P in
> >> order to exclude CONST_INTs that cannot fit into a MOVI machine instruction
> >> from cprop.
> >>
> >> gcc/ChangeLog:
> >>
> >>         * config/xtensa/xtensa.c (TARGET_CONSTANT_OK_FOR_CPROP_P):
> >>         New macro definition.
> >>         (xtensa_constant_ok_for_cprop_p):
> >>         Implement the hook as mentioned above.
> >> ---
> >>  gcc/config/xtensa/xtensa.cc | 20 +++++++++++++++++---
> >>  1 file changed, 17 insertions(+), 3 deletions(-)
> >
> > Regtested for target=xtensa-linux-uclibc, no new regressions.
> > Committed to master.
> >
>
> Oops, sorry, this patch doesn't have the prerequisite patch merged in, so please revert (that target hook isn't working yet).

OK, reverted.
  

Patch

diff --git a/gcc/config/xtensa/xtensa.cc b/gcc/config/xtensa/xtensa.cc
index ac52c015a94..5c432cc65aa 100644
--- a/gcc/config/xtensa/xtensa.cc
+++ b/gcc/config/xtensa/xtensa.cc
@@ -191,6 +191,7 @@  static bool xtensa_can_eliminate (const int from ATTRIBUTE_UNUSED,
 static HOST_WIDE_INT xtensa_starting_frame_offset (void);
 static unsigned HOST_WIDE_INT xtensa_asan_shadow_offset (void);
 static bool xtensa_function_ok_for_sibcall (tree, tree);
+static bool xtensa_constant_ok_for_cprop_p (const_rtx);
 static rtx xtensa_delegitimize_address (rtx);
 
 
@@ -345,12 +346,15 @@  static rtx xtensa_delegitimize_address (rtx);
 #undef TARGET_HAVE_SPECULATION_SAFE_VALUE
 #define TARGET_HAVE_SPECULATION_SAFE_VALUE speculation_safe_value_not_needed
 
-#undef TARGET_DELEGITIMIZE_ADDRESS
-#define TARGET_DELEGITIMIZE_ADDRESS xtensa_delegitimize_address
-
 #undef TARGET_FUNCTION_OK_FOR_SIBCALL
 #define TARGET_FUNCTION_OK_FOR_SIBCALL xtensa_function_ok_for_sibcall
 
+#undef TARGET_CONSTANT_OK_FOR_CPROP_P
+#define TARGET_CONSTANT_OK_FOR_CPROP_P xtensa_constant_ok_for_cprop_p
+
+#undef TARGET_DELEGITIMIZE_ADDRESS
+#define TARGET_DELEGITIMIZE_ADDRESS xtensa_delegitimize_address
+
 struct gcc_target targetm = TARGET_INITIALIZER;
 
 
@@ -4983,6 +4987,16 @@  xtensa_function_ok_for_sibcall (tree decl ATTRIBUTE_UNUSED, tree exp ATTRIBUTE_U
   return true;
 }
 
+/* Implement TARGET_CONSTANT_OK_FOR_CPROP_P.  */
+static bool
+xtensa_constant_ok_for_cprop_p (const_rtx x)
+{
+  if (CONST_INT_P (x) && ! xtensa_simm12b (INTVAL (x)))
+    return false;
+
+  return true;
+}
+
 static rtx
 xtensa_delegitimize_address (rtx op)
 {