This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
promoted_input_arg
- From: Sandra Loosemore <sandra at codesourcery dot com>
- To: Mark Shinwell <shinwell at codesourcery dot com>
- Cc: GCC Patches <gcc-patches at gcc dot gnu dot org>
- Date: Thu, 30 Aug 2007 11:20:51 -0400
- Subject: promoted_input_arg
Nigel sent us the attached new version of this patch -- the original 3.4
version of the patch was too bit-rotten to be usable. He said he hadn't
tested this one yet, but I think the patch and test case combined at
least are adequate to explain what optimization it is they want to happen.
I haven't dug around to familiarize myself with the details of this code
yet, but my concerns over correctness are that (a) all the language
front ends do in fact provide the guarantee that the arguments are
compatible and (b) this won't screw up ABI issues, DWARF information,
etc. And, from an engineering perspective, is this the right place in
the compiler to be inserting an interprocedural optimization?
-Sandra
Index: function.c
===================================================================
RCS file: /cvsroot/gcc/gcc-cvs/gcc/gcc/function.c,v
retrieving revision 1.483.4.2
diff -c -r1.483.4.2 function.c
*** function.c 28 Jan 2004 13:58:19 -0000 1.483.4.2
--- function.c 14 Aug 2007 09:37:28 -0000
***************
*** 5396,5408 ****
rtx
promoted_input_arg (unsigned int regno, enum machine_mode *pmode, int *punsignedp)
{
tree arg;
! for (arg = DECL_ARGUMENTS (current_function_decl); arg;
arg = TREE_CHAIN (arg))
if (GET_CODE (DECL_INCOMING_RTL (arg)) == REG
&& REGNO (DECL_INCOMING_RTL (arg)) == regno
! && TYPE_MODE (DECL_ARG_TYPE (arg)) == TYPE_MODE (TREE_TYPE (arg)))
{
enum machine_mode mode = TYPE_MODE (TREE_TYPE (arg));
int unsignedp = TREE_UNSIGNED (TREE_TYPE (arg));
--- 5459,5489 ----
rtx
promoted_input_arg (unsigned int regno, enum machine_mode *pmode, int *punsignedp)
{
+ tree fndecl = current_function_decl;
+ struct cgraph_local_info *i = NULL;
tree arg;
! /* Handle prototype promotion too, if this function has a
! prototype and is only callable from inside this compile
! unit. Implicit or explicit definition of incompatible
! arguments now generate an error, so this is safe. */
! if (flag_unit_at_a_time
! && TYPE_ARG_TYPES (TREE_TYPE (fndecl))
! && ! DECL_EXTERNAL (fndecl)
! && ! DECL_STATIC_CONSTRUCTOR (fndecl)
! && ! DECL_STATIC_DESTRUCTOR (fndecl)
! && ! (DECL_ASSEMBLER_NAME_SET_P (fndecl)
! && TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (fndecl)))
! && ! lookup_attribute ("used", DECL_ATTRIBUTES (fndecl)))
! i = cgraph_local_info (fndecl);
!
! for (arg = DECL_ARGUMENTS (fndecl); arg;
arg = TREE_CHAIN (arg))
if (GET_CODE (DECL_INCOMING_RTL (arg)) == REG
&& REGNO (DECL_INCOMING_RTL (arg)) == regno
! && (TYPE_MODE (DECL_ARG_TYPE (arg)) == TYPE_MODE (TREE_TYPE (arg))
! || (i && i->local))
! && TREE_CODE (DECL_ARG_TYPE (arg)) == TREE_CODE (TREE_TYPE (arg)))
{
enum machine_mode mode = TYPE_MODE (TREE_TYPE (arg));
int unsignedp = TREE_UNSIGNED (TREE_TYPE (arg));
Take:
static int
promoted (short a)
{
return a > 0;
}
int caller (int a, int b)
{
return promoted (a) + promoted (b);
}
Compiled with gcc-4.2 -O2, promoted() generates :
promoted:
sll $2,$4,16
sra $2,$2,16
j $31
slt $2,$0,$2
Compiled with our local gcc-3.4 including this patch, promoted() generates:
promoted:
j $31
slt $2,$0,$4