[Bug tree-optimization/114277] [12/13/14/15 Regression] Missed optimization: x*(x||b) => x
cvs-commit at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Sat Feb 1 00:05:15 GMT 2025
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114277
--- Comment #13 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Jeff Law <law@gcc.gnu.org>:
https://gcc.gnu.org/g:2c0a9b7fb7902522fb8484342fcc19fd44df53e6
commit r15-7313-g2c0a9b7fb7902522fb8484342fcc19fd44df53e6
Author: Jeff Law <jlaw@ventanamicro.com>
Date: Fri Jan 31 16:59:35 2025 -0700
[committed][PR tree-optimization/114277] Fix missed optimization for
multiplication against boolean value
Andrew, Raphael and I have all poked at it in various ways over the last
year
or so. I think when Raphael and I first looked at it I sent us down a bit
of
rathole.
In particular it's odd that we're using a multiply to implement a select
and it
seemed like recognizing the idiom and rewriting into a conditional move was
the
right path. That looked reasonably good for the test, but runs into
problems
with min/max detection elsewhere.
I think that initial investigation somewhat polluted our thinking. The
regression can be fixed with a fairly simple match.pd pattern.
Essentially we want to handle
x * (x || b) -> x
x * !(x || b) -> 0
There's simplifications that can be made for "&&" cases, but I haven't seen
them in practice. Rather than drop in untested patterns, I'm leaving that
as a
future todo.
My original was two match.pd patterns. Andrew combined them into a single
pattern. I've made this conditional on GIMPLE as an earlier version that
simplified to a conditional move showed that when applied on GENERIC we
could
drop an operand with a side effect which is clearly not good.
I've bootstrapped and regression tested this on x86. I've also tested on
the
various embedded targets in my tester.
PR tree-optimization/114277
gcc/
* match.pd (a * (a || b) -> a): New pattern.
(a * !(a || b) -> 0): Likewise.
gcc/testsuite
* gcc.target/i386/pr114277.c: New test.
* gcc.target/riscv/pr114277.c: Likewise.
Co-author: Andrew Pinski <quic_apinski@quicinc.com>
More information about the Gcc-bugs
mailing list