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

            Bug ID: 124032
           Summary: Apply demorgan's rule to improve aliasing check
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: rtl-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: law at gcc dot gnu.org
  Target Milestone: ---

Consider this on rv64gcbv_zicond at -O3 (from 525.x264_r):

#include <stdint.h>                                                             
void pixel_avg(uint8_t *dst,
               uint8_t *src1,
               uint8_t *src2)
{
  for( int y = 0; y < 8; y++ )
      dst[y] = (src1[y] + src2[y] + 1) >> 1;
}

The guard for the vector loop looks like:

        sltiu   a4,a4,7 # 10    [c=4 l=4]  *sleu_didi
        sltiu   a5,a5,7 # 15    [c=4 l=4]  *sleu_didi
        seqz    a4,a4   # 11    [c=4 l=4]  *seq_zero_didi
        seqz    a5,a5   # 16    [c=4 l=4]  *seq_zero_didi
        and     a5,a4,a5        # 21    [c=4 l=4]  *anddi3/0
        csrwi   vxrm,0  # 118   [c=4 l=4]  vxrmsi
        beq     a5,zero,.L2     # 22    [c=16 l=4]  *branchdi

Note how we effectively have to invert the sltiu result (via seqz), feed those
into an AND then branch on equality.

It would be better to drop the seqz instructions and use IOR instead.

Reply via email to