This is the mail archive of the gcc@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: Common Subexpression Elimination Opportunity not being exploited


Pranav Bhandarkar wrote:
GCC 4.3 does fine here except when the operator is "logical and" (see
attached. test.c uses logical and and test1.c uses plus)

Logical and generates control-flow instructions, i.e. compares, branches, and labels. This makes optimizing it a very different problem than optimizing for plus.


Try compiling with -fdump-tree-all and notice that the "gimple" dump file already contains all of the control-flow expressed in the IL, which means optimizing this is going to be very difficult.

We could perhaps add a new high level gimple that contains the C language && as an operator, run a CSE pass, and then later lower it to expose the control flow, but that will be a lot of work, and probably won't give enough benefit to justify it.

It is simpler to rewrite the code. For instance if you change this
a[0] = ione && itwo && ithree && ifour && ifive;
to
a[0] = !!ione & !!itwo & !!ithree & !!ifour & !!ifive;
then you get the same effect (assuming none of the subexpressions have side-effects), and gcc is able to perform the optimization. You also get code without branches which is likely to be faster on modern workstation cpus.


Jim


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