gcc/gcc/compare-elim.cc
Jakub Jelinek 50332a4fdd gcc: Remove trailing whitespace
I've tried to build stage3 with
-Wleading-whitespace=blanks -Wtrailing-whitespace=blank -Wno-error=leading-whitespace=blanks -Wno-error=trailing-whitespace=blank
added to STRICT_WARN and that expectably resulted in about
2744 unique trailing whitespace warnings and 124837 leading whitespace
warnings when excluding *.md files (which obviously is in big part a
generator issue).  Others from that are generator related, I think those
need to be solved later.

The following patch just fixes up the easy case (trailing whitespace),
which could be easily automated:
for i in `find . -name \*.h -o -name \*.cc -o -name \*.c | xargs grep -l '[ 	]$' | grep -v testsuite/`; do sed -i -e 's/[ 	]*$//' $i; done
I've excluded files which I knew are obviously generated or go FE.

Is there anything else we'd want to avoid the changes?

Due to patch size, I've split it between gcc/ part (this patch)
and rest (include/, libiberty/, libgcc/, libcpp/, libstdc++-v3/).

2024-10-24  Jakub Jelinek  <jakub@redhat.com>

gcc/
	* lra-assigns.cc: Remove trailing whitespace.
	* symtab.cc: Likewise.
	* stmt.cc: Likewise.
	* cgraphbuild.cc: Likewise.
	* cfgcleanup.cc: Likewise.
	* loop-init.cc: Likewise.
	* df-problems.cc: Likewise.
	* diagnostic-macro-unwinding.cc: Likewise.
	* langhooks.h: Likewise.
	* except.cc: Likewise.
	* tree-vect-loop.cc: Likewise.
	* coverage.cc: Likewise.
	* hash-table.cc: Likewise.
	* ggc-page.cc: Likewise.
	* gimple-ssa-strength-reduction.cc: Likewise.
	* tree-parloops.cc: Likewise.
	* internal-fn.cc: Likewise.
	* ipa-split.cc: Likewise.
	* calls.cc: Likewise.
	* reorg.cc: Likewise.
	* sbitmap.h: Likewise.
	* omp-offload.cc: Likewise.
	* cfgrtl.cc: Likewise.
	* reginfo.cc: Likewise.
	* gengtype.h: Likewise.
	* omp-general.h: Likewise.
	* ipa-comdats.cc: Likewise.
	* gimple-range-edge.h: Likewise.
	* tree-ssa-structalias.cc: Likewise.
	* target.def: Likewise.
	* basic-block.h: Likewise.
	* graphite-isl-ast-to-gimple.cc: Likewise.
	* auto-profile.cc: Likewise.
	* optabs.cc: Likewise.
	* gengtype-lex.l: Likewise.
	* optabs.def: Likewise.
	* ira-build.cc: Likewise.
	* ira.cc: Likewise.
	* function.h: Likewise.
	* tree-ssa-propagate.cc: Likewise.
	* gcov-io.cc: Likewise.
	* builtin-types.def: Likewise.
	* ddg.cc: Likewise.
	* lra-spills.cc: Likewise.
	* cfg.cc: Likewise.
	* bitmap.cc: Likewise.
	* gimple-range-gori.h: Likewise.
	* tree-ssa-loop-im.cc: Likewise.
	* cfghooks.h: Likewise.
	* genmatch.cc: Likewise.
	* explow.cc: Likewise.
	* lto-streamer-in.cc: Likewise.
	* graphite-scop-detection.cc: Likewise.
	* ipa-prop.cc: Likewise.
	* gcc.cc: Likewise.
	* vec.h: Likewise.
	* cfgexpand.cc: Likewise.
	* config/alpha/vms.h: Likewise.
	* config/alpha/alpha.cc: Likewise.
	* config/alpha/driver-alpha.cc: Likewise.
	* config/alpha/elf.h: Likewise.
	* config/iq2000/iq2000.h: Likewise.
	* config/iq2000/iq2000.cc: Likewise.
	* config/pa/pa-64.h: Likewise.
	* config/pa/som.h: Likewise.
	* config/pa/pa.cc: Likewise.
	* config/pa/pa.h: Likewise.
	* config/pa/pa32-regs.h: Likewise.
	* config/c6x/c6x.cc: Likewise.
	* config/openbsd-stdint.h: Likewise.
	* config/elfos.h: Likewise.
	* config/lm32/lm32.cc: Likewise.
	* config/lm32/lm32.h: Likewise.
	* config/lm32/lm32-protos.h: Likewise.
	* config/darwin-c.cc: Likewise.
	* config/rx/rx.cc: Likewise.
	* config/host-darwin.h: Likewise.
	* config/netbsd.h: Likewise.
	* config/ia64/ia64.cc: Likewise.
	* config/ia64/freebsd.h: Likewise.
	* config/avr/avr-c.cc: Likewise.
	* config/avr/avr.cc: Likewise.
	* config/avr/avr-arch.h: Likewise.
	* config/avr/avr.h: Likewise.
	* config/avr/stdfix.h: Likewise.
	* config/avr/gen-avr-mmcu-specs.cc: Likewise.
	* config/avr/avr-log.cc: Likewise.
	* config/avr/elf.h: Likewise.
	* config/avr/gen-avr-mmcu-texi.cc: Likewise.
	* config/avr/avr-devices.cc: Likewise.
	* config/nvptx/nvptx.cc: Likewise.
	* config/vx-common.h: Likewise.
	* config/sol2.cc: Likewise.
	* config/rl78/rl78.cc: Likewise.
	* config/cris/cris.cc: Likewise.
	* config/arm/symbian.h: Likewise.
	* config/arm/unknown-elf.h: Likewise.
	* config/arm/linux-eabi.h: Likewise.
	* config/arm/arm.cc: Likewise.
	* config/arm/arm-mve-builtins.h: Likewise.
	* config/arm/bpabi.h: Likewise.
	* config/arm/vxworks.h: Likewise.
	* config/arm/arm.h: Likewise.
	* config/arm/aout.h: Likewise.
	* config/arm/elf.h: Likewise.
	* config/host-linux.cc: Likewise.
	* config/sh/sh_treg_combine.cc: Likewise.
	* config/sh/vxworks.h: Likewise.
	* config/sh/elf.h: Likewise.
	* config/sh/netbsd-elf.h: Likewise.
	* config/sh/sh.cc: Likewise.
	* config/sh/embed-elf.h: Likewise.
	* config/sh/sh.h: Likewise.
	* config/darwin-driver.cc: Likewise.
	* config/m32c/m32c.cc: Likewise.
	* config/frv/frv.cc: Likewise.
	* config/openbsd.h: Likewise.
	* config/aarch64/aarch64-protos.h: Likewise.
	* config/aarch64/aarch64-builtins.cc: Likewise.
	* config/aarch64/aarch64-cost-tables.h: Likewise.
	* config/aarch64/aarch64.cc: Likewise.
	* config/bfin/bfin.cc: Likewise.
	* config/bfin/bfin.h: Likewise.
	* config/bfin/bfin-protos.h: Likewise.
	* config/i386/gmm_malloc.h: Likewise.
	* config/i386/djgpp.h: Likewise.
	* config/i386/sol2.h: Likewise.
	* config/i386/stringop.def: Likewise.
	* config/i386/i386-features.cc: Likewise.
	* config/i386/openbsdelf.h: Likewise.
	* config/i386/cpuid.h: Likewise.
	* config/i386/i386.h: Likewise.
	* config/i386/smmintrin.h: Likewise.
	* config/i386/avx10_2-512convertintrin.h: Likewise.
	* config/i386/i386-options.cc: Likewise.
	* config/i386/i386-opts.h: Likewise.
	* config/i386/i386-expand.cc: Likewise.
	* config/i386/avx512dqintrin.h: Likewise.
	* config/i386/wmmintrin.h: Likewise.
	* config/i386/gnu-user.h: Likewise.
	* config/i386/host-mingw32.cc: Likewise.
	* config/i386/avx10_2bf16intrin.h: Likewise.
	* config/i386/cygwin.h: Likewise.
	* config/i386/driver-i386.cc: Likewise.
	* config/i386/biarch64.h: Likewise.
	* config/i386/host-cygwin.cc: Likewise.
	* config/i386/cygming.h: Likewise.
	* config/i386/i386-builtins.cc: Likewise.
	* config/i386/avx10_2convertintrin.h: Likewise.
	* config/i386/i386.cc: Likewise.
	* config/i386/gas.h: Likewise.
	* config/i386/freebsd.h: Likewise.
	* config/mingw/winnt-cxx.cc: Likewise.
	* config/mingw/winnt.cc: Likewise.
	* config/h8300/h8300.cc: Likewise.
	* config/host-solaris.cc: Likewise.
	* config/m32r/m32r.h: Likewise.
	* config/m32r/m32r.cc: Likewise.
	* config/darwin.h: Likewise.
	* config/sparc/linux64.h: Likewise.
	* config/sparc/sparc-protos.h: Likewise.
	* config/sparc/sysv4.h: Likewise.
	* config/sparc/sparc.h: Likewise.
	* config/sparc/linux.h: Likewise.
	* config/sparc/freebsd.h: Likewise.
	* config/sparc/sparc.cc: Likewise.
	* config/gcn/gcn-run.cc: Likewise.
	* config/gcn/gcn.cc: Likewise.
	* config/gcn/gcn-tree.cc: Likewise.
	* config/kopensolaris-gnu.h: Likewise.
	* config/nios2/nios2.h: Likewise.
	* config/nios2/elf.h: Likewise.
	* config/nios2/nios2.cc: Likewise.
	* config/host-netbsd.cc: Likewise.
	* config/rtems.h: Likewise.
	* config/pdp11/pdp11.cc: Likewise.
	* config/pdp11/pdp11.h: Likewise.
	* config/mn10300/mn10300.cc: Likewise.
	* config/mn10300/linux.h: Likewise.
	* config/moxie/moxie.h: Likewise.
	* config/moxie/moxie.cc: Likewise.
	* config/rs6000/aix71.h: Likewise.
	* config/rs6000/vec_types.h: Likewise.
	* config/rs6000/xcoff.h: Likewise.
	* config/rs6000/rs6000.cc: Likewise.
	* config/rs6000/rs6000-internal.h: Likewise.
	* config/rs6000/rs6000-p8swap.cc: Likewise.
	* config/rs6000/rs6000-c.cc: Likewise.
	* config/rs6000/aix.h: Likewise.
	* config/rs6000/rs6000-logue.cc: Likewise.
	* config/rs6000/rs6000-string.cc: Likewise.
	* config/rs6000/rs6000-call.cc: Likewise.
	* config/rs6000/ppu_intrinsics.h: Likewise.
	* config/rs6000/altivec.h: Likewise.
	* config/rs6000/darwin.h: Likewise.
	* config/rs6000/host-darwin.cc: Likewise.
	* config/rs6000/freebsd64.h: Likewise.
	* config/rs6000/spu2vmx.h: Likewise.
	* config/rs6000/linux.h: Likewise.
	* config/rs6000/si2vmx.h: Likewise.
	* config/rs6000/driver-rs6000.cc: Likewise.
	* config/rs6000/freebsd.h: Likewise.
	* config/vxworksae.h: Likewise.
	* config/mips/frame-header-opt.cc: Likewise.
	* config/mips/mips.h: Likewise.
	* config/mips/mips.cc: Likewise.
	* config/mips/sde.h: Likewise.
	* config/darwin-protos.h: Likewise.
	* config/mcore/mcore-elf.h: Likewise.
	* config/mcore/mcore.h: Likewise.
	* config/mcore/mcore.cc: Likewise.
	* config/epiphany/epiphany.cc: Likewise.
	* config/fr30/fr30.h: Likewise.
	* config/fr30/fr30.cc: Likewise.
	* config/riscv/riscv-vector-builtins-shapes.cc: Likewise.
	* config/riscv/riscv-vector-builtins-bases.cc: Likewise.
	* config/visium/visium.h: Likewise.
	* config/mmix/mmix.cc: Likewise.
	* config/v850/v850.cc: Likewise.
	* config/v850/v850-c.cc: Likewise.
	* config/v850/v850.h: Likewise.
	* config/stormy16/stormy16.cc: Likewise.
	* config/stormy16/stormy16-protos.h: Likewise.
	* config/stormy16/stormy16.h: Likewise.
	* config/arc/arc.cc: Likewise.
	* config/vxworks.cc: Likewise.
	* config/microblaze/microblaze-c.cc: Likewise.
	* config/microblaze/microblaze-protos.h: Likewise.
	* config/microblaze/microblaze.h: Likewise.
	* config/microblaze/microblaze.cc: Likewise.
	* config/freebsd-spec.h: Likewise.
	* config/m68k/m68kelf.h: Likewise.
	* config/m68k/m68k.cc: Likewise.
	* config/m68k/netbsd-elf.h: Likewise.
	* config/m68k/linux.h: Likewise.
	* config/freebsd.h: Likewise.
	* config/host-openbsd.cc: Likewise.
	* regcprop.cc: Likewise.
	* dumpfile.cc: Likewise.
	* combine.cc: Likewise.
	* tree-ssa-forwprop.cc: Likewise.
	* ipa-profile.cc: Likewise.
	* hw-doloop.cc: Likewise.
	* opts.cc: Likewise.
	* gcc-ar.cc: Likewise.
	* tree-cfg.cc: Likewise.
	* incpath.cc: Likewise.
	* tree-ssa-sccvn.cc: Likewise.
	* function.cc: Likewise.
	* genattrtab.cc: Likewise.
	* rtl.def: Likewise.
	* genchecksum.cc: Likewise.
	* profile.cc: Likewise.
	* df-core.cc: Likewise.
	* tree-pretty-print.cc: Likewise.
	* tree.h: Likewise.
	* plugin.cc: Likewise.
	* tree-ssa-loop-ch.cc: Likewise.
	* emit-rtl.cc: Likewise.
	* haifa-sched.cc: Likewise.
	* gimple-range-edge.cc: Likewise.
	* range-op.cc: Likewise.
	* tree-ssa-ccp.cc: Likewise.
	* dwarf2cfi.cc: Likewise.
	* recog.cc: Likewise.
	* vtable-verify.cc: Likewise.
	* system.h: Likewise.
	* regrename.cc: Likewise.
	* tree-ssa-dom.cc: Likewise.
	* loop-unroll.cc: Likewise.
	* lra-constraints.cc: Likewise.
	* pretty-print.cc: Likewise.
	* ifcvt.cc: Likewise.
	* ipa.cc: Likewise.
	* alloc-pool.h: Likewise.
	* collect2.cc: Likewise.
	* pointer-query.cc: Likewise.
	* cfgloop.cc: Likewise.
	* toplev.cc: Likewise.
	* sese.cc: Likewise.
	* gengtype.cc: Likewise.
	* gimplify-me.cc: Likewise.
	* double-int.cc: Likewise.
	* bb-reorder.cc: Likewise.
	* dwarf2out.cc: Likewise.
	* tree-ssa-loop-ivcanon.cc: Likewise.
	* tree-ssa-reassoc.cc: Likewise.
	* cgraph.cc: Likewise.
	* sel-sched.cc: Likewise.
	* attribs.cc: Likewise.
	* expr.cc: Likewise.
	* tree-ssa-scopedtables.h: Likewise.
	* gimple-range-cache.cc: Likewise.
	* ipa-pure-const.cc: Likewise.
	* tree-inline.cc: Likewise.
	* genhooks.cc: Likewise.
	* gimple-range-phi.h: Likewise.
	* shrink-wrap.cc: Likewise.
	* tree.cc: Likewise.
	* gimple.cc: Likewise.
	* backend.h: Likewise.
	* opts-common.cc: Likewise.
	* cfg-flags.def: Likewise.
	* gcse-common.cc: Likewise.
	* tree-ssa-scopedtables.cc: Likewise.
	* ccmp.cc: Likewise.
	* builtins.def: Likewise.
	* builtin-attrs.def: Likewise.
	* postreload.cc: Likewise.
	* sched-deps.cc: Likewise.
	* ipa-inline-transform.cc: Likewise.
	* tree-vect-generic.cc: Likewise.
	* ipa-polymorphic-call.cc: Likewise.
	* builtins.cc: Likewise.
	* sel-sched-ir.cc: Likewise.
	* trans-mem.cc: Likewise.
	* ipa-visibility.cc: Likewise.
	* cgraph.h: Likewise.
	* tree-ssa-phiopt.cc: Likewise.
	* genopinit.cc: Likewise.
	* ipa-inline.cc: Likewise.
	* omp-low.cc: Likewise.
	* ipa-utils.cc: Likewise.
	* tree-ssa-math-opts.cc: Likewise.
	* tree-ssa-ifcombine.cc: Likewise.
	* gimple-range.cc: Likewise.
	* ipa-fnsummary.cc: Likewise.
	* ira-color.cc: Likewise.
	* value-prof.cc: Likewise.
	* varasm.cc: Likewise.
	* ipa-icf.cc: Likewise.
	* ira-emit.cc: Likewise.
	* lto-streamer.h: Likewise.
	* lto-wrapper.cc: Likewise.
	* regs.h: Likewise.
	* gengtype-parse.cc: Likewise.
	* alias.cc: Likewise.
	* lto-streamer.cc: Likewise.
	* real.h: Likewise.
	* wide-int.h: Likewise.
	* targhooks.cc: Likewise.
	* gimple-ssa-warn-access.cc: Likewise.
	* real.cc: Likewise.
	* ipa-reference.cc: Likewise.
	* bitmap.h: Likewise.
	* ginclude/float.h: Likewise.
	* ginclude/stddef.h: Likewise.
	* ginclude/stdarg.h: Likewise.
	* ginclude/stdatomic.h: Likewise.
	* optabs.h: Likewise.
	* sel-sched-ir.h: Likewise.
	* convert.cc: Likewise.
	* cgraphunit.cc: Likewise.
	* lra-remat.cc: Likewise.
	* tree-if-conv.cc: Likewise.
	* gcov-dump.cc: Likewise.
	* tree-predcom.cc: Likewise.
	* dominance.cc: Likewise.
	* gimple-range-cache.h: Likewise.
	* ipa-devirt.cc: Likewise.
	* rtl.h: Likewise.
	* ubsan.cc: Likewise.
	* tree-ssa.cc: Likewise.
	* ssa.h: Likewise.
	* cse.cc: Likewise.
	* jump.cc: Likewise.
	* hwint.h: Likewise.
	* caller-save.cc: Likewise.
	* coretypes.h: Likewise.
	* ipa-fnsummary.h: Likewise.
	* tree-ssa-strlen.cc: Likewise.
	* modulo-sched.cc: Likewise.
	* cgraphclones.cc: Likewise.
	* lto-cgraph.cc: Likewise.
	* hw-doloop.h: Likewise.
	* data-streamer.h: Likewise.
	* compare-elim.cc: Likewise.
	* profile-count.h: Likewise.
	* tree-vect-loop-manip.cc: Likewise.
	* ree.cc: Likewise.
	* reload.cc: Likewise.
	* tree-ssa-loop-split.cc: Likewise.
	* tree-into-ssa.cc: Likewise.
	* gcse.cc: Likewise.
	* cfgloopmanip.cc: Likewise.
	* df.h: Likewise.
	* fold-const.cc: Likewise.
	* wide-int.cc: Likewise.
	* gengtype-state.cc: Likewise.
	* sanitizer.def: Likewise.
	* tree-ssa-sink.cc: Likewise.
	* target-hooks-macros.h: Likewise.
	* tree-ssa-pre.cc: Likewise.
	* gimple-pretty-print.cc: Likewise.
	* ipa-utils.h: Likewise.
	* tree-outof-ssa.cc: Likewise.
	* tree-ssa-coalesce.cc: Likewise.
	* gimple-match.h: Likewise.
	* tree-ssa-loop-niter.cc: Likewise.
	* tree-loop-distribution.cc: Likewise.
	* tree-emutls.cc: Likewise.
	* tree-eh.cc: Likewise.
	* varpool.cc: Likewise.
	* ssa-iterators.h: Likewise.
	* asan.cc: Likewise.
	* reload1.cc: Likewise.
	* cfgloopanal.cc: Likewise.
	* tree-vectorizer.cc: Likewise.
	* simplify-rtx.cc: Likewise.
	* opts-global.cc: Likewise.
	* gimple-ssa-store-merging.cc: Likewise.
	* expmed.cc: Likewise.
	* tree-ssa-loop-prefetch.cc: Likewise.
	* tree-ssa-dse.h: Likewise.
	* tree-vect-stmts.cc: Likewise.
	* gimple-fold.cc: Likewise.
	* lra-coalesce.cc: Likewise.
	* data-streamer-out.cc: Likewise.
	* diagnostic.cc: Likewise.
	* tree-ssa-alias.cc: Likewise.
	* tree-vect-patterns.cc: Likewise.
	* common/common-target.def: Likewise.
	* common/config/rx/rx-common.cc: Likewise.
	* common/config/msp430/msp430-common.cc: Likewise.
	* common/config/avr/avr-common.cc: Likewise.
	* common/config/i386/i386-common.cc: Likewise.
	* common/config/pdp11/pdp11-common.cc: Likewise.
	* common/config/rs6000/rs6000-common.cc: Likewise.
	* common/config/mcore/mcore-common.cc: Likewise.
	* graphite.cc: Likewise.
	* gimple-low.cc: Likewise.
	* genmodes.cc: Likewise.
	* gimple-loop-jam.cc: Likewise.
	* lto-streamer-out.cc: Likewise.
	* predict.cc: Likewise.
	* omp-expand.cc: Likewise.
	* gimple-array-bounds.cc: Likewise.
	* predict.def: Likewise.
	* opts.h: Likewise.
	* tree-stdarg.cc: Likewise.
	* gimplify.cc: Likewise.
	* ira-lives.cc: Likewise.
	* loop-doloop.cc: Likewise.
	* lra.cc: Likewise.
	* gimple-iterator.h: Likewise.
	* tree-sra.cc: Likewise.
