From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 32734 invoked by alias); 14 Jul 2014 08:56:31 -0000 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org Received: (qmail 32485 invoked by uid 48); 14 Jul 2014 08:56:24 -0000 From: "rguenth at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/61757] [4.10 Regression] genmodes failure with enable-checking Date: Mon, 14 Jul 2014 08:56:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: tree-optimization X-Bugzilla-Version: 4.10.0 X-Bugzilla-Keywords: build X-Bugzilla-Severity: normal X-Bugzilla-Who: rguenth at gcc dot gnu.org X-Bugzilla-Status: REOPENED X-Bugzilla-Priority: P1 X-Bugzilla-Assigned-To: rguenth at gcc dot gnu.org X-Bugzilla-Target-Milestone: 4.10.0 X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: 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-07/txt/msg00853.txt.bz2 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61757 --- Comment #23 from Richard Biener --- The first interesting difference is that for : _793 = ASSERT_EXPR <_73, _73 != 18>; switch (_793) , case 0: , case 1: , case 2: , case 3: , case 4 ... 9: , case 10 ... 11: , case 12 ... 17: > : we record an equality instead of a range: @@ -17655,13 +17655,7 @@ BB #19 EDGE 14->19 14 [14.3%] (EXECUTABLE) - PREDICATE: _73 ge_expr 2 - - switch (_73) , case 0: , case 1: , case 2: , case 3: , case 4 ... 9: , case 10 ... 11: , case 12 ... 17: > - - BB #19 - EDGE 14->19 14 [14.3%] (EXECUTABLE) - PREDICATE: _73 le_expr 9 + PREDICATE: _73 eq_expr 2 @@ -19815,9 +19806,8 @@ goto ; : - _792 = ASSERT_EXPR <_794, _794 >= 2>; - _793 = ASSERT_EXPR <_792, _792 <= 9>; - _77 = _793 + 4294967288; + _792 = ASSERT_EXPR <_793, _793 == 2>; + _77 = _792 + 4294967288; _78 = _77 > 1; _79 = (requirement) _78; validate_mode (m_780, 2, 0, 1, 1, _79); that's of course bogus, happens via find_switch_asserts where for correctly sorted ci vector we fail to pick up CASE_HIGH of cast 4...9. We miscompile the loop /* Skip labels until the last of the group. */ do { ++idx; } while (idx < n && cbb == ci[idx].bb); to 0x0000000000b6a492 <+3074>: mov %eax,%r14d 0x0000000000b6a495 <+3077>: lea 0x1(%r14),%r15d => 0x0000000000b6a499 <+3081>: cmp %r15,%rcx 0x0000000000b6a49c <+3084>: mov %r15,%rax 0x0000000000b6a49f <+3087>: ja 0xb6a492 that is, we simply increment idx until it is equal to n and then use CASE_HIGH of the last case label in the vector which is the default label (and thus does not have CASE_HIGH nor CASE_LOW). The following testcase derived from that is miscompiled on trunk at -O2: extern void abort (void); struct X { void *p; int res; } a[32]; int foo (unsigned i, unsigned n, void *q) { if (i + 1 < n && q == a[i + 1].p) { do { ++i; } while (i < n && q == a[i].p); --i; return a[i].res; } } int main () { int x; a[0].p = &x; a[1].p = &x; a[1].res = 1; a[2].p = (void *)0; a[2].res = 0; if (foo (0, 3, &x) != 1) abort (); return 0; }