This is the mail archive of the gcc-patches@gcc.gnu.org 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: [PATCH] PR18002: Undo fold_single_bit_test in do_jump




> From: Ian Lance Taylor <ian@wasabisystems.com>
>> Paul Schlie <schlie@comcast.net> writes:
>>> Roger Sayle wrote:
>>> The issue concerns the code generated for expressions such as
>>> "if (x & C)" where C is a power-of-two.  The trickiness with
>>> trees such as "(x & C) != 0" is that the code we generate for
>>> them depends upon the context in which its used.  For control
>>> flow instructions its better to use a bitwise-AND of the constant
>>> C, however if the tree's value is assigned to a variable its
>>> best to implement this as "var = (x >> C') & 1" which doesn't
>>> require any conditional jumps, and is therefore preferable to
>>> "var = (x & C) ? 1 : 0".
>> 
>> Isn't the case of "var = (x & C) ? 1 : 0" a bit of an anomaly, as
>> would guess that in most conditional assignments of values would
>> not correspond to the simple case of 0 or 1 ? i.e.:
> 
> It's not all that anomalous,, because it is what we get from, e.g.,
>     a.b = (x & C) != 0;
> which is often seen when going from some external interface to
> internal bitfields.
> 
> Anyhow, it's the case that Roger is talking about, so talking about
> some other case is not necessarily relevant.

Thanks for the clarification of context, but the problem introduced by
the initial transform of expressions of the form:

 if (x & <pow2-const>) ... else ... ; // which is a typical bit test

=>

 if ((x >> <log2-const>) & 1) ... else ... ;

Wreak havoc on targets with relatively inefficient shifts, and seems
generally counter productive in circumstances where conditional jumps
are inherently unavoidable, therefore would be nice, if not imperative,
to have remedied. (which I had hoped the refinement was attempting to
address)










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