gcc/fortran/
	* trans-openmp.cc: Remove trailing whitespace.
	* trans-common.cc: Likewise.
	* match.h: Likewise.
	* scanner.cc: Likewise.
	* gfortranspec.cc: Likewise.
	* io.cc: Likewise.
	* iso-c-binding.def: Likewise.
	* iso-fortran-env.def: Likewise.
	* types.def: Likewise.
	* openmp.cc: Likewise.
	* f95-lang.cc: Likewise.
gcc/analyzer/
	* state-purge.cc: Remove trailing whitespace.
	* region-model.h: Likewise.
	* region-model.cc: Likewise.
	* program-point.cc: Likewise.
	* exploded-graph.h: Likewise.
	* program-state.cc: Likewise.
	* supergraph.cc: Likewise.
gcc/c-family/
	* c-ubsan.cc: Remove trailing whitespace.
	* stub-objc.cc: Likewise.
	* c-pragma.cc: Likewise.
	* c-ppoutput.cc: Likewise.
	* c-indentation.cc: Likewise.
	* c-ada-spec.cc: Likewise.
	* c-opts.cc: Likewise.
	* c-common.cc: Likewise.
	* c-format.cc: Likewise.
	* c-omp.cc: Likewise.
	* c-objc.h: Likewise.
	* c-cppbuiltin.cc: Likewise.
	* c-attribs.cc: Likewise.
	* c-target.def: Likewise.
	* c-common.h: Likewise.
