On 07/23/2015 10:33 AM, Segher Boessenkool wrote:
On Thu, Jul 23, 2015 at 10:09:49AM -0600, Jeff Law wrote:
It seems to me in these kind of cases that selection of the canonical
form should be driven by factors outside of which is better for a
particular target.  ie, which is simpler

I agree.  But neither form is simpler here, and we need to have both
forms in other contexts, so there is no real benefit to canonicalising.


a << N ==/!= 0

Looks like two operations. A shift and a comparison against zero regardless of whether or not N is constant.


a&(-1>>N) ==/!= 0

For a varying N, this has a shift, logical and and comparison against zero.

For a constant N obviously the shift collapses to a constant and we're left with two operations again.

So for gimple, I'd prefer to see us using the a << N form.

If we need both forms in other contexts, we ought to be looking to eliminate that need :-)

If we go to the RTL level, then it's more complex -- it might depend on the constant produced by the -1 >> N operation, whether or not the target can shift by more than one bit at a time (H8/300 series is limited here for example), whether or not one operation sets condition codes in a useful way, potentially allowing the comparison to be removed, etc etc. rtx_costs, even with its limitations is probably the way to drive selection of form for the RTL optimizers.


Jeff

Reply via email to