On Sat, 10 Dec 2016, Marc Glisse wrote:
On Sat, 10 Dec 2016, Allan Sandfeld Jensen wrote:
Replaces the definitions of the shift intrinsics with GCC extension syntax
to
allow GCC to reason about what the instructions does. Tests are added to
ensure the intrinsics still produce the right instructions, and that a few
basic optimizations now work.
I don't think we can do it in such a straightforward way. Those intrinsics
are well defined for any shift argument, while operator<< and operator>> are
considered undefined for many input values. I believe you may need to use an
unsigned type for the lhs of left shifts, and write a << (b & 31) to match
the semantics for the rhs (I haven't checked Intel's doc). Which might
require adding a few patterns in sse.md to avoid generating code for that
AND.
Oups, apparently I got that wrong, got confused with the scalar case. Left
shift by more than precision is well defined for vectors, but it gives 0,
it doesn't take the shift count modulo the precision. Which is even harder
to explain to gcc (maybe ((unsigned)b<=31)?a<<b:0...). Yes, the way we
model operations in gcc is often inconvenient.
There was a similar issue for LLVM (https://reviews.llvm.org/D3353).
(also, the patch can't go in until next stage 1, around March or April, but
that doesn't prevent from discussing it)
--
Marc Glisse