[PATCH 00/28] mn10300 cleanup + compare-elim, v2

Richard Henderson rth@redhat.com
Tue Jan 11 18:31:00 GMT 2011


I meant to also give for the record a rationale for some of the
changes from version 1.

The biggest change in the way I'm approaching the compare-elim pass
from the backend point-of-view is that the original suggestion for

(define_insn "arithsi3"
  [(match_parallel "clobber_or_set_CCZCmode"
     [(pattern)])]

works, *nearly*.  While it can properly match the clobber or the
set of the cc-reg with the pattern, what it misses is the auto-
generated recognition of the pattern *without* the clobber, plus
the num_clobbers_to_add quantity.  Without this, combine will 
pretty much fail to match anything, and we miss all sorts of
optimizations.

I thought about different ways to handle this.  The best idea that
I came up with was to extend the definition of define_predicate to
allow attributes.  Then one could write

(define_special_predicate "clobber_or_set_CCZCmode"
  (and (match_code "parallel")
       (match_test "whatever"))
  [(set_attr "num_clobbers_to_add" "1")])

which we could define to mean: match the internals of the match_parallel,
and take the num_clobbers_to_add quantity from the predicate.  It
seems like a plausible course of action, but it was more work than I
had time for over the break.

In the meantime I simply use two separate patterns, as is customary.

The second change for the compare-elim pass is to look for duplicate
compare instructions.  That is,

	cmp	x,y
	stuff-with-no-flags-clobber
	cmp	x,y

and, in particular, look across basic block boundaries.  This turned
out to be way more common than any other optimization that I could find.
For instance, this double compare happens against the high work in every
double-word comparison.  E.g.

	cmp	xh,yh
	blt	true
	cmp	xh,yh
	bne	false
	cmp	xl,yl
	blt	true

The desire to do both -- eliminate duplicate compares and eliminate the
original compare itself -- means that the pass has been rearranged:

First scan the entire function collecting all the compares and the uses.
Eliminate duplicates, and merge the set of uses.  Use the combined set 
of uses to determine the proper CC_MODE that can handle everything, and
only then attempt to eliminate the original compare.

We get to use df.h links to find the uses and (mostly) the insn that
may make the compare redundant.  Thus we have only one full scan over
all insns in the function while looking for the compare insns in the
first place.


r~



More information about the Gcc-patches mailing list