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

            Bug ID: 129220
           Summary: aarch64: vect-widen-{add,sub,lshift}.c and pr113552.c
                    fail after r17-6878-g71466227eb89fd
           Product: gcc
           Version: 17.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: testsuite
          Assignee: unassigned at gcc dot gnu.org
          Reporter: yansendao at 126 dot com
  Target Milestone: ---

After r17-6878-g71466227eb89fd ("tree-optimization/128626 - restrict TBAA
check in vect dependence analysis to read-before-write"), the vectorizer no
longer uses TBAA to disambiguate a write-after-read anti-dependence between
incompatible types.  Four aarch64 codegen tests write through an
int32_t/uint32_t/double pointer and read through a narrower or otherwise
incompatible type, so each loop now gains a runtime aliasing check plus a
second, narrower vectorized version.  That changes the widened instruction
counts and breaks the scan-assembler-times checks (aarch64 trunk daily):

  FAIL: gcc.target/aarch64/pr113552.c scan-assembler-times bl\t_ZGVnN2v_cos 6
         (now 12; two vectorized versions)
  FAIL: gcc.target/aarch64/vect-widen-add.c scan-assembler-times \tsaddl\t 1
  FAIL: gcc.target/aarch64/vect-widen-add.c scan-assembler-times \tuaddl\t 1
  FAIL: gcc.target/aarch64/vect-widen-sub.c scan-assembler-times \tssubl\t 1
  FAIL: gcc.target/aarch64/vect-widen-sub.c scan-assembler-times \tusubl\t 1
  FAIL: gcc.target/aarch64/vect-widen-lshift.c scan-assembler-times \tshll\t 1
         (each widen-low mnemonic now appears 3 times: 1 in the vector loop
          plus 2 in the unrolled fallback loop, which only uses the *low*
          form and not the *2 high form)

The vectorizer change itself is correct (it fixes a wrong-code bug); these
tests are checking the vectorized widening pattern and do not intend the
output to alias the inputs.  Marking the output pointer __restrict makes the
no-alias assumption explicit and restores the single-version vectorization,
so the scan-assembler-times counts are exact again.

Reproduce (aarch64, e.g. a build at 46ccccd5576):

  $ make -k check-gcc \
      RUNTESTFLAGS="aarch64.exp=vect-widen-add.c aarch64.exp=vect-widen-sub.c
aarch64.exp=vect-widen-lshift.c aarch64.exp=pr113552.c"

Proposed fix (add __restrict to the output pointer of each optimized
function):

  gcc.target/aarch64/pr113552.c          foo: double *__restrict b
  gcc.target/aarch64/vect-widen-add.c    uadd_opt, sadd_opt: *__restrict foo
  gcc.target/aarch64/vect-widen-sub.c    usub_opt, ssub_opt: *__restrict foo
  gcc.target/aarch64/vect-widen-lshift.c sshll_opt: *__restrict foo

Reply via email to