From patchwork Mon Mar 6 10:26:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 64582 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp1761395wrd; Mon, 6 Mar 2023 02:27:28 -0800 (PST) X-Google-Smtp-Source: AK7set/hYzGTR4m5Q59FRml90wKrsmImFZyrCkMxEqEHE7rhvvGb0NjqpBK4+rLAOFs05Noh7gDd X-Received: by 2002:a17:906:b882:b0:8b2:3e72:1022 with SMTP id hb2-20020a170906b88200b008b23e721022mr9825137ejb.29.1678098448743; Mon, 06 Mar 2023 02:27:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1678098448; cv=none; d=google.com; s=arc-20160816; b=0ji7gOEwtv6KAggnWOUlN++l0A4qA7QnxQJQonJk9IaKXwONsHzABT6jhhR8mOmdOV TCi34Gd/hYTHhG3cuVUbg2s4zkdWSHopO+NvHN3qJIea90k5XY1IqEQyfquHkqfxdJY+ Eh22JGGCIiX/5MZlH/E3clsiosNOVuiA5HboMFNzzpEcktnqNoYZlWodVU1x3sx769bT hhdT5XaOYwLu/uumsXsBJVWustzKdEW/Fp4SonkXxQKu5JPb3wjif2bih4Skq5BCtH8s /5DMBbt+714SY7/Z43Txa4ZTGCXxrufUg91LVbJ4VVqnW/23VOEGZKQtKrypFkeGXoLg k/0w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence:message-id :mime-version:subject:to:date:dmarc-filter:delivered-to :dkim-signature:dkim-filter; bh=jSwxtwxeiUGQjw4hQF2F9x9ZE4OpHHVB6EE6jq4/pXg=; b=TFfHbYjCQ8xxe6HwAjCbDuRhhLiNQX12sB0vteHGF8BsE7laVXaVNCzCUa1oB5l2wg RyzvioifKmSjZ/2g1MVwwfe1BxAN/Kcjg8YWSxY0X2v7youXWtxgGNpaEwp2j9EOhAAL yHQfyZ2bRgpNk4YeU43TyKV95h/0dc24wpwp/BuViEDGzUjQV/cc8A7SM2LjDJEvtir6 NkPKNssO1B8GDwrYqI1UZ2t/iQjKuqncv/Zp2mmRiNdHttF4NXaF9Wa4SHqz2Uye//U0 VuOQSS3I/zIq7654JQ/kIcBs6Ve1Vnb0MN0lrRDWtGgLah+mxAEvmbtFc8zFZNw6Htob 7skQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=mUIXrFAr; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id u18-20020a056402065200b004accfa7dc27si9647990edx.12.2023.03.06.02.27.28 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Mar 2023 02:27:28 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=mUIXrFAr; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 052043850860 for ; Mon, 6 Mar 2023 10:26:55 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 052043850860 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1678098415; bh=jSwxtwxeiUGQjw4hQF2F9x9ZE4OpHHVB6EE6jq4/pXg=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=mUIXrFArIZ0UmAobf/N9m/WLYqfPdkYzAl3aS/ObmNUloGJ6ZHC/lbtR5FOH7HXme DfK/mp/Kqcgq2cDzvbX6OGd23owthiPIfPASveWvk8VapOrVqqKx5ALlbEYD4GjdcX zz3RFTbKltyRqujGIlUb/mLMwFVMfRH82e2zv+bA= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from smtp-out1.suse.de (smtp-out1.suse.de [IPv6:2001:67c:2178:6::1c]) by sourceware.org (Postfix) with ESMTPS id A64323858D39 for ; Mon, 6 Mar 2023 10:26:10 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A64323858D39 Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 30788222B8 for ; Mon, 6 Mar 2023 10:26:09 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 1310C13A66 for ; Mon, 6 Mar 2023 10:26:09 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id bcO2A8G/BWSWeAAAMHmgww (envelope-from ) for ; Mon, 06 Mar 2023 10:26:09 +0000 Date: Mon, 6 Mar 2023 11:26:08 +0100 (CET) To: gcc-patches@gcc.gnu.org Subject: [PATCH] tree-optimization/109025 - fixup double reduction detection MIME-Version: 1.0 Message-Id: <20230306102609.1310C13A66@imap2.suse-dmz.suse.de> X-Spam-Status: No, score=-11.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) 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: Richard Biener via Gcc-patches From: Richard Biener Reply-To: Richard Biener Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1759613758653902459?= X-GMAIL-MSGID: =?utf-8?q?1759613758653902459?= The following closes a gap in double reduction detection where we in the outer loop analysis fail to verify the inner LC PHI use is the latch definition of the inner loop PHI. That latch definition is used to detect that an inner loop is part of a double reduction when later doing the inner loop analysis. Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed. PR tree-optimization/109025 * tree-vect-loop.cc (vect_is_simple_reduction): Verify the inner LC PHI use is the inner loop PHI latch definition before classifying an outer PHI as double reduction. * gcc.dg/vect/pr109025.c: New testcase. --- gcc/testsuite/gcc.dg/vect/pr109025.c | 14 ++++++++++++++ gcc/tree-vect-loop.cc | 6 +++++- 2 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gcc.dg/vect/pr109025.c diff --git a/gcc/testsuite/gcc.dg/vect/pr109025.c b/gcc/testsuite/gcc.dg/vect/pr109025.c new file mode 100644 index 00000000000..13fb0ce4ba9 --- /dev/null +++ b/gcc/testsuite/gcc.dg/vect/pr109025.c @@ -0,0 +1,14 @@ +/* { dg-do compile } */ +/* { dg-additional-options "-O3" } */ + +int func_4(int t, int b) +{ + for (int tt1 = 0; tt1 < 128 ; tt1 ++) + { + for (int tt = 0; tt < 128; tt ++) + if (b) + t |= 3; + t |= 3; + } + return t; +} diff --git a/gcc/tree-vect-loop.cc b/gcc/tree-vect-loop.cc index b17e8745d3f..320c15f144b 100644 --- a/gcc/tree-vect-loop.cc +++ b/gcc/tree-vect-loop.cc @@ -3894,6 +3894,8 @@ vect_is_simple_reduction (loop_vec_info loop_info, stmt_vec_info phi_info, return NULL; } + /* Verify there is an inner cycle composed of the PHI phi_use_stmt + and the latch definition op1. */ gimple *def1 = SSA_NAME_DEF_STMT (op1); if (gimple_bb (def1) && flow_bb_inside_loop_p (loop, gimple_bb (def_stmt)) @@ -3901,7 +3903,9 @@ vect_is_simple_reduction (loop_vec_info loop_info, stmt_vec_info phi_info, && flow_bb_inside_loop_p (loop->inner, gimple_bb (def1)) && (is_gimple_assign (def1) || is_gimple_call (def1)) && is_a (phi_use_stmt) - && flow_bb_inside_loop_p (loop->inner, gimple_bb (phi_use_stmt))) + && flow_bb_inside_loop_p (loop->inner, gimple_bb (phi_use_stmt)) + && (op1 == PHI_ARG_DEF_FROM_EDGE (phi_use_stmt, + loop_latch_edge (loop->inner)))) { if (dump_enabled_p ()) report_vect_op (MSG_NOTE, def_stmt,