[PATCH] D30137: [InstCombine] shrink truncated insertelement with constant operand

Sanjay Patel via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Mar 7 12:33:02 PST 2017


spatel added a comment.

In https://reviews.llvm.org/D30137#694601, @efriedma wrote:

> On the integer side, I'm sort of worried this could make code generation worse on targets which don't have insert instructions for all relevant widths (for example, SSE2 has i16 insertelement, but not i8 insertelement).


If it's any consolation, the current x86 codegen for tests similar to the ones in this patch -- even with newer features like AVX2 -- looks awful. I can file a bug with this and others:

  define <8 x i16> @wide_insert_into_constant_vector(i32 %x) {
    %vec = insertelement <8 x i32> <i32 1, i32 2, i32 3, i32 4, i32 5, i32 3, i32 -2, i32 65536>, i32 %x, i32 1
    %trunc = trunc <8 x i32> %vec to <8 x i16>
    ret <8 x i16> %trunc
  }
  
  $ ./llc -o - shrinkinselt.ll -mattr=avx2
  ...
  	movl	$1, %eax
  	vmovd	%eax, %xmm0
  	vpinsrd	$1, %edi, %xmm0, %xmm0
  	movl	$3, %eax
  	vpinsrd	$2, %eax, %xmm0, %xmm0
  	movl	$4, %eax
  	vpinsrd	$3, %eax, %xmm0, %xmm0
  	vinserti128	$1, LCPI0_0(%rip), %ymm0, %ymm0
  	vpshufb	LCPI0_1(%rip), %ymm0, %ymm0 ## ymm0 = ymm0[0,1,4,5,8,9,12,13,8,9,12,13,12,13,14,15,16,17,20,21,24,25,28,29,24,25,28,29,28,29,30,31]
  	vpermq	$232, %ymm0, %ymm0      ## ymm0 = ymm0[0,2,2,3]
                                          ## kill: %XMM0<def> %XMM0<kill> %YMM0<kill>
  	vzeroupper
  	retq

Not sure how to explain this...


https://reviews.llvm.org/D30137





More information about the llvm-commits mailing list