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]

[tree-ssa-branch] Optimizing non-SIMPLE trees

I ran into this problem with constant propagation and builtins.
In string-opt-8.c we have something like this:

  const char *const s1 = "hello world";
  const char *s2;
  s2 = s1;
  if (strncmp (++s2, "", 1) <= 0)
    abort ();

The simplifier refuses to simplify the call to strncmp() because
it contains at least one constant argument.  It does this to
avoid tricking the code generator into not outputting a builtin
call when all the arguments are constant.

Clearly, the simplifier could be a bit smarter in this case, but
the point remains that we will many times refuse to simplify a
builtin or other special trees.  The question is now, how do we
tell the optimizers to keep their hands off these trees?  In this
case, constant propagation is generating this:

  s2 = (const char * const)(char *)"hello world";
  T.1 = strncmp ( ++(const char * const)(char *)"hello world", (const char *)(char *)"", 1);
  if (T.1 <= 0)
      abort (); 

Oops.  CCP didn't realize that ++s2 had side-effects.  It didn't
have to, of course.  All the data flow information was correct,
s2 is first used and then defined in that expression, so the
reaching definition from the previous assignment could be
replaced in that expression.  However, the expression wasn't in
SIMPLE form.

An easy way out in this case would be for CCP to ask each
expression whether it's in SIMPLE form or not.  This is a problem
because the SIMPLE grammar is not context free w.r.t. expressions
(a valid RHS cannot be used as a predicate inside an if() node,
for instance).

One idea is for the simplifier to flag these trees and make them
clobber all the symbols that they reference.  I'm not quite sure
how this would affect other optimizers, though.


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