
On 11/03/11 22:05, Matt Calabrese wrote:
Even if a given compiler can't do such further optimizations for you, I wouldn't consider it the end of the road for expression templates. Not that I would necessarily suggest the following solution for all situations, but you could always attach a type-tag to a reused variable when forming an expression, for instance:
some_type a, b, c;
some_tagger< a_tag> a_( a );
c = a_ * b + a_;
Since a_ here has a unique tag "a_tag" associated with it, the hypothetical DSEL can be made to treat the two instances of a_ as the same variable and would therefore know to use specific instructions in such a case. Again, I'm not proposing that this is a great solution as it requires some effort on the part of the user, but by type-tagging objects that appear multiple times in a single expression you can do the kinds of things that you are talking about. This is an usual solution yes. It requires a bit of housekeeping but it is usually what we do. In nt2 matrix can be tagged using mpl string even.
However the compiler should CSE , ET or not as stated in my last post.