arnold@emory.uucp (Arnold D. Robbins {EUCC}) (08/11/87)
Subject: f77 -O breaks certain expressions Index: /usr/src/lib/{c2, pcc}/??? 4.3BSD Description: Quoted directly from the original user: It seems that the optimizer is doing some funny things with expressions such as A(MOD(I - 1 + L, L), J) or A(MOD(I + 1, L), J) which are passed directly to a subroutine (such as the WRITE statements below), as opposed to indirectly through assignment. These expressions refer to (lower and upper) neighbors of the site A(I, J) on a lattice with periodic boundary conditions. If A(15, 0) is set to some value, then the lower neighbor of A(0, J) and the upper neighbor of A(14, J) as calculated above result in that value independent of the value of J (as long as J is a variable rather than a constant). In each of the WRITE statements below, the value 0 is printed out for each expression except the last, which should also be 0. Repeat-By: PROGRAM TEST INTEGER L, N PARAMETER (L = 16, N = L - 1) INTEGER A(0:N, 0:N) INTEGER I, J, B DO 310 I = 0, N DO 310 J = 0, N A(I, J) = 0 310 CONTINUE A(15, 0) = 1 I = 15 J = 1 C Position (15, J) prints correctly: B = A(MOD(I + 0, L), J) WRITE (6, *) B, A(MOD(I + 0, L), J) WRITE (6, *) '' I = 0 J = 1 C Position (15, J) blows it: B = A(MOD(I + N, L), J) WRITE (6, *) B, A(MOD(0 + N, L), J), A(MOD(I + N, L), 1), & A(MOD(I + N, L), J) C Position (1, J) prints correctly: B = A(MOD(I + 1, L), J) WRITE (6, *) B, A(MOD(I + 1, L), J) WRITE (6, *) '' I = 14 J = 1 C Position (13, J) prints correctly: B = A(MOD(I + N, L), J) WRITE (6, *) B, A(MOD(I + N, L), J) C Position (15, J) blows it: B = A(MOD(I + 1, L), J) WRITE (6, *) B, A(MOD(14 + 1, L), J), A(MOD(I + 1, L), 1), & A(I + 1, J), A(MOD(I + 1, L), J) WRITE (6, *) '' STOP END Remarks: I don't know how to fix this, or even where to start looking. I understand that f77 has its own optimizer, as well as using /lib/c2, but don't know which of the two is at fault. I have sent this in to UCB, but am posting here to alert the user community that there is a problem. -- Arnold Robbins ARPA, CSNET: arnold@emory.ARPA BITNET: arnold@emory UUCP: { decvax, gatech, sun!sunatl }!emory!arnold ONE-OF-THESE-DAYS: arnold@emory.mathcs.emory.edu