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 <hjl.tools@gmail.com>
This commit is contained in:
H.J. Lu
2026-01-01 07:14:57 +08:00
parent f8380ded1f
commit fecf542e1d
6 changed files with 25 additions and 24 deletions

View 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

View 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

View 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)
{

View 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);

View 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);

View 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);