public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/56352] New: Simplify testing of related conditions in for loop
@ 2013-02-15 22:36 josh.m.conner at gmail dot com
  2021-08-07 23:17 ` [Bug tree-optimization/56352] " pinskia at gcc dot gnu.org
  2021-08-07 23:30 ` pinskia at gcc dot gnu.org
  0 siblings, 2 replies; 3+ messages in thread
From: josh.m.conner at gmail dot com @ 2013-02-15 22:36 UTC (permalink / raw)
  To: gcc-bugs


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

             Bug #: 56352
           Summary: Simplify testing of related conditions in for loop
    Classification: Unclassified
           Product: gcc
           Version: 4.8.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: josh.m.conner@gmail.com


If we have a loop like this:

for (i = 0; i < a && i < b; i++)
{
  /* Code which cannot affect i, a, or b */
}

gcc should be able to optimize this into:

tmp = MIN(a,b)
for (i = 0; i < tmp; i++)
{
  /* Body */
}

But it does not.  Similarly, code like:

for (i = 0; i < a; i++)
{
  if (i >= b)
    break;

  /* Code which cannot affect i, a, or b */
}

Should be similarly optimized.


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

* [Bug tree-optimization/56352] Simplify testing of related conditions in for loop
  2013-02-15 22:36 [Bug tree-optimization/56352] New: Simplify testing of related conditions in for loop josh.m.conner at gmail dot com
@ 2021-08-07 23:17 ` pinskia at gcc dot gnu.org
  2021-08-07 23:30 ` pinskia at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-08-07 23:17 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Testcase:

int f(int);
void g(int a, int b)
{
    int i;
for (i = 0; i < a; i++)
{
  if (i >= b)
    break;

  f(i);
}

}

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

* [Bug tree-optimization/56352] Simplify testing of related conditions in for loop
  2013-02-15 22:36 [Bug tree-optimization/56352] New: Simplify testing of related conditions in for loop josh.m.conner at gmail dot com
  2021-08-07 23:17 ` [Bug tree-optimization/56352] " pinskia at gcc dot gnu.org
@ 2021-08-07 23:30 ` pinskia at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-08-07 23:30 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |missed-optimization
             Status|UNCONFIRMED                 |RESOLVED
      Known to fail|                            |8.1.0, 8.5.0
         Resolution|---                         |DUPLICATE
      Known to work|                            |10.1.0, 9.1.0, 9.4.0

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
GCC9+ does the correct thing:
.L5:
        movl    %ebx, %edi
        addl    $1, %ebx
        call    f(int)
        cmpl    %ebx, %ebp
        jg      .L5

GCC 8.5 had:
  _9 = b_5(D) <= i_7;
  _8 = a_4(D) <= i_7;
  _10 = _8 | _9;

This was fixed by r9-104.
Note there is some issues with mixing constants and non-constants but that is
still recorded in PR 85143.
And really this is a dup of bug 85143.

*** This bug has been marked as a duplicate of bug 85143 ***

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

end of thread, other threads:[~2021-08-07 23:30 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-02-15 22:36 [Bug tree-optimization/56352] New: Simplify testing of related conditions in for loop josh.m.conner at gmail dot com
2021-08-07 23:17 ` [Bug tree-optimization/56352] " pinskia at gcc dot gnu.org
2021-08-07 23:30 ` 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).