https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113014

            Bug ID: 113014
           Summary: RISC-V: Redundant zeroing instructions in reduction
           Product: gcc
           Version: 14.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: juzhe.zhong at rivai dot ai
  Target Milestone: ---

#define DEF_REDUC_PLUS(TYPE)                                                  
\
  TYPE __attribute__ ((noinline, noclone))                                    
\
  reduc_plus_##TYPE (TYPE *__restrict a, int n)                               
\
  {                                                                           
\
    TYPE r = 0;                                                               
\
    for (int i = 0; i < n; ++i)                                               
\
      r += a[i];                                                              
\
    return r;                                                                 
\
  }

#define TEST_PLUS(T) T (int) T (float)

TEST_PLUS (DEF_REDUC_PLUS)

-fno-vect-cost-model:

        li      a5,0             ---> redundant instruction
        vsetivli        zero,1,e32,m1,ta,ma
        vmv.s.x v2,a5

It should be vmv.s.x v2,zero instead.

I realize this is because this commit:
https://hub.fgit.cf/gcc-mirror/gcc/commit/6223ea766daf7c9155106b9784302442e2ff98d3

we change define_expand into define_insn_and_split, since split1 is after
combine pass.

we missed optimization of (vec_duplicate:const0_rtx) into (const_vector:0).

Reply via email to