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 4; Sink the shufflevector/insertelement pair, followed by the trunc. The sunk instruction end up dead. 5define signext i8 @dead(i16* noalias nocapture readonly %s1, i16 zeroext %x, i8* noalias nocapture %d, i32 %n) { 6; CHECK-LABEL: @dead( 7; CHECK-NEXT: entry: 8; CHECK-NEXT: [[N_VEC:%.*]] = and i32 [[N:%.*]], -8 9; CHECK-NEXT: br label [[VECTOR_BODY:%.*]] 10; CHECK: vector.body: 11; CHECK-NEXT: [[INDEX:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ] 12; CHECK-NEXT: [[TMP0:%.*]] = trunc i16 [[X:%.*]] to i8 13; CHECK-NEXT: [[L6:%.*]] = getelementptr inbounds i16, i16* [[S1:%.*]], i32 [[INDEX]] 14; CHECK-NEXT: [[L7:%.*]] = bitcast i16* [[L6]] to <8 x i16>* 15; CHECK-NEXT: [[WIDE_LOAD:%.*]] = load <8 x i16>, <8 x i16>* [[L7]], 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, i8* [[D:%.*]], i32 [[INDEX]] 21; CHECK-NEXT: [[L14:%.*]] = bitcast i8* [[L13]] to <8 x i8>* 22; CHECK-NEXT: store <8 x i8> [[L9]], <8 x i8>* [[L14]], align 1 23; CHECK-NEXT: [[INDEX_NEXT]] = add i32 [[INDEX]], 8 24; CHECK-NEXT: [[L15:%.*]] = icmp eq i32 [[INDEX_NEXT]], [[N_VEC]] 25; CHECK-NEXT: br i1 [[L15]], label [[EXIT:%.*]], label [[VECTOR_BODY]] 26; CHECK: exit: 27; CHECK-NEXT: ret i8 0 28; 29entry: 30 %n.vec = and i32 %n, -8 31 %l0 = trunc i16 %x to i8 32 %l1 = insertelement <8 x i8> undef, i8 %l0, i32 0 33 %broadcast.splat26 = shufflevector <8 x i8> %l1, <8 x i8> undef, <8 x i32> zeroinitializer 34 br label %vector.body 35 36vector.body: ; preds = %vector.body, %entry 37 %index = phi i32 [ 0, %entry ], [ %index.next, %vector.body ] 38 %l6 = getelementptr inbounds i16, i16* %s1, i32 %index 39 %l7 = bitcast i16* %l6 to <8 x i16>* 40 %wide.load = load <8 x i16>, <8 x i16>* %l7, align 2 41 %l8 = trunc <8 x i16> %wide.load to <8 x i8> 42 %l9 = mul <8 x i8> %broadcast.splat26, %l8 43 %l13 = getelementptr inbounds i8, i8* %d, i32 %index 44 %l14 = bitcast i8* %l13 to <8 x i8>* 45 store <8 x i8> %l9, <8 x i8>* %l14, align 1 46 %index.next = add i32 %index, 8 47 %l15 = icmp eq i32 %index.next, %n.vec 48 br i1 %l15, label %exit, label %vector.body 49 50exit: ; preds = %vector.body 51 ret i8 0 52} 53 54; Same as above, but the shuffle has an extra use meaning it shouldnt be deleted 55define signext i8 @alive(i16* noalias nocapture readonly %s1, i16 zeroext %x, i8* noalias nocapture %d, i32 %n) { 56; CHECK-LABEL: @alive( 57; CHECK-NEXT: entry: 58; CHECK-NEXT: [[N_VEC:%.*]] = and i32 [[N:%.*]], -8 59; CHECK-NEXT: [[L0:%.*]] = trunc i16 [[X:%.*]] to i8 60; CHECK-NEXT: [[L1:%.*]] = insertelement <8 x i8> undef, i8 [[L0]], i32 0 61; CHECK-NEXT: [[BROADCAST_SPLAT26:%.*]] = shufflevector <8 x i8> [[L1]], <8 x i8> undef, <8 x i32> zeroinitializer 62; CHECK-NEXT: [[L2:%.*]] = sub <8 x i8> zeroinitializer, [[BROADCAST_SPLAT26]] 63; CHECK-NEXT: br label [[VECTOR_BODY:%.*]] 64; CHECK: vector.body: 65; CHECK-NEXT: [[INDEX:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ] 66; CHECK-NEXT: [[TMP0:%.*]] = trunc i16 [[X]] to i8 67; CHECK-NEXT: [[L6:%.*]] = getelementptr inbounds i16, i16* [[S1:%.*]], i32 [[INDEX]] 68; CHECK-NEXT: [[L7:%.*]] = bitcast i16* [[L6]] to <8 x i16>* 69; CHECK-NEXT: [[WIDE_LOAD:%.*]] = load <8 x i16>, <8 x i16>* [[L7]], align 2 70; CHECK-NEXT: [[L8:%.*]] = trunc <8 x i16> [[WIDE_LOAD]] to <8 x i8> 71; CHECK-NEXT: [[TMP1:%.*]] = insertelement <8 x i8> undef, i8 [[TMP0]], i32 0 72; CHECK-NEXT: [[TMP2:%.*]] = shufflevector <8 x i8> [[TMP1]], <8 x i8> undef, <8 x i32> zeroinitializer 73; CHECK-NEXT: [[L9:%.*]] = mul <8 x i8> [[TMP2]], [[L8]] 74; CHECK-NEXT: [[L13:%.*]] = getelementptr inbounds i8, i8* [[D:%.*]], i32 [[INDEX]] 75; CHECK-NEXT: [[L14:%.*]] = bitcast i8* [[L13]] to <8 x i8>* 76; CHECK-NEXT: store <8 x i8> [[L9]], <8 x i8>* [[L14]], align 1 77; CHECK-NEXT: [[INDEX_NEXT]] = add i32 [[INDEX]], 8 78; CHECK-NEXT: [[L15:%.*]] = icmp eq i32 [[INDEX_NEXT]], [[N_VEC]] 79; CHECK-NEXT: br i1 [[L15]], label [[EXIT:%.*]], label [[VECTOR_BODY]] 80; CHECK: exit: 81; CHECK-NEXT: ret i8 0 82; 83entry: 84 %n.vec = and i32 %n, -8 85 %l0 = trunc i16 %x to i8 86 %l1 = insertelement <8 x i8> undef, i8 %l0, i32 0 87 %broadcast.splat26 = shufflevector <8 x i8> %l1, <8 x i8> undef, <8 x i32> zeroinitializer 88 %l2 = sub <8 x i8> zeroinitializer, %broadcast.splat26 89 br label %vector.body 90 91vector.body: ; preds = %vector.body, %entry 92 %index = phi i32 [ 0, %entry ], [ %index.next, %vector.body ] 93 %l6 = getelementptr inbounds i16, i16* %s1, i32 %index 94 %l7 = bitcast i16* %l6 to <8 x i16>* 95 %wide.load = load <8 x i16>, <8 x i16>* %l7, align 2 96 %l8 = trunc <8 x i16> %wide.load to <8 x i8> 97 %l9 = mul <8 x i8> %broadcast.splat26, %l8 98 %l13 = getelementptr inbounds i8, i8* %d, i32 %index 99 %l14 = bitcast i8* %l13 to <8 x i8>* 100 store <8 x i8> %l9, <8 x i8>* %l14, align 1 101 %index.next = add i32 %index, 8 102 %l15 = icmp eq i32 %index.next, %n.vec 103 br i1 %l15, label %exit, label %vector.body 104 105exit: ; preds = %vector.body 106 ret i8 0 107} 108