public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/102155] New: LIM fill_always_executed_in handles contains_call incorrectly
@ 2021-09-01  7:09 rguenth at gcc dot gnu.org
  2021-09-01  7:58 ` [Bug tree-optimization/102155] " rguenth at gcc dot gnu.org
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: rguenth at gcc dot gnu.org @ 2021-09-01  7:09 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 102155
           Summary: LIM fill_always_executed_in handles contains_call
                    incorrectly
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: rguenth at gcc dot gnu.org
  Target Milestone: ---

fill_always_executed_in walks loop bodies in dominator order
(get_loop_body_in_dom_order) but that does not run into BB3 before marking BB4
as always executed:

  do
    {
      BB1:
      if (x)
        BB2:
        if (y)
          BB3:
          bar();
      BB4;
    }
  while (++i < n);


the dominator children of BB1 are BB2 and BB4, BB3 with the call to bar()
is only a dominator child of BB2.

Since LIM gives up on "unanalyzable" refs like calls a testcase that is
miscompiled is a bit difficult to construct - it requires a 'pure' (or const)
call but whether it's valid for those to exit the program could be subject
to discussion.  The following uses a looping const function to show the
effect and the testcase segfaults with -O1+ while it runs into the infinite
loop at -O0.  Note we'd technically need to set looping_const but there's
now way to do this and with just -fno-inline and letting IPA figure out
looping-const dominator children are ordered in a "lucky" way for
fill_sons_in_loop to compute an order that happens to work.

extern void abort (void);
int flag[32];
int __attribute__((noinline,const)) bar (int i) { if (i) return i; while (1); }
int __attribute__((noipa)) foo (int *p, int n)
{
  int i = 0, res = 0;
  do
    {
      if (!flag[i])
        {
          if (i % 3 == 0)
            res += bar (i);
          else
            res++;
        }
      res += *p;
    }
  while (++i < n);
  return res;
}

int main()
{
  if (foo ((int *)0, 5) != 0)
    abort ();
  return 0;
}

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

* [Bug tree-optimization/102155] LIM fill_always_executed_in handles contains_call incorrectly
  2021-09-01  7:09 [Bug tree-optimization/102155] New: LIM fill_always_executed_in handles contains_call incorrectly rguenth at gcc dot gnu.org
@ 2021-09-01  7:58 ` rguenth at gcc dot gnu.org
  2021-09-02  5:55 ` cvs-commit at gcc dot gnu.org
  2021-09-02  7:56 ` rguenth at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: rguenth at gcc dot gnu.org @ 2021-09-01  7:58 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|                            |2021-09-01
           Assignee|unassigned at gcc dot gnu.org      |rguenth at gcc dot gnu.org
             Status|UNCONFIRMED                 |ASSIGNED
     Ever confirmed|0                           |1

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

* [Bug tree-optimization/102155] LIM fill_always_executed_in handles contains_call incorrectly
  2021-09-01  7:09 [Bug tree-optimization/102155] New: LIM fill_always_executed_in handles contains_call incorrectly rguenth at gcc dot gnu.org
  2021-09-01  7:58 ` [Bug tree-optimization/102155] " rguenth at gcc dot gnu.org
@ 2021-09-02  5:55 ` cvs-commit at gcc dot gnu.org
  2021-09-02  7:56 ` rguenth at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2021-09-02  5:55 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Richard Biener <rguenth@gcc.gnu.org>:

https://gcc.gnu.org/g:f482bf2af86990329b4df660f8c1eb9e094de9f9

commit r12-3307-gf482bf2af86990329b4df660f8c1eb9e094de9f9
Author: Richard Biener <rguenther@suse.de>
Date:   Wed Sep 1 09:51:45 2021 +0200

    tree-optimization/102155 - fix LIM fill_always_executed_in CFG walk

    This fixes the CFG walk order of fill_always_executed_in to use
    RPO oder rather than the dominator based order computed by
    get_loop_body_in_dom_order.  That fixes correctness issues with
    unordered dominator children.

    The RPO order computed by rev_post_order_and_mark_dfs_back_seme in
    its for-iteration mode is a good match for the algorithm.

    2021-09-01  Richard Biener  <rguenther@suse.de>

            PR tree-optimization/102155
            * tree-ssa-loop-im.c (fill_always_executed_in_1): Iterate
            over a part of the RPO array and do not recurse here.
            Dump blocks marked as always executed.
            (fill_always_executed_in): Walk over the RPO array and
            process loops whose header we run into.
            (loop_invariant_motion_in_fun): Compute the first RPO
            using rev_post_order_and_mark_dfs_back_seme in iteration
            order and pass that to fill_always_executed_in.

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

* [Bug tree-optimization/102155] LIM fill_always_executed_in handles contains_call incorrectly
  2021-09-01  7:09 [Bug tree-optimization/102155] New: LIM fill_always_executed_in handles contains_call incorrectly rguenth at gcc dot gnu.org
  2021-09-01  7:58 ` [Bug tree-optimization/102155] " rguenth at gcc dot gnu.org
  2021-09-02  5:55 ` cvs-commit at gcc dot gnu.org
@ 2021-09-02  7:56 ` rguenth at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: rguenth at gcc dot gnu.org @ 2021-09-02  7:56 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |INVALID
             Status|ASSIGNED                    |RESOLVED

--- Comment #2 from Richard Biener <rguenth at gcc dot gnu.org> ---
It seems I was mistaken, get_loop_body_in_dom_order seems to exactly care for
this specific case.

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

end of thread, other threads:[~2021-09-02  7:56 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-01  7:09 [Bug tree-optimization/102155] New: LIM fill_always_executed_in handles contains_call incorrectly rguenth at gcc dot gnu.org
2021-09-01  7:58 ` [Bug tree-optimization/102155] " rguenth at gcc dot gnu.org
2021-09-02  5:55 ` cvs-commit at gcc dot gnu.org
2021-09-02  7:56 ` 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).