Bug 25558 - Arguments cannot alias local variables
Summary: Arguments cannot alias local variables
Status: RESOLVED DUPLICATE of bug 23086
Alias: None
Product: gcc
Classification: Unclassified
Component: tree-optimization (show other bugs)
Version: 4.2.0
: P3 enhancement
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: alias, missed-optimization, TREE
Depends on:
Blocks: 19721
  Show dependency treegraph
 
Reported: 2005-12-25 04:12 UTC by Andrew Pinski
Modified: 2006-01-11 01:07 UTC (History)
2 users (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 Andrew Pinski 2005-12-25 04:12:57 UTC
I cannot remember if I filed a bug about this or not but I noticed this while looking at some Fortran code.  Here is testcase which shows the issue:
void link_error(void);

int *t;
int g(int *a)
{
  t = a;
  *a = 2;
}

void f(int *a)
{
  int b;
  b = 1;
  g(&b);
  b = 2;
  *a = 1;  <--- a cannot point to b here.
  if (b == 2)
    link_error();
}

int main(void)
{
  int t;
  f(&t);
  return 0;
}
Comment 1 Andrew Pinski 2005-12-25 04:16:24 UTC
Woops I had messed up the testcase, anyways the following line:
  if (b == 2)
Should be replaced with:
  if (b != 2)


This is already done on the RTL level.
Comment 2 Andrew Pinski 2005-12-25 04:19:48 UTC
CSE is the one which does this on the rtl level.
Comment 3 Andrew Pinski 2005-12-25 04:56:06 UTC
What is interesting is that ICC does not even do this optimization.
Comment 4 Andrew Pinski 2005-12-25 05:04:57 UTC
(In reply to comment #3)
> What is interesting is that ICC does not even do this optimization.

Even LLVM does this optimization, I am starting to think ICC is not really a good compiler.
Comment 5 Andrew Pinski 2005-12-25 05:30:22 UTC
(In reply to comment #4)
> (In reply to comment #3)
> > What is interesting is that ICC does not even do this optimization.
> 
> Even LLVM does this optimization, I am starting to think ICC is not really a
> good compiler.

Ifort actually does this optimization, it is just weird that.  Here is the equivalent Fortran code:
module f1
contains
function g(a)
integer g
integer a
g = 1
a = 2
end function
function f(a)
real f
integer a
integer b
integer c
b=1
c = g(b)
b = 1
a = 2
if (b .ne. 1) then
call link_error ()
end if
f = 1
end function
end module
Comment 6 Andrew Pinski 2006-01-11 01:07:09 UTC
Oh, this is a dup of bug 23086.

*** This bug has been marked as a duplicate of 23086 ***