Skip to content

[InstCombine] hoist vector cast above splat as scalar cast? #32212

@rotateright

Description

@rotateright
Bugzilla Link 32865
Version trunk
OS All
CC @RKSimon,@ZviRackover

Extended Description

Forking this off from bug 14657.

One of these should be canonical:

define <8 x i32> @​sext_last(i16 %x) {
%ins = insertelement <8 x i16> undef, i16 %x, i32 0
%splat = shufflevector <8 x i16> %ins, <8 x i16> undef, <8 x i32> zeroinitializer
%sext = sext <8 x i16> %splat to <8 x i32>
ret <8 x i32> %sext
}

define <8 x i32> @​sext_first(i16 %x) {
%sext = sext i16 %x to i32
%ins = insertelement <8 x i32> undef, i32 %sext, i32 0
%splat = shufflevector <8 x i32> %ins, <8 x i32> undef, <8 x i32> zeroinitializer
ret <8 x i32> %splat
}

We may need to prepare the backend to expect the canonical pattern to avoid regressions. Eg, with AVX1, there's a big difference in codegen:

$ ./llc -o - splatsext.ll -mattr=avx
_sext_last: ## @​sext_last
vmovd %edi, %xmm0
vpshuflw $0, %xmm0, %xmm0 ## xmm0 = xmm0[0,0,0,0,4,5,6,7]
vpshufd $80, %xmm0, %xmm0 ## xmm0 = xmm0[0,0,1,1]
vpmovsxwd %xmm0, %xmm1
vpshufd $78, %xmm0, %xmm0 ## xmm0 = xmm0[2,3,0,1]
vpmovsxwd %xmm0, %xmm0
vinsertf128 $1, %xmm0, %ymm1, %ymm0

_sext_first: ## @​sext_first
movswl %di, %eax
vmovd %eax, %xmm0
vpshufd $0, %xmm0, %xmm0 ## xmm0 = xmm0[0,0,0,0]
vinsertf128 $1, %xmm0, %ymm0, %ymm0

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugzillaIssues migrated from bugzillallvm:instcombineCovers the InstCombine, InstSimplify and AggressiveInstCombine passes

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions