This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: patch: Re: rfc: auto-casted vector types
- From: Aldy Hernandez <aldyh at redhat dot com>
- To: Zack Weinberg <zack at codesourcery dot com>
- Cc: Nick Clifton <nickc at redhat dot com>, gcc-patches at gcc dot gnu dot org, Kumar Gala <kumar dot gala at motorola dot com>, Jim Wilson <wilson at redhat dot com>, mark at codesourcery dot com
- Date: Tue, 18 Feb 2003 14:05:55 -0800
- Subject: Re: patch: Re: rfc: auto-casted vector types
I have addressed everyone's suggestions. I have also included a
testcase.
Bootstrapped on powerpc-linux.
OK?
2003-02-18 Nick Clifton <nickc@redhat.com>
Aldy Hernandez <aldyh@redhat.com>
* testsuite/gcc.dg/20030218-1.c: New.
* doc/tm.texi: Document TARGET_VECTOR_TYPES_COMPATIBLE.
* target-def.h (TARGET_INITIALIZER): Add
TARGET_VECTOR_TYPES_COMPATIBLE.
(TARGET_VECTOR_TYPES_COMPATIBLE): New macro.
* target.h (struct gcc_target): Add field vector_types_compatible.
* c-typeck.c (comptypes): Take into account
TARGET_VECTOR_TYPES_COMPATIBLE.
(convert_for_assignment): Same.
(really_start_incremental_init): Disallow initialization of
ev64_opaque types.
* config/rs6000/rs6000-protos.h
(rs6000_spe_vector_types_compatible): Prototype.
* config/rs6000/rs6000.c (is_ev64_opaque_type): New.
(rs6000_spe_vector_types_compatible): New.
* config/rs6000/rs6000.h (TARGET_VECTOR_TYPES_COMPATIBLE): Define.
Index: testsuite/gcc.dg/20030218-1.c
===================================================================
RCS file: testsuite/gcc.dg/20030218-1.c
diff -N testsuite/gcc.dg/20030218-1.c
*** /dev/null 1 Jan 1970 00:00:00 -0000
--- testsuite/gcc.dg/20030218-1.c 18 Feb 2003 19:52:44 -0000
***************
*** 0 ****
--- 1,16 ----
+ /* { dg-do compile { target powerpc-*-eabi* powerpc*-*-elf*
powerpc-*-linux* } } */
+ /* { dg-options "-mcpu=8540" } */
+
+ /* Test vectors that can interconvert without a cast. */
+
+ int vint __attribute__((mode(V2SI)));
+ int vshort __attribute__((mode(V4HI)));
+ int vfloat __attribute__((mode(V2SF)));
+
+ int
+ main (void)
+ {
+ vint = vfloat;
+ vshort = vint;
+ vfloat = vshort; /* { dg-error "incompatible types in assignment" }
*/
+ }
Index: doc/tm.texi
===================================================================
RCS file: /cvs/gcc/gcc/gcc/doc/tm.texi,v
retrieving revision 1.198
diff -c -p -r1.198 tm.texi
*** doc/tm.texi 31 Jan 2003 23:34:17 -0000 1.198
--- doc/tm.texi 18 Feb 2003 19:52:50 -0000
*************** Define this macro to be nonzero if the p
*** 1302,1307 ****
--- 1302,1313 ----
involving vector mode @var{mode}. At the very least, it must have
move
patterns for this mode.
+ @findex TARGET_VECTOR_TYPES_COMPATIBLE
+ @item TARGET_VECTOR_TYPES_COMPATIBLE(@var{tree1}, @var{tree2})
+ Define this macro to return nonzero if no cast is needed when copying
+ a vector value of type @var{tree1} to a vector value of type
+ @var{tree2}.
+
@findex STACK_SAVEAREA_MODE
@item STACK_SAVEAREA_MODE (@var{save_level})
If defined, an expression of type @code{enum machine_mode} that
*************** floating-point arithmetic.
*** 1451,1456 ****
--- 1457,1467 ----
The default definition of this macro returns false for all sizes.
@end table
+
+ @deftypefn {Target Hook} bool TARGET_VECTOR_TYPES_COMPATIBLE (tree
@var{type1}, tree @var{type2})
+ This target hook returns @code{true} if two vector types can be copied
+ without an explicit cast.
+ @end deftypefn
@deftypefn {Target Hook} bool TARGET_MS_BITFIELD_LAYOUT_P (tree
@var{record_type})
This target hook returns @code{true} if bit-fields in the given
Index: target-def.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/target-def.h,v
retrieving revision 1.42
diff -c -p -r1.42 target-def.h
*** target-def.h 28 Jan 2003 18:08:48 -0000 1.42
--- target-def.h 18 Feb 2003 19:52:50 -0000
*************** Foundation, 59 Temple Place - Suite 330,
*** 256,261 ****
--- 256,265 ----
#define TARGET_VALID_POINTER_MODE default_valid_pointer_mode
#endif
+ #ifndef TARGET_VECTOR_TYPES_COMPATIBLE
+ #define TARGET_VECTOR_TYPES_COMPATIBLE hook_bool_tree_tree_false
+ #endif
+
/* In hook.c. */
#define TARGET_CANNOT_MODIFY_JUMPS_P hook_bool_void_false
#define TARGET_CANNOT_FORCE_CONST_MEM hook_bool_rtx_false
*************** Foundation, 59 Temple Place - Suite 330,
*** 299,304 ****
--- 303,309 ----
TARGET_ENCODE_SECTION_INFO, \
TARGET_STRIP_NAME_ENCODING, \
TARGET_VALID_POINTER_MODE, \
+ TARGET_VECTOR_TYPES_COMPATIBLE, \
TARGET_RTX_COSTS, \
TARGET_ADDRESS_COST, \
TARGET_HAVE_NAMED_SECTIONS, \
Index: target.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/target.h,v
retrieving revision 1.48
diff -c -p -r1.48 target.h
*** target.h 28 Jan 2003 18:08:48 -0000 1.48
--- target.h 18 Feb 2003 19:52:50 -0000
*************** struct gcc_target
*** 314,319 ****
--- 314,322 ----
/* True if MODE is valid for a pointer in
__attribute__((mode("MODE"))). */
bool (* valid_pointer_mode) PARAMS ((enum machine_mode mode));
+ /* True if two vector types can be copied without an explicit cast.
*/
+ bool (* vector_types_compatible) PARAMS ((tree, tree));
+
/* Compute a (partial) cost for rtx X. Return true if the complete
cost has been computed, and false if subexpressions should be
scanned. In either case, *TOTAL contains the cost result. */
Index: c-typeck.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-typeck.c,v
retrieving revision 1.218
diff -c -p -r1.218 c-typeck.c
*** c-typeck.c 1 Feb 2003 13:09:39 -0000 1.218
--- c-typeck.c 18 Feb 2003 19:52:54 -0000
*************** comptypes (type1, type2)
*** 574,579 ****
--- 574,584 ----
val = 1;
break;
+ case VECTOR_TYPE:
+ /* The target might allow certain vector types to be
compatible. */
+ val = (*targetm.vector_types_compatible) (t1, t2);
+ break;
+
default:
break;
}
*************** convert_for_assignment (type, rhs, errty
*** 4061,4066 ****
--- 4066,4075 ----
rhs = build1 (NOP_EXPR, type, rhs);
return rhs;
}
+ /* Some types can interconvert without explicit casts. */
+ else if (codel == VECTOR_TYPE && coder == VECTOR_TYPE
+ && (*targetm.vector_types_compatible) (type, rhstype))
+ return convert (type, rhs);
/* Arithmetic types all interconvert, and enum is treated like int.
*/
else if ((codel == INTEGER_TYPE || codel == REAL_TYPE
|| codel == ENUMERAL_TYPE || codel == COMPLEX_TYPE
Index: config/rs6000/rs6000-protos.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/config/rs6000/rs6000-protos.h,v
retrieving revision 1.49
diff -c -p -r1.49 rs6000-protos.h
*** config/rs6000/rs6000-protos.h 28 Jan 2003 23:26:28 -0000 1.49
--- config/rs6000/rs6000-protos.h 18 Feb 2003 19:52:54 -0000
*************** extern int rs6000_register_move_cost PAR
*** 193,198 ****
--- 193,199 ----
enum reg_class, enum reg_class));
extern int rs6000_memory_move_cost PARAMS ((enum machine_mode,
enum reg_class, int));
+ extern bool rs6000_spe_vector_types_compatible PARAMS ((tree, tree));
/* Declare functions in rs6000-c.c */
Index: config/rs6000/rs6000.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/config/rs6000/rs6000.c,v
retrieving revision 1.422
diff -c -p -r1.422 rs6000.c
*** config/rs6000/rs6000.c 10 Feb 2003 18:42:19 -0000 1.422
--- config/rs6000/rs6000.c 18 Feb 2003 19:53:09 -0000
*************** static void is_altivec_return_reg PARAMS
*** 265,270 ****
--- 265,271 ----
static rtx generate_set_vrsave PARAMS ((rtx, rs6000_stack_t *, int));
static void altivec_frame_fixup PARAMS ((rtx, rtx, HOST_WIDE_INT));
static int easy_vector_constant PARAMS ((rtx));
+ static int is_ev64_opaque_type PARAMS ((tree));
/* Hash table stuff for keeping track of TOC entries. */
*************** rs6000_memory_move_cost (mode, class, in
*** 13522,13527 ****
--- 13523,13561 ----
return 4 * HARD_REGNO_NREGS (FIRST_ALTIVEC_REGNO, mode);
else
return 4 + rs6000_register_move_cost (mode, class, GENERAL_REGS);
+ }
+
+ /* Return true if TYPE is of type __ev64_opaque__. */
+
+ static int
+ is_ev64_opaque_type (type)
+ tree type;
+ {
+ return (TYPE_NAME (type)
+ && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
+ && DECL_NAME (TYPE_NAME (type))
+ && strcmp (IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type))),
+ "__ev64_opaque__") == 0);
+ }
+
+ /* Return true if vector type1 can be converted into vector type2. */
+
+ bool
+ rs6000_spe_vector_types_compatible (t1, t2)
+ tree t1;
+ tree t2;
+ {
+ if (!TARGET_SPE
+ || TREE_CODE (t1) != VECTOR_TYPE || TREE_CODE (t2) !=
VECTOR_TYPE)
+ return 0;
+
+ if (TYPE_NAME (t1) || TYPE_NAME (t2))
+ return is_ev64_opaque_type (t1) || is_ev64_opaque_type (t2);
+
+ /* FIXME: We assume V2SI is the opaque type, so we accidentally
+ allow inter conversion to and from V2SI modes. We could use
+ V1D1, and rewrite <spe.h> accordingly. */
+ return t1 == V2SI_type_node || t2 == V2SI_type_node;
}
#include "gt-rs6000.h"
Index: config/rs6000/rs6000.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/config/rs6000/rs6000.h,v
retrieving revision 1.251
diff -c -p -r1.251 rs6000.h
*** config/rs6000/rs6000.h 8 Feb 2003 03:59:40 -0000 1.251
--- config/rs6000/rs6000.h 18 Feb 2003 19:53:11 -0000
*************** extern int rs6000_default_long_calls;
*** 892,897 ****
--- 892,900 ----
|| (MODE) == V1DImode \
|| (MODE) == V2SImode)
+ /* Allow SPE vector types to be inter-converted. */
+ #define TARGET_VECTOR_TYPES_COMPATIBLE
rs6000_spe_vector_types_compatible
+
/* Define this macro to be nonzero if the port is prepared to handle
insns involving vector mode MODE. At the very least, it must have
move patterns for this mode. */