[Bug tree-optimization/45397] [5/6/7 Regression] Issues with integer narrowing conversions
law at redhat dot com
gcc-bugzilla@gcc.gnu.org
Tue Feb 14 16:14:00 GMT 2017
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=45397
Jeffrey A. Law <law at redhat dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |law at redhat dot com
--- Comment #21 from Jeffrey A. Law <law at redhat dot com> ---
Couldn't we solve this with a pattern like this in match.pd:
(simplify
(convert (plus:c @0 (convert @1)))
(if (INTEGRAL_TYPE_P (TREE_TYPE (@1))
&& INTEGRAL_TYPE_P (TREE_TYPE (@0))
&& INTEGRAL_TYPE_P (type)
&& types_match (@1, type)
&& (TYPE_PRECISION (TREE_TYPE (@1)) > TYPE_PRECISION (TREE_TYPE (@0))))
(bit_and (plus (convert @0) @1)
{ wide_int_to_tree
(type, wi::mask (TYPE_PRECISION (TREE_TYPE (@0)), false,
TYPE_PRECISION (type))); })))
Essentially this widens the arithmetic, then masks off undesirable bits in the
result. As written I think this doesn't reduce the number of expressions
consistently even though it helps the testcase.
The reason it helps the testcase is the (convert @0) in the output pattern
turns out to be a common subexpression. If (convert @0) is CSE-able, then this
does reduce the number of expressions. Though we probably want to avoid
widening beyond a target's wordsize (which I loathe to test for).
Thoughts anyone?
More information about the Gcc-bugs
mailing list