diff options
author | Roger Sayle <roger@nextmovesoftware.com> | 2022-05-27 08:57:46 +0100 |
---|---|---|
committer | Roger Sayle <roger@nextmovesoftware.com> | 2022-05-27 09:01:13 +0100 |
commit | 8fb94fc6097c0a934aac0d89c9c5e2038da67655 (patch) | |
tree | ca59552b1d3ccc5c9fc0a1f8c83136a4fa53f093 /gcc/ada/gcc-interface | |
parent | 29ae455901ac711470c4aa4f42d51f62e0b3753a (diff) | |
download | gcc-8fb94fc6097c0a934aac0d89c9c5e2038da67655.zip gcc-8fb94fc6097c0a934aac0d89c9c5e2038da67655.tar.gz gcc-8fb94fc6097c0a934aac0d89c9c5e2038da67655.tar.bz2 |
Canonicalize X&-Y as X*Y in match.pd when Y is [0,1].
"For every pessimization, there's an equal and opposite optimization".
In the review of my original patch for PR middle-end/98865, Richard
Biener pointed out that match.pd shouldn't be transforming X*Y into
X&-Y as the former is considered cheaper by tree-ssa's cost model
(operator count). A corollary of this is that we should instead be
transforming X&-Y into the cheaper X*Y as a preferred canonical form
(especially as RTL expansion now intelligently selects the appropriate
implementation based on the target's costs).
With this patch we now generate identical code for:
int foo(int x, int y) { return -(x&1) & y; }
int bar(int x, int y) { return (x&1) * y; }
specifically on x86_64-pc-linux-gnu both use and/neg/and with -O2,
but both use and/mul with -Os.
One minor wrinkle/improvement is that this patch includes three
additional optimizations (that account for the change in canonical
form) to continue to optimize PR92834 and PR94786.
2022-05-27 Roger Sayle <roger@nextmovesoftware.com>
gcc/ChangeLog
* match.pd (match_zero_one_valued_p): New predicate.
(mult @0 @1): Use zero_one_valued_p for optimization to the
expression "bit_and @0 @1".
(bit_and (negate zero_one_valued_p@0) @1): Optimize to MULT_EXPR.
(plus @0 (mult (minus @1 @0) zero_one_valued_p@2)): New transform.
(minus @0 (mult (minus @0 @1) zero_one_valued_p@2)): Likewise.
(bit_xor @0 (mult (bit_xor @0 @1) zero_one_valued_p@2)): Likewise.
Remove three redundant transforms obsoleted by the three above.
gcc/testsuite/ChangeLog
* gcc.dg/pr98865.c: New test case.
Diffstat (limited to 'gcc/ada/gcc-interface')
0 files changed, 0 insertions, 0 deletions