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]

RFC: Handle conditional expression in sccvn/fre/pre


Hi,
Since SCCVN operates on SSA graph instead of the control flow graph
for the sake of efficiency,
it does not handle or value number the conditional expression of
GIMPLE_COND statement.
As a result, FRE/PRE does not simplify conditional expression, as
reported in bug 30997.

Since it would be complicate and difficult to process conditional
expression in currently SCCVN
algorithm, how about following method?

STEP1  Before starting FRE/PRE, we can factor out the conditional
expression, like change following
codes:
--------------------------------
if (cond_expr)
  goto lable_a
else
  goto label_b

into codes:
--------------------------------
tmp = cond_expr
if (tmp == 1)
  goto label_a
else
  goto label_b

STEP2  Let SCCVN/FRE/PRE do its job on value numbering cond_expr and
redundancy elimination;
STEP3  After FRE/PRE, for those "tmp=cond_expr" not used in any
redundancy elimination,
we can forward it to the corresponding GIMPLE_COND statement, just
like tree-ssa-forwprop.c.

In this way, the conditional expression will be handled as other
expressions and no
redundant assignment generated.
Most important,this does not affect the current implementation of SCCVN/FRE/PRE.

The only problem is the method cannot work on reversion of conditional
expression.
For example:
--------------------------------
x = a > 2;
if (a<=2)
  goto label_a
else
  goto lable_b
could be optimized as:
--------------------------------
x = a > 2
if (x == 0)
  goto label_a
else
  goto label_b

I have worked a draft patch to do the work and would like to hear your
comments on this.

Thanks very much.
-- 
Best Regards.


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