]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Add default_promote_function_mode_sign_extend
authorH.J. Lu <hjl.tools@gmail.com>
Wed, 31 Dec 2025 23:14:57 +0000 (07:14 +0800)
committerH.J. Lu <hjl.tools@gmail.com>
Thu, 26 Feb 2026 07:52:34 +0000 (15:52 +0800)
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 <hjl.tools@gmail.com>
gcc/config/mcore/mcore.cc
gcc/config/xtensa/xtensa.cc
gcc/targhooks.cc
gcc/targhooks.h
gcc/testsuite/gcc.dg/sign-extend.c [moved from gcc/testsuite/gcc.target/xtensa/pr120888-2.c with 80% similarity]
gcc/testsuite/gcc.dg/zero-extend.c [moved from gcc/testsuite/gcc.target/xtensa/pr120888-1.c with 80% similarity]

index 9be652e3748ff3f49c75766f121f0c4983039412..e5ee2c1fc743fa89ab8e4cb4a24ad884455b34f5 100644 (file)
@@ -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
index c2a6a1610662cdf97b04dd2b934940b7f4e7af23..d9420bb2cda8683135f92e0dcfb5265590a1d0bc 100644 (file)
@@ -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
index 7cb4819225593f2c99076f4fffae350ede2dc56b..5f1eac75122c9cc945012a02426784f6c2584328 100644 (file)
@@ -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)
 {
index dc24eec5e0465f5e341ac6ad197bf9fbac0183c1..9582233e69fee1b56ab9d2f2573707621f9837ff 100644 (file)
@@ -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);
similarity index 80%
rename from gcc/testsuite/gcc.target/xtensa/pr120888-2.c
rename to gcc/testsuite/gcc.dg/sign-extend.c
index 9b5caad832983b715cca0c7f74520a85a2b304ee..3ded5050d17ece49868e0549aef8e4c0479a4e1c 100644 (file)
@@ -1,4 +1,4 @@
-/* { dg-do compile } */
+/* { dg-do compile { target mcore-*-* xtensa-*-* } } */
 /* { dg-options "-O1 -fdump-rtl-expand" } */
 
 void s8(signed char c);
similarity index 80%
rename from gcc/testsuite/gcc.target/xtensa/pr120888-1.c
rename to gcc/testsuite/gcc.dg/zero-extend.c
index f438e4c676cb0a456d5166bc326da45b9a819449..22671e568971f12cef5a2fb4fa0411acfd70cdd4 100644 (file)
@@ -1,4 +1,4 @@
-/* { dg-do compile } */
+/* { dg-do compile { target mcore-*-* xtensa-*-* } } */
 /* { dg-options "-O1 -fdump-rtl-expand" } */
 
 void u8(unsigned char c);