]> git.ipfire.org Git - thirdparty/gcc.git/commit
[to-be-committed][RISC-V][V3] DCE analysis for extension elimination
authorJeff Law <jlaw@ventanamicro.com>
Mon, 8 Jul 2024 23:06:55 +0000 (17:06 -0600)
committerJeff Law <jlaw@ventanamicro.com>
Mon, 8 Jul 2024 23:15:12 +0000 (17:15 -0600)
commit98914f9eba5f19d3eb93fbce8726b5264631cba0
tree2357d5cff40cedd7f4c890b4d3b41767546bd191
parent113b5ce0610207717f651a3f8a3f1123d93f97af
[to-be-committed][RISC-V][V3] DCE analysis for extension elimination

The pre-commit testing showed that making ext-dce only active at -O2 and above
would require minor edits to the tests.  In some cases we had specified -O1 in
the test or specified no optimization level at all. Those need to be bumped to
-O2.   In one test we had one set of dg-options overriding another.

The other approach that could have been taken would be to drop the -On
argument, add an explicit -fext-dce and add dg-skip-if options.  I originally
thought that was going to be way to go, but the dg-skip-if aspect was going to
get ugly as things like interaction between unrolling, peeling and -ftracer
would have to be accounted for and would likely need semi-regular adjustment.

Changes since V2:
  Testsuite changes to deal with pass only being enabled at -O2 or
  higher.

--

Changes since V1:

  Check flag_ext_dce before running the new pass.  I'd forgotten that
  I had removed that part of the gate to facilitate more testing.
  Turn flag_ext_dce on at -O2 and above.
  Adjust one of the riscv tests to explicitly avoid vectors
  Adjust a few aarch64 tests
    In tbz_2.c we remove an unnecessary extension which causes us to use
    "x" registers instead of "w" registers.

    In the pred_clobber tests we also remove an extension and that
    ultimately causes a reg->reg copy to change locations.

--

This was actually ack'd late in the gcc-14 cycle, but I chose not to integrate
it given how late we were in the cycle.

The basic idea here is to track liveness of subobjects within a word and if we
find an extension where the bits set aren't actually used, then we convert the
extension into a subreg.  The subreg typically simplifies away.

I've seen this help a few routines in coremark, fix one bug in the testsuite
(pr111384) and fix a couple internally reported bugs in Ventana.

The original idea and code were from Joern; Jivan and I hacked it into usable
shape.  I've had this in my tester for ~8 months, so it's been through more
build/test cycles than I care to contemplate and nearly every architecture we
support.

But just in case, I'm going to wait for it to spin through the pre-commit CI
tester.  I'll find my old ChangeLog before committing.

gcc/
* Makefile.in (OBJS): Add ext-dce.o
* common.opt (ext-dce): Document new option.
* df-scan.cc (df_get_ext_block_use_set): Delete prototype and
make extern.
* df.h (df_get_exit_block_use_set): Prototype.
* ext-dce.cc: New file/pass.
* opts.cc (default_options_table): Handle ext-dce at -O2 or higher.
* passes.def: Add ext-dce before combine.
* tree-pass.h (make_pass_ext_dce): Prototype.

gcc/testsuite
* gcc.target/aarch64/sve/pred_clobber_1.c: Update expected output.
* gcc.target/aarch64/sve/pred_clobber_2.c: Likewise.
* gcc.target/aarch64/sve/pred_clobber_3.c: Likewise.
* gcc.target/aarch64/tbz_2.c: Likewise.
* gcc.target/riscv/core_bench_list.c: New test.
* gcc.target/riscv/core_init_matrix.c: New test.
* gcc.target/riscv/core_list_init.c: New test.
* gcc.target/riscv/matrix_add_const.c: New test.
* gcc.target/riscv/mem-extend.c: New test.
* gcc.target/riscv/pr111384.c: New test.

Co-authored-by: Jivan Hakobyan <jivanhakobyan9@gmail.com>
Co-authored-by: Joern Rennecke <joern.rennecke@embecosm.com>
18 files changed:
gcc/Makefile.in
gcc/common.opt
gcc/df-scan.cc
gcc/df.h
gcc/ext-dce.cc [new file with mode: 0644]
gcc/opts.cc
gcc/passes.def
gcc/testsuite/gcc.target/aarch64/sve/pred_clobber_1.c
gcc/testsuite/gcc.target/aarch64/sve/pred_clobber_2.c
gcc/testsuite/gcc.target/aarch64/sve/pred_clobber_3.c
gcc/testsuite/gcc.target/aarch64/tbz_2.c
gcc/testsuite/gcc.target/riscv/core_bench_list.c [new file with mode: 0644]
gcc/testsuite/gcc.target/riscv/core_init_matrix.c [new file with mode: 0644]
gcc/testsuite/gcc.target/riscv/core_list_init.c [new file with mode: 0644]
gcc/testsuite/gcc.target/riscv/matrix_add_const.c [new file with mode: 0644]
gcc/testsuite/gcc.target/riscv/mem-extend.c [new file with mode: 0644]
gcc/testsuite/gcc.target/riscv/pr111384.c [new file with mode: 0644]
gcc/tree-pass.h