public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/107880] New: bool tautology missed optimisation
@ 2022-11-26 18:03 pinskia at gcc dot gnu.org
2022-11-26 18:06 ` [Bug tree-optimization/107880] " pinskia at gcc dot gnu.org
` (6 more replies)
0 siblings, 7 replies; 8+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-11-26 18:03 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107880
Bug ID: 107880
Summary: bool tautology missed optimisation
Product: gcc
Version: 13.0
Status: UNCONFIRMED
Keywords: missed-optimization
Severity: enhancement
Priority: P3
Component: tree-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: pinskia at gcc dot gnu.org
Target Milestone: ---
From bug 91882 comment #1 (since the testcase in that was in bug 91882 comment
#0 is now fixed):
bool impl(bool a, bool b)
{
return (!a || b);
}
// bad optimisation
bool always_true(bool a, bool b)
{
return (impl(a,b) == impl(b,a)) == (a == b);
// ( (a -> b) = (b -> a) ) = (a = b) tautology
}
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug tree-optimization/107880] bool tautology missed optimisation
2022-11-26 18:03 [Bug tree-optimization/107880] New: bool tautology missed optimisation pinskia at gcc dot gnu.org
@ 2022-11-26 18:06 ` pinskia at gcc dot gnu.org
2022-11-26 18:11 ` pinskia at gcc dot gnu.org
` (5 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-11-26 18:06 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107880
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Ever confirmed|0 |1
Status|UNCONFIRMED |NEW
Last reconfirmed| |2022-11-26
--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
We get in optimized:
_9 = ~a_4(D);
_10 = b_3(D) | _9;
_7 = ~b_3(D);
_8 = a_4(D) | _7;
_1 = _8 == _10;
_2 = b_3(D) == a_4(D);
_6 = _1 == _2;
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug tree-optimization/107880] bool tautology missed optimisation
2022-11-26 18:03 [Bug tree-optimization/107880] New: bool tautology missed optimisation pinskia at gcc dot gnu.org
2022-11-26 18:06 ` [Bug tree-optimization/107880] " pinskia at gcc dot gnu.org
@ 2022-11-26 18:11 ` pinskia at gcc dot gnu.org
2023-05-24 1:15 ` pinskia at gcc dot gnu.org
` (4 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-11-26 18:11 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107880
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
See Also| |https://gcc.gnu.org/bugzill
| |a/show_bug.cgi?id=101807
--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
One way of fixing this is first transform:
_9 = ~a_4(D);
_10 = b_3(D) | _9;
Into:
_10 = a_4(D) <= b_3(D);
And then we have:
_8 = b_3(D) >= a_4(D);
_7 = b_3(D) <= a_4(D);
_1 = _7 == _8;
_2 = b_3(D) == a_4(D);
_6 = _1 == _2;
But _1 is true iff a_4(D) == b_3(D) .
Let me file that second one as we don't optimize it also for int.
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug tree-optimization/107880] bool tautology missed optimisation
2022-11-26 18:03 [Bug tree-optimization/107880] New: bool tautology missed optimisation pinskia at gcc dot gnu.org
2022-11-26 18:06 ` [Bug tree-optimization/107880] " pinskia at gcc dot gnu.org
2022-11-26 18:11 ` pinskia at gcc dot gnu.org
@ 2023-05-24 1:15 ` pinskia at gcc dot gnu.org
2023-08-28 20:36 ` pinskia at gcc dot gnu.org
` (3 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-05-24 1:15 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107880
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
See Also| |https://gcc.gnu.org/bugzill
| |a/show_bug.cgi?id=71762
--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Turns out this was there before but was removed (r7-4801-g0eb078fe20d443e2)
because it caused some issues.
See PR 71762 .
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug tree-optimization/107880] bool tautology missed optimisation
2022-11-26 18:03 [Bug tree-optimization/107880] New: bool tautology missed optimisation pinskia at gcc dot gnu.org
` (2 preceding siblings ...)
2023-05-24 1:15 ` pinskia at gcc dot gnu.org
@ 2023-08-28 20:36 ` pinskia at gcc dot gnu.org
2023-08-28 21:30 ` pinskia at gcc dot gnu.org
` (2 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-08-28 20:36 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107880
Bug 107880 depends on bug 107881, which changed state.
Bug 107881 Summary: (a <= b) == (b >= a) should be optimized to (a == b)
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107881
What |Removed |Added
----------------------------------------------------------------------------
Status|ASSIGNED |RESOLVED
Resolution|--- |DUPLICATE
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug tree-optimization/107880] bool tautology missed optimisation
2022-11-26 18:03 [Bug tree-optimization/107880] New: bool tautology missed optimisation pinskia at gcc dot gnu.org
` (3 preceding siblings ...)
2023-08-28 20:36 ` pinskia at gcc dot gnu.org
@ 2023-08-28 21:30 ` pinskia at gcc dot gnu.org
2023-08-28 22:52 ` pinskia at gcc dot gnu.org
2023-09-12 15:03 ` pinskia at gcc dot gnu.org
6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-08-28 21:30 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107880
Bug 107880 depends on bug 107881, which changed state.
Bug 107881 Summary: (a <= b) == (b >= a) should be optimized to (a == b)
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107881
What |Removed |Added
----------------------------------------------------------------------------
Status|RESOLVED |ASSIGNED
Resolution|DUPLICATE |---
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug tree-optimization/107880] bool tautology missed optimisation
2022-11-26 18:03 [Bug tree-optimization/107880] New: bool tautology missed optimisation pinskia at gcc dot gnu.org
` (4 preceding siblings ...)
2023-08-28 21:30 ` pinskia at gcc dot gnu.org
@ 2023-08-28 22:52 ` pinskia at gcc dot gnu.org
2023-09-12 15:03 ` pinskia at gcc dot gnu.org
6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-08-28 22:52 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107880
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |ASSIGNED
--- Comment #4 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
With a patch I have for PR 95185
we get:
```
_1 = b_2(D) == a_3(D);
_10 = b_2(D) ^ a_3(D);
_5 = _1 ^ _10;
```
Which is better than before.
One more improvement would be:
```
bool a(bool x, bool y)
{
bool t = x == y;
return t ^ x;
}
```
Into:
```
bool a0(bool x, bool y)
{
bool t = (x ^ y);
return t ^ x ^1; // ~y
}
```
So the 2 which are needed still:
/* (a == b) ^ a -> b^1 */
(simplify
(bit_xor:c (eq:c zero_one_valued_p@0 zero_one_valued_p@1) @0)
(bit_xor @1 { build_one_cst (type); })
/* (a == b) ^ (a^b) -> b^(b^1) or (b^b)^1 or rather 1 */
(simplify
(bit_xor:c (eq:c zero_one_valued_p@0 zero_one_valued_p@1) (bit_xor:c @0 @1))
{ build_one_cst (type); })
So mine.
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug tree-optimization/107880] bool tautology missed optimisation
2022-11-26 18:03 [Bug tree-optimization/107880] New: bool tautology missed optimisation pinskia at gcc dot gnu.org
` (5 preceding siblings ...)
2023-08-28 22:52 ` pinskia at gcc dot gnu.org
@ 2023-09-12 15:03 ` pinskia at gcc dot gnu.org
6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-09-12 15:03 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107880
Bug 107880 depends on bug 107881, which changed state.
Bug 107881 Summary: (a <= b) == (b >= a) should be optimized to (a == b)
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107881
What |Removed |Added
----------------------------------------------------------------------------
Status|ASSIGNED |RESOLVED
Resolution|--- |FIXED
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2023-09-12 15:03 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-26 18:03 [Bug tree-optimization/107880] New: bool tautology missed optimisation pinskia at gcc dot gnu.org
2022-11-26 18:06 ` [Bug tree-optimization/107880] " pinskia at gcc dot gnu.org
2022-11-26 18:11 ` pinskia at gcc dot gnu.org
2023-05-24 1:15 ` pinskia at gcc dot gnu.org
2023-08-28 20:36 ` pinskia at gcc dot gnu.org
2023-08-28 21:30 ` pinskia at gcc dot gnu.org
2023-08-28 22:52 ` pinskia at gcc dot gnu.org
2023-09-12 15:03 ` 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).