This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
CSE failing for SH due to weak alias analysis
- From: "Sanjiv Kumar Gupta, Noida" <sanjivg at noida dot hcltech dot com>
- To: gcc at gcc dot gnu dot org
- Date: Sat, 26 Oct 2002 16:35:57 +0530
- Subject: CSE failing for SH due to weak alias analysis
This is in continuation to my earlier mails
with subject "Improving alias analysis". Pls. see thread
http://gcc.gnu.org/ml/gcc/2002-10/msg01032.html
This describes a simple case of CSE failure on SH due to weak alias
analysis.
Consider following code snippet,
void func (double *d)
{
int i = 0;
for (i = 0; i < 20; i++)
{
d[i+2] += d[i+1];
d[i+1] += d[i];
}
}
Below is the RTL dump after CSE, (with -ml -m4 -O2 -fno-schedule-insns2),
'@' indicates 64-bit dereferencing here
...
1: r164 = r163 +16
2: r172 = r163 + 8
3: r173 = @r164 ; loading d[i+2]
4: r174 = @r172 ; loading d[i+1]
5: r175 = r173 + r174 ; add d[i+2] and d[i+1]
6: @r164 = r175 ; store result into d[i+2]
7: r187 = @r172 ;<-- LOADING d[i+1] AGAIN !!!!!
...
line 7 need not dereference r172 again as the value is already loaded
in r174 by line 4.
The *alias analysis tells CSE that r172 and r164 may alias*, and CSE
concludes that storing at r164 at line 6 invalidates any previous
load from r172.
But by looking at the lines 1,2 it is fairly obvious that *r172 and r164 do
NOT
alias*.
So, this is a case of alias analysis (true_dependence() in alias.c) failing
while determining aliasing between two pointer REGs. This affects code
quality
for SH very badly as SH does not allow reg+offset addressing mode for
floats.
This problem could also be there in IA64 and there might be other variants
of
the problem.
There seems to be NO existing alias code which correctly determines aliasing
between two such pointer REGs. base_alias_check() only checks the base
addresses,
and memrefs_conflict_p() does NOTHING for cse.
I am looking to improve the existing alias code so that it can handle
aliasing
between two pointer REGs by looking at their history.
I hope to come up with some solutions in my future mails. meanwhile any
ideas,
suggestions from you people would feel great.
Sanjiv