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; }
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.
CSE is the one which does this on the rtl level.
What is interesting is that ICC does not even do this optimization.
(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.
(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
Oh, this is a dup of bug 23086. *** This bug has been marked as a duplicate of 23086 ***