On Mon, 2006-03-20 at 19:47 -0700, Jeffrey A Law wrote: > On Sat, 2006-03-18 at 10:24 +0100, Laurent GUERBY wrote: > > On Fri, 2006-03-17 at 12:51 -0700, Jeffrey A Law wrote: > > > I'm not suggesting the FEs deduce more types and track ranges; > > > that would be rather absurd. What I'm saying is that exposing > > > these types outside the FE is most likely costing you both on > > > the compile-time side and on the run-time side. > > > > About optimization, in most languages with array bounds and > > range checks, the FE will build a structure with bounds > > and code like the following for a typical array loop (sorry > > for poor C): > > > > struct { > > int low,high; /* no alias */ > > double *data; > > } X; > > > > int first_i=X.low+2; > > int last_i=X.high-3; > > int i; > > > > if (first_i<=last_i) { > > for(i=first_i;i<=last_i;i++) { > > if (i<X.low||i>X.high) raise_bound_error(); /* CHECK */ > > do_something(array_with_bounds[i]); > > } > > } > > > > The interesting thing performance wise would be to be able to remove the > > CHECK in the BE. > > > > Is there some optimization pass able to do that? > > > > And when "+2" and "-3" are replaced by "+x" and "-y" and we > > know through typing that x>=0 and y>=0? > Not sure, mostly because of the structure accesses and my lack > of knowledge about the symbolic range support. I know we have > symbolic range support, but haven't looked to see how good it > really is. What we're doing now is certainly better than what > DOM did for symbolic ranges (nothing).
A casual read of tree-vrp.c showed that symbolic_range_p is mostly used to do nothing, did I miss something? May be it's in another file. > Note that this is closely related to some of the bounds checking > elimination we want to support for Java one day IIRC. Pascal and Ada will benefit (may be Fortran too, I don't know enough to say). > Note also that if i, first_i and/or last_i are globals, then the > odds of these kind of tests being deleted go down considerably > as they're likely call-clobbered by the call to do_something. Very likely to be all locals in typical Ada code. Laurent