From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 16872 invoked by alias); 15 Aug 2017 11:35:53 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 12376 invoked by uid 89); 15 Aug 2017 11:35:49 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-9.8 required=5.0 tests=AWL,BAYES_00,FREEMAIL_FROM,GIT_PATCH_2,GIT_PATCH_3,KAM_ASCII_DIVIDERS,RCVD_IN_DNSWL_NONE,RCVD_IN_SORBS_SPAM,SPF_PASS autolearn=ham version=3.3.2 spammy=2017-08-14 X-HELO: mail-wm0-f41.google.com Received: from mail-wm0-f41.google.com (HELO mail-wm0-f41.google.com) (74.125.82.41) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 15 Aug 2017 11:35:47 +0000 Received: by mail-wm0-f41.google.com with SMTP id t201so6890471wmt.1 for ; Tue, 15 Aug 2017 04:35:47 -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:in-reply-to:references:from:date :message-id:subject:to; bh=0hN/za9t22wEXLwPHg7xj6Jm5p+m+iA6PEMOiTd4qa8=; b=ZUt9XnFcKLjnG33ZXrt+yC1g7rYEhfeOBFcsDBemE1r/l3SWrxQYxyGmYizO+K0Ng9 BDE2NnTrSqJpSJBRlSWmZVBOj34ueAmyqLg67Q1qurVchNJiHCArndEupqvlTsl27ZSY Dh7psetyXD5NL104RQM066F5dZvNjVUBp1rMR6BS5eFG2Y71ZraQVWljhMRS8BeqUXpu Qcn4b5N+DlaRcfCogOSto4JbOpzWOHtrbHTaKDNSNGj8C3HXNi/ORYUcOgTSSTOGIul8 EJ9yjnuUPJwftLpq8a+rf3NNs4qIhif9KqSH5Tf0FBaE5DMk9kQCLQ8HPdyCpsIVuGpG +8tQ== X-Gm-Message-State: AHYfb5hZ46cDuhxyp/jGI4cNKuGiUVn2skK/jcfml1ZwYkzcpXcxU4dY zcJn0BN5zJqrruoeQf/U3fCO1jh/i9Ad X-Received: by 10.80.148.36 with SMTP id p33mr27871507eda.174.1502796945254; Tue, 15 Aug 2017 04:35:45 -0700 (PDT) MIME-Version: 1.0 Received: by 10.80.180.249 with HTTP; Tue, 15 Aug 2017 04:35:44 -0700 (PDT) In-Reply-To: <87zib2pb7g.fsf@linaro.org> References: <87zib2pb7g.fsf@linaro.org> From: Richard Biener Date: Tue, 15 Aug 2017 12:47:00 -0000 Message-ID: Subject: Re: PR81815: Invalid conditional reduction To: GCC Patches , Richard Sandiford Content-Type: text/plain; charset="UTF-8" X-IsSubscribed: yes X-SW-Source: 2017-08/txt/msg00927.txt.bz2 On Mon, Aug 14, 2017 at 2:48 PM, Richard Sandiford wrote: > We weren't checking whether the phi in a conditional reduction was > used by the condition itself (which isn't a case we handle). > > Tested on aarch64-linux-gnu and x86_64-linux-gnu. OK to install? Ok. Richard. > Thanks, > Richard > > > 2017-08-11 Richard Sandiford > > gcc/ > PR tree-optimization/81835 > * tree-vect-loop.c (vect_is_simple_reduction): Simply checks for > the phi SSA_NAME. Check that the condition in a COND_EXPR does > not depend on the phi. > > gcc/testsuite/ > PR tree-optimization/81835 > * gcc.dg/vect/pr81815.c: New test. > > Index: gcc/tree-vect-loop.c > =================================================================== > --- gcc/tree-vect-loop.c 2017-08-04 11:41:05.710206063 +0100 > +++ gcc/tree-vect-loop.c 2017-08-14 13:46:28.336459006 +0100 > @@ -2690,15 +2690,15 @@ vect_is_simple_reduction (loop_vec_info > *double_reduc = false; > *v_reduc_type = TREE_CODE_REDUCTION; > > - name = PHI_RESULT (phi); > + tree phi_name = PHI_RESULT (phi); > /* ??? If there are no uses of the PHI result the inner loop reduction > won't be detected as possibly double-reduction by vectorizable_reduction > because that tries to walk the PHI arg from the preheader edge which > can be constant. See PR60382. */ > - if (has_zero_uses (name)) > + if (has_zero_uses (phi_name)) > return NULL; > nloop_uses = 0; > - FOR_EACH_IMM_USE_FAST (use_p, imm_iter, name) > + FOR_EACH_IMM_USE_FAST (use_p, imm_iter, phi_name) > { > gimple *use_stmt = USE_STMT (use_p); > if (is_gimple_debug (use_stmt)) > @@ -2847,10 +2847,7 @@ vect_is_simple_reduction (loop_vec_info > simply rewriting this into "res += -x[i]". Avoid changing > gimple instruction for the first simple tests and only do this > if we're allowed to change code at all. */ > - if (code == MINUS_EXPR > - && ! ((op1 = gimple_assign_rhs2 (def_stmt)) > - && TREE_CODE (op1) == SSA_NAME > - && SSA_NAME_DEF_STMT (op1) == phi)) > + if (code == MINUS_EXPR && gimple_assign_rhs2 (def_stmt) != phi_name) > code = PLUS_EXPR; > > if (code == COND_EXPR) > @@ -2864,6 +2861,14 @@ vect_is_simple_reduction (loop_vec_info > op4 = TREE_OPERAND (op3, 1); > op3 = TREE_OPERAND (op3, 0); > } > + if (op3 == phi_name || op4 == phi_name) > + { > + if (dump_enabled_p ()) > + report_vect_op (MSG_MISSED_OPTIMIZATION, def_stmt, > + "reduction: condition depends on previous" > + " iteration: "); > + return NULL; > + } > > op1 = gimple_assign_rhs2 (def_stmt); > op2 = gimple_assign_rhs3 (def_stmt); > Index: gcc/testsuite/gcc.dg/vect/pr81815.c > =================================================================== > --- /dev/null 2017-08-14 10:10:17.469973707 +0100 > +++ gcc/testsuite/gcc.dg/vect/pr81815.c 2017-08-14 13:46:28.334496436 +0100 > @@ -0,0 +1,26 @@ > +/* { dg-do run } */ > + > +int __attribute__ ((noinline, noclone)) > +f (int *x, int n) > +{ > + int b = 13; > + for (int i = 0; i < n; ++i) > + { > + int next = x[i]; > + b = b < 100 ? next : 200; > + } > + return b; > +} > + > +static int res[32]; > + > +int > +main (void) > +{ > + for (int i = 0; i < 32; ++i) > + res[i] = i; > + res[15] = 100; > + if (f (res, 32) != 200) > + __builtin_abort (); > + return 0; > +}