https://gcc.gnu.org/g:fecf542e1db9bbe874bbfed94bbd8b1c7151972e

commit r16-7709-gfecf542e1db9bbe874bbfed94bbd8b1c7151972e
Author: H.J. Lu <[email protected]>
Date:   Thu Jan 1 07:14:57 2026 +0800

    Add default_promote_function_mode_sign_extend
    
    TARGET_PROMOTE_PROTOTYPES is an optimization, not an ABI requirement.
    TARGET_PROMOTE_FUNCTION_MODE should be used for ABI requirement.  Like
    xtensa, mcore ABI requires sign extension of signed 8/16-bit integer
    arguments to 32 bits and zero extension of unsigned integer 8/16-bit
    arguments to 32 bits:
    
    1. Rename xtensa_promote_function_mode to
    default_promote_function_mode_sign_extend to sign-extend signed 8/16-bit
    integer arguments to 32 bits and zero-extend of unsigned 8/16-bit
    integer arguments to 32 bits.
    2. Replace xtensa_promote_function_mode with
    default_promote_function_mode_sign_extend.
    3. Remove TARGET_PROMOTE_PROTOTYPES for mcore and define
    TARGET_PROMOTE_FUNCTION_MODE with
    default_promote_function_mode_sign_extend to properly extend 8/16-bit
    arguments to 32 bits.
    
    Targets with the same ABI requirement should define
    TARGET_PROMOTE_FUNCTION_MODE with
    default_promote_function_mode_sign_extend.
    
    gcc/
    
            PR target/119979
            PR target/120888
            * targhooks.cc (default_promote_function_mode_sign_extend): New.
            * targhooks.h (default_promote_function_mode_sign_extend):
            Likewise.
            * config/mcore/mcore.cc (TARGET_PROMOTE_FUNCTION_MODE): Use
            default_promote_function_mode_sign_extend.
            (TARGET_PROMOTE_PROTOTYPES): Removed.
            * config/xtensa/xtensa.cc (xtensa_promote_function_mode): Removed.
            (TARGET_PROMOTE_FUNCTION_MODE): Use
            default_promote_function_mode_sign_extend.
    
    gcc/testsuite/
    
            PR target/119979
            PR target/120888
            * gcc.target/xtensa/pr120888-1.c: Removed to ...
            * gcc.dg/zero-extend.c: This.  Enable for mcore and xtensa.
            * gcc.target/xtensa/pr120888-2.c: Removed to ...
            * gcc.dg/sign-extend.c: This.  Enable for mcore and xtensa.
    
    Signed-off-by: H.J. Lu <[email protected]>

Diff:
---
 gcc/config/mcore/mcore.cc                            |  6 ++----
 gcc/config/xtensa/xtensa.cc                          | 20 ++------------------
 gcc/targhooks.cc                                     | 17 +++++++++++++++++
 gcc/targhooks.h                                      |  2 ++
 .../xtensa/pr120888-2.c => gcc.dg/sign-extend.c}     |  2 +-
 .../xtensa/pr120888-1.c => gcc.dg/zero-extend.c}     |  2 +-
 6 files changed, 25 insertions(+), 24 deletions(-)

