Consider: unsigned int bar (void); void foo (void) { unsigned int a = bar (); if (65536 > a) bar (); } ./cc1 -quiet -O2 -fomit-frame-pointer generates foo: move.l %a2,-(%sp) lea bar,%a2 jbsr (%a2) cmp.l #65535,%d0 jbhi .L10 jbsr (%a2) .L10: move.l (%sp)+,%a2 rts Note that cmp.l #65535,%d0 jbhi .L10 can be replaced with swap %d0 tst.w %d0 jbne .L10 A similar trick can be applied to signed comparisons as well.
Confirmed.
> Note that > > cmp.l #65535,%d0 > jbhi .L10 > > can be replaced with > > swap %d0 > tst.w %d0 > jbne .L10 > > A similar trick can be applied to signed comparisons as well. But this "trick" will run slower on the higher 68k CPUs. On 68040 or 68060 or SuperScalar Coldfire its better to generate less instructions that do not have dependancies. I think "cmp.l #65535,%d0" is the code that should be generated by "O2" as its faster on many 68K models. The shorter two instruction trick might be an option for compile optiont "Os" Kind regards Gunnar von Boehn
Author: law Date: Mon Nov 21 18:19:12 2016 New Revision: 242676 URL: https://gcc.gnu.org/viewcvs?rev=242676&root=gcc&view=rev Log: PR target/25128 * config/m68k/predicates.md (swap_peephole_relational_operator): New predicate. * config/m68k/m68k.md (relational tests against 65535/65536): New peephole2. PR target/25128 * gcc.target/m68k/pr25128.c: New test. Added: trunk/gcc/testsuite/gcc.target/m68k/pr25128.c Modified: trunk/gcc/ChangeLog trunk/gcc/config/m68k/m68k.md trunk/gcc/config/m68k/predicates.md trunk/gcc/testsuite/ChangeLog
Fixed on the trunk.