; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
; RUN: llc < %s -mtriple=i686-unknown-linux-gnu -mattr=+avx | FileCheck %s --check-prefix=X86
; RUN: llc < %s -mtriple=x86_64-unknown-linux-gnu -mattr=+avx | FileCheck %s --check-prefix=X64
; Verify that the backend correctly folds a sign/zero extend of a vector where
; elements are all constant values or UNDEFs.
; The backend should be able to optimize all the test functions below into
; simple loads from constant pool of the result. That is because the resulting
; vector should be known at static time.
define <4 x i16> @test_sext_4i8_4i16() {
; X86-LABEL: test_sext_4i8_4i16:
; X86: # %bb.0:
; X86-NEXT: vmovsd {{.*#+}} xmm0 = [0,65535,2,65533,0,0,0,0]
; X86-NEXT: retl
;
; X64-LABEL: test_sext_4i8_4i16:
; X64: # %bb.0:
; X64-NEXT: vmovsd {{.*#+}} xmm0 = [0,65535,2,65533,0,0,0,0]
; X64-NEXT: retq
%1 = insertelement <4 x i8> undef, i8 0, i32 0
%2 = insertelement <4 x i8> %1, i8 -1, i32 1
%3 = insertelement <4 x i8> %2, i8 2, i32 2
%4 = insertelement <4 x i8> %3, i8 -3, i32 3
%5 = sext <4 x i8> %4 to <4 x i16>
ret <4 x i16> %5
}
define <4 x i16> @test_sext_4i8_4i16_undef() {
; X86-LABEL: test_sext_4i8_4i16_undef:
; X86: # %bb.0:
; X86-NEXT: vmovsd {{.*#+}} xmm0 = [0,65535,0,65533,0,0,0,0]
; X86-NEXT: retl
;
; X64-LABEL: test_sext_4i8_4i16_undef:
; X64: # %bb.0:
; X64-NEXT: vmovsd {{.*#+}} xmm0 = [0,65535,0,65533,0,0,0,0]
; X64-NEXT: retq
%1 = insertelement <4 x i8> undef, i8 undef, i32 0
%2 = insertelement <4 x i8> %1, i8 -1, i32 1
%3 = insertelement <4 x i8> %2, i8 undef, i32 2
%4 = insertelement <4 x i8> %3, i8 -3, i32 3
%5 = sext <4 x i8> %4 to <4 x i16>
ret <4 x i16> %5
}
define <4 x i32> @test_sext_4i8_4i32() {
; X86-LABEL: test_sext_4i8_4i32:
; X86: # %bb.0:
; X86-NEXT: vmovaps {{.*#+}} xmm0 = [0,4294967295,2,4294967293]
; X86-NEXT: retl
;
; X64-LABEL: test_sext_4i8_4i32:
; X64: # %bb.0:
; X64-NEXT: vmovaps {{.*#+}} xmm0 = [0,4294967295,2,4294967293]
; X64-NEXT: retq
%1 = insertelement <4 x i8> undef, i8 0, i32 0
%2 = insertelement <4 x i8> %1, i8 -1, i32 1
%3 = insertelement <4 x i8> %2, i8 2, i32 2
%4 = insertelement <4 x i8> %3, i8 -3, i32 3
%5 = sext <4 x i8> %4 to <4 x i32>
ret <4 x i32> %5
}
define <4 x i32> @test_sext_4i8_4i32_undef() {
; X86-LABEL: test_sext_4i8_4i32_undef:
; X86: # %bb.0:
; X86-NEXT: vmovaps {{.*#+}} xmm0 = [0,4294967295,0,4294967293]
; X86-NEXT: retl
;
; X64-LABEL: test_sext_4i8_4i32_undef:
; X64: # %bb.0:
; X64-NEXT: vmovaps {{.*#+}} xmm0 = [0,4294967295,0,4294967293]
; X64-NEXT: retq
%1 = insertelement <4 x i8> undef, i8 undef, i32 0
%2 = insertelement <4 x i8> %1, i8 -1, i32 1
%3 = insertelement <4 x i8> %2, i8 undef, i32 2
%4 = insertelement <4 x i8> %3, i8 -3, i32 3
%5 = sext <4 x i8> %4 to <4 x i32>
ret <4 x i32> %5
}
define <4 x i64> @test_sext_4i8_4i64() {
; X86-LABEL: test_sext_4i8_4i64:
; X86: # %bb.0:
; X86-NEXT: vmovaps {{.*#+}} ymm0 = [0,0,4294967295,4294967295,2,0,4294967293,4294967295]
; X86-NEXT: retl
;
; X64-LABEL: test_sext_4i8_4i64:
; X64: # %bb.0:
; X64-NEXT: vmovaps {{.*#+}} ymm0 = [0,18446744073709551615,2,18446744073709551613]
; X64-NEXT: retq
%1 = insertelement <4 x i8> undef, i8 0, i32 0
%2 = insertelement <4 x i8> %1, i8 -1, i32 1
%3 = insertelement <4 x i8> %2, i8 2, i32 2
%4 = insertelement <4 x i8> %3, i8 -3, i32 3
%5 = sext <4 x i8> %4 to <4 x i64>
ret <4 x i64> %5
}
define <4 x i64> @test_sext_4i8_4i64_undef() {
; X86-LABEL: test_sext_4i8_4i64_undef:
; X86: # %bb.0:
; X86-NEXT: vmovaps {{.*#+}} ymm0 = [0,0,4294967295,4294967295,0,0,4294967293,4294967295]
; X86-NEXT: retl
;
; X64-LABEL: test_sext_4i8_4i64_undef:
; X64: # %bb.0:
; X64-NEXT: vmovaps {{.*#+}} ymm0 = [0,18446744073709551615,0,18446744073709551613]
; X64-NEXT: retq
%1 = insertelement <4 x i8> undef, i8 undef, i32 0
%2 = insertelement <4 x i8> %1, i8 -1, i32 1
%3 = insertelement <4 x i8> %2, i8 undef, i32 2
%4 = insertelement <4 x i8> %3, i8 -3, i32 3
%5 = sext <4 x i8> %4 to <4 x i64>
ret <4 x i64> %5
}
define <8 x i16> @test_sext_8i8_8i16() {
; X86-LABEL: test_sext_8i8_8i16:
; X86: # %bb.0:
; X86-NEXT: vmovaps {{.*#+}} xmm0 = [0,65535,2,65533,4,65531,6,65529]
; X86-NEXT: retl
;
; X64-LABEL: test_sext_8i8_8i16:
; X64: # %bb.0:
; X64-NEXT: vmovaps {{.*#+}} xmm0 = [0,65535,2,65533,4,65531,6,65529]
; X64-NEXT: retq
%1 = insertelement <8 x i8> undef, i8 0, i32 0
%2 = insertelement <8 x i8> %1, i8 -1, i32 1
%3 = insertelement <8 x i8> %2, i8 2, i32 2
%4 = insertelement <8 x i8> %3, i8 -3, i32 3
%5 = insertelement <8 x i8> %4, i8 4, i32 4
%6 = insertelement <8 x i8> %5, i8 -5, i32 5
%7 = insertelement <8 x i8> %6, i8 6, i32 6
%8 = insertelement <8 x i8> %7, i8 -7, i32 7
%9 = sext <8 x i8> %8 to <8 x i16>
ret <8 x i16> %9
}
define <8 x i32> @test_sext_8i8_8i32() {
; X86-LABEL: test_sext_8i8_8i32:
; X86: # %bb.0:
; X86-NEXT: vmovaps {{.*#+}} ymm0 = [0,4294967295,2,4294967293,4,4294967291,6,4294967289]
; X86-NEXT: retl
;
; X64-LABEL: test_sext_8i8_8i32:
; X64: # %bb.0:
; X64-NEXT: vmovaps {{.*#+}} ymm0 = [0,4294967295,2,4294967293,4,4294967291,6,4294967289]
; X64-NEXT: retq
%1 = insertelement <8 x i8> undef, i8 0, i32 0
%2 = insertelement <8 x i8> %1, i8 -1, i32 1
%3 = insertelement <8 x i8> %2, i8 2, i32 2
%4 = insertelement <8 x i8> %3, i8 -3, i32 3
%5 = insertelement <8 x i8> %4, i8 4, i32 4
%6 = insertelement <8 x i8> %5, i8 -5, i32 5
%7 = insertelement <8 x i8> %6, i8 6, i32 6
%8 = insertelement <8 x i8> %7, i8 -7, i32 7
%9 = sext <8 x i8> %8 to <8 x i32>
ret <8 x i32> %9
}
define <8 x i16> @test_sext_8i8_8i16_undef() {
; X86-LABEL: test_sext_8i8_8i16_undef:
; X86: # %bb.0:
; X86-NEXT: vmovaps {{.*#+}} xmm0 = [0,65535,0,65533,0,65531,0,65529]
; X86-NEXT: retl
;
; X64-LABEL: test_sext_8i8_8i16_undef:
; X64: # %bb.0:
; X64-NEXT: vmovaps {{.*#+}} xmm0 = [0,65535,0,65533,0,65531,0,65529]
; X64-NEXT: retq
%1 = insertelement <8 x i8> undef, i8 undef, i32 0
%2 = insertelement <8 x i8> %1, i8 -1, i32 1
%3 = insertelement <8 x i8> %2, i8 undef, i32 2
%4 = insertelement <8 x i8> %3, i8 -3, i32 3
%5 = insertelement <8 x i8> %4, i8 undef, i32 4
%6 = insertelement <8 x i8> %5, i8 -5, i32 5
%7 = insertelement <8 x i8> %6, i8 undef, i32 6
%8 = insertelement <8 x i8> %7, i8 -7, i32 7
%9 = sext <8 x i8> %8 to <8 x i16>
ret <8 x i16> %9
}
define <8 x i32> @test_sext_8i8_8i32_undef() {
; X86-LABEL: test_sext_8i8_8i32_undef:
; X86: # %bb.0:
; X86-NEXT: vmovaps {{.*#+}} ymm0 = [0,0,2,0,4,0,6,0]
; X86-NEXT: retl
;
; X64-LABEL: test_sext_8i8_8i32_undef:
; X64: # %bb.0:
; X64-NEXT: vmovaps {{.*#+}} ymm0 = [0,0,2,0,4,0,6,0]
; X64-NEXT: retq
%1 = insertelement <8 x i8> undef, i8 0, i32 0
%2 = insertelement <8 x i8> %1, i8 undef, i32 1
%3 = insertelement <8 x i8> %2, i8 2, i32 2
%4 = insertelement <8 x i8> %3, i8 undef, i32 3
%5 = insertelement <8 x i8> %4, i8 4, i32 4
%6 = insertelement <8 x i8> %5, i8 undef, i32 5
%7 = insertelement <8 x i8> %6, i8 6, i32 6
%8 = insertelement <8 x i8> %7, i8 undef, i32 7
%9 = sext <8 x i8> %8 to <8 x i32>
ret <8 x i32> %9
}
define <4 x i16> @test_zext_4i8_4i16() {
; X86-LABEL: test_zext_4i8_4i16:
; X86: # %bb.0:
; X86-NEXT: vmovsd {{.*#+}} xmm0 = [0,255,2,253,0,0,0,0]
; X86-NEXT: retl
;
; X64-LABEL: test_zext_4i8_4i16:
; X64: # %bb.0:
; X64-NEXT: vmovsd {{.*#+}} xmm0 = [0,255,2,253,0,0,0,0]
; X64-NEXT: retq
%1 = insertelement <4 x i8> undef, i8 0, i32 0
%2 = insertelement <4 x i8> %1, i8 -1, i32 1
%3 = insertelement <4 x i8> %2, i8 2, i32 2
%4 = insertelement <4 x i8> %3, i8 -3, i32 3
%5 = zext <4 x i8> %4 to <4 x i16>
ret <4 x i16> %5
}
define <4 x i32> @test_zext_4i8_4i32() {
; X86-LABEL: test_zext_4i8_4i32:
; X86: # %bb.0:
; X86-NEXT: vmovaps {{.*#+}} xmm0 = [0,255,2,253]
; X86-NEXT: retl
;
; X64-LABEL: test_zext_4i8_4i32:
; X64: # %bb.0:
; X64-NEXT: vmovaps {{.*#+}} xmm0 = [0,255,2,253]
; X64-NEXT: retq
%1 = insertelement <4 x i8> undef, i8 0, i32 0
%2 = insertelement <4 x i8> %1, i8 -1, i32 1
%3 = insertelement <4 x i8> %2, i8 2, i32 2
%4 = insertelement <4 x i8> %3, i8 -3, i32 3
%5 = zext <4 x i8> %4 to <4 x i32>
ret <4 x i32> %5
}
define <4 x i64> @test_zext_4i8_4i64() {
; X86-LABEL: test_zext_4i8_4i64:
; X86: # %bb.0:
; X86-NEXT: vmovaps {{.*#+}} ymm0 = [0,0,255,0,2,0,253,0]
; X86-NEXT: retl
;
; X64-LABEL: test_zext_4i8_4i64:
; X64: # %bb.0:
; X64-NEXT: vmovaps {{.*#+}} ymm0 = [0,255,2,253]
; X64-NEXT: retq
%1 = insertelement <4 x i8> undef, i8 0, i32 0
%2 = insertelement <4 x i8> %1, i8 -1, i32 1
%3 = insertelement <4 x i8> %2, i8 2, i32 2
%4 = insertelement <4 x i8> %3, i8 -3, i32 3
%5 = zext <4 x i8> %4 to <4 x i64>
ret <4 x i64> %5
}
define <4 x i16> @test_zext_4i8_4i16_undef() {
; X86-LABEL: test_zext_4i8_4i16_undef:
; X86: # %bb.0:
; X86-NEXT: vmovsd {{.*#+}} xmm0 = [0,255,0,253,0,0,0,0]
; X86-NEXT: retl
;
; X64-LABEL: test_zext_4i8_4i16_undef:
; X64: # %bb.0:
; X64-NEXT: vmovsd {{.*#+}} xmm0 = [0,255,0,253,0,0,0,0]
; X64-NEXT: retq
%1 = insertelement <4 x i8> undef, i8 undef, i32 0
%2 = insertelement <4 x i8> %1, i8 -1, i32 1
%3 = insertelement <4 x i8> %2, i8 undef, i32 2
%4 = insertelement <4 x i8> %3, i8 -3, i32 3
%5 = zext <4 x i8> %4 to <4 x i16>
ret <4 x i16> %5
}
define <4 x i32> @test_zext_4i8_4i32_undef() {
; X86-LABEL: test_zext_4i8_4i32_undef:
; X86: # %bb.0:
; X86-NEXT: vmovaps {{.*#+}} xmm0 = [0,0,2,0]
; X86-NEXT: retl
;
; X64-LABEL: test_zext_4i8_4i32_undef:
; X64: # %bb.0:
; X64-NEXT: vmovaps {{.*#+}} xmm0 = [0,0,2,0]
; X64-NEXT: retq
%1 = insertelement <4 x i8> undef, i8 0, i32 0
%2 = insertelement <4 x i8> %1, i8 undef, i32 1
%3 = insertelement <4 x i8> %2, i8 2, i32 2
%4 = insertelement <4 x i8> %3, i8 undef, i32 3
%5 = zext <4 x i8> %4 to <4 x i32>
ret <4 x i32> %5
}
define <4 x i64> @test_zext_4i8_4i64_undef() {
; X86-LABEL: test_zext_4i8_4i64_undef:
; X86: # %bb.0:
; X86-NEXT: vmovaps {{.*#+}} ymm0 = [0,0,255,0,2,0,0,0]
; X86-NEXT: retl
;
; X64-LABEL: test_zext_4i8_4i64_undef:
; X64: # %bb.0:
; X64-NEXT: vmovaps {{.*#+}} ymm0 = [0,255,2,0]
; X64-NEXT: retq
%1 = insertelement <4 x i8> undef, i8 undef, i32 0
%2 = insertelement <4 x i8> %1, i8 -1, i32 1
%3 = insertelement <4 x i8> %2, i8 2, i32 2
%4 = insertelement <4 x i8> %3, i8 undef, i32 3
%5 = zext <4 x i8> %4 to <4 x i64>
ret <4 x i64> %5
}
define <8 x i16> @test_zext_8i8_8i16() {
; X86-LABEL: test_zext_8i8_8i16:
; X86: # %bb.0:
; X86-NEXT: vmovaps {{.*#+}} xmm0 = [0,255,2,253,4,251,6,249]
; X86-NEXT: retl
;
; X64-LABEL: test_zext_8i8_8i16:
; X64: # %bb.0:
; X64-NEXT: vmovaps {{.*#+}} xmm0 = [0,255,2,253,4,251,6,249]
; X64-NEXT: retq
%1 = insertelement <8 x i8> undef, i8 0, i32 0
%2 = insertelement <8 x i8> %1, i8 -1, i32 1
%3 = insertelement <8 x i8> %2, i8 2, i32 2
%4 = insertelement <8 x i8> %3, i8 -3, i32 3
%5 = insertelement <8 x i8> %4, i8 4, i32 4
%6 = insertelement <8 x i8> %5, i8 -5, i32 5
%7 = insertelement <8 x i8> %6, i8 6, i32 6
%8 = insertelement <8 x i8> %7, i8 -7, i32 7
%9 = zext <8 x i8> %8 to <8 x i16>
ret <8 x i16> %9
}
define <8 x i32> @test_zext_8i8_8i32() {
; X86-LABEL: test_zext_8i8_8i32:
; X86: # %bb.0:
; X86-NEXT: vmovaps {{.*#+}} ymm0 = [0,255,2,253,4,251,6,249]
; X86-NEXT: retl
;
; X64-LABEL: test_zext_8i8_8i32:
; X64: # %bb.0:
; X64-NEXT: vmovaps {{.*#+}} ymm0 = [0,255,2,253,4,251,6,249]
; X64-NEXT: retq
%1 = insertelement <8 x i8> undef, i8 0, i32 0
%2 = insertelement <8 x i8> %1, i8 -1, i32 1
%3 = insertelement <8 x i8> %2, i8 2, i32 2
%4 = insertelement <8 x i8> %3, i8 -3, i32 3
%5 = insertelement <8 x i8> %4, i8 4, i32 4
%6 = insertelement <8 x i8> %5, i8 -5, i32 5
%7 = insertelement <8 x i8> %6, i8 6, i32 6
%8 = insertelement <8 x i8> %7, i8 -7, i32 7
%9 = zext <8 x i8> %8 to <8 x i32>
ret <8 x i32> %9
}
define <8 x i16> @test_zext_8i8_8i16_undef() {
; X86-LABEL: test_zext_8i8_8i16_undef:
; X86: # %bb.0:
; X86-NEXT: vmovaps {{.*#+}} xmm0 = [0,255,0,253,0,251,0,249]
; X86-NEXT: retl
;
; X64-LABEL: test_zext_8i8_8i16_undef:
; X64: # %bb.0:
; X64-NEXT: vmovaps {{.*#+}} xmm0 = [0,255,0,253,0,251,0,249]
; X64-NEXT: retq
%1 = insertelement <8 x i8> undef, i8 undef, i32 0
%2 = insertelement <8 x i8> %1, i8 -1, i32 1
%3 = insertelement <8 x i8> %2, i8 undef, i32 2
%4 = insertelement <8 x i8> %3, i8 -3, i32 3
%5 = insertelement <8 x i8> %4, i8 undef, i32 4
%6 = insertelement <8 x i8> %5, i8 -5, i32 5
%7 = insertelement <8 x i8> %6, i8 undef, i32 6
%8 = insertelement <8 x i8> %7, i8 -7, i32 7
%9 = zext <8 x i8> %8 to <8 x i16>
ret <8 x i16> %9
}
define <8 x i32> @test_zext_8i8_8i32_undef() {
; X86-LABEL: test_zext_8i8_8i32_undef:
; X86: # %bb.0:
; X86-NEXT: vmovaps {{.*#+}} ymm0 = [0,0,2,253,4,0,6,0]
; X86-NEXT: retl
;
; X64-LABEL: test_zext_8i8_8i32_undef:
; X64: # %bb.0:
; X64-NEXT: vmovaps {{.*#+}} ymm0 = [0,0,2,253,4,0,6,0]
; X64-NEXT: retq
%1 = insertelement <8 x i8> undef, i8 0, i32 0
%2 = insertelement <8 x i8> %1, i8 undef, i32 1
%3 = insertelement <8 x i8> %2, i8 2, i32 2
%4 = insertelement <8 x i8> %3, i8 -3, i32 3
%5 = insertelement <8 x i8> %4, i8 4, i32 4
%6 = insertelement <8 x i8> %5, i8 undef, i32 5
%7 = insertelement <8 x i8> %6, i8 6, i32 6
%8 = insertelement <8 x i8> %7, i8 undef, i32 7
%9 = zext <8 x i8> %8 to <8 x i32>
ret <8 x i32> %9
}