[X86] Avoid introducing extra shuffles when lowering packed vector shifts.
authorAndrea Di Biagio <Andrea_DiBiagio@sn.scee.net>
Fri, 5 Dec 2014 12:13:30 +0000 (12:13 +0000)
committerAndrea Di Biagio <Andrea_DiBiagio@sn.scee.net>
Fri, 5 Dec 2014 12:13:30 +0000 (12:13 +0000)
commit2876a673121a9cba849edc614446255a767bdd9c
tree40002e72948a7caf13b33941c6f5dfc41b13a02f
parentbc0c423a46adde261cee400a74a84311c84ce287
[X86] Avoid introducing extra shuffles when lowering packed vector shifts.

When lowering a vector shift node, the backend checks if the shift count is a
shuffle with a splat mask. If so, then it introduces an extra dag node to
extract the splat value from the shuffle. The splat value is then used
to generate a shift count of a target specific shift.

However, if we know that the shift count is a splat shuffle, we can use the
splat index 'I' to extract the I-th element from the first shuffle operand.
The advantage is that the splat shuffle may become dead since we no longer
use it.

Example:

;;
define <4 x i32> @example(<4 x i32> %a, <4 x i32> %b) {
  %c = shufflevector <4 x i32> %b, <4 x i32> undef, <4 x i32> zeroinitializer
  %shl = shl <4 x i32> %a, %c
  ret <4 x i32> %shl
}
;;

Before this patch, llc generated the following code (-mattr=+avx):
  vpshufd $0, %xmm1, %xmm1   # xmm1 = xmm1[0,0,0,0]
  vpxor  %xmm2, %xmm2
  vpblendw $3, %xmm1, %xmm2, %xmm1 # xmm1 = xmm1[0,1],xmm2[2,3,4,5,6,7]
  vpslld %xmm1, %xmm0, %xmm0
  retq

With this patch, the redundant splat operation is removed from the code.
  vpxor  %xmm2, %xmm2
  vpblendw $3, %xmm1, %xmm2, %xmm1 # xmm1 = xmm1[0,1],xmm2[2,3,4,5,6,7]
  vpslld %xmm1, %xmm0, %xmm0
  retq

llvm-svn: 223461
llvm/lib/Target/X86/X86ISelLowering.cpp
llvm/test/CodeGen/X86/lower-vec-shift-2.ll [new file with mode: 0644]
llvm/test/CodeGen/X86/vshift-4.ll