From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ed1-x531.google.com (mail-ed1-x531.google.com [IPv6:2a00:1450:4864:20::531]) by sourceware.org (Postfix) with ESMTPS id 8E4C2385B515 for ; Mon, 13 Nov 2023 08:07:10 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 8E4C2385B515 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 8E4C2385B515 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::531 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1699862832; cv=none; b=mr/oJFSMkeMoC7F0HKnJg0LkMFtevjyhssWVQCZHFLJrNsW6ajL3sLZmTHxvJsmsP4UebhevzTxUBcfDa139J1NgTI7+3RmtJuFq9QpBJVUwOQpAC5ct02zEIj4vS0B9a3g/On0wbGMKTZy53smATq9flYOrL5y8uApzniqdXSc= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1699862832; c=relaxed/simple; bh=MWKUDj54db6vahffU1MyhJ9DIC7dZGpmttrojRWiqPI=; h=DKIM-Signature:Message-ID:Date:MIME-Version:To:From:Subject; b=sotVK0MXeqXMg7IbyyK3SaumjzVdmXB9WrHCo84So+zRtyKQtqmAZldIlLcjkpaF/oVVB3A6RbZvObnk/vlQQRF4N3WFKT7Kzp2LM63wQjID4Httkswmz4UPqAofFkHK4sZJwSJo/ZHMERkH8zrXdh9Fw9VApGD5y5bHzCbjbR0= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-ed1-x531.google.com with SMTP id 4fb4d7f45d1cf-53de8fc1ad8so6257726a12.0 for ; Mon, 13 Nov 2023 00:07:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1699862829; x=1700467629; darn=gcc.gnu.org; h=content-transfer-encoding:subject:from:to:content-language:cc :user-agent:mime-version:date:message-id:from:to:cc:subject:date :message-id:reply-to; bh=70e0uXbQh/LINqfvNwHNniibUoAPl2cfJFkA1azmf3k=; b=lQFmNke0R+TCQZfJcAhOzOdm7U31lvCv0PlY6C87Fq3DSXm9kSkU2/l+vjR5/JMGp5 54S3ZxvjmJzxz+SHMOnxvHdVkDLsWLENc4MWzx73heNB/iJqGJJPFJL+PEw7Nx7ARYa+ RgCWZOHIZ092fWwk5Y9gAfNFJRtFd8JvqEvTXnKYOVz2ng8tt+OASCaqABJn1CIQOm5b 6PAaW/tzbVDAU6TVTF2LMIMSFiAhiab342VKfgYjUsQ6YLnT/Yei32Sdthp7UosoRIMv +uVLSeG2tdjkUhmszuBqoVyhMiXpjqkmV03fX99X/gsfbeuXZZd/dpCy70vyJNRm0sz5 QV9w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699862829; x=1700467629; h=content-transfer-encoding:subject:from:to:content-language:cc :user-agent:mime-version:date:message-id:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=70e0uXbQh/LINqfvNwHNniibUoAPl2cfJFkA1azmf3k=; b=Wj9KV0iUVAS6PioIQSA8qXXfI63x9twDqPtG5LxCqTOKsJY6Up0xsiCb6FTU0qBOEc Lkma/X++ds9NS0Y4AU3+xl2xvALM3QxiG+TeR4dp+ZcuIDZFeOzXPgIscVU/wJjDlbTz 5qiGjUQptDc+UynYEqpuQYrVcQrc2taRbBE0PHbGitcRVoH+vhequKYvza+IsXCeydLI fmGKMV4FOz0JZVdo0RO5D7mkXrs3TSgzqVfKZxkUuJzgHCCMlaFhhcfibUfNdfume8cM 5Un4uSMpwhwjQtS0Td2gwiM1JC7DGkXUQCqaTaMKklwxj5KKCV01nYpliAOue6Qcc5Y9 lhpg== X-Gm-Message-State: AOJu0Yz7lPTvbUDEfHnQfzK1rGudV5Ue7y1UrWmMfL1VQLBeBnjgSqrF WKqE3had9oPmh0hJy0BUGFxQ5JgDnJM= X-Google-Smtp-Source: AGHT+IGdSn4v6qrsllYD9S8e8W5geTYLMMeBawfVN1t/VIkm8D7arqq8cTWcJ0RlT4MZS2mEtdJH1w== X-Received: by 2002:aa7:d4c2:0:b0:543:9670:7ee8 with SMTP id t2-20020aa7d4c2000000b0054396707ee8mr3888787edr.14.1699862828599; Mon, 13 Nov 2023 00:07:08 -0800 (PST) Received: from [192.168.1.23] (ip-046-223-203-173.um13.pools.vodafone-ip.de. [46.223.203.173]) by smtp.gmail.com with ESMTPSA id r20-20020aa7cfd4000000b005435c317fedsm3285558edy.80.2023.11.13.00.07.00 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 13 Nov 2023 00:07:08 -0800 (PST) Message-ID: Date: Mon, 13 Nov 2023 09:06:35 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Cc: rdapp.gcc@gmail.com Content-Language: en-US To: gcc-patches , palmer , Kito Cheng , jeffreyalaw , "juzhe.zhong@rivai.ai" From: Robin Dapp Subject: [PATCH] RISC-V: vsetvl: Refine REG_EQUAL equality. Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-9.3 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,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 List-Id: Hi, this patch enhances the equality check for REG_EQUAL notes in the vsetvl pass. Currently, we assume that two such notes describe the same value when they have the same rtx representation. This is not true when either of the note's source operands is modified by an insn between the two notes. Suppose: (insn 62 60 63 4 (set (reg:DI 17 a7 [orig:154 loop_len_54 ] [154]) (umin:DI (reg:DI 15 a5 [orig:174 _100 ] [174]) (reg:DI 30 t5 [219]))) 442 {umindi3} (expr_list:REG_EQUAL (umin:DI (reg:DI 15 a5 [orig:174 _100 ] [174]) (const_int 8 [0x8])) (nil))) (insn 63 62 65 4 (set (reg:DI 15 a5 [orig:175 _103 ] [175]) (minus:DI (reg:DI 15 a5 [orig:174 _100 ] [174]) (reg:DI 17 a7 [orig:154 loop_len_54 ] [154]))) 11 {subdi3} (nil)) (insn 65 63 66 4 (set (reg:DI 16 a6 [orig:153 loop_len_53 ] [153]) (umin:DI (reg:DI 15 a5 [orig:175 _103 ] [175]) (reg:DI 30 t5 [219]))) 442 {umindi3} (expr_list:REG_EQUAL (umin:DI (reg:DI 15 a5 [orig:175 _103 ] [175]) (const_int 8 [0x8])) (nil))) where insn 63 overwrites a5 and insn 65's REG_EQUAL note that refers to a5 describes a different value than insn 62's REG_EQUAL note. In order to catch this situation this patch has source_equal_p check every instruction between two notes for modification of any participating register. Regards Robin gcc/ChangeLog: * config/riscv/riscv-vsetvl.cc (modify_reg_between_p): Move. (source_equal_p): Check if source registers were modified in between. --- gcc/config/riscv/riscv-vsetvl.cc | 62 ++++++++++++++++++++++++-------- 1 file changed, 47 insertions(+), 15 deletions(-) diff --git a/gcc/config/riscv/riscv-vsetvl.cc b/gcc/config/riscv/riscv-vsetvl.cc index 3fa25a6404d..34bf7498103 100644 --- a/gcc/config/riscv/riscv-vsetvl.cc +++ b/gcc/config/riscv/riscv-vsetvl.cc @@ -85,6 +85,7 @@ along with GCC; see the file COPYING3. If not see #include "predict.h" #include "profile-count.h" #include "gcse.h" +#include "rtl-iter.h" using namespace rtl_ssa; using namespace riscv_vector; @@ -548,6 +549,21 @@ get_all_sets (set_info *set, bool /* get_real_inst */ real_p, return hash_set (); } +static bool +modify_reg_between_p (insn_info *prev_insn, insn_info *curr_insn, + unsigned regno) +{ + gcc_assert (prev_insn->compare_with (curr_insn) < 0); + for (insn_info *i = curr_insn->prev_nondebug_insn (); i != prev_insn; + i = i->prev_nondebug_insn ()) + { + // no def of regno + if (find_access (i->defs (), regno)) + return true; + } + return false; +} + static bool source_equal_p (insn_info *insn1, insn_info *insn2) { @@ -561,7 +577,37 @@ source_equal_p (insn_info *insn1, insn_info *insn2) rtx note1 = find_reg_equal_equiv_note (rinsn1); rtx note2 = find_reg_equal_equiv_note (rinsn2); if (note1 && note2 && rtx_equal_p (note1, note2)) - return true; + { + /* REG_EQUIVs are globally. */ + if (REG_NOTE_KIND (note2) == REG_EQUIV) + return true; + + /* If both insns are the same, the notes are definitely equivalent. */ + if (insn2->compare_with (insn1) == 0) + return true; + + /* Canonicalize order so insn1 is always before insn2 for the following + check. */ + if (insn2->compare_with (insn1) < 0) + std::swap (insn1, insn2); + + /* If two REG_EQUAL notes are similar the value they calculate can still + be different. The value is only identical if none of the sources have + been modified in between. */ + subrtx_iterator::array_type array; + FOR_EACH_SUBRTX (iter, array, note2, NONCONST) + { + if (!*iter) + continue; + + if (!REG_P (*iter)) + continue; + + if (modify_reg_between_p (insn1, insn2, REGNO (*iter))) + return false; + } + return true; + } return false; } @@ -1439,20 +1485,6 @@ private: && find_access (i->defs (), REGNO (info.get_avl ())); } - inline bool modify_reg_between_p (insn_info *prev_insn, insn_info *curr_insn, - unsigned regno) - { - gcc_assert (prev_insn->compare_with (curr_insn) < 0); - for (insn_info *i = curr_insn->prev_nondebug_insn (); i != prev_insn; - i = i->prev_nondebug_insn ()) - { - // no def of regno - if (find_access (i->defs (), regno)) - return true; - } - return false; - } - inline bool reg_avl_equal_p (const vsetvl_info &prev, const vsetvl_info &next) { if (!prev.has_nonvlmax_reg_avl () || !next.has_nonvlmax_reg_avl ()) -- 2.41.0