public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/65440] New: pass_lim misses support for predicated code motion
@ 2015-03-16 14:27 vries at gcc dot gnu.org
  2015-03-16 14:39 ` [Bug tree-optimization/65440] " vries at gcc dot gnu.org
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: vries at gcc dot gnu.org @ 2015-03-16 14:27 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 65440
           Summary: pass_lim misses support for predicated code motion
           Product: gcc
           Version: 5.0
            Status: UNCONFIRMED
          Severity: enhancement
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: vries at gcc dot gnu.org

tree-ssa-loop-im.c (
https://gcc.gnu.org/git/?p=gcc.git;a=blob;f=gcc/tree-ssa-loop-im.c;h=9aba79ba776944ec6fba8459354deabe8c126b75;hb=HEAD#l74
):
...
/* TODO:  Support for predicated code motion.  I.e.

   while (1)
     {
       if (cond)
     {
       a = inv;
       something;
     }
     }

   Where COND and INV are invariants, but evaluating INV may trap or be
   invalid from some other reason if !COND.  This may be transformed to

   if (cond)
     a = inv;
   while (1)
     {
       if (cond)
     something;
     }  */
...


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

* [Bug tree-optimization/65440] pass_lim misses support for predicated code motion
  2015-03-16 14:27 [Bug tree-optimization/65440] New: pass_lim misses support for predicated code motion vries at gcc dot gnu.org
@ 2015-03-16 14:39 ` vries at gcc dot gnu.org
  2015-03-16 14:58 ` vries at gcc dot gnu.org
  2015-03-18 11:36 ` rguenth at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: vries at gcc dot gnu.org @ 2015-03-16 14:39 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from vries at gcc dot gnu.org ---
Concrete example ( based on example at
https://gcc.gnu.org/git/?p=gcc.git;a=blob;f=gcc/tree-ssa-loop-im.c;h=9aba79ba776944ec6fba8459354deabe8c126b75;hb=HEAD#l333)

test.c:
...
#include <string.h>

const char *something (void);

size_t
f (unsigned int n)
{
  const char *s = something ();
  size_t sum = 0;
  size_t t;
  unsigned int i;

  for (i = 0; i < n; ++i)
    {
      if (s)
        t = strlen (s);
      else
        t = i * 2;
      sum += t;
    }
  return sum;
}
...


The resulting code with -O2 from the optimized dump is: 
...
f (unsigned int n)
{
  unsigned int i;
  size_t t;
  size_t sum;
  const char * s;
  unsigned int _9;

  <bb 2>:
  s_6 = something ();
  if (n_7(D) != 0)
    goto <bb 3>;
  else
    goto <bb 8>;

  <bb 3>:
  # sum_13 = PHI <0(2)>
  # i_1 = PHI <0(2)>

  <bb 4>:
  # sum_14 = PHI <sum_13(3), sum_11(7)>
  # i_17 = PHI <i_1(3), i_12(7)>
  if (s_6 != 0B)
    goto <bb 5>;
  else
    goto <bb 6>;

  <bb 5>:
  t_8 = strlen (s_6);
  goto <bb 7>;

  <bb 6>:
  _9 = i_17 * 2;
  t_10 = (size_t) _9;

  <bb 7>:
  # t_2 = PHI <t_8(5), t_10(6)>
  sum_11 = t_2 + sum_14;
  i_12 = i_17 + 1;
  if (n_7(D) != i_12)
    goto <bb 4>;
  else
    goto <bb 8>;

  <bb 8>:
  # sum_16 = PHI <sum_11(7), 0(2)>
  return sum_16;

}
...

[ The same code is generated with -O3 -fno-tree-vectorize -fno-unswitch-loops.
-funswitch-loops manages to take the strlen out of the loop, but by generating
two loops. ]


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

* [Bug tree-optimization/65440] pass_lim misses support for predicated code motion
  2015-03-16 14:27 [Bug tree-optimization/65440] New: pass_lim misses support for predicated code motion vries at gcc dot gnu.org
  2015-03-16 14:39 ` [Bug tree-optimization/65440] " vries at gcc dot gnu.org
@ 2015-03-16 14:58 ` vries at gcc dot gnu.org
  2015-03-18 11:36 ` rguenth at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: vries at gcc dot gnu.org @ 2015-03-16 14:58 UTC (permalink / raw)
  To: gcc-bugs

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

vries at gcc dot gnu.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |missed-optimization

--- Comment #2 from vries at gcc dot gnu.org ---
See also related PR65442 - pass_lim misses support for exit-first loops


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

* [Bug tree-optimization/65440] pass_lim misses support for predicated code motion
  2015-03-16 14:27 [Bug tree-optimization/65440] New: pass_lim misses support for predicated code motion vries at gcc dot gnu.org
  2015-03-16 14:39 ` [Bug tree-optimization/65440] " vries at gcc dot gnu.org
  2015-03-16 14:58 ` vries at gcc dot gnu.org
@ 2015-03-18 11:36 ` rguenth at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: rguenth at gcc dot gnu.org @ 2015-03-18 11:36 UTC (permalink / raw)
  To: gcc-bugs

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

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2015-03-18
     Ever confirmed|0                           |1

--- Comment #3 from Richard Biener <rguenth at gcc dot gnu.org> ---
Confirmed.  We might already have a bug for this...


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

end of thread, other threads:[~2015-03-18 11:36 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-03-16 14:27 [Bug tree-optimization/65440] New: pass_lim misses support for predicated code motion vries at gcc dot gnu.org
2015-03-16 14:39 ` [Bug tree-optimization/65440] " vries at gcc dot gnu.org
2015-03-16 14:58 ` vries at gcc dot gnu.org
2015-03-18 11:36 ` rguenth 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).