Jakub Jelinek 049ce9d233 middle-end: __builtin_mul_overflow expansion improvements [PR95862]
The following patch adds some improvements for __builtin_mul_overflow
expansion.
One optimization is for the u1 * u2 -> sr case, as documented we normally
do:
     u1 * u2 -> sr
        res = (S) (u1 * u2)
        ovf = res < 0 || main_ovf (true)
where main_ovf (true) stands for jump on unsigned multiplication overflow.
If we know that the most significant bits of both operands are clear (such
as when they are zero extended from something smaller), we can
emit better coe by handling it like s1 * s2 -> sr, i.e. just jump on
overflow after signed multiplication.

Another two cases are s1 * s2 -> ur or s1 * u2 -> ur, if we know the minimum
precision needed to encode all values of both arguments summed together
is smaller or equal to destination precision (such as when the two arguments
are sign (or zero) extended from half precision types, we know the overflows
happen only iff one argument is negative and the other argument is positive
(not zero), because even if both have maximum possible values, the maximum
is still representable (e.g. for char * char -> unsigned short
0x7f * 0x7f = 0x3f01 and for char * unsigned char -> unsigned short
0x7f * 0xffU = 0x7e81) and as the result is unsigned, all negative results
do overflow, but are also representable if we consider the result signed
- all of them have the MSB set.  So, it is more efficient to just
do the normal multiplication in that case and compare the result considered
as signed value against 0, if it is smaller, overflow happened.

And the get_min_precision change is to improve the char to short handling,
we have there in the IL
  _2 = (int) arg_1(D);
promotion from C promotions from char or unsigned char arg, and the caller
adds a NOP_EXPR cast to short or unsigned short.  get_min_precision punts
on the narrowing cast though, it handled only widening casts, but we can
handle narrowing casts fine too, by recursing on the narrowing cast operands
and using it only if it has in the end smaller minimal precision, which
would duplicate the sign bits (or zero bits) to both the bits above the
narrowing conversion and also at least one below that.

2020-10-25  Jakub Jelinek  <jakub@redhat.com>

	PR rtl-optimization/95862
	* internal-fn.c (get_min_precision): For narrowing conversion, recurse
	on the operand and if the operand precision is smaller than the
	current one, return that smaller precision.
	(expand_mul_overflow): For s1 * u2 -> ur and s1 * s2 -> ur cases
	if the sum of minimum precisions of both operands is smaller or equal
	to the result precision, just perform normal multiplication and
	set overflow to the sign bit of the multiplication result.  For
	u1 * u2 -> sr if both arguments have the MSB known zero, use
	normal s1 * s2 -> sr expansion.

	* gcc.dg/builtin-artih-overflow-5.c: New test.
2020-11-25 15:42:38 +01:00
2020-09-10 10:17:51 +02:00
2020-11-25 09:34:01 +00:00
2020-11-19 00:16:30 +00:00
2020-10-30 00:16:29 +00:00
2020-09-25 00:16:27 +00:00
2020-10-12 00:16:25 +00:00
2020-10-21 00:16:36 +00:00
2020-11-12 00:16:39 +00:00
2020-11-25 09:34:01 +00:00
2020-07-31 00:16:26 +00:00
2020-09-25 00:16:27 +00:00
2020-11-21 00:16:29 +00:00
2020-11-22 00:16:24 +00:00
2020-11-25 13:55:45 +00:00
2020-11-14 00:16:38 +00:00
2020-10-02 00:16:27 +00:00
2020-10-12 00:16:25 +00:00
2020-11-19 00:16:30 +00:00
2020-11-22 00:16:24 +00:00
2020-09-11 00:16:28 +00:00
2020-11-16 12:52:43 +01:00
2020-11-24 00:16:44 +00:00

This directory contains the GNU Compiler Collection (GCC).

The GNU Compiler Collection is free software.  See the files whose
names start with COPYING for copying permission.  The manuals, and
some of the runtime libraries, are under different terms; see the
individual source files for details.

The directory INSTALL contains copies of the installation information
as HTML and plain text.  The source of this information is
gcc/doc/install.texi.  The installation information includes details
of what is included in the GCC sources and what files GCC installs.

See the file gcc/doc/gcc.texi (together with other files that it
includes) for usage and porting information.  An online readable
version of the manual is in the files gcc/doc/gcc.info*.

See http://gcc.gnu.org/bugs/ for how to report bugs usefully.

Copyright years on GCC source files may be listed using range
notation, e.g., 1987-2012, indicating that every year in the range,
inclusive, is a copyrightable year that could otherwise be listed
individually.
Description
No description provided
Readme 2.1 GiB
Languages
C++ 31.9%
C 31.3%
Ada 12%
D 6.5%
Go 6.4%
Other 11.5%