
On Fri, Mar 11, 2011 at 3:04 PM, Simonson, Lucanus J < lucanus.j.simonson@intel.com> wrote:
If you have the same variable in more than one place in an expression you can map that expression to different/fewer instructions than if they were all different variables in different places. There is no way to perform that mapping using expression templates because it cannot be detected in template metaprogramming which varaibles are the same, only that they have the same type. Therefor you cannot map expression to the optimal instructions using template metaprogramming.
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. -- -Matt Calabrese