|
|
Bugzilla Link |
880 |
Created on |
Oct 19, 2011 19:08 |
Resolution |
FIXED |
Resolved on |
Oct 21, 2011 15:50 |
Version |
svn |
OS |
Linux |
Architecture |
PC |
Extended Description
The advent of -doivecyc shows up a problem in CF or, more properly,
in the reduced semantic information available to CF.
Consider this code (trimmed SCCFprf_selivecyc.sac) from the CF unit test suit:
int[*] id(int[*] y)
{ return(y);
}
int main()
{
two = id(2);
three = id(3);
four = id(4);
five = id(5);
XX = [[two, three],[four, five]];
/* CF should turn this into "three" */
z = _add_SxS_(z, _sel_VxA_([0,1], XX));
z = _sub_SxS_(z,8); /* 0 = success */
return(z);
}
StructOpSel in SCCF turns:
z = _sel_VxA_( [0, 1], XX);
into:
z = _sel_VxA_( [1], [two, three]);
and a subsequent CF turns that into:
z = three;
This optimization requires, at present, the index vector
to be available as a constant.
With -doivecyc, the original code is converted into:
offset = _vect2offset( shape(XX), [ 0, 1]);
z = _idx_sel( offset, XX);
The first line quickly becomes:
offset = 1;
However, we are unable to index into the ravel of XX
using "offset", as it is a structural constant. At present,
CF dies with a rank error.
I see two ways to resolve this problem:
1. Introduce a function to perform the mixed-radix inverse
of vect2offset:
iv' = offset2vect( shape(XX), offset);
If StructOpSel is the only victim of -doivecyc, then
this approach makes sense.
2. Replace idx_sel( offset, mat) within the opt cycle, with
a new N_prf function that preserves iv and lets optimizations take
their choice of representation:
z = _idxiv_sel( offset, mat, iv);
This function would be turned back into idx_sel() by a post-optimization
traversal.