This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
RE: Incorrect optimization of inlined functions?
- To: gcc-bugs at gcc dot gnu dot org
- Subject: RE: Incorrect optimization of inlined functions?
- From: Tom Truscott <trt at unx dot sas dot com>
- Date: Mon, 25 Oct 1999 12:35:44 -0400 (EDT)
> [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