From patchwork Wed Nov 15 17:39:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vineet Gupta X-Patchwork-Id: 165540 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b909:0:b0:403:3b70:6f57 with SMTP id t9csp2700952vqg; Wed, 15 Nov 2023 09:39:43 -0800 (PST) X-Google-Smtp-Source: AGHT+IFOC+m4nP3PEhxq+d0u9ZGoKZ0NB0a/rF9o2GaPZ0xhA7YBnYQhqxJnXbomDyvpqKHqgIro X-Received: by 2002:a05:622a:2c1:b0:41c:cfc0:5c52 with SMTP id a1-20020a05622a02c100b0041ccfc05c52mr7968030qtx.39.1700069982930; Wed, 15 Nov 2023 09:39:42 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1700069982; cv=pass; d=google.com; s=arc-20160816; b=u9S1LH+SKCORcldPDsRfuuHh2z0fjCkSoEpdiJ6WU4Y4lfpHoFQQp/USa0+1fd0DJF 9aFdHXAsVLtS3V/ZWoDXbxr9d6U2fgOc02glkUJDhQKueFFm+b0/dUwIqsJxwSPF7tnx S1BDSfRLkFoZgTyXRmd/rgxF5H427x/UyL+i/n1rIlWkNz5ikmPrtXTBqVPUks4J2msj 2ETXDLl23bwFApHEuYyg7r4traGgt3ovMyVCkSeILkm0XZqdpfQj3jZhrpIZF/5l7F8W fpAEtJ9iWkqKYuUp79MuC8tuoAocV4u8TaEIFhwVAb5psRV97QTgpma7x1atOct24e7N PSXQ== 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:content-transfer-encoding :mime-version:message-id:date:subject:cc:to:from:dkim-signature :arc-filter:dmarc-filter:delivered-to; bh=HV6u4RBpra9EOP5PX2IwZZAUfDb47svvYvMaGAbEySw=; fh=CZ/VdAO3K8aUNSVYZslzUjpEzhHKKJoD1ujy9UE+t68=; b=ojzd9bEHRgtr814rZ9qKF3YrQmNeOLa1PpsYyyQ7UkJGugr86I66X9dIySF82dqwKX WPLZYGLz4DOXB8/2XIbGo6U0R2+yDpwtmBcHfelkoKw3DjvmwmKyv6ZT9RSz+tmxLvLg txEXL1eGfnliMthaddK0e5QbGAKSHrWO78w4PNXRO/JRVz8mFkAOPVci48iv2mFkZroH r8Day9FucPIvSNLt0bRyx1wYUt/wtc/MHVuiTjQqFQlD+JPdENQzLP/JA/qoeaUyx93w GMVhBUlOja3PxSqLogbFX49gDZj5Yq8zCO1zzzGBnEA5GyXnWXlIqfq7htqiOhCVQ3BR NRng== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b="TeL598/n"; arc=pass (i=1); 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" Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id 3-20020ac85743000000b004198fbc2a07si9637850qtx.344.2023.11.15.09.39.42 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Nov 2023 09:39:42 -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=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b="TeL598/n"; arc=pass (i=1); 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" Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id B1A7938582A2 for ; Wed, 15 Nov 2023 17:39:42 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-pl1-x62c.google.com (mail-pl1-x62c.google.com [IPv6:2607:f8b0:4864:20::62c]) by sourceware.org (Postfix) with ESMTPS id 272A03858425 for ; Wed, 15 Nov 2023 17:39:19 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 272A03858425 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=rivosinc.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=rivosinc.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 272A03858425 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::62c ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1700069960; cv=none; b=KyaJTeY3cVOyiFlJ68HDRl7V17uiQZMq0uoxId99pPDv8Yy64Ey1zq2xFU7EcyD5ko8FfQNf7Wi/EQvbpBTlVshlIN8gEJVlFw698Qp5I4G/uLxLjBSMsOxwXDx4UIfHz6x44dgGFmfZh7EfQoIgO2Jj37nSR1dQfdIdJ9yAQRQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1700069960; c=relaxed/simple; bh=FCtoWNGyaxxrG4Np7fuA9PCTflu4KV8mbA5WrP0JP6Y=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=dEThaGQ32WJBHnz39AEvfN2ufPVYnsN0I1TzTiBMXyHRvcV5zeu/66eg84T6Fql1rJPrvEct3bc5t5FO/2x39JKE4+9uhKEO9VqrEjcPS0FZarRLpMTDLpYv97geoFS2gUAntFFFMMKoMsfo9+s57Elmhig1G4dVkFPjjp+ADyE= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pl1-x62c.google.com with SMTP id d9443c01a7336-1cc5fa0e4d5so63189245ad.0 for ; Wed, 15 Nov 2023 09:39:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1700069958; x=1700674758; darn=gcc.gnu.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=HV6u4RBpra9EOP5PX2IwZZAUfDb47svvYvMaGAbEySw=; b=TeL598/nLuxrCIvnfl+e1cGGeuuzsUGzUI8An4H2196JwauiBfkvNUCvX+56ydJOok dQY0QCPXPapFIc4UpOw2fcYom5JfQ40F9S/gYIGORKgTzv3aczcyw2z8vU4svY4UGXPj c5I+WSM0160WLr0NdUISKNCc1s5IHEx7D+cgj62j65uwGnEWo43srFoxrx4TGsUdLRtR cEgMe8s4Qjgmun+v55+lAHzoel8cTGN3doekKCcpqn0TXPpGKnmze5evM6WpiyywJ+BX T9ol8hkckm/qA+MtesozYPmUUKF8XiV/yS6w7jKsuHPXIl3XIE8532HCADa2EskGatBd lN2Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700069958; x=1700674758; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=HV6u4RBpra9EOP5PX2IwZZAUfDb47svvYvMaGAbEySw=; b=KdWayYgnLoNEfab18VMWJ00cm1YIEOww0NwAUdiioqEcQYNwN/e/ghrVBe8IKGEBJ6 /dNxqwPuBemo4V1RV7+WN+MvfuxSudTw+xGexhVd7Em4yCnHt/5kHU85UboM4XNVQiT2 V8/YA0C6pedJSw45M8rstYMvvWtXEuqhb9Y+PJgh0uGjtJ+ZmjOHhBJMOOHjaqEYrvA1 qORYCh6Y09XnQqOlVL91SyjrpRluhmDPAy0PzYlLPXensvrU4re2MdqxnKyJvWw7eyJP r4Xl1VB56XH4dsnoo4fm1M7HLh/bos9P4vV6CQ0IZ40xijTlLgIvkPPHVpDDHE32yvLw iKGw== X-Gm-Message-State: AOJu0YzxvMbq0z1xS6wM2fxpP+nZ/OlleYcC9CvXlf5JVKkqlw8xeogy /sSxFZMESPP0BI+aDs9hM9JSChgzULtKQr2xTfSwxg== X-Received: by 2002:a17:902:f651:b0:1cc:6b55:fd3 with SMTP id m17-20020a170902f65100b001cc6b550fd3mr6474368plg.42.1700069957756; Wed, 15 Nov 2023 09:39:17 -0800 (PST) Received: from vineet-framework.. (c-73-170-212-163.hsd1.ca.comcast.net. [73.170.212.163]) by smtp.gmail.com with ESMTPSA id m6-20020a170902db8600b001c0a414695bsm7592703pld.43.2023.11.15.09.39.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Nov 2023 09:39:17 -0800 (PST) From: Vineet Gupta To: gcc-patches@gcc.gnu.org Cc: Jeff Law , Robin Dapp , gnu-toolchain@rivosinc.com, Juzhe-Zhong , Vineet Gupta Subject: [Committed] RISC-V: fix vsetvli pass testsuite failure [PR/112447] Date: Wed, 15 Nov 2023 09:39:13 -0800 Message-Id: <20231115173913.2159755-1-vineetg@rivosinc.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Spam-Status: No, score=-11.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, 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: 1782652582480374077 X-GMAIL-MSGID: 1782652582480374077 From: Juzhe-Zhong Fixes: f0e28d8c1371 ("RISC-V: Fix failed hoist in LICM of vmv.v.x instruction") Since above commit, we have following failure: FAIL: gcc.c-torture/execute/memset-3.c -O3 -fomit-frame-pointer -funroll-loops -fpeel-loops -ftracer -finline-functions execution test FAIL: gcc.c-torture/execute/memset-3.c -O3 -g execution test The issue was not the commit but rather it unravelled an issue in the vsetvli pass. Here's Juzhe's analysis: We have 2 types of global vsetvls insertion. One is earliest fusion of each end of the block. The other is LCM suggested edge vsetvls. So before this patch, insertion as follows: | (insn 2817 2820 2818 361 (set (reg:SI 67 vtype) | (unspec:SI [ | (const_int 8 [0x8]) | (const_int 7 [0x7]) | (const_int 1 [0x1]) repeated x2 | ] UNSPEC_VSETVL)) 1708 {vsetvl_vtype_change_only} | (nil)) | (insn 2818 2817 999 361 (set (reg:SI 67 vtype) | (unspec:SI [ | (const_int 32 [0x20]) | (const_int 1 [0x1]) repeated x3 | ] UNSPEC_VSETVL)) 1708 {vsetvl_vtype_change_only} | (nil)) After this patch: | (insn 2817 2820 2819 361 (set (reg:SI 67 vtype) | (unspec:SI [ | (const_int 32 [0x20]) | (const_int 1 [0x1]) repeated x3 | ] UNSPEC_VSETVL)) 1708 {vsetvl_vtype_change_only} | (nil)) | (insn 2819 2817 999 361 (set (reg:SI 67 vtype) | (unspec:SI [ | (const_int 8 [0x8]) | (const_int 7 [0x7]) | (const_int 1 [0x1]) repeated x2 | ] UNSPEC_VSETVL)) 1708 {vsetvl_vtype_change_only} | (nil)) The original insertion order is incorrect. We should first insert earliest fusion since it is the vsetvls information already there which was seen by later LCM. We just delay the insertion. So it should be come before the LCM suggested insertion. PR target/112447 gcc/ChangeLog: * config/riscv/riscv-vsetvl.cc (pre_vsetvl::emit_vsetvl): Insert local vsetvl info before LCM suggested one. Tested-by: Patrick O'Neill # pre-commit-CI #679 Co-developed-by: Vineet Gupta Signed-off-by: Vineet Gupta --- gcc/config/riscv/riscv-vsetvl.cc | 70 ++++++++++++++++---------------- 1 file changed, 35 insertions(+), 35 deletions(-) diff --git a/gcc/config/riscv/riscv-vsetvl.cc b/gcc/config/riscv/riscv-vsetvl.cc index 8466b5d019ea..74367ec8d8e9 100644 --- a/gcc/config/riscv/riscv-vsetvl.cc +++ b/gcc/config/riscv/riscv-vsetvl.cc @@ -3229,6 +3229,41 @@ pre_vsetvl::emit_vsetvl () remove_vsetvl_insn (item); } + /* Insert vsetvl info that was not deleted after lift up. */ + for (const bb_info *bb : crtl->ssa->bbs ()) + { + const vsetvl_block_info &block_info = get_block_info (bb); + if (!block_info.has_info ()) + continue; + + const vsetvl_info &footer_info = block_info.get_exit_info (); + + if (footer_info.delete_p ()) + continue; + + edge eg; + edge_iterator eg_iterator; + FOR_EACH_EDGE (eg, eg_iterator, bb->cfg_bb ()->succs) + { + gcc_assert (!(eg->flags & EDGE_ABNORMAL)); + if (dump_file) + { + fprintf ( + dump_file, + "\n Insert missed vsetvl info at edge(bb %u -> bb %u): ", + eg->src->index, eg->dest->index); + footer_info.dump (dump_file, " "); + } + start_sequence (); + insert_vsetvl_insn (EMIT_DIRECT, footer_info); + rtx_insn *rinsn = get_insns (); + end_sequence (); + default_rtl_profile (); + insert_insn_on_edge (rinsn, eg); + need_commit = true; + } + } + /* m_insert vsetvl as LCM suggest. */ for (int ed = 0; ed < NUM_EDGES (m_edges); ed++) { @@ -3267,41 +3302,6 @@ pre_vsetvl::emit_vsetvl () insert_insn_on_edge (rinsn, eg); } - /* Insert vsetvl info that was not deleted after lift up. */ - for (const bb_info *bb : crtl->ssa->bbs ()) - { - const vsetvl_block_info &block_info = get_block_info (bb); - if (!block_info.has_info ()) - continue; - - const vsetvl_info &footer_info = block_info.get_exit_info (); - - if (footer_info.delete_p ()) - continue; - - edge eg; - edge_iterator eg_iterator; - FOR_EACH_EDGE (eg, eg_iterator, bb->cfg_bb ()->succs) - { - gcc_assert (!(eg->flags & EDGE_ABNORMAL)); - if (dump_file) - { - fprintf ( - dump_file, - "\n Insert missed vsetvl info at edge(bb %u -> bb %u): ", - eg->src->index, eg->dest->index); - footer_info.dump (dump_file, " "); - } - start_sequence (); - insert_vsetvl_insn (EMIT_DIRECT, footer_info); - rtx_insn *rinsn = get_insns (); - end_sequence (); - default_rtl_profile (); - insert_insn_on_edge (rinsn, eg); - need_commit = true; - } - } - if (need_commit) commit_edge_insertions (); }