From patchwork Fri Nov 3 14:16:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 161319 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:8f47:0:b0:403:3b70:6f57 with SMTP id j7csp1066495vqu; Fri, 3 Nov 2023 07:16:52 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFJzTmpj7NiQ1r5CHCQtBD0+0QQNXZXgVB+NujR2OT4Gwha87hdB/6jKVEcs2BXYijQYDLJ X-Received: by 2002:a05:6359:d1d:b0:168:d0a3:202f with SMTP id gp29-20020a0563590d1d00b00168d0a3202fmr21822052rwb.15.1699021012119; Fri, 03 Nov 2023 07:16:52 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1699021012; cv=pass; d=google.com; s=arc-20160816; b=wKzRfOG8KuCpsaOpqFURYPfMTSm7QVSb3lFuQanORoQ9UVXiqKn8RdANcLXtAO3lO7 Ti3VgwwLLwwPhdqCZsHAuEZpO2EZtb1dkLMeywyPBI7KTUfDYoL/nBYZ39aiVnTSdxRi lBz9Cyg0/hwCTUZMozBlFvPEbj4TDOKdxU2K/X9N5bKNZZt9tek/nUjMpgIgv+o312pH bZzzLd5MnlU95hi2NKYRS8tY+24IcYawSH73BVNAvrGnmvPi886XVMZIDhrQszE3b3R7 37AVIcX88s3F0u4FBeBPUNpWp9xwChkVlXI58O/1QDlQOqRnW7sx6tp5OoNuxieBXL3m rkJA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:message-id:mime-version:subject :to:from:date:dkim-signature:dkim-signature:arc-filter:dmarc-filter :delivered-to; bh=rYl+Q4qmCVNQF6DYqBwkeIPRsYRbqkfs/2VWHKvGUg8=; fh=hPrbWPhweUx4V0GV9uXJqbyAzg2ABmTz7kczrAQqMmM=; b=WYez6owGVSKu9mKWRYTWVhrSCakXvHxktIXdt6vjIDwJjAwQMkPOKIDB81p2myD1es ZcWNEs+0HBOcazM08WtI+1Ubz0PMLgW4E2gdD5nLwBTrclPbO0sz38Ipt1OULYByKfIw e6Z+5E4tgXOfp5uOxcdlZZF8ciqcRFRrdtQM2cj8D4NaBeUPybVbJE1fBb0ja72rS85Q LYc/Sl2p9WA601erFJdmL69iyRIn66p+CEE4p+yq9JboSsOclHbgApPxqsvVhiOw5G6o hOOoQ2MVE3//GZgUODY+0bl2xyOd10d5B1IyYuXDjmL1PBQWgvSSgdSUWG/v/AjsnEFo tsxw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=nvtruuU9; dkim=neutral (no key) header.i=@suse.de; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=suse.de Received: from server2.sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id c22-20020a056214071600b0066d054257a6si1491900qvz.476.2023.11.03.07.16.52 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Nov 2023 07:16:52 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=nvtruuU9; dkim=neutral (no key) header.i=@suse.de; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=suse.de Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id AB6253858C35 for ; Fri, 3 Nov 2023 14:16:50 +0000 (GMT) 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 [195.135.220.28]) by sourceware.org (Postfix) with ESMTPS id C70F13858D37 for ; Fri, 3 Nov 2023 14:16:16 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C70F13858D37 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.de ARC-Filter: OpenARC Filter v1.0.0 sourceware.org C70F13858D37 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=195.135.220.28 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1699020987; cv=none; b=aCau59460BMBdbORgnBxtYeprSd93ACNHmoj8rOth3Q+ppqcHMzLLlY//nOLa3jQlKs226tXdfpNJSbq1WKf3cTPAbGdgdpckJnLIbuZj2Od0NFOLKRp73dSN8kCHnE5O3UKzLDYkqtpjlwrABfuptpPS65lRnNCXKwwXxkZzs0= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1699020987; c=relaxed/simple; bh=cZPcjbbRiTx4nq2nn9aB0ZeA1i0WQ93S4g0F8pweBf8=; h=DKIM-Signature:DKIM-Signature:Date:From:To:Subject:MIME-Version: Message-Id; b=ktN2FQHMpqbhFalWppQgc3qiU70eSPlTpsb+qEnL89lD4LDkwkPhBRJV//SvBXI0wDNasEP81udWEFNT0DQwAq3u4vHhRha4D6/qWX9oD7N9aN3R+ddAXTcIIxtizR2i+jhIJDAHxYpqpU96GidDiEXeUGkIHEktjgz0GZBCsLc= ARC-Authentication-Results: i=1; server2.sourceware.org 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 85920218E4 for ; Fri, 3 Nov 2023 14:16:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1699020975; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type; bh=rYl+Q4qmCVNQF6DYqBwkeIPRsYRbqkfs/2VWHKvGUg8=; b=nvtruuU9v2cDuL7757T5Hqrr7qVcdVJd2HKSV1VuOb3YTv2P1TiwlvUJTsWDV/u9smPhvK xRWeUUhjmQqqfKOevSgoyyUcl9Zq0gLSB0JEOAj9lT+bHZVmRPc3lP5dHmrVik5TjFbGEP SeyMNvyN3Fa+5kfhWiDZSKb0GRe/6nQ= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1699020975; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type; bh=rYl+Q4qmCVNQF6DYqBwkeIPRsYRbqkfs/2VWHKvGUg8=; b=Eur6oV4ObVx7Kgh/8QCTiSKqpR+PL3HSsiH2LhVDV53OvTgG5QgLvhKYcJ9/ukWcx5pcxW h+0ox7Mvy9608WAg== 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 6FD4913907 for ; Fri, 3 Nov 2023 14:16:15 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id 6vUDGq8ARWX1DQAAMHmgww (envelope-from ) for ; Fri, 03 Nov 2023 14:16:15 +0000 Date: Fri, 3 Nov 2023 15:16:15 +0100 (CET) From: Richard Biener To: gcc-patches@gcc.gnu.org Subject: [PATCH] Cleanup vectorizable_live_operation MIME-Version: 1.0 Message-Id: <20231103141615.6FD4913907@imap2.suse-dmz.suse.de> X-Spam-Status: No, score=-11.6 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, T_SCC_BODY_TEXT_LINE 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.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1781552656956439400 X-GMAIL-MSGID: 1781552656956439400 During analyzing PR111950 I found the loop live operation code-gen odd, in particular only replacing a single PHI but then adjusting possibly remaining PHIs afterwards where there shouldn't really be any out-of-loop uses of the scalar in-loop def left. Bootstrapped and tested together with another patch, quickly re-testing after splitting out now. Richard. * tree-vect-loop.cc (vectorizable_live_operation): Simplify LC PHI replacement. --- gcc/tree-vect-loop.cc | 53 ++++++++++++++----------------------------- 1 file changed, 17 insertions(+), 36 deletions(-) diff --git a/gcc/tree-vect-loop.cc b/gcc/tree-vect-loop.cc index 2a43176bcfd..362856a6507 100644 --- a/gcc/tree-vect-loop.cc +++ b/gcc/tree-vect-loop.cc @@ -10698,49 +10698,30 @@ vectorizable_live_operation (vec_info *vinfo, stmt_vec_info stmt_info, &stmts, true, NULL_TREE); } + gimple_stmt_iterator exit_gsi = gsi_after_labels (exit_bb); if (stmts) - { - gimple_stmt_iterator exit_gsi = gsi_after_labels (exit_bb); - gsi_insert_seq_before (&exit_gsi, stmts, GSI_SAME_STMT); + gsi_insert_seq_before (&exit_gsi, stmts, GSI_SAME_STMT); - /* Remove existing phi from lhs and create one copy from new_tree. */ - tree lhs_phi = NULL_TREE; - gimple_stmt_iterator gsi; - for (gsi = gsi_start_phis (exit_bb); - !gsi_end_p (gsi); gsi_next (&gsi)) + /* Remove existing phis that copy from lhs and create copies + from new_tree. */ + gimple_stmt_iterator gsi; + for (gsi = gsi_start_phis (exit_bb); !gsi_end_p (gsi);) + { + gimple *phi = gsi_stmt (gsi); + if ((gimple_phi_arg_def (phi, 0) == lhs)) { - gimple *phi = gsi_stmt (gsi); - if ((gimple_phi_arg_def (phi, 0) == lhs)) - { - remove_phi_node (&gsi, false); - lhs_phi = gimple_phi_result (phi); - gimple *copy = gimple_build_assign (lhs_phi, new_tree); - gsi_insert_before (&exit_gsi, copy, GSI_SAME_STMT); - break; - } + remove_phi_node (&gsi, false); + tree lhs_phi = gimple_phi_result (phi); + gimple *copy = gimple_build_assign (lhs_phi, new_tree); + gsi_insert_before (&exit_gsi, copy, GSI_SAME_STMT); } + else + gsi_next (&gsi); } - /* Replace use of lhs with newly computed result. If the use stmt is a - single arg PHI, just replace all uses of PHI result. It's necessary - because lcssa PHI defining lhs may be before newly inserted stmt. */ - use_operand_p use_p; + /* There a no further out-of-loop uses of lhs by LC-SSA construction. */ FOR_EACH_IMM_USE_STMT (use_stmt, imm_iter, lhs) - if (!flow_bb_inside_loop_p (loop, gimple_bb (use_stmt)) - && !is_gimple_debug (use_stmt)) - { - if (gimple_code (use_stmt) == GIMPLE_PHI - && gimple_phi_num_args (use_stmt) == 1) - { - replace_uses_by (gimple_phi_result (use_stmt), new_tree); - } - else - { - FOR_EACH_IMM_USE_ON_STMT (use_p, imm_iter) - SET_USE (use_p, new_tree); - } - update_stmt (use_stmt); - } + gcc_assert (flow_bb_inside_loop_p (loop, gimple_bb (use_stmt))); } else {