gcc/c/
	* c-typeck.cc: Remove trailing whitespace.
	* gimple-parser.cc: Likewise.
	* c-parser.cc: Likewise.
	* c-decl.cc: Likewise.
gcc/cp/
	* vtable-class-hierarchy.cc: Remove trailing whitespace.
	* typeck2.cc: Likewise.
	* decl.cc: Likewise.
	* init.cc: Likewise.
	* semantics.cc: Likewise.
	* module.cc: Likewise.
	* rtti.cc: Likewise.
	* cxx-pretty-print.cc: Likewise.
	* cvt.cc: Likewise.
	* mangle.cc: Likewise.
	* name-lookup.h: Likewise.
	* coroutines.cc: Likewise.
	* error.cc: Likewise.
	* lambda.cc: Likewise.
	* tree.cc: Likewise.
	* g++spec.cc: Likewise.
	* decl2.cc: Likewise.
	* cp-tree.h: Likewise.
	* parser.cc: Likewise.
	* pt.cc: Likewise.
	* call.cc: Likewise.
	* lex.cc: Likewise.
	* cp-lang.cc: Likewise.
	* cp-tree.def: Likewise.
	* constexpr.cc: Likewise.
	* typeck.cc: Likewise.
	* name-lookup.cc: Likewise.
	* optimize.cc: Likewise.
	* search.cc: Likewise.
	* mapper-client.cc: Likewise.
	* ptree.cc: Likewise.
	* class.cc: Likewise.
