Need help understanding cse.c/cse_insn()
Jim Wilson
wilson@chestnut.cygnus.com
Mon Sep 1 18:22:00 GMT 1997
The main function of cse is to find common subexpressions and eliminate
them. If it sees a sequence like this:
(set (reg X) (plus (reg A) (constant)))
(set (reg Y) (plus (reg A) (constant)))
it will change it to this:
(set (reg X) (plus (reg A) (constant)))
(set (reg Y) (reg X))
We must pass the entire SET_SRC to lookup so that we can handle sequences
like the above.
There is also some other code that tries to canonicalize pseudo reg
references, so that if you have something like this
(set (reg X) (reg Y))
(set (reg Z) (plus (reg X) (constant)))
it can be changed to this
(set (reg X) (reg Y))
(set (reg Z) (plus (reg Y) (constant)))
See the `canon_reg' code. However, this only replaces one pseudo with
another pseudo.
There are also some other various cases that are handled.
There does happen to be some code in find_best_addr that does what you
are looking for. However, this code is only used for addresses inside
a MEM. It will not apply to your example because the RTL in your example
is not inside a MEM. See the code at the end of find_best_addr inside
the flag_expensive_optimizations conditional. Note also that this code
is O(N^2) worst case, and that this is a real problem. Doing this for
addresses is bad enough, but trying to do this for every SET_SRC might
make the cse pass unacceptable slow. We might be able to do this for
a few of the most useful cases, e.g. handling a SET_SRC of PLUS (as in your
example) might be useful enough to be worth the compiler slowdown.
Jim
More information about the Gcc-bugs
mailing list