1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -passes=aggressive-instcombine -S | FileCheck %s
4 define <4 x i16> @shuffle(<2 x i8> %a, <2 x i8> %b) {
5 ; CHECK-LABEL: @shuffle(
6 ; CHECK-NEXT: [[ZEXTA:%.*]] = zext <2 x i8> [[A:%.*]] to <2 x i32>
7 ; CHECK-NEXT: [[ZEXTB:%.*]] = zext <2 x i8> [[B:%.*]] to <2 x i32>
8 ; CHECK-NEXT: [[SHUF:%.*]] = shufflevector <2 x i32> [[ZEXTA]], <2 x i32> [[ZEXTB]], <4 x i32> <i32 3, i32 2, i32 1, i32 0>
9 ; CHECK-NEXT: [[TRUNC:%.*]] = trunc <4 x i32> [[SHUF]] to <4 x i16>
10 ; CHECK-NEXT: ret <4 x i16> [[TRUNC]]
12 %zexta = zext <2 x i8> %a to <2 x i32>
13 %zextb = zext <2 x i8> %b to <2 x i32>
14 %shuf = shufflevector <2 x i32> %zexta, <2 x i32> %zextb, <4 x i32> <i32 3, i32 2, i32 1, i32 0>
15 %trunc = trunc <4 x i32> %shuf to <4 x i16>
19 define <2 x i16> @unary_shuffle(<2 x i8> %a) {
20 ; CHECK-LABEL: @unary_shuffle(
21 ; CHECK-NEXT: [[ZEXTA:%.*]] = zext <2 x i8> [[A:%.*]] to <2 x i32>
22 ; CHECK-NEXT: [[SHUF:%.*]] = shufflevector <2 x i32> [[ZEXTA]], <2 x i32> undef, <2 x i32> <i32 1, i32 0>
23 ; CHECK-NEXT: [[TRUNC:%.*]] = trunc <2 x i32> [[SHUF]] to <2 x i16>
24 ; CHECK-NEXT: ret <2 x i16> [[TRUNC]]
26 %zexta = zext <2 x i8> %a to <2 x i32>
27 %shuf = shufflevector <2 x i32> %zexta, <2 x i32> undef, <2 x i32> <i32 1, i32 0>
28 %trunc = trunc <2 x i32> %shuf to <2 x i16>
32 define <4 x i16> @const_shuffle() {
33 ; CHECK-LABEL: @const_shuffle(
34 ; CHECK-NEXT: [[SHUF:%.*]] = shufflevector <2 x i32> <i32 1, i32 2>, <2 x i32> <i32 3, i32 7>, <4 x i32> <i32 3, i32 2, i32 1, i32 0>
35 ; CHECK-NEXT: [[TRUNC:%.*]] = trunc <4 x i32> [[SHUF]] to <4 x i16>
36 ; CHECK-NEXT: ret <4 x i16> [[TRUNC]]
38 %shuf = shufflevector <2 x i32> <i32 1, i32 2>, <2 x i32> <i32 3, i32 7>, <4 x i32> <i32 3, i32 2, i32 1, i32 0>
39 %trunc = trunc <4 x i32> %shuf to <4 x i16>
44 define <2 x i16> @extract_insert(<2 x i8> %a, <2 x i8> %b) {
45 ; CHECK-LABEL: @extract_insert(
46 ; CHECK-NEXT: [[ZEXTA:%.*]] = zext <2 x i8> [[A:%.*]] to <2 x i16>
47 ; CHECK-NEXT: [[ZEXTB:%.*]] = zext <2 x i8> [[B:%.*]] to <2 x i16>
48 ; CHECK-NEXT: [[EXTR:%.*]] = extractelement <2 x i16> [[ZEXTA]], i32 0
49 ; CHECK-NEXT: [[INSR:%.*]] = insertelement <2 x i16> [[ZEXTB]], i16 [[EXTR]], i32 1
50 ; CHECK-NEXT: ret <2 x i16> [[INSR]]
52 %zexta = zext <2 x i8> %a to <2 x i32>
53 %zextb = zext <2 x i8> %b to <2 x i32>
54 %extr = extractelement <2 x i32> %zexta, i32 0
55 %insr = insertelement <2 x i32> %zextb, i32 %extr, i32 1
56 %trunc = trunc <2 x i32> %insr to <2 x i16>
60 define <2 x i16> @insert_poison(i8 %a) {
61 ; CHECK-LABEL: @insert_poison(
62 ; CHECK-NEXT: [[ZEXTA:%.*]] = zext i8 [[A:%.*]] to i16
63 ; CHECK-NEXT: [[INSR:%.*]] = insertelement <2 x i16> poison, i16 [[ZEXTA]], i32 0
64 ; CHECK-NEXT: ret <2 x i16> [[INSR]]
66 %zexta = zext i8 %a to i32
67 %insr = insertelement <2 x i32> poison, i32 %zexta, i32 0
68 %trunc = trunc <2 x i32> %insr to <2 x i16>
72 ; This demonstrates test not folded by 'opt -instcombine'
73 define <2 x i16> @extract_mul_insert(<2 x i8> %x) {
74 ; CHECK-LABEL: @extract_mul_insert(
75 ; CHECK-NEXT: [[ZEXT:%.*]] = zext <2 x i8> [[X:%.*]] to <2 x i16>
76 ; CHECK-NEXT: [[LSHR:%.*]] = lshr <2 x i16> [[ZEXT]], <i16 4, i16 5>
77 ; CHECK-NEXT: [[EXTR:%.*]] = extractelement <2 x i16> [[LSHR]], i32 1
78 ; CHECK-NEXT: [[MUL:%.*]] = mul i16 [[EXTR]], 5
79 ; CHECK-NEXT: [[INSR:%.*]] = insertelement <2 x i16> [[LSHR]], i16 [[MUL]], i32 1
80 ; CHECK-NEXT: ret <2 x i16> [[INSR]]
82 %zext = zext <2 x i8> %x to <2 x i32>
83 %lshr = lshr <2 x i32> %zext, <i32 4, i32 5>
84 %extr = extractelement <2 x i32> %lshr, i32 1
85 %mul = mul i32 %extr, 5
86 %insr = insertelement <2 x i32> %lshr, i32 %mul, i32 1
87 %trunc = trunc <2 x i32> %insr to <2 x i16>