From patchwork Thu Oct 20 10:49:42 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 6151 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4242:0:0:0:0:0 with SMTP id s2csp31409wrr; Thu, 20 Oct 2022 03:50:32 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6P62K3l8IJSeBrHbpnxP3itOS4Kd4cwIJ5kUzkc2CZSjsM4fOCUaI1T6bOlX1eLmXb5u9+ X-Received: by 2002:a05:6402:448b:b0:43b:5ec6:8863 with SMTP id er11-20020a056402448b00b0043b5ec68863mr11384838edb.377.1666263032220; Thu, 20 Oct 2022 03:50:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666263032; cv=none; d=google.com; s=arc-20160816; b=sQtWDuuM6b4vpysxldUCMJ4gfJQdLLUS6Lo+yMhmmdRA58waZFcsZJAwYtDUSOmNcb kPGHMEzBT0wiAdtm+aF1phNfP9xxhwBR/a1LPiPJKKjAfqyAVYbCGb+gBg7Gl3et5wSs FQ0wviWbczfgoxwdc+lg7RDOskWgaVUPqOnBOLuNAKKq4dkKcmsF+zLfxPIjwzHu4rfm 0Vap29AgsFS5/Env+m1zcYZ1z5vcz17Fz9SL5CxeSJc4Cfm/Cv+KQ27tRLeuwQZHymAI 1rgDt58SmUIV4k5zc0sa1goK9yxqV+6roBqB6F7gNBrbYQldRZC6RZCsAQZ6rfji5MEK wHfw== 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=guP/NgZ3whYSjWjsqEbBHvnX129XwqE/0w8o+THn0vA=; b=v+J8Nfgc0MUI71Y+beeOJ2Bwd1KUHRRrplzhASR9zXrW2jMPDoJIdI+jRJUKty11Ry fHWEEE9lzidCmhaO+dVmnuJB1QeoO8Yyfl4o3Kb6PSivv5ttuLc2TgO3Z4n92+mPsfBt moxnNRsynIYwOorH2fVbV/jbSbE6IEMbJxe3UutiYtx4G4mzX/aOlHWQa66QpOt4xBNY DJAUcvn4yfdUlRbv7jfJq7bh/oyMRpQtRxTCGgGR3hTUqYA4wNt9S0gCOFOfaYYU82Nq dfO0+buwtzKoZEAtaYouDGxKUYTZpEeFTBxAgkkUirIT3+I1gybdwSwq4Qr17UndJlBg KuYQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=pLqRMtys; 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 hq40-20020a1709073f2800b0073866c0672asi10750026ejc.73.2022.10.20.03.50.32 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Oct 2022 03:50:32 -0700 (PDT) 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=pLqRMtys; 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 0CB57385085B for ; Thu, 20 Oct 2022 10:50:31 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0CB57385085B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1666263031; bh=guP/NgZ3whYSjWjsqEbBHvnX129XwqE/0w8o+THn0vA=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=pLqRMtys2F54LaKi2HT0ggPa3FkekHU/4AaWvarFdkJj9FCP3hqmQ8iHqpPDPqp17 H1WByE42ESG8LiXuXcGcvE8uZ2EsD39PYWfP1K3NsDN9wnbHuoQgepAg+Be8RHiBWG 9UURmtN5+oUhsfQq2VSZEkwmtVcTAcj7RLXcjupY= 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 09E3C3851173 for ; Thu, 20 Oct 2022 10:49:44 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 09E3C3851173 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 EF0AD22B39 for ; Thu, 20 Oct 2022 10:49:42 +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 DDA6113AF5 for ; Thu, 20 Oct 2022 10:49:42 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id hl1QNMYnUWNTagAAMHmgww (envelope-from ) for ; Thu, 20 Oct 2022 10:49:42 +0000 Date: Thu, 20 Oct 2022 12:49:42 +0200 (CEST) To: gcc-patches@gcc.gnu.org Subject: [PATCH] Avoid PHI - PHI recurrence in vectorization MIME-Version: 1.0 Message-Id: <20221020104942.DDA6113AF5@imap2.suse-dmz.suse.de> X-Spam-Status: No, score=-12.2 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, 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?1747203425334168496?= X-GMAIL-MSGID: =?utf-8?q?1747203425334168496?= The reported regression of libgomp loop-14.C shows that there isn't generally a good reliable place to insert the permute upfront so the following simply restricts recurrence vectorization to the cases where the latch value isn't defined by a PHI. Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed. * tree-vect-loop.cc (vect_phi_first_order_recurrence_p): Disallow latch PHI defs. (vectorizable_recurr): Revert previous change. --- gcc/tree-vect-loop.cc | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/gcc/tree-vect-loop.cc b/gcc/tree-vect-loop.cc index 92790bd8095..d5c2bff80be 100644 --- a/gcc/tree-vect-loop.cc +++ b/gcc/tree-vect-loop.cc @@ -543,6 +543,7 @@ vect_phi_first_order_recurrence_p (loop_vec_info loop_vinfo, class loop *loop, tree ldef = PHI_ARG_DEF_FROM_EDGE (phi, latch); if (TREE_CODE (ldef) != SSA_NAME || SSA_NAME_IS_DEFAULT_DEF (ldef) + || is_a (SSA_NAME_DEF_STMT (ldef)) || !flow_bb_inside_loop_p (loop, gimple_bb (SSA_NAME_DEF_STMT (ldef)))) return false; @@ -8486,14 +8487,8 @@ vectorizable_recurr (loop_vec_info loop_vinfo, stmt_vec_info stmt_info, vectorized the latch definition. */ edge le = loop_latch_edge (LOOP_VINFO_LOOP (loop_vinfo)); gimple *latch_def = SSA_NAME_DEF_STMT (PHI_ARG_DEF_FROM_EDGE (phi, le)); - gimple_stmt_iterator gsi2; - if (is_a (latch_def)) - gsi2 = gsi_after_labels (gimple_bb (latch_def)); - else - { - gsi2 = gsi_for_stmt (latch_def); - gsi_next (&gsi2); - } + gimple_stmt_iterator gsi2 = gsi_for_stmt (latch_def); + gsi_next (&gsi2); for (unsigned i = 0; i < ncopies; ++i) {