* config/cris/cris.c (cris_reduce_compare): New function. * config/cris/cris-protos.h (cris_reduce_compare): Add prototype. * config/cris/cris.md ("cbranch<mode>4", "cbranchdi4", "cstoredi4") (cstore<mode>4"): Apply cris_reduce_compare in expanders. The decc0ration work of the CRIS port made me look closer at the code for trivial comparisons, as in the condition for branches and conditional-stores, like in: void g(short int a, short int b) { short int c = a + b; if (c >= 0) foo (); } At -O2, the cc0 version of the CRIS port has an explicit *uneliminated* compare instruction ("cmp.w -1,$r10") instead of an (eliminated) compare against 0 (which below I'll call a zero-compare). This for the CRIS-cc0 version, but I see this also for a much older gcc, at 4.7. For the decc0rated port, the compare *is* a test against 0, eventually eliminated. To wit, for cc0 (mind the delay-slot): _g: subq 4,$sp add.w $r11,$r10 cmp.w -1,$r10 ble .L9 move $srp,[$sp] jsr _foo .L9: jump [$sp+] The compare instruction is expected to be eliminated, i.e. the following diff to the above is desired, modulo the missing sibling call, which corresponds to what I get from 4.7 and for the decc0rated port: !--- a Wed Feb 5 15:22:27 2020 !+++ b Wed Feb 5 15:22:51 2020 !@@ -1,8 +1,7 @@ ! _g: ! subq 4,$sp ! add.w $r11,$r10 !- cmp.w -1,$r10 !- ble .L9 !+ bmi .L9 ! move $srp,[$sp] ! ! jsr _foo Tracking this difference, I see that for both cc0-CRIS and the decc0rated CRIS, the comparison actually starts out as a compare against -1 at "expand" time, but is transformed for decc0rated CRIS to a zero-compare in "cse1". For CRIS-cc0 "cse1" does try to replace the compare with a zero-compare, but fails because at the same time it tries to replace the c operand with (a + b). Or some such; it fails and no other pass succeeds. I was not into fixing cc0-handling in core gcc, so I didn't look closer. BTW, at first, I was a bit surprised to see that for compares against a constant, a zero-compare is not canonical RTX for *all* conditions, and that instead only a subset of all RTX conditions against a constant are canonical, transforming one condition to the canonical one by adding 1 or -1 to the constant. It does makes sense at a closer look, but still not so much when emitting RTL. There are several places that mention in comments that emitting RTX as zero-compare is preferable, but nothing is done about it. Some generic code instead seems confused that the *target* is helped by seeing canonical RTX, or perhaps it (its authors) like me, confused about what a canonical comparison is. For example, prepare_cmp_insn calls canonicalize_comparison last before emitting the actual instructions. I see most ports for various port-specific reasons does their own massaging in their cbranch and cstore expanders. Still, the suboptimal compares *should* be fixed at expand time; better start out right than just relying on later optimizations. This kind of change is not acceptable in the current gcc development stage, at least as a change in generic code. However, it's problematic enough that I chose to fix this right now in the CRIS port. For that, I claim a possibly long-standing regression. After this, code before and after decc0ration is similar enough that I can spot compare-elimination-efforts and apply regression test-cases without them drowning in cc0-specific xfailing. I hope to eventually lift out cris_reduce_compare (renamed) into say expmed.c, called in e.g. emit_store_flag_1 (replacing the in-line code) and prepare_cmp_insn. Later.
Name |
Last commit
|
Last update |
---|---|---|
INSTALL | Loading commit data... | |
config | Loading commit data... | |
contrib | Loading commit data... | |
fixincludes | Loading commit data... | |
gcc | Loading commit data... | |
gnattools | Loading commit data... | |
gotools | Loading commit data... | |
include | Loading commit data... | |
intl | Loading commit data... | |
libada | Loading commit data... | |
libatomic | Loading commit data... | |
libbacktrace | Loading commit data... | |
libcc1 | Loading commit data... | |
libcpp | Loading commit data... | |
libdecnumber | Loading commit data... | |
libffi | Loading commit data... | |
libgcc | Loading commit data... | |
libgfortran | Loading commit data... | |
libgo | Loading commit data... | |
libgomp | Loading commit data... | |
libhsail-rt | Loading commit data... | |
libiberty | Loading commit data... | |
libitm | Loading commit data... | |
libobjc | Loading commit data... | |
liboffloadmic | Loading commit data... | |
libphobos | Loading commit data... | |
libquadmath | Loading commit data... | |
libsanitizer | Loading commit data... | |
libssp | Loading commit data... | |
libstdc++-v3 | Loading commit data... | |
libvtv | Loading commit data... | |
lto-plugin | Loading commit data... | |
maintainer-scripts | Loading commit data... | |
zlib | Loading commit data... | |
.dir-locals.el | Loading commit data... | |
.gitattributes | Loading commit data... | |
.gitignore | Loading commit data... | |
ABOUT-NLS | Loading commit data... | |
COPYING | Loading commit data... | |
COPYING.LIB | Loading commit data... | |
COPYING.RUNTIME | Loading commit data... | |
COPYING3 | Loading commit data... | |
COPYING3.LIB | Loading commit data... | |
ChangeLog | Loading commit data... | |
ChangeLog.jit | Loading commit data... | |
ChangeLog.tree-ssa | Loading commit data... | |
MAINTAINERS | Loading commit data... | |
Makefile.def | Loading commit data... | |
Makefile.in | Loading commit data... | |
Makefile.tpl | Loading commit data... | |
README | Loading commit data... | |
ar-lib | Loading commit data... | |
compile | Loading commit data... | |
config-ml.in | Loading commit data... | |
config.guess | Loading commit data... | |
config.rpath | Loading commit data... | |
config.sub | Loading commit data... | |
configure | Loading commit data... | |
configure.ac | Loading commit data... | |
depcomp | Loading commit data... | |
install-sh | Loading commit data... | |
libtool-ldflags | Loading commit data... | |
libtool.m4 | Loading commit data... | |
ltgcc.m4 | Loading commit data... | |
ltmain.sh | Loading commit data... | |
ltoptions.m4 | Loading commit data... | |
ltsugar.m4 | Loading commit data... | |
ltversion.m4 | Loading commit data... | |
lt~obsolete.m4 | Loading commit data... | |
missing | Loading commit data... | |
mkdep | Loading commit data... | |
mkinstalldirs | Loading commit data... | |
move-if-change | Loading commit data... | |
multilib.am | Loading commit data... | |
symlink-tree | Loading commit data... | |
test-driver | Loading commit data... | |
ylwrap | Loading commit data... |