public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug rtl-optimization/110087] New: Missing if conversion
@ 2023-06-02 9:39 ubizjak at gmail dot com
2023-06-02 9:47 ` [Bug rtl-optimization/110087] " ubizjak at gmail dot com
` (8 more replies)
0 siblings, 9 replies; 10+ messages in thread
From: ubizjak at gmail dot com @ 2023-06-02 9:39 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110087
Bug ID: 110087
Summary: Missing if conversion
Product: gcc
Version: 13.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: rtl-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: ubizjak at gmail dot com
Target Milestone: ---
Following testcase:
--cut here--
#include <stdbool.h>
_Bool foo (void);
_Bool bar (_Bool r)
{
if (foo ())
r = true;
return r;
}
--cut here--
compiles for x86_64 target (-O2) to:
movl %edi, %ebx
call foo
testb %al, %al
cmove %ebx, %eax
More optimal code would be:
movl %edi, %ebx
call foo
orb %bl, %al
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug rtl-optimization/110087] Missing if conversion
2023-06-02 9:39 [Bug rtl-optimization/110087] New: Missing if conversion ubizjak at gmail dot com
@ 2023-06-02 9:47 ` ubizjak at gmail dot com
2023-06-02 9:48 ` [Bug tree-optimization/110087] " rguenth at gcc dot gnu.org
` (7 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: ubizjak at gmail dot com @ 2023-06-02 9:47 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110087
--- Comment #1 from Uroš Bizjak <ubizjak at gmail dot com> ---
BTW: If the result of foo is random, then cmove gets badly predicted.
Considering the problems with cmove on x86 (even without bad prediction), the
above optimization can be quite important. Clang does it.
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug tree-optimization/110087] Missing if conversion
2023-06-02 9:39 [Bug rtl-optimization/110087] New: Missing if conversion ubizjak at gmail dot com
2023-06-02 9:47 ` [Bug rtl-optimization/110087] " ubizjak at gmail dot com
@ 2023-06-02 9:48 ` rguenth at gcc dot gnu.org
2023-06-02 10:11 ` amonakov at gcc dot gnu.org
` (6 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: rguenth at gcc dot gnu.org @ 2023-06-02 9:48 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110087
Richard Biener <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Component|rtl-optimization |tree-optimization
Ever confirmed|0 |1
Status|UNCONFIRMED |NEW
Keywords| |missed-optimization
Last reconfirmed| |2023-06-02
CC| |pinskia at gcc dot gnu.org
--- Comment #2 from Richard Biener <rguenth at gcc dot gnu.org> ---
_Bool _1;
<bb 2> :
_1 = foo ();
if (_1 != 0)
goto <bb 3>; [INV]
else
goto <bb 4>; [INV]
<bb 3> :
<bb 4> :
# r_2 = PHI <r_5(D)(2), 1(3)>
return r_2;
I wonder if we should address this in PHI-OPT and transform it to
r_2 = r_5(D) | _1;
there? There's zero_one_valued_p we could use for both the
tested value and the value or-ed into.
We already have
/* ((x & 0x1) == 0) ? y : z <op> y -> (-(typeof(y))(x & 0x1) & z) <op> y */
and
/* ((x & 0x1) == 0) ? z <op> y : y -> (-(typeof(y))(x & 0x1) & z) <op> y */
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug tree-optimization/110087] Missing if conversion
2023-06-02 9:39 [Bug rtl-optimization/110087] New: Missing if conversion ubizjak at gmail dot com
2023-06-02 9:47 ` [Bug rtl-optimization/110087] " ubizjak at gmail dot com
2023-06-02 9:48 ` [Bug tree-optimization/110087] " rguenth at gcc dot gnu.org
@ 2023-06-02 10:11 ` amonakov at gcc dot gnu.org
2023-06-02 14:12 ` pinskia at gcc dot gnu.org
` (5 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: amonakov at gcc dot gnu.org @ 2023-06-02 10:11 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110087
Alexander Monakov <amonakov at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |amonakov at gcc dot gnu.org
--- Comment #3 from Alexander Monakov <amonakov at gcc dot gnu.org> ---
(In reply to Uroš Bizjak from comment #1)
> BTW: If the result of foo is random, then cmove gets badly predicted.
> Considering the problems with cmove on x86 (even without bad prediction),
> the above optimization can be quite important. Clang does it.
There is no prediction involved in execution of CMOV. It is one ALU uop with
latency 1 on any recent x86, or two uops with latency 1 on Haswell, going back
to Intel Core: https://uops.info/html-instr/CMOVZ_R32_R32.html
If you convert a control dependency to a data dependency with CMOV you may end
up with slower code due to longer dependency chains, but this is not the case
here.
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug tree-optimization/110087] Missing if conversion
2023-06-02 9:39 [Bug rtl-optimization/110087] New: Missing if conversion ubizjak at gmail dot com
` (2 preceding siblings ...)
2023-06-02 10:11 ` amonakov at gcc dot gnu.org
@ 2023-06-02 14:12 ` pinskia at gcc dot gnu.org
2023-06-02 14:17 ` pinskia at gcc dot gnu.org
` (4 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-06-02 14:12 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110087
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Assignee|unassigned at gcc dot gnu.org |pinskia at gcc dot gnu.org
Status|NEW |ASSIGNED
--- Comment #4 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
I have a patch that converts this into the or.
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug tree-optimization/110087] Missing if conversion
2023-06-02 9:39 [Bug rtl-optimization/110087] New: Missing if conversion ubizjak at gmail dot com
` (3 preceding siblings ...)
2023-06-02 14:12 ` pinskia at gcc dot gnu.org
@ 2023-06-02 14:17 ` pinskia at gcc dot gnu.org
2023-06-02 19:42 ` pinskia at gcc dot gnu.org
` (3 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-06-02 14:17 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110087
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|ASSIGNED |RESOLVED
Resolution|--- |DUPLICATE
--- Comment #5 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Really this is a dup of bug 89263.
*** This bug has been marked as a duplicate of bug 89263 ***
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug tree-optimization/110087] Missing if conversion
2023-06-02 9:39 [Bug rtl-optimization/110087] New: Missing if conversion ubizjak at gmail dot com
` (4 preceding siblings ...)
2023-06-02 14:17 ` pinskia at gcc dot gnu.org
@ 2023-06-02 19:42 ` pinskia at gcc dot gnu.org
2023-06-07 12:03 ` ubizjak at gmail dot com
` (2 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-06-02 19:42 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110087
--- Comment #6 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to Richard Biener from comment #2)
> there? There's zero_one_valued_p we could use for both the
> tested value and the value or-ed into.
>
> We already have
>
> /* ((x & 0x1) == 0) ? y : z <op> y -> (-(typeof(y))(x & 0x1) & z) <op> y */
>
> and
>
> /* ((x & 0x1) == 0) ? z <op> y : y -> (-(typeof(y))(x & 0x1) & z) <op> y */
That is exactly what my patch does (I put it in PR 89263), I was going to
submit this patch a couple of days ago but got side tracked with other fixes
not to add the testcases to the patch and submit it.
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug tree-optimization/110087] Missing if conversion
2023-06-02 9:39 [Bug rtl-optimization/110087] New: Missing if conversion ubizjak at gmail dot com
` (5 preceding siblings ...)
2023-06-02 19:42 ` pinskia at gcc dot gnu.org
@ 2023-06-07 12:03 ` ubizjak at gmail dot com
2023-06-07 12:10 ` pinskia at gcc dot gnu.org
2023-06-07 12:21 ` ubizjak at gmail dot com
8 siblings, 0 replies; 10+ messages in thread
From: ubizjak at gmail dot com @ 2023-06-07 12:03 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110087
--- Comment #7 from Uroš Bizjak <ubizjak at gmail dot com> ---
Similar conversion, not performed by gcc:
--cut here--
#include <stdbool.h>
_Bool foo (void);
int bar (int r)
{
if (foo ())
r++;
return r;
}
--cut here--
gcc -O2:
movl %edi, %ebx
call foo
cmpb $1, %al
sbbl $-1, %ebx
movl %ebx, %eax
could be:
movl %edi, %ebx
callq foo
movzbl %al, %eax
addl %ebx, %eax
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug tree-optimization/110087] Missing if conversion
2023-06-02 9:39 [Bug rtl-optimization/110087] New: Missing if conversion ubizjak at gmail dot com
` (6 preceding siblings ...)
2023-06-07 12:03 ` ubizjak at gmail dot com
@ 2023-06-07 12:10 ` pinskia at gcc dot gnu.org
2023-06-07 12:21 ` ubizjak at gmail dot com
8 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-06-07 12:10 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110087
--- Comment #8 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to Uroš Bizjak from comment #7)
> Similar conversion, not performed by gcc:
>
> --cut here--
> #include <stdbool.h>
>
> _Bool foo (void);
>
> int bar (int r)
> {
> if (foo ())
> r++;
>
> return r;
> }
> --cut here--
>
> gcc -O2:
>
> movl %edi, %ebx
> call foo
> cmpb $1, %al
> sbbl $-1, %ebx
> movl %ebx, %eax
>
> could be:
>
> movl %edi, %ebx
> callq foo
> movzbl %al, %eax
> addl %ebx, %eax
Please file this separately, since it is a different issue. Though I think
there are dups of that one too.
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug tree-optimization/110087] Missing if conversion
2023-06-02 9:39 [Bug rtl-optimization/110087] New: Missing if conversion ubizjak at gmail dot com
` (7 preceding siblings ...)
2023-06-07 12:10 ` pinskia at gcc dot gnu.org
@ 2023-06-07 12:21 ` ubizjak at gmail dot com
8 siblings, 0 replies; 10+ messages in thread
From: ubizjak at gmail dot com @ 2023-06-07 12:21 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110087
--- Comment #9 from Uroš Bizjak <ubizjak at gmail dot com> ---
(In reply to Andrew Pinski from comment #8)
> Please file this separately, since it is a different issue.
PR110155.
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2023-06-07 12:21 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-02 9:39 [Bug rtl-optimization/110087] New: Missing if conversion ubizjak at gmail dot com
2023-06-02 9:47 ` [Bug rtl-optimization/110087] " ubizjak at gmail dot com
2023-06-02 9:48 ` [Bug tree-optimization/110087] " rguenth at gcc dot gnu.org
2023-06-02 10:11 ` amonakov at gcc dot gnu.org
2023-06-02 14:12 ` pinskia at gcc dot gnu.org
2023-06-02 14:17 ` pinskia at gcc dot gnu.org
2023-06-02 19:42 ` pinskia at gcc dot gnu.org
2023-06-07 12:03 ` ubizjak at gmail dot com
2023-06-07 12:10 ` pinskia at gcc dot gnu.org
2023-06-07 12:21 ` ubizjak at gmail dot com
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).