[Altivec] Change vec_sl to a << (b % (sizeof(a) * 8))
authorTim Shen <timshen91@gmail.com>
Fri, 20 Jan 2017 22:05:33 +0000 (22:05 +0000)
committerTim Shen <timshen91@gmail.com>
Fri, 20 Jan 2017 22:05:33 +0000 (22:05 +0000)
commit867be0d14ce393108d848bcd9d080a92ca6b0006
tree6ca351b65868feb97cbb4fa202597ba6486274af
parentd88f928a5c4c4a40ee6bdf785767e43ec6167aa8
[Altivec] Change vec_sl to a << (b % (sizeof(a) * 8))

For a << b (as original vec_sl does), if b >= sizeof(a) * 8, the
behavior is undefined. However, Power instructions do define the
behavior, which is equivalent to a << (b % (sizeof(a) * 8)).

This patch changes altivec.h to use a << (b % (sizeof(a) * 8)), to
ensure the consistent semantic of the instructions. Then it combines
the generated multiple instructions back to a single shift.

This patch handles left shift only. Right shift, on the other hand, is
more complicated, considering arithematic/logical right shift.

Differential Revision: https://reviews.llvm.org/D28037

llvm-svn: 292659
clang/lib/Headers/altivec.h
clang/test/CodeGen/builtins-ppc-altivec.c