diff --git a/gcc/config/mcore/mcore.cc b/gcc/config/mcore/mcore.cc
index 9be652e3748f..e5ee2c1fc743 100644
--- a/gcc/config/mcore/mcore.cc
+++ b/gcc/config/mcore/mcore.cc
@@ -202,10 +202,8 @@ TARGET_GNU_ATTRIBUTES (mcore_attribute_table,
 #define TARGET_MACHINE_DEPENDENT_REORG mcore_reorg
 
 #undef  TARGET_PROMOTE_FUNCTION_MODE
-#define TARGET_PROMOTE_FUNCTION_MODE   
default_promote_function_mode_always_promote
-#undef  TARGET_PROMOTE_PROTOTYPES
-#define TARGET_PROMOTE_PROTOTYPES      hook_bool_const_tree_true
-
+#define TARGET_PROMOTE_FUNCTION_MODE \
+  default_promote_function_mode_sign_extend
 #undef  TARGET_RETURN_IN_MEMORY
 #define TARGET_RETURN_IN_MEMORY                mcore_return_in_memory
 #undef  TARGET_MUST_PASS_IN_STACK
diff --git a/gcc/config/xtensa/xtensa.cc b/gcc/config/xtensa/xtensa.cc
index c2a6a1610662..d9420bb2cda8 100644
--- a/gcc/config/xtensa/xtensa.cc
+++ b/gcc/config/xtensa/xtensa.cc
@@ -158,10 +158,6 @@ static void xtensa_asm_trampoline_template (FILE *);
 static void xtensa_trampoline_init (rtx, tree, rtx);
 static bool xtensa_output_addr_const_extra (FILE *, rtx);
 static bool xtensa_cannot_force_const_mem (machine_mode, rtx);
-static machine_mode xtensa_promote_function_mode (const_tree,
-                                                 machine_mode,
-                                                 int *, const_tree,
-                                                 int);
 
 static reg_class_t xtensa_preferred_reload_class (rtx, reg_class_t);
 static reg_class_t xtensa_preferred_output_reload_class (rtx, reg_class_t);
@@ -242,7 +238,8 @@ static rtx_insn *xtensa_md_asm_adjust (vec<rtx> &, vec<rtx> 
&,
 #define TARGET_EXPAND_BUILTIN_VA_START xtensa_va_start
 
 #undef TARGET_PROMOTE_FUNCTION_MODE
-#define TARGET_PROMOTE_FUNCTION_MODE xtensa_promote_function_mode
+#define TARGET_PROMOTE_FUNCTION_MODE \
+  default_promote_function_mode_sign_extend
 
 #undef TARGET_RETURN_IN_MEMORY
 #define TARGET_RETURN_IN_MEMORY xtensa_return_in_memory
@@ -4675,19 +4672,6 @@ xtensa_insn_cost (rtx_insn *insn, bool speed)
   return pattern_cost (PATTERN (insn), speed);
 }
 
-/* Worker function for TARGET_PROMOTE_FUNCTION_MODE.  */
-
-static machine_mode
-xtensa_promote_function_mode (const_tree type, machine_mode mode,
-                             int *punsignedp, const_tree, int)
-{
-  if (GET_MODE_CLASS (mode) == MODE_INT
-      && GET_MODE_SIZE (mode) < GET_MODE_SIZE (SImode))
-    return SImode;
-
-  return promote_mode (type, mode, punsignedp);
-}
-
 /* Worker function for TARGET_RETURN_IN_MEMORY.  */
 
 static bool
diff --git a/gcc/targhooks.cc b/gcc/targhooks.cc
index 7cb481922559..5f1eac75122c 100644
--- a/gcc/targhooks.cc
+++ b/gcc/targhooks.cc
@@ -162,6 +162,23 @@ default_promote_function_mode_always_promote (const_tree 
type,
   return promote_mode (type, mode, punsignedp);
 }
 
+/* Sign-extend signed 8/16-bit integer arguments to 32 bits and
+   zero-extend unsigned 8/16-bit integer arguments to 32 bits.  */
+
+machine_mode
+default_promote_function_mode_sign_extend (const_tree type,
+                                          machine_mode mode,
+                                          int *punsignedp,
+                                          const_tree, int)
+{
+  if (GET_MODE_CLASS (mode) == MODE_INT
+      && (GET_MODE_SIZE (as_a <scalar_int_mode> (mode))
+         < GET_MODE_SIZE (SImode)))
+    return SImode;
+
+  return promote_mode (type, mode, punsignedp);
+}
+
 machine_mode
 default_cc_modes_compatible (machine_mode m1, machine_mode m2)
 {
diff --git a/gcc/targhooks.h b/gcc/targhooks.h
index dc24eec5e046..9582233e69fe 100644
--- a/gcc/targhooks.h
+++ b/gcc/targhooks.h
@@ -33,6 +33,8 @@ extern machine_mode default_promote_function_mode 
(const_tree, machine_mode,
                                                        int *, const_tree, int);
 extern machine_mode default_promote_function_mode_always_promote
                        (const_tree, machine_mode, int *, const_tree, int);
+extern machine_mode default_promote_function_mode_sign_extend
+  (const_tree, machine_mode, int *, const_tree, int);
 
 extern machine_mode default_cc_modes_compatible (machine_mode,
                                                      machine_mode);
diff --git a/gcc/testsuite/gcc.target/xtensa/pr120888-2.c 
b/gcc/testsuite/gcc.dg/sign-extend.c
similarity index 80%
rename from gcc/testsuite/gcc.target/xtensa/pr120888-2.c
rename to gcc/testsuite/gcc.dg/sign-extend.c
index 9b5caad83298..3ded5050d17e 100644
--- a/gcc/testsuite/gcc.target/xtensa/pr120888-2.c
+++ b/gcc/testsuite/gcc.dg/sign-extend.c
@@ -1,4 +1,4 @@
-/* { dg-do compile } */
+/* { dg-do compile { target mcore-*-* xtensa-*-* } } */
 /* { dg-options "-O1 -fdump-rtl-expand" } */
 
 void s8(signed char c);
diff --git a/gcc/testsuite/gcc.target/xtensa/pr120888-1.c 
b/gcc/testsuite/gcc.dg/zero-extend.c
similarity index 80%
rename from gcc/testsuite/gcc.target/xtensa/pr120888-1.c
rename to gcc/testsuite/gcc.dg/zero-extend.c
index f438e4c676cb..22671e568971 100644
--- a/gcc/testsuite/gcc.target/xtensa/pr120888-1.c
+++ b/gcc/testsuite/gcc.dg/zero-extend.c
@@ -1,4 +1,4 @@
-/* { dg-do compile } */
+/* { dg-do compile { target mcore-*-* xtensa-*-* } } */
 /* { dg-options "-O1 -fdump-rtl-expand" } */
 
 void u8(unsigned char c);

Reply via email to