From patchwork Fri May 17 08:12:20 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladislav Ivanishin X-Patchwork-Id: 1100876 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-500994-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=ispras.ru Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="Cy9IUJxl"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4551HR1j5kz9s9y for ; Fri, 17 May 2019 18:12:33 +1000 (AEST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id:mime-version:content-type; q=dns; s=default; b=iq4+C9l2XUygFAWqTway4t4Dw+a6YZn7X2FytBwOfge6/Og3fv ty+vaHM7amxFY79xEtceUPZZ8OLaZcrrgoRqhOEzxCrBeu33ACgqfHLXob4Uaf5m sZASwDHH53oGxZ9jykVbx+DIMxLKEKq7MMgxFmLxVaN67RIo1+Xv9N/mY= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id:mime-version:content-type; s= default; bh=upptLtX09xx8xJSwF81zmGS9dck=; b=Cy9IUJxlTVduY6A1Osom uVP8X1VCYAmJKDDc0Hn+C4IBxSBQDM9w13CUj0lOU8BtABTRfxDOo2MmxmQqzkj7 lXuxei2nKAaIGklQAC0Xuxdof5gSxupgmxz/p15yDDbsnyF1zbFfrfyKPI6jmYv3 /eQkzyYaWgrAOI26HqafusU= Received: (qmail 115755 invoked by alias); 17 May 2019 08:12:26 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 115745 invoked by uid 89); 17 May 2019 08:12:26 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.8 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.1 spammy=sponsor, bootstraped X-HELO: mail.ispras.ru Received: from mail.ispras.ru (HELO mail.ispras.ru) (83.149.199.45) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 17 May 2019 08:12:23 +0000 Received: from archbook (broadband-5-228-107-246.ip.moscow.rt.ru [5.228.107.246]) by mail.ispras.ru (Postfix) with ESMTPSA id 99A04540089; Fri, 17 May 2019 11:12:20 +0300 (MSK) From: Vladislav Ivanishin To: gcc-patches@gcc.gnu.org Cc: Richard Biener Subject: [PATCH] tree-ssa-uninit: suppress more spurious warnings Date: Fri, 17 May 2019 11:12:20 +0300 Message-ID: <87v9y9ebyz.fsf@ispras.ru> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.2 (gnu/linux) MIME-Version: 1.0 X-IsSubscribed: yes Hi! Without the patch, two of the newly added tests fail with bogus warnings: - gcc.dg/uninit-28-gimple.c (Definition guarded with NE_EXPR, use with BIT_AND_EXPR. This is an FP my previous patch [1] knowingly overlooks.) - gcc.dg/uninit-30-gimple.c (EQ_EXPR in the predicate guarding use. This is what I spotted while refactoring. It never worked, and is easy to handle). Bootstraped with `BOOT_CFLAGS="-O -Wno-error=maybe-uninitialized -Wuninitialized"` and regtested on x86_64-pc-linux-gnu. OK for trunk? Also, Richard, would you mind being a sponsor for my svn account? [1]: https://gcc.gnu.org/ml/gcc-patches/2019-05/msg00896.html * tree-ssa-uninit.c (value_sat_pred_p): This new function is a wrapper around is_value_included_in that knows how to handle BIT_AND_EXPR. (is_pred_expr_subset_of): Use the new function. Handle more cases where code1 == EQ_EXPR and where code1 == BIT_AND_EXPR and thus fix some false positives. testsuite/ * gcc.dg/uninit-28-gimple.c: New test. * gcc.dg/uninit-29-gimple.c: New test. * gcc.dg/uninit-30-gimple.c: New test. * gcc.dg/uninit-31-gimple.c: New test. --- gcc/testsuite/gcc.dg/uninit-28-gimple.c | 47 ++++++++++++++++++++++++ gcc/testsuite/gcc.dg/uninit-29-gimple.c | 45 +++++++++++++++++++++++ gcc/testsuite/gcc.dg/uninit-30-gimple.c | 43 ++++++++++++++++++++++ gcc/testsuite/gcc.dg/uninit-31-gimple.c | 48 +++++++++++++++++++++++++ gcc/tree-ssa-uninit.c | 37 +++++++++++++------ 5 files changed, 210 insertions(+), 10 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/uninit-28-gimple.c create mode 100644 gcc/testsuite/gcc.dg/uninit-29-gimple.c create mode 100644 gcc/testsuite/gcc.dg/uninit-30-gimple.c create mode 100644 gcc/testsuite/gcc.dg/uninit-31-gimple.c diff --git a/gcc/testsuite/gcc.dg/uninit-28-gimple.c b/gcc/testsuite/gcc.dg/uninit-28-gimple.c new file mode 100644 index 00000000000..0648b8a4aa7 --- /dev/null +++ b/gcc/testsuite/gcc.dg/uninit-28-gimple.c @@ -0,0 +1,47 @@ +/* { dg-do compile } */ +/* { dg-options "-fgimple -O -Wmaybe-uninitialized" } */ + +unsigned int __GIMPLE (ssa,startwith("uninit1")) +foo (unsigned int v) +{ + /* Uninit warning here would be bogus, because (16 & 3) == 0 and therefore + if v == 16, the uninit value is not used (the use is properly guarded). */ + unsigned int undef; /* { dg-bogus "may be used uninitialized" } */ + unsigned int _2; + unsigned int _9; + unsigned int _10; + unsigned pred; + + __BB(2): + if (v_4(D) != 16u) + goto __BB3; + else + goto __BB4; + + /* 'undef' is defined conditionally (under 'v != 16' predicate) */ + __BB(3): + undef_8 = 8u; + goto __BB4; + + /* An undef value flows into a phi. */ + __BB(4): + undef_1 = __PHI (__BB2: undef_5(D), __BB3: undef_8); + pred = v_4(D) & 3u; + if (pred != 0u) + goto __BB5; + else + goto __BB6; + + /* The phi value is used here (under 'v & 3' predicate). */ + __BB(5): + _9 = undef_1; + goto __BB7; + + __BB(6): + _10 = v_4(D); + goto __BB7; + + __BB(7): + _2 = __PHI (__BB5: _9, __BB6: _10); + return _2; +} diff --git a/gcc/testsuite/gcc.dg/uninit-29-gimple.c b/gcc/testsuite/gcc.dg/uninit-29-gimple.c new file mode 100644 index 00000000000..cb5bc97164e --- /dev/null +++ b/gcc/testsuite/gcc.dg/uninit-29-gimple.c @@ -0,0 +1,45 @@ +/* { dg-do compile } */ +/* { dg-options "-fgimple -O -Wmaybe-uninitialized" } */ + +unsigned int __GIMPLE (ssa,startwith("uninit1")) +foo (unsigned int v) +{ + unsigned int undef; /* { dg-warning "may be used uninitialized" } */ + unsigned int _2; + unsigned int _9; + unsigned int _10; + unsigned pred; + + __BB(2): + pred = v_4(D) & 3u; + if (pred != 0u) + goto __BB3; + else + goto __BB4; + + /* 'undef' is defined conditionally (under 'v & 3' predicate) */ + __BB(3): + undef_8 = 8u; + goto __BB4; + + /* An undef value flows into a phi. */ + __BB(4): + undef_1 = __PHI (__BB2: undef_5(D), __BB3: undef_8); + if (v_4(D) != 16u) + goto __BB5; + else + goto __BB6; + + /* The phi value is used here (under 'v != 16' predicate). */ + __BB(5): + _9 = undef_1; + goto __BB7; + + __BB(6): + _10 = v_4(D); + goto __BB7; + + __BB(7): + _2 = __PHI (__BB5: _9, __BB6: _10); + return _2; +} diff --git a/gcc/testsuite/gcc.dg/uninit-30-gimple.c b/gcc/testsuite/gcc.dg/uninit-30-gimple.c new file mode 100644 index 00000000000..8c91f79d509 --- /dev/null +++ b/gcc/testsuite/gcc.dg/uninit-30-gimple.c @@ -0,0 +1,43 @@ +/* { dg-do compile } */ +/* { dg-options "-fgimple -O -Wmaybe-uninitialized" } */ + +unsigned int __GIMPLE (ssa,startwith("uninit1")) +foo (unsigned int v) +{ + unsigned int undef; /* { dg-bogus "may be used uninitialized" } */ + unsigned int _2; + unsigned int _9; + unsigned int _10; + + __BB(2): + if (v_4(D) < 100u) + goto __BB3; + else + goto __BB4; + + /* 'undef' is defined conditionally (under 'v < 100' predicate). */ + __BB(3): + undef_8 = 8u; + goto __BB4; + + /* An undef value flows into a phi. */ + __BB(4): + undef_1 = __PHI (__BB2: undef_5(D), __BB3: undef_8); + if (v_4(D) == 42u) + goto __BB5; + else + goto __BB6; + + /* The phi value is used here (under 'v == 42' predicate). */ + __BB(5): + _9 = undef_1; + goto __BB7; + + __BB(6): + _10 = v_4(D); + goto __BB7; + + __BB(7): + _2 = __PHI (__BB5: _9, __BB6: _10); + return _2; +} diff --git a/gcc/testsuite/gcc.dg/uninit-31-gimple.c b/gcc/testsuite/gcc.dg/uninit-31-gimple.c new file mode 100644 index 00000000000..01118ef9823 --- /dev/null +++ b/gcc/testsuite/gcc.dg/uninit-31-gimple.c @@ -0,0 +1,48 @@ +/* { dg-do compile } */ +/* { dg-options "-fgimple -O -Wmaybe-uninitialized" } */ + +unsigned int __GIMPLE (ssa,startwith("uninit1")) +foo (unsigned int v) +{ + /* If v == 2, then undef is used w/o being initialized. */ + unsigned int undef; /* { dg-warning "may be used uninitialized" } */ + unsigned int _2; + unsigned int _9; + unsigned int _10; + unsigned int pred2; + unsigned int pred1; + + __BB(2): + pred2 = v_4(D) & 5u; + if (pred2 != 0u) + goto __BB3; + else + goto __BB4; + + /* 'undef' is defined conditionally (under 'v & 5' predicate). */ + __BB(3): + undef_8 = 8u; + goto __BB4; + + /* An undef value flows into a phi. */ + __BB(4): + undef_1 = __PHI (__BB2: undef_5(D), __BB3: undef_8); + pred1 = v_4(D) & 3u; + if (pred1 != 0u) + goto __BB5; + else + goto __BB6; + + /* The phi value is used here (under 'v & 3' predicate). */ + __BB(5): + _9 = undef_1; + goto __BB7; + + __BB(6): + _10 = v_4(D); + goto __BB7; + + __BB(7): + _2 = __PHI (__BB5: _9, __BB6: _10); + return _2; +} diff --git a/gcc/tree-ssa-uninit.c b/gcc/tree-ssa-uninit.c index b89da4017e8..bc07afe32c8 100644 --- a/gcc/tree-ssa-uninit.c +++ b/gcc/tree-ssa-uninit.c @@ -1045,6 +1045,26 @@ is_value_included_in (tree val, tree boundary, enum tree_code cmpc) return result; } +/* Returns whether VAL satisfies (x CMPC BOUNDARY) predicate. CMPC can be + either one of the range comparison codes ({GE,LT,EQ,NE}_EXPR and the like), + or BIT_AND_EXPR. EXACT_P is only meaningful for the latter. It modifies the + question from whether VAL & BOUNDARY != 0 to whether VAL & BOUNDARY == VAL. + For other values of CMPC, EXACT_P is ignored. */ + +static bool +value_sat_pred_p (tree val, tree boundary, enum tree_code cmpc, + bool exact_p = false) +{ + if (cmpc != BIT_AND_EXPR) + return is_value_included_in (val, boundary, cmpc); + + wi::tree_to_wide_ref andw = wi::to_wide (val) & wi::to_wide (boundary); + if (exact_p) + return andw == wi::to_wide (val); + else + return andw.to_uhwi (); +} + /* Returns true if PRED is common among all the predicate chains (PREDS) (and therefore can be factored out). NUM_PRED_CHAIN is the size of array PREDS. */ @@ -1471,18 +1491,15 @@ is_pred_expr_subset_of (pred_info expr1, pred_info expr2) if (code2 == NE_EXPR && code1 == NE_EXPR) return false; - if (code2 == NE_EXPR && code1 != BIT_AND_EXPR) - return !is_value_included_in (expr2.pred_rhs, expr1.pred_rhs, code1); + if (code2 == NE_EXPR) + return !value_sat_pred_p (expr2.pred_rhs, expr1.pred_rhs, code1); - if ((code1 == EQ_EXPR || code1 == BIT_AND_EXPR) && code2 == BIT_AND_EXPR) - return (wi::to_wide (expr1.pred_rhs) - == (wi::to_wide (expr1.pred_rhs) & wi::to_wide (expr2.pred_rhs))); + if (code1 == EQ_EXPR) + return value_sat_pred_p (expr1.pred_rhs, expr2.pred_rhs, code2); - if (code1 != code2) - return false; - - if (is_value_included_in (expr1.pred_rhs, expr2.pred_rhs, code2)) - return true; + if (code1 == code2) + return value_sat_pred_p (expr1.pred_rhs, expr2.pred_rhs, code2, + code1 == BIT_AND_EXPR); return false; } -- 2.20.1