Bug 38691 - missed optimization with const pointers
Summary: missed optimization with const pointers
Status: RESOLVED INVALID
Alias: None
Product: gcc
Classification: Unclassified
Component: tree-optimization (show other bugs)
Version: 4.4.0
: P3 enhancement
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: alias
Depends on:
Blocks: 23169
  Show dependency treegraph
 
Reported: 2009-01-02 09:48 UTC by Thomas Koenig
Modified: 2009-01-02 10:27 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Thomas Koenig 2009-01-02 09:48:56 UTC
This is one possible C equivalent of PR 23169, a Fortran PR.

$ cat foo.c
void bar(const int *, const int *);

int foo(const int *b, const int *c)
{
    int d,e;
    d = *b;
    e = *c;

    bar(b, c);
    return (d- *b) + (e - *c);
}
$ gcc -O3 -fdump-tree-optimized -S foo.c
$ cat foo.c.123t.optimized

;; Function foo (foo)

Analyzing Edge Insertions.
foo (const int * b, const int * c)
{
  int e;
  int d;

<bb 2>:
  d = *b;
  e = *c;
  bar (b, c);
  return ((e - *b) + d) - *c;

}

Without the call to bar, the function is optimized
to "return 0".  This should be possible even with the
call to bar, because all pointers in sight are marked const.
Comment 1 Richard Biener 2009-01-02 10:27:48 UTC
const doesn't have any semantic meaning.  Which means that it is valid for bar
to change the memory pointed to by its arguments - just not through the const
qualified pointers.

There is no way to tell the middle-end about anonymous readonly memory.