public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/50286] New: Missed optimization, fails to propagate bool
@ 2011-09-03 23:35 gmaxwell at gmail dot com
  2011-12-14 23:27 ` [Bug c/50286] " pinskia at gcc dot gnu.org
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: gmaxwell at gmail dot com @ 2011-09-03 23:35 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50286

             Bug #: 50286
           Summary: Missed optimization, fails to propagate bool
    Classification: Unclassified
           Product: gcc
           Version: 4.7.0
            Status: UNCONFIRMED
          Severity: minor
          Priority: P3
         Component: c
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: gmaxwell@gmail.com


GCC 4.7.0 (and prior) are unable to determine maximum loop counts in code that
looks like:

#include <stdio.h>
int main(int argc, char **argv)
{
  int i;
  const int flag=argc>1;
  i=0;
  do{
    printf("%d\n",i*i);
  }while(++i<1+flag);
  return 0;
}

and so it doesn't unroll the loop.

If 1+flag is changed to 1+!!flag, 1+(bool)flag, or 1+(argc>1) then -O3 unrolls
the loop.

Interestingly, making flag type bool doesn't fix it and also doesn't unroll in
the 1+!!flag case.


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug c/50286] Missed optimization, fails to propagate bool
  2011-09-03 23:35 [Bug c/50286] New: Missed optimization, fails to propagate bool gmaxwell at gmail dot com
@ 2011-12-14 23:27 ` pinskia at gcc dot gnu.org
  2021-07-26 19:12 ` [Bug tree-optimization/50286] " pinskia at gcc dot gnu.org
  2023-05-30 19:18 ` pinskia at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu.org @ 2011-12-14 23:27 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50286

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |missed-optimization
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2011-12-14
     Ever Confirmed|0                           |1

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> 2011-12-14 23:23:20 UTC ---
++i<1+flag gets changed to:
++i<=flag

Which we don't turn back into:
++i<(flag?1:2)


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug tree-optimization/50286] Missed optimization, fails to propagate bool
  2011-09-03 23:35 [Bug c/50286] New: Missed optimization, fails to propagate bool gmaxwell at gmail dot com
  2011-12-14 23:27 ` [Bug c/50286] " pinskia at gcc dot gnu.org
@ 2021-07-26 19:12 ` pinskia at gcc dot gnu.org
  2023-05-30 19:18 ` pinskia at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-07-26 19:12 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=50286

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|2011-12-14 00:00:00         |2021-7-26

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
EVRP is able to convert the loop to:
  <bb 3> :
  # i_3 = PHI <0(2), 1(3)>
  _2 = i_3 * i_3;
  printf ("%d\n", _2);
  i_10 = i_3 == 0 ? 1 : 2;
  if (flag_6 >= i_10)
    goto <bb 3>; [INV]
  else
    goto <bb 4>; [INV]

flag_6 range is [0,1] even

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug tree-optimization/50286] Missed optimization, fails to propagate bool
  2011-09-03 23:35 [Bug c/50286] New: Missed optimization, fails to propagate bool gmaxwell at gmail dot com
  2011-12-14 23:27 ` [Bug c/50286] " pinskia at gcc dot gnu.org
  2021-07-26 19:12 ` [Bug tree-optimization/50286] " pinskia at gcc dot gnu.org
@ 2023-05-30 19:18 ` pinskia at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-05-30 19:18 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=50286

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |FIXED
             Status|NEW                         |RESOLVED
   Target Milestone|---                         |13.0

--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Fixed in GCC 13.

Checking profitability of path (backwards):  bb:3 (8 insns) bb:5 (latch)
  Control statement insns: 2
  Overall: 6 insns

 Registering killing_def (path_oracle) i_9
 Registering killing_def (path_oracle) _10
 Registering killing_def (path_oracle) _11
Checking profitability of path (backwards): 
  [1] Registering jump thread: (5, 3) incoming edge;  (3, 4) nocopy; 
path: 5->3->4 SUCCESS
Jump threading proved probability of edge 3->4 too small (it is 11.0% (guessed)
should be always (guessed))

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2023-05-30 19:18 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-09-03 23:35 [Bug c/50286] New: Missed optimization, fails to propagate bool gmaxwell at gmail dot com
2011-12-14 23:27 ` [Bug c/50286] " pinskia at gcc dot gnu.org
2021-07-26 19:12 ` [Bug tree-optimization/50286] " pinskia at gcc dot gnu.org
2023-05-30 19:18 ` 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).