This is the mail archive of the mailing list for the GCC project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Optimising redundant compares

Jon Beniston wrote:
I am working on a port of GCC to a machine that has a CC register that
is only modified by compare instructions. I have modeled this in GCC
using a single hard register rather than cc0. I would like to optimise
away redundant compare operations that are produced from the following

You just emit compare instructions that use the COMPARE operator, and the optimizer will optimize away redundant compares.

define_expand for each branch instruction. I assume that somehow in my
gen_conditional_branch function, I have to look at the previously
generated compare to see if it takes the same operands, and then omit
emitting a second compare instruction if they are identical. However,

That sounds unwise. The compiler guarantees that a compare is always followed by a branch (or scc), so it is safe to save the compare operands in global variables to be used by the next branch. However, there is no guarantee that the next compare will even be in the same function. So using the saved values is unsafe unless you are saving/restoring them with function context. Then you have to worry about marking them as garbage collection roots, and worrying about data flow, etc. This seems pretty pointless. Just emit the compares, and let the optimizer handle it.
Jim Wilson, GNU Tools Support,

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]