From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ed1-x52b.google.com (mail-ed1-x52b.google.com [IPv6:2a00:1450:4864:20::52b]) by sourceware.org (Postfix) with ESMTPS id 792A2384F031 for ; Tue, 6 Jul 2021 07:11:14 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 792A2384F031 Received: by mail-ed1-x52b.google.com with SMTP id ch27so180715edb.10 for ; Tue, 06 Jul 2021 00:11:14 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=GCdQr4O1Eb7IAMiVMjmWDmjtpSVVYTamr79XJWAMtKE=; b=rey4QOY/hGQFTiHxZLOoQi6uxPx4Cb1i5WzGol6BU3AbZ3M4087J3ygawyQ5pvlBkL wg43AgWx0zDm9TjTb49NCJXySZAepj8fOabKeADmbqzrIcuRaO3Plvb6Z2stfq1CVl6b EIiNTbcwdzmqnmyrCtHR+hYN5eqJJmQArsrPWeBsNW+QJ5BAVAfyd6U+ufQc3HXycFZr NruLGgerlsqEODV/wD4JOxycCbQkOD7neav2niEQXk/y/lwIJM3FhywvPEiEsAXYf0nX a7YwZDTUhxI1YMsPdyMU5q+iUmXX1Q2dxnADxoez+a9XC3gU24nAGAFKe5sB/fElIu8y dJKQ== X-Gm-Message-State: AOAM531yKHUL8ynfsHK0neJWJVrXFyhRJRlM2ch/X1tI3Qx9v3LYOXis GR2i03B2CdY2cGmsONYpUYiQUwmMC7upxZ92+u4= X-Google-Smtp-Source: ABdhPJzn1WFSPfaWhxBWbJUDJWDHCskan12k/oPIuQ85aU66zA7lcVtggIxUoC9EQmxxyODvUsUG4naklBIP6MR6H5c= X-Received: by 2002:a05:6402:35d4:: with SMTP id z20mr21884464edc.138.1625555472884; Tue, 06 Jul 2021 00:11:12 -0700 (PDT) MIME-Version: 1.0 References: <1625534003-6730-1-git-send-email-apinski@marvell.com> In-Reply-To: <1625534003-6730-1-git-send-email-apinski@marvell.com> From: Richard Biener Date: Tue, 6 Jul 2021 09:11:01 +0200 Message-ID: Subject: Re: [PATCH] Fix 101256: Wrong code due to range incorrect from PHI-OPT To: Andrew Pinski Cc: GCC Patches Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-8.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, 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-List-Received-Date: Tue, 06 Jul 2021 07:11:16 -0000 On Tue, Jul 6, 2021 at 3:14 AM apinski--- via Gcc-patches wrote: > > From: Andrew Pinski > > So the problem here is that replace_phi_edge_with_variable > will copy range information to a already (not newly) defined > ssa name. This causes wrong code later on. > This fixes the problem by require the new ssa name to > be defined in the same bb as the conditional that is > about to be deleted. > > OK? Bootstrapped and tested on x86_64-linux-gnu with no regressions. OK. Richard. > Changes from v1: > * this is a simplification of what was trying to be done before. > > gcc/ChangeLog: > > PR tree-optimization/101256 > * dbgcnt.def (phiopt_edge_range): New counter. > * tree-ssa-phiopt.c (replace_phi_edge_with_variable): > > gcc/testsuite/ChangeLog: > > PR tree-optimization/101256 > * g++.dg/torture/pr101256.C: New test. > --- > gcc/dbgcnt.def | 1 + > gcc/testsuite/g++.dg/torture/pr101256.C | 28 +++++++++++++++++++++++++ > gcc/tree-ssa-phiopt.c | 16 ++++++++------ > 3 files changed, 39 insertions(+), 6 deletions(-) > create mode 100644 gcc/testsuite/g++.dg/torture/pr101256.C > > diff --git a/gcc/dbgcnt.def b/gcc/dbgcnt.def > index 93e7b4fd30e..2345899ba68 100644 > --- a/gcc/dbgcnt.def > +++ b/gcc/dbgcnt.def > @@ -183,6 +183,7 @@ DEBUG_COUNTER (lim) > DEBUG_COUNTER (local_alloc_for_sched) > DEBUG_COUNTER (match) > DEBUG_COUNTER (merged_ipa_icf) > +DEBUG_COUNTER (phiopt_edge_range) > DEBUG_COUNTER (postreload_cse) > DEBUG_COUNTER (pre) > DEBUG_COUNTER (pre_insn) > diff --git a/gcc/testsuite/g++.dg/torture/pr101256.C b/gcc/testsuite/g++.dg/torture/pr101256.C > new file mode 100644 > index 00000000000..973a8b4caf3 > --- /dev/null > +++ b/gcc/testsuite/g++.dg/torture/pr101256.C > @@ -0,0 +1,28 @@ > +// { dg-do run } > + > +template > +const T& max(const T& a, const T& b) > +{ > + return (a < b) ? b : a; > +} > + > +signed char var_5 = -128; > +unsigned int var_11 = 2144479212U; > +unsigned long long int arr [22]; > + > +void > +__attribute__((noipa)) > +test(signed char var_5, unsigned var_11) { > + for (short i_61 = 0; i_61 < var_5 + 149; i_61 += 10000) > + arr[i_61] = max((signed char)0, var_5) ? max((signed char)1, var_5) : var_11; > +} > + > +int main() { > + for (int i_0 = 0; i_0 < 22; ++i_0) > + arr [i_0] = 11834725929543695741ULL; > + > + test(var_5, var_11); > + if (arr [0] != 2144479212ULL && arr [0] != 11834725929543695741ULL) > + __builtin_abort (); > + return 0; > +} > diff --git a/gcc/tree-ssa-phiopt.c b/gcc/tree-ssa-phiopt.c > index ab63bf699e3..8b60ee81082 100644 > --- a/gcc/tree-ssa-phiopt.c > +++ b/gcc/tree-ssa-phiopt.c > @@ -51,6 +51,7 @@ along with GCC; see the file COPYING3. If not see > #include "internal-fn.h" > #include "gimple-range.h" > #include "gimple-match.h" > +#include "dbgcnt.h" > > static unsigned int tree_ssa_phiopt_worker (bool, bool, bool); > static bool two_value_replacement (basic_block, basic_block, edge, gphi *, > @@ -390,7 +391,7 @@ replace_phi_edge_with_variable (basic_block cond_block, > gimple_stmt_iterator gsi; > tree phi_result = PHI_RESULT (phi); > > - /* Duplicate range info if we're the only things setting the target PHI. > + /* Duplicate range info if they are the only things setting the target PHI. > This is needed as later on, the new_tree will be replacing > The assignement of the PHI. > For an example: > @@ -398,19 +399,22 @@ replace_phi_edge_with_variable (basic_block cond_block, > _4 = min > goto bb2 > > - range<-INF,255> > + # RANGE [-INF, 255] > a_3 = PHI<_4(1)> > bb3: > > use(a_3) > - And _4 gets prograted into the use of a_3 and losing the range info. > - This can't be done for more than 2 incoming edges as the progration > - won't happen. */ > + And _4 gets propagated into the use of a_3 and losing the range info. > + This can't be done for more than 2 incoming edges as the propagation > + won't happen. > + The new_tree needs to be defined in the same basic block as the conditional. */ > if (TREE_CODE (new_tree) == SSA_NAME > && EDGE_COUNT (gimple_bb (phi)->preds) == 2 > && INTEGRAL_TYPE_P (TREE_TYPE (phi_result)) > && !SSA_NAME_RANGE_INFO (new_tree) > - && SSA_NAME_RANGE_INFO (phi_result)) > + && SSA_NAME_RANGE_INFO (phi_result) > + && gimple_bb (SSA_NAME_DEF_STMT (new_tree)) == cond_block > + && dbg_cnt (phiopt_edge_range)) > duplicate_ssa_name_range_info (new_tree, > SSA_NAME_RANGE_TYPE (phi_result), > SSA_NAME_RANGE_INFO (phi_result)); > -- > 2.27.0 >