From patchwork Mon Aug 14 12:48:03 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Sandiford X-Patchwork-Id: 109995 Delivered-To: patch@linaro.org Received: by 10.140.95.78 with SMTP id h72csp4287895qge; Mon, 14 Aug 2017 05:49:40 -0700 (PDT) X-Received: by 10.99.98.3 with SMTP id w3mr24688365pgb.350.1502714980859; Mon, 14 Aug 2017 05:49:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1502714980; cv=none; d=google.com; s=arc-20160816; b=KxGe3YfeFuBHNKB5BAgo3ZkaMC5FZYF2E+93chbkvPLyZinpAbPWQmBosVCFj3Dmv1 PwnaLH1eIOW3ZxxTmFYtYTjQLVIoP9U9zOqYbSq9smdEF3DQyYbrL8A2Miej1CAJXOTL CpxLKwBsv6HOEh++1IS0bgIvTowoodTl2qqd5ylnJvwfyX0pOuTBCrKTDgn1auZpjoPZ YxUrjcEJ6deuNlemG8SHeN3YBdxNAd/7Se89jf1Lto+bK+53UTytuaCTsfPpE1HtAh7X qDe7FZ6xakYEKUb6GHgynDbN+LjBwQuq/iBI7sjfYmA6zbO2Gr4MCRWQreB8X0V/NDn4 coZA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:user-agent:message-id:date:subject:mail-followup-to:to :from:delivered-to:sender:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:mailing-list:dkim-signature :domainkey-signature:arc-authentication-results; bh=6CmzI0Frm364n2SqWiCg5xt64vHoO42yn9G6xa8iRFA=; b=JR3WQZ1GxSerlLVGb3L9Z027TNUi673MPh29szc2/JcgobBvuN25oJDKMqGcaXy3Gu r8LLeXUF13bsetzt8FL3A+1LF6MJYR0OunYfdwd524r8N1455rheu/aWg5fkRgkbzkNP /ITFwpitcYO076qQjv4MHVBtJaCr2uK7gJ7yh0twh0ZvGBXPfs5TRKEPzHp8OYCcnubB tEkbKWwqTKOCv0jDgtM2ZyqYgNLGEVL7VKbRJKMRUs1RyQ4EcPjJR4CTcdcQElwWADx6 2hyqdtiQC/gDMfCPAmD5KlgVLrqPoRlpwhiXo+X52FO9hmIwoR/nvGFG9KlI336Bt9bt haXg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=yycNxsUF; spf=pass (google.com: domain of gcc-patches-return-460311-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-460311-patch=linaro.org@gcc.gnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id d37si4597805plb.324.2017.08.14.05.49.40 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 14 Aug 2017 05:49:40 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-return-460311-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) client-ip=209.132.180.131; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=yycNxsUF; spf=pass (google.com: domain of gcc-patches-return-460311-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-460311-patch=linaro.org@gcc.gnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org 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:subject:date:message-id:mime-version:content-type; q=dns; s= default; b=tkZRfpmxv9LReq0WUKmnx55Vqi4hRMOyQQA8FpjVoPRZyDlwP4iaZ 52WPB7PVxywsY5X6wL3mO1cBbMPIFueXsy9OjzYgWC0Pog8EG+vDKtHuycgSqs6O EeHgilDUNOEQUWM0yupxBpf8TPIDmAV5rsd9sUnzkRRKERXZ12waJc= 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:subject:date:message-id:mime-version:content-type; s= default; bh=WOhSwpaZrV/5WC4c8+XWVQG4bbg=; b=yycNxsUFnmXRkbs28hVZ BpLwM2Z8K++QY0MdQMR2Jlbqk43KQLFanxwA7SZFFB7kn1+NXHkQPDKMKdrQSNST 7FRjsoodOyuLaVfFfihHV5Bl2b97qikY+G1d6wQ6a456NwPtnJZY1Kr75cq522uv p32emuROI4SUehi+cWyUNuY= Received: (qmail 29758 invoked by alias); 14 Aug 2017 12:49:08 -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 29194 invoked by uid 89); 14 Aug 2017 12:48:25 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-10.5 required=5.0 tests=AWL, BAYES_00, 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= X-HELO: mail-wm0-f45.google.com Received: from mail-wm0-f45.google.com (HELO mail-wm0-f45.google.com) (74.125.82.45) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 14 Aug 2017 12:48:23 +0000 Received: by mail-wm0-f45.google.com with SMTP id i66so42929610wmg.0 for ; Mon, 14 Aug 2017 05:48:08 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:mail-followup-to:subject:date:message-id :user-agent:mime-version; bh=6CmzI0Frm364n2SqWiCg5xt64vHoO42yn9G6xa8iRFA=; b=aOJFchSBECY7IVdIQeA6nBHYusRvZaFh8wnN2P6g0uR3HDms1h4Tdo/Q9c2Jh3Nea2 vQ5dgqQqEy3Y0UZoMmz18gXv7EIz0kMffkkxqTPjsVUCwPO9YIxAvEGZWRNdfsElXfGO IWxHXkU1n0NmXc6WknwM5SAp/K/pwe15JUi2WwFN5HA4n1BysEtcwbrjIk6x/YeUGJ1r +Ne1J4GElH0dVEnAchzsO1IBZZPHj03sjoNHuackyzky4GgtE2zpxztWf0AsAP9lryyR F2rrRMBkzW9W0t8S4eja6uaeBPgUMnmSOiORerWfX082xFBbp+gNsF09uHCCSGSkZRa6 rl3g== X-Gm-Message-State: AHYfb5jynZGV9HUXAmjgNZRT8N5mPMlGs7QwWEi2DePd4BD1QR+/fLpn jqOqKIZmPjrMdGtTspN8Tg== X-Received: by 10.28.98.137 with SMTP id w131mr4089301wmb.158.1502714886968; Mon, 14 Aug 2017 05:48:06 -0700 (PDT) Received: from localhost (188.29.164.177.threembb.co.uk. [188.29.164.177]) by smtp.gmail.com with ESMTPSA id g26sm5350064wrb.21.2017.08.14.05.48.05 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 14 Aug 2017 05:48:06 -0700 (PDT) From: Richard Sandiford To: gcc-patches@gcc.gnu.org Mail-Followup-To: gcc-patches@gcc.gnu.org, richard.sandiford@linaro.org Subject: PR81815: Invalid conditional reduction Date: Mon, 14 Aug 2017 13:48:03 +0100 Message-ID: <87zib2pb7g.fsf@linaro.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.2 (gnu/linux) MIME-Version: 1.0 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? 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; +}