From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-vs1-xe32.google.com (mail-vs1-xe32.google.com [IPv6:2607:f8b0:4864:20::e32]) by sourceware.org (Postfix) with ESMTPS id E145338493E6 for ; Thu, 26 Jan 2023 19:13:34 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E145338493E6 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-vs1-xe32.google.com with SMTP id v127so2920892vsb.12 for ; Thu, 26 Jan 2023 11:13:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=i8jSf0A5PzpimTAyJgKZfqAhtLUIKZ/aUvPaI+E79W8=; b=VcxT/VYNTMAwTpl6KKfGx65PLDl248n/hz7CGiCAslfhW8a9g07uC+c/XMF8VeXdxh nnm4FlPbJbaaz/mSpDdMwY6JhfjZmbZqQnHgLNq7bdkC+BaCv6SmRaEvMeT0dszMIsH8 YWUrRwBjl07ZjdDZ1KpVYR3INub0nWx5lKuA+DZkN9H2i75vr8Mv8Dplfssk3sFi0CsX ADVRhHP0zDm2oZAm4V38oDGk7yniWtnXrU9Jr/iYWekJxYDQe+PH+qRCyOa3jCeE3Leh RhwKZvAIfJcm7MTQgKgInFKlOyknmY7EiUuucXoSMUhTxv3CK2/dx2nU4C1Uql97RrEI av1Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=i8jSf0A5PzpimTAyJgKZfqAhtLUIKZ/aUvPaI+E79W8=; b=FQqGaQwpRyfWQN2HNONWm9O2YkTwllXnNkkVmS5/qpjgcju6rmQRcOgDcjdGgxDkv4 tnmSgDKjvz2+4sZbLOaH14K4dDMlcVYYVydgmOe1bWXPCCd475xm/ScDVgeMZF6jibzS tN5gW1vqYnNEEhIbPEiE5Kh4yuqGH5shW/qDxb0Ddn3xJY1CweThqJ0fPZognEbskNWr f2/LCgzKfm21+XUARKKsKrM91yENEeLFtrxY6j63Zc+Es2DzoBmhCL0QI+ToHit6ONdb YyEp+Uvle/SDMvLmYaYGKmvdSmnhY4Lhp2vwyKVu5fy1Ggmuky7or6Cj42WXG5HJ+YUY ME3A== X-Gm-Message-State: AFqh2kq+z1Q8rdOxME8saYiGObe3GVhnY4zM40oXEBEfyC/mXR/KZa3C VxZxBfC2GlWn+xAMkk8y79NZaGS7jJZKGYCygVw= X-Google-Smtp-Source: AMrXdXuIYjwknRjZSb28GIjpjYS+Rpa0qrPuBUjIYJ0f2iumM8ZjsFQyoGpCQ2ZwJj1nEDodtwRsUsGaxmFc89+nSoc= X-Received: by 2002:a05:6102:6c2:b0:3ce:bced:178 with SMTP id m2-20020a05610206c200b003cebced0178mr4992998vsg.84.1674760414112; Thu, 26 Jan 2023 11:13:34 -0800 (PST) MIME-Version: 1.0 References: <20230103071641.149958-1-juzhe.zhong@rivai.ai> In-Reply-To: <20230103071641.149958-1-juzhe.zhong@rivai.ai> From: Kito Cheng Date: Fri, 27 Jan 2023 03:13:22 +0800 Message-ID: Subject: Re: [PATCH] RISC-V: Fix backward_propagate_worthwhile_p To: juzhe.zhong@rivai.ai Cc: gcc-patches@gcc.gnu.org, palmer@dabbelt.com Content-Type: multipart/alternative; boundary="00000000000091338a05f32f8bec" X-Spam-Status: No, score=-8.3 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,GIT_PATCH_0,HTML_MESSAGE,RCVD_IN_DNSWL_NONE,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 List-Id: --00000000000091338a05f32f8bec Content-Type: text/plain; charset="UTF-8" committed, thanks. On Tue, Jan 3, 2023 at 3:17 PM wrote: > From: Ju-Zhe Zhong > > gcc/ChangeLog: > > * config/riscv/riscv-vsetvl.cc (loop_basic_block_p): Adjust > function. > (backward_propagate_worthwhile_p): Fix non-worthwhile. > > --- > gcc/config/riscv/riscv-vsetvl.cc | 91 +++++++++++++++++++++++++------- > 1 file changed, 71 insertions(+), 20 deletions(-) > > diff --git a/gcc/config/riscv/riscv-vsetvl.cc > b/gcc/config/riscv/riscv-vsetvl.cc > index ad0457ed89d..fe76bea297e 100644 > --- a/gcc/config/riscv/riscv-vsetvl.cc > +++ b/gcc/config/riscv/riscv-vsetvl.cc > @@ -116,10 +116,27 @@ vlmax_avl_insn_p (rtx_insn *rinsn) > || INSN_CODE (rinsn) == CODE_FOR_vlmax_avldi); > } > > +/* Return true if the block is a loop itself: > + local_dem > + __________ > + ____|____ | > + | | | > + |________| | > + |_________| > + reaching_out > +*/ > static bool > loop_basic_block_p (const basic_block cfg_bb) > { > - return JUMP_P (BB_END (cfg_bb)) && any_condjump_p (BB_END (cfg_bb)); > + if (JUMP_P (BB_END (cfg_bb)) && any_condjump_p (BB_END (cfg_bb))) > + { > + edge e; > + edge_iterator ei; > + FOR_EACH_EDGE (e, ei, cfg_bb->succs) > + if (e->dest->index == cfg_bb->index) > + return true; > + } > + return false; > } > > /* Return true if it is an RVV instruction depends on VTYPE global > @@ -271,26 +288,60 @@ backward_propagate_worthwhile_p (const basic_block > cfg_bb, > { > if (loop_basic_block_p (cfg_bb)) > { > - if (block_info.local_dem.compatible_p (block_info.reaching_out)) > - return true; > - > - /* There is a obvious case that is not worthwhile and meaningless > - to propagate the demand information: > - local_dem > - __________ > - ____|____ | > - | | | > - |________| | > - |_________| > - reaching_out > - Header is incompatible with reaching_out and the block is loop > itself, > - we don't backward propagate the local_dem since we can't avoid > emit > - vsetvl for the local_dem. */ > - edge e; > - edge_iterator ei; > - FOR_EACH_EDGE (e, ei, cfg_bb->succs) > - if (e->dest->index == cfg_bb->index) > + if (block_info.reaching_out.valid_or_dirty_p ()) > + { > + if (block_info.local_dem.compatible_p (block_info.reaching_out)) > + { > + /* Case 1 (Can backward propagate): > + .... > + bb0: > + ... > + for (int i = 0; i < n; i++) > + { > + vint16mf4_t v = __riscv_vle16_v_i16mf4 (in + i + 5, > 7); > + __riscv_vse16_v_i16mf4 (out + i + 5, v, 7); > + } > + The local_dem is compatible with reaching_out. Such case > is > + worthwhile backward propagation. */ > + return true; > + } > + else > + { > + /* Case 2 (Don't backward propagate): > + .... > + bb0: > + ... > + for (int i = 0; i < n; i++) > + { > + vint16mf4_t v = __riscv_vle16_v_i16mf4 (in + i + > 5, 7); > + __riscv_vse16_v_i16mf4 (out + i + 5, v, 7); > + vint16mf2_t v2 = __riscv_vle16_v_i16mf2 (in + i + > 6, 8); > + __riscv_vse16_v_i16mf2 (out + i + 6, v, 8); > + } > + The local_dem is incompatible with reaching_out. > + It makes no sense to backward propagate the local_dem > since we > + can't avoid VSETVL inside the loop. */ > + return false; > + } > + } > + else > + { > + gcc_assert (block_info.reaching_out.unknown_p ()); > + /* Case 3 (Don't backward propagate): > + .... > + bb0: > + ... > + for (int i = 0; i < n; i++) > + { > + vint16mf4_t v = __riscv_vle16_v_i16mf4 (in + i + 5, 7); > + __riscv_vse16_v_i16mf4 (out + i + 5, v, 7); > + fn3 (); > + } > + The local_dem is VALID, but the reaching_out is UNKNOWN. > + It makes no sense to backward propagate the local_dem since we > + can't avoid VSETVL inside the loop. */ > return false; > + } > } > > return true; > -- > 2.36.3 > > --00000000000091338a05f32f8bec--