From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 12556 invoked by alias); 2 Jan 2012 10:19:58 -0000 Received: (qmail 12545 invoked by uid 22791); 2 Jan 2012 10:19:57 -0000 X-SWARE-Spam-Status: No, hits=-2.9 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_00 X-Spam-Check-By: sourceware.org Received: from localhost (HELO gcc.gnu.org) (127.0.0.1) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Mon, 02 Jan 2012 10:19:44 +0000 From: "rguenth at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/51721] -Warray-bounds false positives and inconsistencies Date: Mon, 02 Jan 2012 10:19: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-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: rguenth 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: --- X-Bugzilla-Changed-Fields: Status Last reconfirmed Ever Confirmed Message-ID: In-Reply-To: References: X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated Content-Type: text/plain; charset="UTF-8" MIME-Version: 1.0 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 X-SW-Source: 2012-01/txt/msg00062.txt.bz2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51721 Richard Guenther changed: What |Removed |Added ---------------------------------------------------------------------------- Status|UNCONFIRMED |NEW Last reconfirmed| |2012-01-02 Ever Confirmed|0 |1 --- Comment #4 from Richard Guenther 2012-01-02 10:19:13 UTC --- (In reply to comment #2) > This is a common problem with the -Warray-bounds warning, first jump threading > (during vrp1) optimizes it into just a single s == 17 check, followed by > a[11] = 0; b[11] = 0; c[17] = 0; d[11] = 0; if true and a[s] = 0; etc. if false > (well, at the end of vrp1 the constants aren't in the array refs yet, but they > are propagated there afterwards), and as no optimization figures out the weird > if (s >> 1 == 0) check (if (s < 2) would DTRT) to determine that s is not 17, > vrp2 warns about those accesses. > Perhaps for -Warray-bounds (at least if not -Warray-bounds=2 or similar) we > shouldn't warn on code that has been jump threaded, anyway, I don't think that > is solvable for 4.7 easily. > > What we perhaps could do more easily for this testcase (and could improve code > too) is during VRP for: > : > D.1716_2 = s_1(D) >> 1; > if (D.1716_2 == 0) > goto ; > else > goto ; > (or any other constant after >>, both signed and unsigned right shift, and == > or !=) insert ASSERT_EXPRs into both bbs, saying that the SSA_NAME in rhs1 of > the > shift is in/out of second ==/!= operand << rhs2 of shift, -""- + ((1 << rhs2) - > 1) range. In this case it would be ASSERT_EXPRs that s_1(D) <= 1 at the start > of bb 3 (and if bb 12 had only one predecessor, also that s_1(D) > 1 at bb 12 > start). Richard, what do you think about that? Yeah, if that turns out to be a common pattern, though maybe restrict it to ==/!= 0 tests? (if that simplifies the patch)