[rs6000] Add support for signed overflow arithmetic

Eric Botcazou ebotcazou@adacore.com
Fri Oct 21 23:03:00 GMT 2016


Hi,

this implements support for signed overflow arithmetic on PowerPC.  It's an 
implementation for Power ISA v2.0x, i.e. it doesn't take account the new OV32 
flag introduced in v3.0.  It doesn't implement unsigned overflow arithmetic 
because my understanding is that the generic support already generates optimal 
code in most cases on PowerPC for unsigned.

It introduces a new MODE_CC mode (CCVmode) which represents the OV flag of the 
XER, and the overflow arithmetic instructions are paired with a mcrxr.  The 
comparisons are written in terms of UNSPECs because I used that for Visium and 
SPARC, but I can rewrite them a la x86/ARM if requested.

There is also a tweak to expand_arith_overflow, because it would otherwise 
"promote" signed multiplication to unsigned multiplication in some cases and 
this badly pessimizes for PowerPC.

Tested on PowerPC/Linux and PowerPC64/Linux, OK for the mainline?


2016-10-21  Eric Botcazou  <ebotcazou@adacore.com>

	* internal-fn.c (expand_arith_overflow): Do not promote a signed
	multiplication done in hardware to an unsigned open-coded one.
	* config/rs6000/rs6000-modes.def (CCV): New.
	* config/rs6000/rs6000-protos.h (rs6000_select_cc_mode): Declare.
	* config/rs6000/rs6000.h (SELECT_CC_MODE): Call it.
	* config/rs6000/rs6000.c (rs6000_debug_reg_global): Handle CCVmode.
	(validate_condition_mode): Likewise.
	(print_operand): Handle %C modifier.
	(rs6000_select_cc_mode): Likewise.
	(output_cbranch): Likewise.  Tidy up.
	* config/rs6000/rs6000.md (UNSPEC_{ADD,SUB,NEG,MUL}V): New constants.
	(addv<mode>4): New expander.
	(add<mode>3_overflow): New instruction.
	(add<mode>3_overflow_carry_in): New expander.
	(add<mode>3_overflow_carry_in_internal): New instruction.
	(add<mode>3_overflow_carry_in_0): Likewise.
	(add<mode>3_overflow_carry_in_m1): Likewise.
	(subv<mode>4): New expander.
	(subf<mode>3_overflow): New instruction.
	(subf<mode>3_overflow_carry_in): New expander.
	(sub<mode>3_overflow_carry_in_internal): New instruction.
	(subf<mode>3_overflow_carry_in_0): Likewise.
	(subf<mode>3_overflow_carry_in_m1): Likewise.
	(negv<mode>3): New expander.
	(neg<mode>2_overflow): New instruction.
	(mulv<mode>4): New expander.
	(mulv<mode>3_overflow): New instruction.
testsuite/
	* gcc.target/powerpc/overflow-1.c: New test.
	* gcc.target/powerpc/overflow-2.c: Likewise.
	* gcc.target/powerpc/overflow-3.c: Likewise.
	* gcc.target/powerpc/overflow-4.c: Likewise.

-- 
Eric Botcazou
-------------- next part --------------
A non-text attachment was scrubbed...
Name: powerpc_overflow.diff
Type: text/x-patch
Size: 25998 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20161021/00439ba4/attachment.bin>


More information about the Gcc-patches mailing list