1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -instcombine -mtriple=x86_64-unknown-unknown -S | FileCheck %s
3 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
5 ; Verify that instcombine is able to fold identity shuffles.
7 define <8 x i32> @identity_test_vpermd(<8 x i32> %a0) {
8 ; CHECK-LABEL: @identity_test_vpermd(
9 ; CHECK-NEXT: ret <8 x i32> [[A0:%.*]]
11 %a = tail call <8 x i32> @llvm.x86.avx2.permd(<8 x i32> %a0, <8 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7>)
15 define <8 x float> @identity_test_vpermps(<8 x float> %a0) {
16 ; CHECK-LABEL: @identity_test_vpermps(
17 ; CHECK-NEXT: ret <8 x float> [[A0:%.*]]
19 %a = tail call <8 x float> @llvm.x86.avx2.permps(<8 x float> %a0, <8 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7>)
23 ; Instcombine should be able to fold the following shuffle to a builtin shufflevector
24 ; with a shuffle mask of all zeroes.
26 define <8 x i32> @zero_test_vpermd(<8 x i32> %a0) {
27 ; CHECK-LABEL: @zero_test_vpermd(
28 ; CHECK-NEXT: [[TMP1:%.*]] = shufflevector <8 x i32> [[A0:%.*]], <8 x i32> poison, <8 x i32> zeroinitializer
29 ; CHECK-NEXT: ret <8 x i32> [[TMP1]]
31 %a = tail call <8 x i32> @llvm.x86.avx2.permd(<8 x i32> %a0, <8 x i32> zeroinitializer)
35 define <8 x float> @zero_test_vpermps(<8 x float> %a0) {
36 ; CHECK-LABEL: @zero_test_vpermps(
37 ; CHECK-NEXT: [[TMP1:%.*]] = shufflevector <8 x float> [[A0:%.*]], <8 x float> poison, <8 x i32> zeroinitializer
38 ; CHECK-NEXT: ret <8 x float> [[TMP1]]
40 %a = tail call <8 x float> @llvm.x86.avx2.permps(<8 x float> %a0, <8 x i32> zeroinitializer)
44 ; Verify that instcombine is able to fold constant shuffles.
46 define <8 x i32> @shuffle_test_vpermd(<8 x i32> %a0) {
47 ; CHECK-LABEL: @shuffle_test_vpermd(
48 ; CHECK-NEXT: [[TMP1:%.*]] = shufflevector <8 x i32> [[A0:%.*]], <8 x i32> poison, <8 x i32> <i32 7, i32 6, i32 5, i32 4, i32 3, i32 2, i32 1, i32 0>
49 ; CHECK-NEXT: ret <8 x i32> [[TMP1]]
51 %a = tail call <8 x i32> @llvm.x86.avx2.permd(<8 x i32> %a0, <8 x i32> <i32 7, i32 6, i32 5, i32 4, i32 3, i32 2, i32 1, i32 0>)
55 define <8 x float> @shuffle_test_vpermps(<8 x float> %a0) {
56 ; CHECK-LABEL: @shuffle_test_vpermps(
57 ; CHECK-NEXT: [[TMP1:%.*]] = shufflevector <8 x float> [[A0:%.*]], <8 x float> poison, <8 x i32> <i32 7, i32 6, i32 5, i32 4, i32 3, i32 2, i32 1, i32 0>
58 ; CHECK-NEXT: ret <8 x float> [[TMP1]]
60 %a = tail call <8 x float> @llvm.x86.avx2.permps(<8 x float> %a0, <8 x i32> <i32 7, i32 6, i32 5, i32 4, i32 3, i32 2, i32 1, i32 0>)
64 ; Verify that instcombine is able to fold constant shuffles with undef mask elements.
66 define <8 x i32> @undef_test_vpermd(<8 x i32> %a0) {
67 ; CHECK-LABEL: @undef_test_vpermd(
68 ; CHECK-NEXT: [[TMP1:%.*]] = shufflevector <8 x i32> [[A0:%.*]], <8 x i32> poison, <8 x i32> <i32 undef, i32 6, i32 5, i32 4, i32 3, i32 2, i32 1, i32 0>
69 ; CHECK-NEXT: ret <8 x i32> [[TMP1]]
71 %a = tail call <8 x i32> @llvm.x86.avx2.permd(<8 x i32> %a0, <8 x i32> <i32 undef, i32 6, i32 5, i32 4, i32 3, i32 2, i32 1, i32 0>)
75 define <8 x float> @undef_test_vpermps(<8 x float> %a0) {
76 ; CHECK-LABEL: @undef_test_vpermps(
77 ; CHECK-NEXT: [[TMP1:%.*]] = shufflevector <8 x float> [[A0:%.*]], <8 x float> poison, <8 x i32> <i32 undef, i32 6, i32 5, i32 4, i32 3, i32 2, i32 1, i32 0>
78 ; CHECK-NEXT: ret <8 x float> [[TMP1]]
80 %a = tail call <8 x float> @llvm.x86.avx2.permps(<8 x float> %a0, <8 x i32> <i32 undef, i32 6, i32 5, i32 4, i32 3, i32 2, i32 1, i32 0>)
84 ; Verify simplify demanded elts.
86 define <8 x i32> @elts_test_vpermd(<8 x i32> %a0, i32 %a1) {
87 ; CHECK-LABEL: @elts_test_vpermd(
88 ; CHECK-NEXT: [[TMP1:%.*]] = shufflevector <8 x i32> [[A0:%.*]], <8 x i32> undef, <8 x i32> <i32 undef, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7>
89 ; CHECK-NEXT: ret <8 x i32> [[TMP1]]
91 %1 = insertelement <8 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7>, i32 %a1, i32 0
92 %2 = tail call <8 x i32> @llvm.x86.avx2.permd(<8 x i32> %a0, <8 x i32> %1)
93 %3 = shufflevector <8 x i32> %2, <8 x i32> undef, <8 x i32> <i32 undef, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7>
97 define <8 x float> @elts_test_vpermps(<8 x float> %a0, <8 x i32> %a1) {
98 ; CHECK-LABEL: @elts_test_vpermps(
99 ; CHECK-NEXT: [[TMP1:%.*]] = tail call <8 x float> @llvm.x86.avx2.permps(<8 x float> [[A0:%.*]], <8 x i32> [[A1:%.*]])
100 ; CHECK-NEXT: [[TMP2:%.*]] = shufflevector <8 x float> [[TMP1]], <8 x float> undef, <8 x i32> zeroinitializer
101 ; CHECK-NEXT: ret <8 x float> [[TMP2]]
103 %1 = insertelement <8 x i32> %a1, i32 0, i32 7
104 %2 = tail call <8 x float> @llvm.x86.avx2.permps(<8 x float> %a0, <8 x i32> %1)
105 %3 = shufflevector <8 x float> %2, <8 x float> undef, <8 x i32> zeroinitializer
109 declare <8 x i32> @llvm.x86.avx2.permd(<8 x i32>, <8 x i32>)
110 declare <8 x float> @llvm.x86.avx2.permps(<8 x float>, <8 x i32>)