1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -mtriple=thumbv8.1m.main-none-none-eabi -mattr=+mve.fp < %s -codegenprepare -S | FileCheck -check-prefix=CHECK %s
3 ; RUN: opt -mtriple=thumbv8.1m.main-none-none-eabi -mattr=+mve.fp < %s -codegenprepare -cgpp-huge-func=0 -S | FileCheck -check-prefix=CHECK %s
5 ; Sink the shufflevector/insertelement pair, followed by the trunc. The sunk instruction end up dead.
6 define signext i8 @dead(ptr noalias nocapture readonly %s1, i16 zeroext %x, ptr noalias nocapture %d, i32 %n) {
9 ; CHECK-NEXT: [[N_VEC:%.*]] = and i32 [[N:%.*]], -8
10 ; CHECK-NEXT: br label [[VECTOR_BODY:%.*]]
12 ; CHECK-NEXT: [[INDEX:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
13 ; CHECK-NEXT: [[TMP0:%.*]] = trunc i16 [[X:%.*]] to i8
14 ; CHECK-NEXT: [[L6:%.*]] = getelementptr inbounds i16, ptr [[S1:%.*]], i32 [[INDEX]]
15 ; CHECK-NEXT: [[WIDE_LOAD:%.*]] = load <8 x i16>, ptr [[L6]], align 2
16 ; CHECK-NEXT: [[L8:%.*]] = trunc <8 x i16> [[WIDE_LOAD]] to <8 x i8>
17 ; CHECK-NEXT: [[TMP1:%.*]] = insertelement <8 x i8> undef, i8 [[TMP0]], i32 0
18 ; CHECK-NEXT: [[TMP2:%.*]] = shufflevector <8 x i8> [[TMP1]], <8 x i8> undef, <8 x i32> zeroinitializer
19 ; CHECK-NEXT: [[L9:%.*]] = mul <8 x i8> [[TMP2]], [[L8]]
20 ; CHECK-NEXT: [[L13:%.*]] = getelementptr inbounds i8, ptr [[D:%.*]], i32 [[INDEX]]
21 ; CHECK-NEXT: store <8 x i8> [[L9]], ptr [[L13]], align 1
22 ; CHECK-NEXT: [[INDEX_NEXT]] = add i32 [[INDEX]], 8
23 ; CHECK-NEXT: [[L15:%.*]] = icmp eq i32 [[INDEX_NEXT]], [[N_VEC]]
24 ; CHECK-NEXT: br i1 [[L15]], label [[EXIT:%.*]], label [[VECTOR_BODY]]
26 ; CHECK-NEXT: ret i8 0
29 %n.vec = and i32 %n, -8
30 %l0 = trunc i16 %x to i8
31 %l1 = insertelement <8 x i8> undef, i8 %l0, i32 0
32 %broadcast.splat26 = shufflevector <8 x i8> %l1, <8 x i8> undef, <8 x i32> zeroinitializer
35 vector.body: ; preds = %vector.body, %entry
36 %index = phi i32 [ 0, %entry ], [ %index.next, %vector.body ]
37 %l6 = getelementptr inbounds i16, ptr %s1, i32 %index
38 %wide.load = load <8 x i16>, ptr %l6, align 2
39 %l8 = trunc <8 x i16> %wide.load to <8 x i8>
40 %l9 = mul <8 x i8> %broadcast.splat26, %l8
41 %l13 = getelementptr inbounds i8, ptr %d, i32 %index
42 store <8 x i8> %l9, ptr %l13, align 1
43 %index.next = add i32 %index, 8
44 %l15 = icmp eq i32 %index.next, %n.vec
45 br i1 %l15, label %exit, label %vector.body
47 exit: ; preds = %vector.body
51 ; Same as above, but the shuffle has an extra use meaning it shouldnt be deleted
52 define signext i8 @alive(ptr noalias nocapture readonly %s1, i16 zeroext %x, ptr noalias nocapture %d, i32 %n) {
53 ; CHECK-LABEL: @alive(
55 ; CHECK-NEXT: [[N_VEC:%.*]] = and i32 [[N:%.*]], -8
56 ; CHECK-NEXT: [[L0:%.*]] = trunc i16 [[X:%.*]] to i8
57 ; CHECK-NEXT: [[L1:%.*]] = insertelement <8 x i8> undef, i8 [[L0]], i32 0
58 ; CHECK-NEXT: [[BROADCAST_SPLAT26:%.*]] = shufflevector <8 x i8> [[L1]], <8 x i8> undef, <8 x i32> zeroinitializer
59 ; CHECK-NEXT: [[L2:%.*]] = sub <8 x i8> zeroinitializer, [[BROADCAST_SPLAT26]]
60 ; CHECK-NEXT: br label [[VECTOR_BODY:%.*]]
62 ; CHECK-NEXT: [[INDEX:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
63 ; CHECK-NEXT: [[TMP0:%.*]] = trunc i16 [[X]] to i8
64 ; CHECK-NEXT: [[L6:%.*]] = getelementptr inbounds i16, ptr [[S1:%.*]], i32 [[INDEX]]
65 ; CHECK-NEXT: [[WIDE_LOAD:%.*]] = load <8 x i16>, ptr [[L6]], align 2
66 ; CHECK-NEXT: [[L8:%.*]] = trunc <8 x i16> [[WIDE_LOAD]] to <8 x i8>
67 ; CHECK-NEXT: [[TMP1:%.*]] = insertelement <8 x i8> undef, i8 [[TMP0]], i32 0
68 ; CHECK-NEXT: [[TMP2:%.*]] = shufflevector <8 x i8> [[TMP1]], <8 x i8> undef, <8 x i32> zeroinitializer
69 ; CHECK-NEXT: [[L9:%.*]] = mul <8 x i8> [[TMP2]], [[L8]]
70 ; CHECK-NEXT: [[L13:%.*]] = getelementptr inbounds i8, ptr [[D:%.*]], i32 [[INDEX]]
71 ; CHECK-NEXT: store <8 x i8> [[L9]], ptr [[L13]], align 1
72 ; CHECK-NEXT: [[INDEX_NEXT]] = add i32 [[INDEX]], 8
73 ; CHECK-NEXT: [[L15:%.*]] = icmp eq i32 [[INDEX_NEXT]], [[N_VEC]]
74 ; CHECK-NEXT: br i1 [[L15]], label [[EXIT:%.*]], label [[VECTOR_BODY]]
76 ; CHECK-NEXT: ret i8 0
79 %n.vec = and i32 %n, -8
80 %l0 = trunc i16 %x to i8
81 %l1 = insertelement <8 x i8> undef, i8 %l0, i32 0
82 %broadcast.splat26 = shufflevector <8 x i8> %l1, <8 x i8> undef, <8 x i32> zeroinitializer
83 %l2 = sub <8 x i8> zeroinitializer, %broadcast.splat26
86 vector.body: ; preds = %vector.body, %entry
87 %index = phi i32 [ 0, %entry ], [ %index.next, %vector.body ]
88 %l6 = getelementptr inbounds i16, ptr %s1, i32 %index
89 %wide.load = load <8 x i16>, ptr %l6, align 2
90 %l8 = trunc <8 x i16> %wide.load to <8 x i8>
91 %l9 = mul <8 x i8> %broadcast.splat26, %l8
92 %l13 = getelementptr inbounds i8, ptr %d, i32 %index
93 store <8 x i8> %l9, ptr %l13, align 1
94 %index.next = add i32 %index, 8
95 %l15 = icmp eq i32 %index.next, %n.vec
96 br i1 %l15, label %exit, label %vector.body
98 exit: ; preds = %vector.body