public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/62217] New: Extra iteration peeled during cunroll. Makes VRP warn.
@ 2014-08-21 13:31 kyukhin at gcc dot gnu.org
  2014-08-22  4:41 ` [Bug tree-optimization/62217] " pinskia at gcc dot gnu.org
                   ` (19 more replies)
  0 siblings, 20 replies; 21+ messages in thread
From: kyukhin at gcc dot gnu.org @ 2014-08-21 13:31 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 62217
           Summary: Extra iteration peeled during cunroll. Makes VRP warn.
           Product: gcc
           Version: 4.9.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: kyukhin at gcc dot gnu.org

Suppose we have a test:

typedef struct { unsigned data; } s1;
s1 g_x[4];

extern void foo (s1 *x1, s1 *x2, int a, int b)
{
  int i;
  for(i = 0; i < a; i++)
    if(i == b)
      g_x[i] = *x1;
    else
      g_x[i] = *x2;
}

$ ./build-x86_64-linux/gcc/xgcc -B./build-x86_64-linux/gcc -O3 -Wall -S x1.c
x1.c: In function ‘foo’:
x1.c:9:10: warning: array subscript is above array bounds [-Warray-bounds]
       g_x[i] = *x1;
          ^
Which come from second pass of VRP:
  # i_14 = PHI <4(14)>
  if (b_6(D) == 4)
    goto <bb 17>;
  else
    goto <bb 18>;

  <bb 17>:
  g_x[4] = *x1_7(D);
  i_11 = 5;
  goto <bb 3>;

  <bb 18>:
  __builtin_unreachable ();

VRP checker fairly warns that g_x[4] is out-of-bounds mem ref.

This code was generated by tree-ssa-loop-ivcanon.c

I do not completely understand logic of cunroll pass,
however dumps say:

Loop 1 iterates at most 4 times.
...
x1.c:7:3: note: loop with 5 iterations completely unrolled
Last iteration exit edge was proved true.
Forced statement unreachable: g_x[i_14] = *x2_9(D);

In function `try_unroll_loop_completely' argument `maxiter'
equals to 4, which is correct. Then (through n_unroll var)
this value is passed to `gimple_duplicate_loop_to_header_edge'
routine, which perform the peeling. This routine as far
as I understand perform peel `n_unroll' copies from original
loop, resulting to (n_unroll+1) overall copies (including original
loop).

I think of 2 solutions:
- Reduce peel number by 1
- Improve remove_exits_and_undefined_stmts (), which correctly
  insert `gcc_unreachable' for `false' part of the if-stmt on
  5-th iteration.

It obviously don't warns, when limit is reduced:
./build-x86_64-linux/gcc/xgcc -B./build-x86_64-linux/gcc -O3 -Wall  -msse3  -c
-m32  x1.c --param max-completely-peel-times=3
>From gcc-bugs-return-458965-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org Thu Aug 21 13:48:52 2014
Return-Path: <gcc-bugs-return-458965-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org>
Delivered-To: listarch-gcc-bugs@gcc.gnu.org
Received: (qmail 15758 invoked by alias); 21 Aug 2014 13:48:52 -0000
Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm
Precedence: bulk
List-Id: <gcc-bugs.gcc.gnu.org>
List-Archive: <http://gcc.gnu.org/ml/gcc-bugs/>
List-Post: <mailto:gcc-bugs@gcc.gnu.org>
List-Help: <mailto:gcc-bugs-help@gcc.gnu.org>
Sender: gcc-bugs-owner@gcc.gnu.org
Delivered-To: mailing list gcc-bugs@gcc.gnu.org
Received: (qmail 15716 invoked by uid 48); 21 Aug 2014 13:48:49 -0000
From: "hp at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug lto/62213] [5 Rgression] ICE in lto for test case 20081120-1
Date: Thu, 21 Aug 2014 13:48:00 -0000
X-Bugzilla-Reason: CC
X-Bugzilla-Type: changed
X-Bugzilla-Watch-Reason: None
X-Bugzilla-Product: gcc
X-Bugzilla-Component: lto
X-Bugzilla-Version: 5.0
X-Bugzilla-Keywords:
X-Bugzilla-Severity: normal
X-Bugzilla-Who: hp at gcc dot gnu.org
X-Bugzilla-Status: NEW
X-Bugzilla-Priority: P3
X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org
X-Bugzilla-Target-Milestone: 5.0
X-Bugzilla-Flags:
X-Bugzilla-Changed-Fields: cc
Message-ID: <bug-62213-4-JA96V89qsN@http.gcc.gnu.org/bugzilla/>
In-Reply-To: <bug-62213-4@http.gcc.gnu.org/bugzilla/>
References: <bug-62213-4@http.gcc.gnu.org/bugzilla/>
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: 7bit
X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/
Auto-Submitted: auto-generated
MIME-Version: 1.0
X-SW-Source: 2014-08/txt/msg01462.txt.bz2
Content-length: 408

https://gcc.gnu.org/bugzilla/show_bug.cgi?idb213

Hans-Peter Nilsson <hp at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |hp at gcc dot gnu.org

--- Comment #2 from Hans-Peter Nilsson <hp at gcc dot gnu.org> ---
cris-elf too, (214220:214238].


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

end of thread, other threads:[~2015-06-26 20:29 UTC | newest]

Thread overview: 21+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-08-21 13:31 [Bug tree-optimization/62217] New: Extra iteration peeled during cunroll. Makes VRP warn kyukhin at gcc dot gnu.org
2014-08-22  4:41 ` [Bug tree-optimization/62217] " pinskia at gcc dot gnu.org
2014-08-22  7:00 ` pinskia at gcc dot gnu.org
2014-08-22  7:45 ` [Bug tree-optimization/62217] DOM confuses complete unrolling which in turn causes VRP to warn kyukhin at gcc dot gnu.org
2014-08-26 11:16 ` [Bug tree-optimization/62217] [4.9/5 Regression] " rguenth at gcc dot gnu.org
2014-10-30 10:39 ` jakub at gcc dot gnu.org
2014-11-24 13:07 ` rguenth at gcc dot gnu.org
2015-02-12 22:42 ` law at redhat dot com
2015-02-13  9:16 ` rguenth at gcc dot gnu.org
2015-02-13 23:29 ` law at redhat dot com
2015-02-16  8:55 ` rguenther at suse dot de
2015-02-16 19:05 ` law at redhat dot com
2015-02-17  9:44 ` rguenther at suse dot de
2015-02-17 14:31 ` rguenth at gcc dot gnu.org
2015-02-17 15:02 ` rguenth at gcc dot gnu.org
2015-02-17 15:40 ` law at redhat dot com
2015-02-17 20:01 ` law at redhat dot com
2015-02-18  9:49 ` rguenth at gcc dot gnu.org
2015-02-18  9:49 ` [Bug tree-optimization/62217] [4.9 " rguenth at gcc dot gnu.org
2015-06-26 19:59 ` jakub at gcc dot gnu.org
2015-06-26 20:29 ` jakub 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).