This is the mail archive of the gcc-bugs@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]

RE: Incorrect optimization of inlined functions?


> [from e-mail dated Sat, 23 Oct 1999 ]
> I don't know if this is really a bug,
> or only some feature that has to be implemented, ...

I think it is the latter.  Here is a simpler "equivalent"
example that shows the inefficiency.
It introduces a temporary pointer to simulate the in-lining:

    void ff(char *s) {
        char *_tmp_ = (s && (*s)) ? s : 0;
        if (_tmp_)
            *s = 1;
    }


The problem is that _tmp_ is assigned either the value s
(which gcc knows to be non-zero) or the value 0.
But when gcc evaluates "if (_tmp_)" it does not exploit that info.

Here is a similar example, in which gcc unnecessarily tests "s" twice.

    void foo(char *s) {
        if (s)
            s[0] = 1;
        if (s)
            s[1] = 1;
    }

Tom Truscott

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