public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/95924] New: Failure to optimize some bit magic to one of the operands
@ 2020-06-27 1:06 gabravier at gmail dot com
2020-06-27 12:27 ` [Bug tree-optimization/95924] " glisse at gcc dot gnu.org
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: gabravier at gmail dot com @ 2020-06-27 1:06 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95924
Bug ID: 95924
Summary: Failure to optimize some bit magic to one of the
operands
Product: gcc
Version: 11.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: tree-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: gabravier at gmail dot com
Target Milestone: ---
bool f(bool a, bool b)
{
return (a | !b) ? (~a & b) ? 0 : a : 0;
}
This can be optimized to `return a;`. This transformation is done by LLVM, but
not by GCC.
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug tree-optimization/95924] Failure to optimize some bit magic to one of the operands
2020-06-27 1:06 [Bug tree-optimization/95924] New: Failure to optimize some bit magic to one of the operands gabravier at gmail dot com
@ 2020-06-27 12:27 ` glisse at gcc dot gnu.org
2021-07-25 4:53 ` pinskia at gcc dot gnu.org
2023-08-22 5:29 ` pinskia at gcc dot gnu.org
2 siblings, 0 replies; 4+ messages in thread
From: glisse at gcc dot gnu.org @ 2020-06-27 12:27 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95924
--- Comment #1 from Marc Glisse <glisse at gcc dot gnu.org> ---
* If I replace ~a with !a, we manage to do everything with type bool. With ~a,
we don't, we stick to int.
* We don't handle a?b:false the same as a&&b.
* Even for (a | !b) && (!(!a & b) && a) we don't completely simplify, because
that would be replacing too many && with & (I think). If I manually replace one
&& with &, gcc manages.
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug tree-optimization/95924] Failure to optimize some bit magic to one of the operands
2020-06-27 1:06 [Bug tree-optimization/95924] New: Failure to optimize some bit magic to one of the operands gabravier at gmail dot com
2020-06-27 12:27 ` [Bug tree-optimization/95924] " glisse at gcc dot gnu.org
@ 2021-07-25 4:53 ` pinskia at gcc dot gnu.org
2023-08-22 5:29 ` pinskia at gcc dot gnu.org
2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-07-25 4:53 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95924
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Severity|normal |enhancement
Ever confirmed|0 |1
Status|UNCONFIRMED |NEW
CC| |pinskia at gcc dot gnu.org
Last reconfirmed| |2021-07-25
--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Confirmed.
I have a few patches which improve this but the following still needs to be
done:
_3 = (int) a_9(D);
_4 = ~_3;
_5 = (int) b_8(D);
_6 = _4 & _5;
_7 = _6 == 0;
To:
_3 = ~a_9(D)
_7 = b_8(D) & _3
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug tree-optimization/95924] Failure to optimize some bit magic to one of the operands
2020-06-27 1:06 [Bug tree-optimization/95924] New: Failure to optimize some bit magic to one of the operands gabravier at gmail dot com
2020-06-27 12:27 ` [Bug tree-optimization/95924] " glisse at gcc dot gnu.org
2021-07-25 4:53 ` pinskia at gcc dot gnu.org
@ 2023-08-22 5:29 ` pinskia at gcc dot gnu.org
2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-08-22 5:29 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95924
--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
_4 = (int) a_11(D);
_5 = ~_4;
_6 = (int) b_10(D);
_7 = _5 & _6;
(simplify
(bit_and:c (bit_not zero_one_valued_p@0) zero_one_valued_p@1)
(bit_and @1 (bit_xor! @0 { build_one_cst (type); } )))
Might be enough.
_4 = ~_3;
# RANGE [irange] int [0, 1] MASK 0x1 VALUE 0x0
_5 = (intD.9) b_8(D);
# RANGE [irange] int [0, 1] MASK 0x1 VALUE 0x0
_6 = _4 & _5;
# RANGE [irange] int [0, 1]
_15 = _6 ^ 1;
Or even:
(simplify
(bit_xor (bit_and:c zero_one_valued_p@0 @1) integer_onep@2)
(bit_or (bit_xor @0 @2) (bit_not! @1)))
Or:
(simplify
(bit_xor (bit_and:c zero_one_valued_p@0 (bit_not @1)) integer_onep@2)
(bit_or (bit_xor @0 @2) @1))
All of the above will work just trying to figure out which one would be better
here ...
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2023-08-22 5:29 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-27 1:06 [Bug tree-optimization/95924] New: Failure to optimize some bit magic to one of the operands gabravier at gmail dot com
2020-06-27 12:27 ` [Bug tree-optimization/95924] " glisse at gcc dot gnu.org
2021-07-25 4:53 ` pinskia at gcc dot gnu.org
2023-08-22 5:29 ` pinskia at gcc dot gnu.org
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).