|
|
Bugzilla Link |
1038 |
Created on |
Dec 10, 2012 21:08 |
Version |
svn |
OS |
Linux |
Architecture |
PC |
Extended Description
Here is a problem that has been with us since guards were introduced.
Consider this expression, used to guard against upper bound index errors
in sel() code:
y = m - 1;
x', p = _val_lt_val_SxS_( x, y);
AVIS_MAX( x) = 1 + (m - 2);
CF could check for AVIS_MAX(x) == y and simplify
this particular case. However, in general, we may have
AVIS_MAX( x) = 1 + ( m -3), so the CF change would not
help.
At first glance, it seems that what we want is
something along the lines of CTZ,
where we would subtract x (or y) from both arguments of the guard.
This, however, would cause AWLFI backtrace of index vectors from the sel()
to the WITHID_VEC to fail, so that idea is out of the picture.
A more likely approach, it seems to me, is to include an extra
argument in most/all guards, and put the computation there, as
a predicate, e.g.,:
pred = ( x - y) < 0;
x', p = _val_lt_val_SxS_( x, y, pred);
If CF (or some other traversal) determines that pred is true,
then the guard can be removed. If pred is false, then we raise an
index error. Otherwise, we really do not know at compile time
whether the index is valid or not, so a post-optimization path
merely removes the pred argument, and we're back to the situation
as it is today.
I stumbled onto this while looking at AWLF unit test relaxAKDnotake.sac,
compiled with -doawlf -nowlf.
sac2c -V
sac2c v1.00-beta (Haggis And Apple)
developer rev 18038 linux-gnu_x86_64
(Sun Dec 9 16:58:31 EST 2012 by sac)