Aliasing pitfall in std::valarray
Bastian Pranzas
bastian@moduleworks.com
Sat Dec 7 08:31:00 GMT 2013
Ah, found it, thanks.
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48365
Seems to refer to "The valarray array classes are defined to be free of
certain forms of aliasing, thus allowing operations on these classes to
be optimized." in the standard. So it seems users of that class have to
be aware of such issues and guard against them.
So this is merely a pitfall not a bug.
I still have a question:
Could this particular pitfall not be avoided "for free" by making a
temporary copy of the scalar(s) involved in a valarray assignment? Since
this kind of problem only seems to happen when scalars are involved,
making a copy should be cheap. And since the scalar is guaranteed to be
constant throughout the operation, it might even improve the
optimization opportunities for the compiler. As it is, the compiler
can't possibly emit vector operations for example unless it can prove
that no aliasing happens.
Regards,
Bastian Pranzas
More information about the Libstdc++
mailing list