gcc/jit/
	* docs/examples/tut04-toyvm/toyvm.cc: Remove trailing whitespace.
gcc/lto/
	* lto-object.cc: Remove trailing whitespace.
	* lto-symtab.cc: Likewise.
	* lto-partition.cc: Likewise.
	* lang-specs.h: Likewise.
	* lto-lang.cc: Likewise.
gcc/objc/
	* objc-encoding.cc: Remove trailing whitespace.
	* objc-map.h: Likewise.
	* objc-next-runtime-abi-01.cc: Likewise.
	* objc-act.cc: Likewise.
	* objc-map.cc: Likewise.
gcc/objcp/
	* objcp-decl.cc: Remove trailing whitespace.
	* objcp-lang.cc: Likewise.
	* objcp-decl.h: Likewise.
gcc/rust/
	* util/optional.h: Remove trailing whitespace.
	* util/expected.h: Likewise.
	* util/rust-unicode-data.h: Likewise.
gcc/m2/
	* mc-boot/GFpuIO.cc: Remove trailing whitespace.
	* mc-boot/GFIO.cc: Likewise.
	* mc-boot/GFormatStrings.cc: Likewise.
	* mc-boot/GCmdArgs.cc: Likewise.
	* mc-boot/GDebug.h: Likewise.
	* mc-boot/GM2Dependent.cc: Likewise.
	* mc-boot/GRTint.cc: Likewise.
	* mc-boot/GDebug.cc: Likewise.
	* mc-boot/GmcError.cc: Likewise.
	* mc-boot/Gmcp4.cc: Likewise.
	* mc-boot/GM2RTS.cc: Likewise.
	* mc-boot/GIO.cc: Likewise.
	* mc-boot/Gmcp5.cc: Likewise.
	* mc-boot/GDynamicStrings.cc: Likewise.
	* mc-boot/Gmcp1.cc: Likewise.
	* mc-boot/GFormatStrings.h: Likewise.
	* mc-boot/Gmcp2.cc: Likewise.
	* mc-boot/Gmcp3.cc: Likewise.
	* pge-boot/GFIO.cc: Likewise.
	* pge-boot/GDebug.h: Likewise.
	* pge-boot/GM2Dependent.cc: Likewise.
	* pge-boot/GDebug.cc: Likewise.
	* pge-boot/GM2RTS.cc: Likewise.
	* pge-boot/GSymbolKey.cc: Likewise.
	* pge-boot/GIO.cc: Likewise.
	* pge-boot/GIndexing.cc: Likewise.
	* pge-boot/GDynamicStrings.cc: Likewise.
	* pge-boot/GFormatStrings.h: Likewise.
gcc/go/
	* go-gcc.cc: Remove trailing whitespace.
	* gospec.cc: Likewise.
2024-10-25 10:00:29 +02:00

