From patchwork Thu Jul 22 12:53:56 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andrew MacLeod X-Patchwork-Id: 1508706 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=xhW8XywA; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4GVss93Xcfz9sXJ for ; Thu, 22 Jul 2021 22:56:28 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id CF9D5384B110 for ; Thu, 22 Jul 2021 12:56:25 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org CF9D5384B110 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1626958585; bh=BMXVeG7Sr65YJA9CsAYGrydcydzsSIatn+UU7NQrNrQ=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=xhW8XywAqIeuB5mPfwqQd/bN8ff59zObtZD+iH7Cbs8sV6YeRXGULOnjallj+9Q0Y 9ThEp02x0l3BiiKBnGzVylylj9PTKgPcjNn/x3kvAqS0B4h81RMCWazREbEu3zSo+S I7Uh+xImfv4xlKF0mJEgyqpFQKiQrh2wj/uWoMJ4= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTP id 2D4E6387102C for ; Thu, 22 Jul 2021 12:54:01 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 2D4E6387102C Received: from mail-qt1-f200.google.com (mail-qt1-f200.google.com [209.85.160.200]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-270-JAeZIDYpNi6bPz25HfpEbQ-1; Thu, 22 Jul 2021 08:53:59 -0400 X-MC-Unique: JAeZIDYpNi6bPz25HfpEbQ-1 Received: by mail-qt1-f200.google.com with SMTP id i9-20020ac871c90000b0290252173fe79cso1152655qtp.2 for ; Thu, 22 Jul 2021 05:53:59 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:to:from:subject:cc:message-id:date:user-agent :mime-version:content-language; bh=BMXVeG7Sr65YJA9CsAYGrydcydzsSIatn+UU7NQrNrQ=; b=JJ2qu1BTilny3KcvGKI9PC+eXzsztD9rv3bbQC15LJida0A2k53KgCcbvZR8fPGpyd 1pV0qvbq0Jz1A9TdYlQ7omaiwtjmz7iDtA5XJ7TxytQ7VM47FzC0L8TruGic8e4TrDbi pnGolowJEBNGH8WfDKnkJzcXH1mtWwjszIbqbmN5vl8DstVVIud6kJNKRDuq/4c6cghk snnQitkJzRTThlBgupbm6mpzWzQVVu4n02j2ZfnslQgWn62isZdvbyNPKBwkdXmuCBlL iMW6S12xtMRgXk3Axv9QUBZcF1mdWjz4oV8tV394SqOcXKr+HXjbF8kPxtNRXf4ghc6k Dk+g== X-Gm-Message-State: AOAM533vx6VqzjfMvLjL8hGBDO0sRDe9tWCGOk9rt8g5PbKBWZY2W3P5 YTYv1UFvE4PHnTjUanAjaE7Z4iBkMeSbHwrs/Q70ztjVEL9BHL55ppzBCgoBN+RctVnkIoY5Nvo Rj0j+6TgDWg/EVvor8A== X-Received: by 2002:a0c:85a3:: with SMTP id o32mr41386790qva.42.1626958438945; Thu, 22 Jul 2021 05:53:58 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxgYTgknQQAC/8W9+DYoJDJKnexudcdBLi411Yti1okbpPVsTzl+3OTahXwHC0/AC9+fh5Pmg== X-Received: by 2002:a0c:85a3:: with SMTP id o32mr41386777qva.42.1626958438775; Thu, 22 Jul 2021 05:53:58 -0700 (PDT) Received: from ?IPv6:2607:fea8:a241:4600::74d4? ([2607:fea8:a241:4600::74d4]) by smtp.gmail.com with ESMTPSA id p19sm3735145qtx.10.2021.07.22.05.53.57 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 22 Jul 2021 05:53:58 -0700 (PDT) To: gcc-patches Subject: [COMMITTED] PR tree-optimization/101496 - Only call vrp_visit_cond_stmt if range_of_stmt doesn't resolve to a const. Message-ID: Date: Thu, 22 Jul 2021 08:53:56 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.12.0 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-CA X-Spam-Status: No, score=-13.5 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Andrew MacLeod via Gcc-patches From: Andrew MacLeod Reply-To: Andrew MacLeod Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" Resolve the issue of nonsensical conditions resolving differently than vrp_visit_cond_stmt expects  by resolving range_of_stmt first. this resolves an issue where ranger was using equality between two values to choose a branch when the ranges specified a different branch.  Its in unreachable code, which is why the condition is both true and false at the same time. Ultimately we'll simply remove the call to vrp_visit_cond_stmt. Bootstrapped on x86_64 & powerpc64-unknown-linux-gnu with no regressions.  Pushed. Andrew From e58093276a6e319c2a6d9f02e343fbf8400dab60 Mon Sep 17 00:00:00 2001 From: Andrew MacLeod Date: Mon, 19 Jul 2021 14:02:57 -0400 Subject: [PATCH 1/3] Only call vrp_visit_cond_stmt if range_of_stmt doesn't resolve to a const. Eevntually all functionality will be subsumed. Until then, call it only if needed. gcc/ PR tree-optimization/101496 * vr-values.c (simplify_using_ranges::fold_cond): Call range_of_stmt first, then vrp_visit_cond_Stmt. gcc/testsuite * gcc.dg/pr101496.c: New. --- gcc/testsuite/gcc.dg/pr101496.c | 22 ++++++++++++++++++++++ gcc/vr-values.c | 30 +++++++++++++++++------------- 2 files changed, 39 insertions(+), 13 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/pr101496.c diff --git a/gcc/testsuite/gcc.dg/pr101496.c b/gcc/testsuite/gcc.dg/pr101496.c new file mode 100644 index 00000000000..091d4ad8f26 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr101496.c @@ -0,0 +1,22 @@ +/* PR tree-optimization/101496 */ +/* { dg-do compile } */ +/* { dg-options "-O2 " } */ + +int c_1, li_2, us_3, func_14_s_5; + +void func_14() { + { + unsigned uli_8 = 0; + lbl1806324B: + if (uli_8 /= us_3 |= func_14_s_5 < 0 | func_14_s_5 != c_1) { + uli_8 += c_1 >= us_3; + if (uli_8) + ; + else + li_2 &&func_14_s_5 <= c_1 ?: 0; + unsigned *ptr_9 = &uli_8; + } + } + goto lbl1806324B; +} + diff --git a/gcc/vr-values.c b/gcc/vr-values.c index 1b3ec38d288..c999ca80f03 100644 --- a/gcc/vr-values.c +++ b/gcc/vr-values.c @@ -3460,11 +3460,6 @@ range_fits_type_p (const value_range *vr, bool simplify_using_ranges::fold_cond (gcond *cond) { - /* ?? vrp_folder::fold_predicate_in() is a superset of this. At - some point we should merge all variants of this code. */ - edge taken_edge; - vrp_visit_cond_stmt (cond, &taken_edge); - int_range_max r; if (query->range_of_stmt (r, cond) && r.singleton_p ()) { @@ -3475,17 +3470,13 @@ simplify_using_ranges::fold_cond (gcond *cond) if (r.zero_p ()) { - gcc_checking_assert (!taken_edge - || taken_edge->flags & EDGE_FALSE_VALUE); - if (dump_file && (dump_flags & TDF_DETAILS) && !taken_edge) + if (dump_file && (dump_flags & TDF_DETAILS)) fprintf (dump_file, "\nPredicate evaluates to: 0\n"); gimple_cond_make_false (cond); } else { - gcc_checking_assert (!taken_edge - || taken_edge->flags & EDGE_TRUE_VALUE); - if (dump_file && (dump_flags & TDF_DETAILS) && !taken_edge) + if (dump_file && (dump_flags & TDF_DETAILS)) fprintf (dump_file, "\nPredicate evaluates to: 1\n"); gimple_cond_make_true (cond); } @@ -3493,12 +3484,25 @@ simplify_using_ranges::fold_cond (gcond *cond) return true; } + /* ?? vrp_folder::fold_predicate_in() is a superset of this. At + some point we should merge all variants of this code. */ + edge taken_edge; + vrp_visit_cond_stmt (cond, &taken_edge); + if (taken_edge) { if (taken_edge->flags & EDGE_TRUE_VALUE) - gimple_cond_make_true (cond); + { + if (dump_file && (dump_flags & TDF_DETAILS)) + fprintf (dump_file, "\nVRP Predicate evaluates to: 1\n"); + gimple_cond_make_true (cond); + } else if (taken_edge->flags & EDGE_FALSE_VALUE) - gimple_cond_make_false (cond); + { + if (dump_file && (dump_flags & TDF_DETAILS)) + fprintf (dump_file, "\nVRP Predicate evaluates to: 0\n"); + gimple_cond_make_false (cond); + } else gcc_unreachable (); update_stmt (cond); -- 2.17.2