[SPARC] Add support for overflow arithmetic

Eric Botcazou ebotcazou@adacore.com
Fri Oct 28 17:28:00 GMT 2016


> Then to some extent defining WORD_REGISTER_OPERATIONS on SPARC is a lie,
> it only has "INT_REGISTER_OPERATIONS", i.e. all operations smaller than
> int are performed on the whole register, int operations can be really done
> in SImode in the IL (no need to sign/zero extend anything to DImode, if you
> just ignore the high 32 bits).

On the other hand SPARC perfectly matches the documentation:

 -- Macro: WORD_REGISTER_OPERATIONS
     Define this macro to 1 if operations between registers with
     integral mode smaller than a word are always performed on the
     entire register.  Most RISC machines have this property and most
     CISC machines do not.

If you don't define it for SPARC, then you'll never define it!  The macro 
makes it possible to do some optimizations in combine.c and rtlanal.c so it 
looks quite useful.  Note that SPARC is one of the very few RISC targets that 
don't define PROMOTE_MODE for variables since a patch of yours from 1999:
  https://gcc.gnu.org/ml/gcc-patches/1999-12n/msg00202.html
so it's already parameterized to avoid sign/zero-extending to DImode.

> Guess easiest would be to add some targetm constant or hook that gives
> you bit precision - integral arithmetics smaller than this precision is
> performed in precision.  Then define it by default to
> #ifdef WORD_REGISTER_OPERATIONS
>   BITS_PER_WORD
> #else
>   BITS_PER_UNIT
> #endif
> and for sparc set to 32, then use this targetm constant or hook in
> internal-fn.c instead of WORD_REGISTER_OPERATIONS and BITS_PER_WORD.

Thanks for the hint.  The hook is the way to go I think because BITS_PER_WORD 
is not a constant, so the default would not be properly initialized.  Here's a 
tentative patch, I'll add a couple of SPARC-specific testcases if accepted.

Tested on SPARC/Solaris, OK for the mainline?


	* doc/tm.texi.in (Target Macros) Add TARGET_MIN_ARITHMETIC_PRECISION.
	* doc/tm.texi: Regenerate.
	* internal-fn.c (expand_arith_overflow): Rewrite handling of target
	dependent support by means of TARGET_MIN_ARITHMETIC_PRECISION.
	* target.def (min_arithmetic_precision): New hook.
	* targhooks.c (default_min_arithmetic_precision): New function.
	* targhooks.h (default_min_arithmetic_precision): Declare.
	* config/sparc/sparc.c (TARGET_MIN_ARITHMETIC_PRECISION): Define.
	(sparc_min_arithmetic_precision): New function.

-- 
Eric Botcazou
-------------- next part --------------
A non-text attachment was scrubbed...
Name: sparc_overflow-2.diff
Type: text/x-patch
Size: 6887 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20161028/1a7161f1/attachment.bin>


More information about the Gcc-patches mailing list