[Bug tree-optimization/110087] Missing if conversion
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110087 --- Comment #9 from Uroš Bizjak --- (In reply to Andrew Pinski from comment #8) > Please file this separately, since it is a different issue. PR110155.
[Bug tree-optimization/110087] Missing if conversion
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110087 --- Comment #8 from Andrew Pinski --- (In reply to Uroš Bizjak from comment #7) > Similar conversion, not performed by gcc: > > --cut here-- > #include > > _Bool foo (void); > > int bar (int r) > { > if (foo ()) > r++; > > return r; > } > --cut here-- > > gcc -O2: > > movl%edi, %ebx > callfoo > 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.
[Bug tree-optimization/110087] Missing if conversion
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110087 --- Comment #7 from Uroš Bizjak --- Similar conversion, not performed by gcc: --cut here-- #include _Bool foo (void); int bar (int r) { if (foo ()) r++; return r; } --cut here-- gcc -O2: movl%edi, %ebx callfoo cmpb$1, %al sbbl$-1, %ebx movl%ebx, %eax could be: movl%edi, %ebx callq foo movzbl %al, %eax addl%ebx, %eax
[Bug tree-optimization/110087] Missing if conversion
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110087 --- Comment #6 from Andrew Pinski --- (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 y -> (-(typeof(y))(x & 0x1) & z) y */ > > and > > /* ((x & 0x1) == 0) ? z y : y -> (-(typeof(y))(x & 0x1) & z) 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.
[Bug tree-optimization/110087] Missing if conversion
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110087 Andrew Pinski changed: What|Removed |Added Status|ASSIGNED|RESOLVED Resolution|--- |DUPLICATE --- Comment #5 from Andrew Pinski --- Really this is a dup of bug 89263. *** This bug has been marked as a duplicate of bug 89263 ***
[Bug tree-optimization/110087] Missing if conversion
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110087 Andrew Pinski 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 --- I have a patch that converts this into the or.
[Bug tree-optimization/110087] Missing if conversion
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110087 Alexander Monakov changed: What|Removed |Added CC||amonakov at gcc dot gnu.org --- Comment #3 from Alexander Monakov --- (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.
[Bug tree-optimization/110087] Missing if conversion
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110087 Richard Biener 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 --- _Bool _1; : _1 = foo (); if (_1 != 0) goto ; [INV] else goto ; [INV] : : # r_2 = PHI 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 y -> (-(typeof(y))(x & 0x1) & z) y */ and /* ((x & 0x1) == 0) ? z y : y -> (-(typeof(y))(x & 0x1) & z) y */