Revised patch to address conservative behavior in redundant extend elimination that was resulting in redundant extends not being removed. Now uses a new target hook machine_mode_from_attr_mode which is currently enabled only for i386.
Bootstrapped and tested on x86_64-unknown-linux-gnu. Is this ok for trunk? Thanks, Teresa 2012-10-11 Teresa Johnson <tejohn...@google.com> * doc/tm.texi: Document TARGET_MACHINE_MODE_FROM_ATTR_MODE. * doc/tm.texi.in: Regenerated. * targhooks.c (default_machine_mode_from_attr_mode): New function. * targhooks.h (default_machine_mode_from_attr_mode): Declare. * target.def (machine_mode_from_attr_mode): New target hook. * ree.c (get_mode): New function. (add_removable_extension): Use get_mode to obtain the machine mode for comparison with other extends. * config/i386/i386.c (ix86_machine_mode_from_attr_mode): New function. Index: doc/tm.texi =================================================================== --- doc/tm.texi (revision 192265) +++ doc/tm.texi (working copy) @@ -10468,6 +10468,10 @@ In order to enforce the representation of @code{mo @code{mode}. @end deftypefn +@deftypefn {Target Hook} {enum machine_mode} TARGET_MACHINE_MODE_FROM_ATTR_MODE (rtx @var{insn}) +If @var{insn} has an attr_mode that is equivalent to a @code{machine_mode}, return the corresponding @code{machine_mode}, otherwise return @code{MAX_MACHINE_MODE}. +@end deftypefn + @defmac STORE_FLAG_VALUE A C expression describing the value returned by a comparison operator with an integral mode and stored by a store-flag instruction Index: doc/tm.texi.in =================================================================== --- doc/tm.texi.in (revision 192265) +++ doc/tm.texi.in (working copy) @@ -10326,6 +10326,8 @@ In order to enforce the representation of @code{mo @code{mode}. @end deftypefn +@hook TARGET_MACHINE_MODE_FROM_ATTR_MODE + @defmac STORE_FLAG_VALUE A C expression describing the value returned by a comparison operator with an integral mode and stored by a store-flag instruction Index: targhooks.c =================================================================== --- targhooks.c (revision 192265) +++ targhooks.c (working copy) @@ -250,6 +250,14 @@ default_mode_rep_extended (enum machine_mode mode return UNKNOWN; } +/* The default implementation of TARGET_MACHINE_MODE_FROM_ATTR_MODE. */ + +enum machine_mode +default_machine_mode_from_attr_mode (rtx insn ATTRIBUTE_UNUSED) +{ + return MAX_MACHINE_MODE; +} + /* Generic hook that takes a CUMULATIVE_ARGS pointer and returns true. */ bool Index: targhooks.h =================================================================== --- targhooks.h (revision 192265) +++ targhooks.h (working copy) @@ -47,6 +47,7 @@ extern unsigned HOST_WIDE_INT default_shift_trunca (enum machine_mode); extern unsigned int default_min_divisions_for_recip_mul (enum machine_mode); extern int default_mode_rep_extended (enum machine_mode, enum machine_mode); +enum machine_mode default_machine_mode_from_attr_mode (rtx insn); extern tree default_stack_protect_guard (void); extern tree default_external_stack_protect_fail (void); Index: target.def =================================================================== --- target.def (revision 192265) +++ target.def (working copy) @@ -1576,6 +1576,17 @@ DEFHOOK int, (enum machine_mode mode, enum machine_mode rep_mode), default_mode_rep_extended) +/* If the machine description for an rtl INSN defines the + attr_mode, and that mode is equivalent to a machine_mode, return + the corresponding machine_mode. Return MAX_MACHINE_MODE otherwise. */ +DEFHOOK +(machine_mode_from_attr_mode, + "If @var{insn} has an attr_mode that is equivalent to a @code{machine_mode},\ + return the corresponding @code{machine_mode}, otherwise return\ + @code{MAX_MACHINE_MODE}.", + enum machine_mode, (rtx insn), + default_machine_mode_from_attr_mode) + /* True if MODE is valid for a pointer in __attribute__((mode("MODE"))). */ DEFHOOK (valid_pointer_mode, Index: ree.c =================================================================== --- ree.c (revision 192265) +++ ree.c (working copy) @@ -756,6 +756,20 @@ combine_reaching_defs (ext_cand *cand, const_rtx s return false; } +/* Given an INSN, obtain the attr_mode specified by the machine + description, and map it to the corresponding machine_mode. If the + attr_mode isn't specified, return the machine mode for DEST. */ + +static enum machine_mode +get_mode (rtx insn, rtx dest) +{ + enum machine_mode mode; + mode = targetm.machine_mode_from_attr_mode(insn); + if (mode == MAX_MACHINE_MODE) + mode = GET_MODE (dest); + return mode; +} + /* Add an extension pattern that could be eliminated. */ static void @@ -775,7 +789,7 @@ add_removable_extension (const_rtx expr, rtx insn, src = SET_SRC (expr); code = GET_CODE (src); dest = SET_DEST (expr); - mode = GET_MODE (dest); + mode = get_mode (insn, dest); if (REG_P (dest) && (code == SIGN_EXTEND || code == ZERO_EXTEND) Index: config/i386/i386.c =================================================================== --- config/i386/i386.c (revision 192265) +++ config/i386/i386.c (working copy) @@ -15074,6 +15074,48 @@ ix86_print_operand_address (FILE *file, rtx addr) } } +/* Implementation of TARGET_MACHINE_MODE_FROM_ATTR_MODE. */ + +static enum machine_mode +ix86_machine_mode_from_attr_mode (rtx insn) +{ + switch (get_attr_mode (insn)) + { + case MODE_QI: + return QImode; + case MODE_HI: + return HImode; + case MODE_SI: + return SImode; + case MODE_DI: + return DImode; + case MODE_TI: + return TImode; + case MODE_OI: + return OImode; + case MODE_SF: + return SFmode; + case MODE_DF: + return DFmode; + case MODE_XF: + return XFmode; + case MODE_TF: + return TFmode; + case MODE_V8SF: + return V8SFmode; + case MODE_V4DF: + return V4DFmode; + case MODE_V4SF: + return V4SFmode; + case MODE_V2DF: + return V2DFmode; + case MODE_V2SF: + return V2SFmode; + default: + return MAX_MACHINE_MODE; + } +} + /* Implementation of TARGET_ASM_OUTPUT_ADDR_CONST_EXTRA. */ static bool @@ -41171,6 +41213,9 @@ ix86_memmodel_check (unsigned HOST_WIDE_INT val) #undef TARGET_EXPAND_TO_RTL_HOOK #define TARGET_EXPAND_TO_RTL_HOOK ix86_maybe_switch_abi +#undef TARGET_MACHINE_MODE_FROM_ATTR_MODE +#define TARGET_MACHINE_MODE_FROM_ATTR_MODE ix86_machine_mode_from_attr_mode + #undef TARGET_LEGITIMATE_ADDRESS_P #define TARGET_LEGITIMATE_ADDRESS_P ix86_legitimate_address_p -- This patch is available for review at http://codereview.appspot.com/6631066