— Jojo
在 2021年8月10日 +0800 PM7:03,Richard Biener <richard.guent...@gmail.com>,写道:
> On Tue, Aug 10, 2021 at 10:33 AM Jojo R via Gcc-patches
> <gcc-patches@gcc.gnu.org> wrote:
> >
> > Some target like RISC-V allow to group vector register as a whole,
> > and only operate part of it in fact, but the 'init-regs' pass will add 
> > initialization
> > for uninitialized registers. Add this hook to reject this action for 
> > reducing instruction.
>
> Are these groups "visible"? That is, are the pseudos multi-reg
> pseudos? I wonder
> if there's a more generic way to tame down initregs w/o introducing a new 
> target
> hook.

Yes, it is visible. I make a simple demo as:

vuint8m1_t
foo (vuint8m1_t a, vuint8m2_t b, int vl)
{
  vuint8m2_t tmp;
  tmp = vset_v_u8m1_u8m2(tmp, 0, a);
  tmp = vadd_vv_u8m2 (tmp, b, vl);
  return vget_v_u8m2_u8m1(tmp, 0);
}

The intrinsic spec refer to:
https://github.com/riscv/rvv-intrinsic-doc/blob/master/rvv-intrinsic-api.md#vector-insertion-functions

The problematic intrinsic is vset_v_u8m1_u8m2() here,
Only half of it is operated, and

RTL dump from ‘266r.auto_inc_dec’ is :

(insn 11 8 12 2 (set (reg:VNx32QI 138 [ _10 ])
 (unspec:VNx32QI [
 (reg/v:VNx32QI 135 [ tmp ])
 (reg:SI 66 vl)
 ] UNSPEC_USEVL)) "riscv_vector.h":235:1 21133 {*movvnx32qi}
 (expr_list:REG_DEAD (reg/v:VNx32QI 135 [ tmp ])
 (nil)))

(insn 12 11 13 2 (set (subreg:VNx16QI (reg:VNx32QI 138 [ _10 ]) 0)
 (unspec:VNx16QI [
 (reg/v:VNx16QI 141 [ a ])
 (reg:SI 66 vl)
 ] UNSPEC_USEVL)) "riscv_vector.h":235:1 21132 {*movvnx16qi}
 (expr_list:REG_DEAD (reg/v:VNx16QI 141 [ a ])
 (expr_list:REG_DEAD (reg:SI 66 vl)
 (nil))))

RTL dump from ‘267r.init-regs’ is :

starting the processing of deferred insns
ending the processing of deferred insns
df_analyze called
scanning new insn with uid = 24.
scanning new insn with uid = 25.
scanning new insn with uid = 26.
scanning new insn with uid = 27.
adding initialization in foo of reg 135 at in block 2 for insn 11.
starting the processing of deferred insns
ending the processing of deferred insns

… …
>
> Btw, initregs is a red herring - it ideally should go away. See PR61810.
>
> So instead of adding to it can you see whether disabling the pass for RISC-V
> works w/o fallout (and add a comment to the PR)? Maybe some more RTL
> literate (in particular DF literate) can look at the remaining issue.
> Richard, did you
> ever have a look into the "issue" that initregs covers up (whatever
> that exactly is)?
>
> Thanks,
> Richard.
>
> > gcc/
> > * init-regs.c (initialize_uninitialized_regs): Call register_reject_init_p.
> > * target.def (register_reject_init_p): New hook.
> > * doc/tm.texi.in: Add TARGET_REGISTER_REJECT_INIT_P.
> > * doc/tm.texi: Regenerated.
> > ---
> > gcc/doc/tm.texi | 6 ++++++
> > gcc/doc/tm.texi.in | 2 ++
> > gcc/init-regs.c | 5 +++++
> > gcc/target.def | 8 ++++++++
> > 4 files changed, 21 insertions(+)
> >
> > diff --git a/gcc/doc/tm.texi b/gcc/doc/tm.texi
> > index a30fdcbbf3d6..83fd5496ca3f 100644
> > --- a/gcc/doc/tm.texi
> > +++ b/gcc/doc/tm.texi
> > @@ -12588,3 +12588,9 @@ Return an RTX representing @var{tagged_pointer} 
> > with its tag set to zero.
> > Store the result in @var{target} if convenient.
> > The default clears the top byte of the original pointer.
> > @end deftypefn
> > +
> > +@deftypefn {Target Hook} bool TARGET_REGISTER_REJECT_INIT_P (rtx @var{reg})
> > +This target hook should return @code{true} if reject initialization for a 
> > uninitialized @var{reg}.
> > +
> > +The default value of this hook is @code{NULL}.
> > +@end deftypefn
> > diff --git a/gcc/doc/tm.texi.in b/gcc/doc/tm.texi.in
> > index 611fc500ac86..13174ce66d59 100644
> > --- a/gcc/doc/tm.texi.in
> > +++ b/gcc/doc/tm.texi.in
> > @@ -8180,3 +8180,5 @@ maintainer is familiar with.
> > @hook TARGET_MEMTAG_EXTRACT_TAG
> >
> > @hook TARGET_MEMTAG_UNTAGGED_POINTER
> > +
> > +@hook TARGET_REGISTER_REJECT_INIT_P
> > diff --git a/gcc/init-regs.c b/gcc/init-regs.c
> > index 72e898f3e334..51c0d669d30b 100644
> > --- a/gcc/init-regs.c
> > +++ b/gcc/init-regs.c
> > @@ -21,6 +21,7 @@ along with GCC; see the file COPYING3. If not see
> > #include "system.h"
> > #include "coretypes.h"
> > #include "backend.h"
> > +#include "target.h"
> > #include "rtl.h"
> > #include "tree.h"
> > #include "df.h"
> > @@ -101,6 +102,10 @@ initialize_uninitialized_regs (void)
> > rtx_insn *move_insn;
> > rtx reg = DF_REF_REAL_REG (use);
> >
> > + if (targetm.register_reject_init_p
> > + && targetm.register_reject_init_p (reg))
> > + continue;
> > +
> > bitmap_set_bit (already_genned, regno);
> >
> > start_sequence ();
> > diff --git a/gcc/target.def b/gcc/target.def
> > index 7676d5e626e3..c2b54421618d 100644
> > --- a/gcc/target.def
> > +++ b/gcc/target.def
> > @@ -4545,6 +4545,14 @@ by a subtarget.",
> > unsigned HOST_WIDE_INT, (void),
> > NULL)
> >
> > +/* Return true if reject initialization for a uninitialized register. */
> > +DEFHOOK
> > +(register_reject_init_p,
> > + "This target hook should return @code{true} if reject initialization for 
> > a uninitialized @var{reg}.\n\
> > +\n\
> > +The default value of this hook is @code{NULL}.",
> > + bool, (rtx reg), NULL)
> > +
> > /* Functions relating to calls - argument passing, returns, etc. */
> > /* Members of struct call have no special macro prefix. */
> > HOOK_VECTOR (TARGET_CALLS, calls)
> > --
> > 2.24.3 (Apple Git-128)

Reply via email to