980 lines
27 KiB
C++
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/* Post-reload compare elimination.
Copyright (C) 2010-2024 Free Software Foundation, Inc.
This file is part of GCC.
GCC is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free
Software Foundation; either version 3, or (at your option) any later
version.
GCC is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with GCC; see the file COPYING3. If not see
<http://www.gnu.org/licenses/>. */
/* There is a set of targets whose general-purpose move or addition
instructions clobber the flags. These targets cannot split their
CBRANCH/CSTORE etc patterns before reload is complete, lest reload
itself insert these instructions in between the flags setter and user.
Because these targets cannot split the compare from the use, they
cannot make use of the comparison elimination offered by the combine pass.
This is a small pass intended to provide comparison elimination similar to
what was available via NOTICE_UPDATE_CC for cc0 targets.
This pass assumes:
(0) CBRANCH/CSTORE etc have been split in pass_split_after_reload.
(1) All comparison patterns are represented as
[(set (reg:CC) (compare:CC (reg) (reg_or_immediate)))]
(2) All insn patterns that modify the flags are represented as
[(set (reg) (operation)
(clobber (reg:CC))]
(3) If an insn of form (2) can usefully set the flags, there is
another pattern of the form
[(set (reg:CCM) (compare:CCM (operation) (immediate)))
(set (reg) (operation)]
The mode CCM will be chosen as if by SELECT_CC_MODE.
Note that unlike NOTICE_UPDATE_CC, we do not handle memory operands.
This could be handled as a future enhancement.
*/
#include "config.h"
#include "system.h"
#include "coretypes.h"
#include "backend.h"
#include "target.h"
#include "rtl.h"
#include "df.h"
#include "memmodel.h"
#include "tm_p.h"
#include "insn-config.h"
#include "recog.h"
#include "emit-rtl.h"
#include "cfgrtl.h"
#include "tree-pass.h"
#include "domwalk.h"
/* These structures describe a comparison and how it is used. */
/* The choice of maximum 3 uses comes from wanting to eliminate the two
duplicate compares from a three-way branch on the sign of a value.
This is also sufficient to eliminate the duplicate compare against the
high-part of a double-word comparison. */
#define MAX_CMP_USE 3
struct comparison_use
{
/* The instruction in which the result of the compare is used. */
rtx_insn *insn;
/* The location of the flags register within the use. */
rtx *loc;
/* The comparison code applied against the flags register. */
enum rtx_code code;
};
struct comparison
{
/* The comparison instruction. */
rtx_insn *insn;
/* The insn prior to the comparison insn that clobbers the flags. */
rtx_insn *prev_clobber;
/* The insn prior to the comparison insn that sets in_a REG. */
rtx_insn *in_a_setter;
/* The two values being compared. These will be either REGs or
constants. */
rtx in_a, in_b;
/* The REG_EH_REGION of the comparison. */
rtx eh_note;
/* Information about how this comparison is used. */
struct comparison_use uses[MAX_CMP_USE];
/* The original CC_MODE for this comparison. */
machine_mode orig_mode;
/* The number of uses identified for this comparison. */
unsigned short n_uses;
/* True if not all uses of this comparison have been identified.
This can happen either for overflowing the array above, or if
the flags register is used in some unusual context. */
bool missing_uses;
/* True if its inputs are still valid at the end of the block. */
bool inputs_valid;
/* Whether IN_A is wrapped in a NOT before being compared. */
bool not_in_a;
};
static vec<comparison *> all_compares;
/* Return whether X is a NOT unary expression. */
static bool
is_not (rtx x)
{
return GET_CODE (x) == NOT;
}
/* Strip a NOT unary expression around X, if any. */
static rtx
strip_not (rtx x)
{
if (is_not (x))
return XEXP (x, 0);
return x;
}
/* Look for a "conforming" comparison, as defined above. If valid, return
the rtx for the COMPARE itself. */
static rtx
conforming_compare (rtx_insn *insn)
{
rtx set, src, dest;
set = single_set (insn);
if (set == NULL)
return NULL;
src = SET_SRC (set);
if (GET_CODE (src) != COMPARE)
return NULL;
dest = SET_DEST (set);
if (!REG_P (dest) || REGNO (dest) != targetm.flags_regnum)
return NULL;
if (!REG_P (strip_not (XEXP (src, 0))))
return NULL;
if (CONSTANT_P (XEXP (src, 1)) || REG_P (XEXP (src, 1)))
return src;
if (GET_CODE (XEXP (src, 1)) == UNSPEC)
{
for (int i = 0; i < XVECLEN (XEXP (src, 1), 0); i++)
if (!REG_P (XVECEXP (XEXP (src, 1), 0, i)))
return NULL;
return src;
}
return NULL;
}
/* Look for a pattern of the "correct" form for an insn with a flags clobber
for which we may be able to eliminate a compare later. We're not looking
to validate any inputs at this time, merely see that the basic shape is
correct. The term "arithmetic" may be somewhat misleading... */
static bool
arithmetic_flags_clobber_p (rtx_insn *insn)
{
rtx pat, x;
if (!NONJUMP_INSN_P (insn))
return false;
pat = PATTERN (insn);
if (asm_noperands (pat) >= 0)
return false;
if (GET_CODE (pat) == PARALLEL && XVECLEN (pat, 0) == 2)
{
x = XVECEXP (pat, 0, 0);
if (GET_CODE (x) != SET)
return false;
x = SET_DEST (x);
if (!REG_P (x))
return false;
x = XVECEXP (pat, 0, 1);
if (GET_CODE (x) == CLOBBER)
{
x = XEXP (x, 0);
if (REG_P (x) && REGNO (x) == targetm.flags_regnum)
return true;
}
}
return false;
}
/* Look for uses of FLAGS in INSN. If we find one we can analyze, record
it in CMP; otherwise indicate that we've missed a use. */
static void
find_flags_uses_in_insn (struct comparison *cmp, rtx_insn *insn)
{
df_ref use;
/* If we've already lost track of uses, don't bother collecting more. */
if (cmp->missing_uses)
return;
/* Find a USE of the flags register. */
FOR_EACH_INSN_USE (use, insn)
if (DF_REF_REGNO (use) == targetm.flags_regnum)
{
rtx x, *loc;
/* If this is an unusual use, quit. */
if (DF_REF_TYPE (use) != DF_REF_REG_USE)
goto fail;
/* If we've run out of slots to record uses, quit. */
if (cmp->n_uses == MAX_CMP_USE)
goto fail;
/* Unfortunately the location of the flags register, while present
in the reference structure, doesn't help. We need to find the
comparison code that is outer to the actual flags use. */
loc = DF_REF_LOC (use);
x = PATTERN (insn);
if (GET_CODE (x) == PARALLEL)
x = XVECEXP (x, 0, 0);
if (GET_CODE (x) == SET)
x = SET_SRC (x);
if (GET_CODE (x) == IF_THEN_ELSE)
x = XEXP (x, 0);
if (COMPARISON_P (x)
&& loc == &XEXP (x, 0)
&& XEXP (x, 1) == const0_rtx)
{
/* We've found a use of the flags that we understand. */
struct comparison_use *cuse = &cmp->uses[cmp->n_uses++];
cuse->insn = insn;
cuse->loc = loc;
cuse->code = GET_CODE (x);
}
else
goto fail;
}
return;
fail:
/* We failed to recognize this use of the flags register. */
cmp->missing_uses = true;
}
class find_comparison_dom_walker : public dom_walker
{
public:
find_comparison_dom_walker (cdi_direction direction)
: dom_walker (direction) {}
edge before_dom_children (basic_block) final override;
};
/* Return true if conforming COMPARE with EH_NOTE is redundant with comparison
CMP and can thus be eliminated. */
static bool
can_eliminate_compare (rtx compare, rtx eh_note, struct comparison *cmp)
{
/* Take care that it's in the same EH region. */
if (cfun->can_throw_non_call_exceptions
&& !rtx_equal_p (eh_note, cmp->eh_note))
return false;
/* Make sure the compare is redundant with the previous. */
if (!rtx_equal_p (strip_not (XEXP (compare, 0)), cmp->in_a)
|| !rtx_equal_p (XEXP (compare, 1), cmp->in_b))
return false;
if (is_not (XEXP (compare, 0)) != cmp->not_in_a)
return false;
/* New mode must be compatible with the previous compare mode. */
machine_mode new_mode
= targetm.cc_modes_compatible (GET_MODE (compare), cmp->orig_mode);
if (new_mode == VOIDmode)
return false;
if (cmp->orig_mode != new_mode)
{
/* Generate new comparison for substitution. */
rtx flags = gen_rtx_REG (new_mode, targetm.flags_regnum);
rtx x = gen_rtx_COMPARE (new_mode, cmp->in_a, cmp->in_b);
x = gen_rtx_SET (flags, x);
if (!validate_change (cmp->insn, &PATTERN (cmp->insn), x, false))
return false;
cmp->orig_mode = new_mode;
}
return true;
}
/* Identify comparison instructions within BB. If the flags from the last
compare in the BB is live at the end of the block, install the compare
in BB->AUX. Called via dom_walker.walk (). */
edge
find_comparison_dom_walker::before_dom_children (basic_block bb)
{
rtx_insn *insn, *next;
bool need_purge = false;
rtx_insn *last_setter[FIRST_PSEUDO_REGISTER];
/* The last comparison that was made. Will be reset to NULL
once the flags are clobbered. */
struct comparison *last_cmp = NULL;
/* True iff the last comparison has not been clobbered, nor
have its inputs. Used to eliminate duplicate compares. */
bool last_cmp_valid = false;
/* The last insn that clobbered the flags, if that insn is of
a form that may be valid for eliminating a following compare.
To be reset to NULL once the flags are set otherwise. */
rtx_insn *last_clobber = NULL;
/* Propagate the last live comparison throughout the extended basic block. */
if (single_pred_p (bb))
{
last_cmp = (struct comparison *) single_pred (bb)->aux;
if (last_cmp)
last_cmp_valid = last_cmp->inputs_valid;
}
memset (last_setter, 0, sizeof (last_setter));
for (insn = BB_HEAD (bb); insn; insn = next)
{
rtx src;
next = (insn == BB_END (bb) ? NULL : NEXT_INSN (insn));
if (!NONDEBUG_INSN_P (insn))
continue;
src = conforming_compare (insn);
if (src)
{
rtx eh_note = NULL;
if (cfun->can_throw_non_call_exceptions)
eh_note = find_reg_note (insn, REG_EH_REGION, NULL);
if (last_cmp_valid && can_eliminate_compare (src, eh_note, last_cmp))
{
if (eh_note)
need_purge = true;
delete_insn (insn);
continue;
}
last_cmp = XCNEW (struct comparison);
last_cmp->insn = insn;
last_cmp->prev_clobber = last_clobber;
last_cmp->in_a = strip_not (XEXP (src, 0));
last_cmp->in_b = XEXP (src, 1);
last_cmp->not_in_a = is_not (XEXP (src, 0));
last_cmp->eh_note = eh_note;
last_cmp->orig_mode = GET_MODE (src);
if (last_cmp->in_b == const0_rtx
&& last_setter[REGNO (last_cmp->in_a)])
{
rtx set = single_set (last_setter[REGNO (last_cmp->in_a)]);
if (set && rtx_equal_p (SET_DEST (set), last_cmp->in_a))
last_cmp->in_a_setter = last_setter[REGNO (last_cmp->in_a)];
}
all_compares.safe_push (last_cmp);
/* It's unusual, but be prepared for comparison patterns that
also clobber an input, or perhaps a scratch. */
last_clobber = NULL;
last_cmp_valid = true;
}
else
{
/* Notice if this instruction uses the flags register. */
if (last_cmp)
find_flags_uses_in_insn (last_cmp, insn);
/* Notice if this instruction kills the flags register. */
df_ref def;
FOR_EACH_INSN_DEF (def, insn)
if (DF_REF_REGNO (def) == targetm.flags_regnum)
{
/* See if this insn could be the "clobber" that eliminates
a future comparison. */
last_clobber = (arithmetic_flags_clobber_p (insn)
? insn : NULL);
/* In either case, the previous compare is no longer valid. */
last_cmp = NULL;
last_cmp_valid = false;
break;
}
}
/* Notice if any of the inputs to the comparison have changed
and remember last insn that sets each register. */
df_ref def;
FOR_EACH_INSN_DEF (def, insn)
{
if (last_cmp_valid
&& (DF_REF_REGNO (def) == REGNO (last_cmp->in_a)
|| (REG_P (last_cmp->in_b)
&& DF_REF_REGNO (def) == REGNO (last_cmp->in_b))))
last_cmp_valid = false;
last_setter[DF_REF_REGNO (def)] = insn;
}
}
/* Remember the live comparison for subsequent members of
the extended basic block. */
if (last_cmp)
{
bb->aux = last_cmp;
last_cmp->inputs_valid = last_cmp_valid;
/* Look to see if the flags register is live outgoing here, and
incoming to any successor not part of the extended basic block. */
if (bitmap_bit_p (df_get_live_out (bb), targetm.flags_regnum))
{
edge e;
edge_iterator ei;
FOR_EACH_EDGE (e, ei, bb->succs)
{
basic_block dest = e->dest;
if (bitmap_bit_p (df_get_live_in (bb), targetm.flags_regnum)
&& !single_pred_p (dest))
{
last_cmp->missing_uses = true;
break;
}
}
}
}
/* If we deleted a compare with a REG_EH_REGION note, we may need to
remove EH edges. */
if (need_purge)
purge_dead_edges (bb);
return NULL;
}
/* Find all comparisons in the function. */
static void
find_comparisons (void)
{
calculate_dominance_info (CDI_DOMINATORS);
find_comparison_dom_walker (CDI_DOMINATORS)
.walk (cfun->cfg->x_entry_block_ptr);
clear_aux_for_blocks ();
free_dominance_info (CDI_DOMINATORS);
}
/* Select an alternate CC_MODE for a comparison insn comparing A and B.
Note that inputs are almost certainly different than the IN_A and IN_B
stored in CMP -- we're called while attempting to eliminate the compare
after all. Return the new FLAGS rtx if successful, else return NULL.
Note that this function may start a change group. */
static rtx
maybe_select_cc_mode (struct comparison *cmp, rtx a ATTRIBUTE_UNUSED,
rtx b ATTRIBUTE_UNUSED)
{
machine_mode sel_mode;
const int n = cmp->n_uses;
rtx flags = NULL;
#ifndef SELECT_CC_MODE
/* Minimize code differences when this target macro is undefined. */
return NULL;
#define SELECT_CC_MODE(A,B,C) (gcc_unreachable (), VOIDmode)
#endif
/* If we don't have access to all of the uses, we can't validate. */
if (cmp->missing_uses || n == 0)
return NULL;
/* Find a new mode that works for all of the uses. Special case the
common case of exactly one use. */
if (n == 1)
{
sel_mode = SELECT_CC_MODE (cmp->uses[0].code, a, b);
if (sel_mode != cmp->orig_mode)
{
flags = gen_rtx_REG (sel_mode, targetm.flags_regnum);
validate_change (cmp->uses[0].insn, cmp->uses[0].loc, flags, true);
}
}
else
{
int i;
sel_mode = SELECT_CC_MODE (cmp->uses[0].code, a, b);
for (i = 1; i < n; ++i)
{
machine_mode new_mode = SELECT_CC_MODE (cmp->uses[i].code, a, b);
if (new_mode != sel_mode)
{
sel_mode = targetm.cc_modes_compatible (sel_mode, new_mode);
if (sel_mode == VOIDmode)
return NULL;
}
}
if (sel_mode != cmp->orig_mode)
{
flags = gen_rtx_REG (sel_mode, targetm.flags_regnum);
for (i = 0; i < n; ++i)
validate_change (cmp->uses[i].insn, cmp->uses[i].loc, flags, true);
}
}
return flags;
}
/* Return a register RTX holding the same value at START as REG at END, or
NULL_RTX if there is none. */
static rtx
equivalent_reg_at_start (rtx reg, rtx_insn *end, rtx_insn *start)
{
machine_mode orig_mode = GET_MODE (reg);
rtx_insn *bb_head = BB_HEAD (BLOCK_FOR_INSN (end));
for (rtx_insn *insn = PREV_INSN (end);
insn != start;
insn = PREV_INSN (insn))
{
const int abnormal_flags
= (DF_REF_CONDITIONAL | DF_REF_PARTIAL | DF_REF_MAY_CLOBBER
| DF_REF_MUST_CLOBBER | DF_REF_SIGN_EXTRACT
| DF_REF_ZERO_EXTRACT | DF_REF_STRICT_LOW_PART
| DF_REF_PRE_POST_MODIFY);
df_ref def;
/* Note that the BB_HEAD is always either a note or a label, but in
any case it means that REG is defined outside the block. */
if (insn == bb_head)
return NULL_RTX;
if (NOTE_P (insn) || DEBUG_INSN_P (insn))
continue;
/* Find a possible def of REG in INSN. */
FOR_EACH_INSN_DEF (def, insn)
if (DF_REF_REGNO (def) == REGNO (reg))
break;
/* No definitions of REG; continue searching. */
if (def == NULL)
continue;
/* Bail if this is not a totally normal set of REG. */
if (DF_REF_IS_ARTIFICIAL (def))
return NULL_RTX;
if (DF_REF_FLAGS (def) & abnormal_flags)
return NULL_RTX;
/* We've found an insn between the compare and the clobber that sets
REG. Given that pass_cprop_hardreg has not yet run, we still find
situations in which we can usefully look through a copy insn. */
rtx x = single_set (insn);
if (x == NULL_RTX)
return NULL_RTX;
reg = SET_SRC (x);
if (!REG_P (reg))
return NULL_RTX;
}
if (GET_MODE (reg) != orig_mode)
return NULL_RTX;
return reg;
}
/* Return true if it is okay to merge the comparison CMP_INSN with
the instruction ARITH_INSN. Both instructions are assumed to be in the
same basic block with ARITH_INSN appearing before CMP_INSN. This checks
that there are no uses or defs of the condition flags or control flow
changes between the two instructions. */
static bool
can_merge_compare_into_arith (rtx_insn *cmp_insn, rtx_insn *arith_insn)
{
for (rtx_insn *insn = PREV_INSN (cmp_insn);
insn && insn != arith_insn;
insn = PREV_INSN (insn))
{
if (!NONDEBUG_INSN_P (insn))
continue;
/* Bail if there are jumps or calls in between. */
if (!NONJUMP_INSN_P (insn))
return false;
/* Bail on old-style asm statements because they lack
data flow information. */
if (GET_CODE (PATTERN (insn)) == ASM_INPUT)
return false;
df_ref ref;
/* Find a USE of the flags register. */
FOR_EACH_INSN_USE (ref, insn)
if (DF_REF_REGNO (ref) == targetm.flags_regnum)
return false;
/* Find a DEF of the flags register. */
FOR_EACH_INSN_DEF (ref, insn)
if (DF_REF_REGNO (ref) == targetm.flags_regnum)
return false;
}
return true;
}
/* Given two SET expressions, SET_A and SET_B determine whether they form
a recognizable pattern when emitted in parallel. Return that parallel
if so. Otherwise return NULL. */
static rtx
try_validate_parallel (rtx set_a, rtx set_b)
{
rtx par = gen_rtx_PARALLEL (VOIDmode, gen_rtvec (2, set_a, set_b));
rtx_insn *insn = make_insn_raw (par);
if (insn_invalid_p (insn, false))
{
crtl->emit.x_cur_insn_uid--;
return NULL_RTX;
}
SET_PREV_INSN (insn) = NULL_RTX;
SET_NEXT_INSN (insn) = NULL_RTX;
INSN_LOCATION (insn) = 0;
return insn;
}
/* For a comparison instruction described by CMP check if it compares a
register with zero i.e. it is of the form CC := CMP R1, 0.
If it is, find the instruction defining R1 (say I1) and try to create a
PARALLEL consisting of I1 and the comparison, representing a flag-setting
arithmetic instruction. Example:
I1: R1 := R2 + R3
<instructions that don't read the condition register>
I2: CC := CMP R1 0
I2 can be merged with I1 into:
I1: { CC := CMP (R2 + R3) 0 ; R1 := R2 + R3 }
This catches cases where R1 is used between I1 and I2 and therefore
combine and other RTL optimisations will not try to propagate it into
I2. Return true if we succeeded in merging CMP. */
static bool
try_merge_compare (struct comparison *cmp)
{
rtx_insn *cmp_insn = cmp->insn;
if (cmp->in_b != const0_rtx || cmp->in_a_setter == NULL)
return false;
rtx in_a = cmp->in_a;
df_ref use;
FOR_EACH_INSN_USE (use, cmp_insn)
if (DF_REF_REGNO (use) == REGNO (in_a))
break;
if (!use)
return false;
rtx_insn *def_insn = cmp->in_a_setter;
rtx set = single_set (def_insn);
if (!set)
return false;
if (!can_merge_compare_into_arith (cmp_insn, def_insn))
return false;
rtx src = SET_SRC (set);
/* If the source uses addressing modes with side effects, we can't
do the merge because we'd end up with a PARALLEL that has two
instances of that side effect in it. */
if (side_effects_p (src))
return false;
rtx flags = maybe_select_cc_mode (cmp, src, CONST0_RTX (GET_MODE (src)));
if (!flags)
{
/* We may already have a change group going through maybe_select_cc_mode.
Discard it properly. */
cancel_changes (0);
return false;
}
rtx flag_set
= gen_rtx_SET (flags, gen_rtx_COMPARE (GET_MODE (flags),
copy_rtx (src),
CONST0_RTX (GET_MODE (src))));
rtx arith_set = copy_rtx (PATTERN (def_insn));
rtx par = try_validate_parallel (flag_set, arith_set);
if (!par)
{
/* We may already have a change group going through maybe_select_cc_mode.
Discard it properly. */
cancel_changes (0);
return false;
}
if (!apply_change_group ())
return false;
emit_insn_after (par, def_insn);
delete_insn (def_insn);
delete_insn (cmp->insn);
return true;
}
/* Attempt to replace a comparison with a prior arithmetic insn that can
compute the same flags value as the comparison itself. Return true if
successful, having made all rtl modifications necessary. */
static bool
try_eliminate_compare (struct comparison *cmp)
{
rtx flags, in_a, in_b, cmp_a, cmp_b;
if (try_merge_compare (cmp))
return true;
/* We must have found an interesting "clobber" preceding the compare. */
if (cmp->prev_clobber == NULL)
return false;
/* Verify that IN_A is not clobbered in between CMP and PREV_CLOBBER.
Given that this target requires this pass, we can assume that most
insns do clobber the flags, and so the distance between the compare
and the clobber is likely to be small. */
/* ??? This is one point at which one could argue that DF_REF_CHAIN would
be useful, but it is thought to be too heavy-weight a solution here. */
in_a = equivalent_reg_at_start (cmp->in_a, cmp->insn, cmp->prev_clobber);
if (!in_a)
return false;
/* Likewise for IN_B if need be. */
if (CONSTANT_P (cmp->in_b))
in_b = cmp->in_b;
else if (REG_P (cmp->in_b))
{
in_b = equivalent_reg_at_start (cmp->in_b, cmp->insn, cmp->prev_clobber);
if (!in_b)
return false;
}
else if (GET_CODE (cmp->in_b) == UNSPEC)
{
const int len = XVECLEN (cmp->in_b, 0);
rtvec v = rtvec_alloc (len);
for (int i = 0; i < len; i++)
{
rtx r = equivalent_reg_at_start (XVECEXP (cmp->in_b, 0, i),
cmp->insn, cmp->prev_clobber);
if (!r)
return false;
RTVEC_ELT (v, i) = r;
}
in_b = gen_rtx_UNSPEC (GET_MODE (cmp->in_b), v, XINT (cmp->in_b, 1));
}
else
gcc_unreachable ();
/* We've reached PREV_CLOBBER without finding a modification of IN_A.
Validate that PREV_CLOBBER itself does in fact refer to IN_A. Do
recall that we've already validated the shape of PREV_CLOBBER. */
rtx_insn *insn = cmp->prev_clobber;
rtx x = XVECEXP (PATTERN (insn), 0, 0);
if (rtx_equal_p (SET_DEST (x), in_a))
cmp_a = SET_SRC (x);
/* Also check operations with implicit extensions, e.g.:
[(set (reg:DI)
(zero_extend:DI (plus:SI (reg:SI) (reg:SI))))
(set (reg:CCZ flags)
(compare:CCZ (plus:SI (reg:SI) (reg:SI))
(const_int 0)))] */
else if (REG_P (SET_DEST (x))
&& REG_P (in_a)
&& REGNO (SET_DEST (x)) == REGNO (in_a)
&& (GET_CODE (SET_SRC (x)) == ZERO_EXTEND
|| GET_CODE (SET_SRC (x)) == SIGN_EXTEND)
&& GET_MODE (XEXP (SET_SRC (x), 0)) == GET_MODE (in_a))
cmp_a = XEXP (SET_SRC (x), 0);
/* Also check fully redundant comparisons, e.g.:
[(set (reg:SI)
(minus:SI (reg:SI) (reg:SI))))
(set (reg:CC flags)
(compare:CC (reg:SI) (reg:SI)))] */
else if (REG_P (in_b)
&& GET_CODE (SET_SRC (x)) == MINUS
&& rtx_equal_p (XEXP (SET_SRC (x), 0), in_a)
&& rtx_equal_p (XEXP (SET_SRC (x), 1), in_b))
cmp_a = in_a;
else
return false;
/* If the source uses addressing modes with side effects, we can't
do the merge because we'd end up with a PARALLEL that has two
instances of that side effect in it. */
if (side_effects_p (cmp_a))
return false;
if (in_a == in_b)
cmp_b = cmp_a;
else if (rtx_equal_p (SET_DEST (x), in_b))
cmp_b = SET_SRC (x);
else
cmp_b = in_b;
if (side_effects_p (cmp_b))
return false;
/* Determine if we ought to use a different CC_MODE here. */
flags = maybe_select_cc_mode (cmp, cmp_a, cmp_b);
if (flags == NULL)
flags = gen_rtx_REG (cmp->orig_mode, targetm.flags_regnum);
/* Generate a new comparison for installation in the setter. */
rtx y = cmp->not_in_a
? gen_rtx_NOT (GET_MODE (cmp_a), copy_rtx (cmp_a))
: copy_rtx (cmp_a);
y = gen_rtx_COMPARE (GET_MODE (flags), y, copy_rtx (cmp_b));
y = gen_rtx_SET (flags, y);
/* Canonicalize instruction to:
[(set (reg:CCM) (compare:CCM (operation) (immediate)))
(set (reg) (operation)] */
rtvec v = rtvec_alloc (2);
RTVEC_ELT (v, 0) = y;
RTVEC_ELT (v, 1) = x;
rtx pat = gen_rtx_PARALLEL (VOIDmode, v);
/* Succeed if the new instruction is valid. Note that we may have started
a change group within maybe_select_cc_mode, therefore we must continue. */
validate_change (insn, &PATTERN (insn), pat, true);
if (!apply_change_group ())
return false;
/* Success. Delete the compare insn... */
delete_insn (cmp->insn);
/* ... and any notes that are now invalid due to multiple sets. */
x = find_regno_note (insn, REG_UNUSED, targetm.flags_regnum);
if (x)
remove_note (insn, x);
x = find_reg_note (insn, REG_EQUAL, NULL);
if (x)
remove_note (insn, x);
x = find_reg_note (insn, REG_EQUIV, NULL);
if (x)
remove_note (insn, x);
return true;
}
/* Main entry point to the pass. */
static unsigned int
execute_compare_elim_after_reload (void)
{
df_set_flags (DF_LR_RUN_DCE);
df_analyze ();
gcc_checking_assert (!all_compares.exists ());
/* Locate all comparisons and their uses, and eliminate duplicates. */
find_comparisons ();
if (all_compares.exists ())
{
struct comparison *cmp;
size_t i;
/* Eliminate comparisons that are redundant with flags computation. */
FOR_EACH_VEC_ELT (all_compares, i, cmp)
{
try_eliminate_compare (cmp);
XDELETE (cmp);
}
all_compares.release ();
}
return 0;
}
namespace {
const pass_data pass_data_compare_elim_after_reload =
{
RTL_PASS, /* type */
"cmpelim", /* name */
OPTGROUP_NONE, /* optinfo_flags */
TV_NONE, /* tv_id */
0, /* properties_required */
0, /* properties_provided */
0, /* properties_destroyed */
0, /* todo_flags_start */
( TODO_df_finish | TODO_df_verify ), /* todo_flags_finish */
};
class pass_compare_elim_after_reload : public rtl_opt_pass
{
public:
pass_compare_elim_after_reload (gcc::context *ctxt)
: rtl_opt_pass (pass_data_compare_elim_after_reload, ctxt)
{}
/* opt_pass methods: */
bool gate (function *) final override
{
/* Setting this target hook value is how a backend indicates the need. */
if (targetm.flags_regnum == INVALID_REGNUM)
return false;
return flag_compare_elim_after_reload;
}
unsigned int execute (function *) final override
{
return execute_compare_elim_after_reload ();
}
}; // class pass_compare_elim_after_reload
} // anon namespace
rtl_opt_pass *
make_pass_compare_elim_after_reload (gcc::context *ctxt)
{
return new pass_compare_elim_after_reload (ctxt);
}