1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -mtriple=thumbv6m-none-eabi -loop-reduce %s -S -o - | FileCheck %s
4 target datalayout = "e-m:e-p:32:32-i64:64-v128:64:128-a:0:32-n32-S64"
6 %struct.arm_matrix_instance_q15 = type { i16, i16, ptr }
8 define i32 @arm_mat_add_q15(ptr nocapture readonly %pSrcA, ptr nocapture readonly %pSrcB, ptr nocapture readonly %pDst) {
9 ; CHECK-LABEL: @arm_mat_add_q15(
11 ; CHECK-NEXT: [[NUMROWS:%.*]] = getelementptr inbounds [[STRUCT_ARM_MATRIX_INSTANCE_Q15:%.*]], ptr [[PSRCA:%.*]], i32 0, i32 0
12 ; CHECK-NEXT: [[I0:%.*]] = load i16, ptr [[NUMROWS]], align 4
13 ; CHECK-NEXT: [[NUMCOLS:%.*]] = getelementptr inbounds [[STRUCT_ARM_MATRIX_INSTANCE_Q15]], ptr [[PSRCA]], i32 0, i32 1
14 ; CHECK-NEXT: [[I1:%.*]] = load i16, ptr [[NUMCOLS]], align 2
15 ; CHECK-NEXT: [[MUL:%.*]] = mul i16 [[I1]], [[I0]]
16 ; CHECK-NEXT: [[CMP22:%.*]] = icmp eq i16 [[MUL]], 0
17 ; CHECK-NEXT: br i1 [[CMP22]], label [[WHILE_END:%.*]], label [[WHILE_BODY_PREHEADER:%.*]]
18 ; CHECK: while.body.preheader:
19 ; CHECK-NEXT: [[CONV5:%.*]] = zext i16 [[MUL]] to i32
20 ; CHECK-NEXT: [[PDATA2:%.*]] = getelementptr inbounds [[STRUCT_ARM_MATRIX_INSTANCE_Q15]], ptr [[PDST:%.*]], i32 0, i32 2
21 ; CHECK-NEXT: [[I2:%.*]] = load ptr, ptr [[PDATA2]], align 4
22 ; CHECK-NEXT: [[PDATA1:%.*]] = getelementptr inbounds [[STRUCT_ARM_MATRIX_INSTANCE_Q15]], ptr [[PSRCB:%.*]], i32 0, i32 2
23 ; CHECK-NEXT: [[I3:%.*]] = load ptr, ptr [[PDATA1]], align 4
24 ; CHECK-NEXT: [[PDATA:%.*]] = getelementptr inbounds [[STRUCT_ARM_MATRIX_INSTANCE_Q15]], ptr [[PSRCA]], i32 0, i32 2
25 ; CHECK-NEXT: [[I4:%.*]] = load ptr, ptr [[PDATA]], align 4
26 ; CHECK-NEXT: br label [[WHILE_BODY:%.*]]
28 ; CHECK-NEXT: [[PINA_026:%.*]] = phi ptr [ [[INCDEC_PTR:%.*]], [[WHILE_BODY]] ], [ [[I4]], [[WHILE_BODY_PREHEADER]] ]
29 ; CHECK-NEXT: [[BLKCNT_025:%.*]] = phi i32 [ [[DEC:%.*]], [[WHILE_BODY]] ], [ [[CONV5]], [[WHILE_BODY_PREHEADER]] ]
30 ; CHECK-NEXT: [[PINB_024:%.*]] = phi ptr [ [[INCDEC_PTR8:%.*]], [[WHILE_BODY]] ], [ [[I3]], [[WHILE_BODY_PREHEADER]] ]
31 ; CHECK-NEXT: [[POUT_023:%.*]] = phi ptr [ [[INCDEC_PTR11:%.*]], [[WHILE_BODY]] ], [ [[I2]], [[WHILE_BODY_PREHEADER]] ]
32 ; CHECK-NEXT: [[INCDEC_PTR]] = getelementptr inbounds i16, ptr [[PINA_026]], i32 1
33 ; CHECK-NEXT: [[I5:%.*]] = load i16, ptr [[PINA_026]], align 2
34 ; CHECK-NEXT: [[CONV7:%.*]] = sext i16 [[I5]] to i32
35 ; CHECK-NEXT: [[INCDEC_PTR8]] = getelementptr inbounds i16, ptr [[PINB_024]], i32 1
36 ; CHECK-NEXT: [[I6:%.*]] = load i16, ptr [[PINB_024]], align 2
37 ; CHECK-NEXT: [[CONV9:%.*]] = sext i16 [[I6]] to i32
38 ; CHECK-NEXT: [[ADD:%.*]] = add nsw i32 [[CONV9]], [[CONV7]]
39 ; CHECK-NEXT: [[I7:%.*]] = icmp sgt i32 [[ADD]], -32768
40 ; CHECK-NEXT: [[SPEC_SELECT_I:%.*]] = select i1 [[I7]], i32 [[ADD]], i32 -32768
41 ; CHECK-NEXT: [[I8:%.*]] = icmp slt i32 [[SPEC_SELECT_I]], 32767
42 ; CHECK-NEXT: [[CALL21:%.*]] = select i1 [[I8]], i32 [[SPEC_SELECT_I]], i32 32767
43 ; CHECK-NEXT: [[CONV10:%.*]] = trunc i32 [[CALL21]] to i16
44 ; CHECK-NEXT: [[INCDEC_PTR11]] = getelementptr inbounds i16, ptr [[POUT_023]], i32 1
45 ; CHECK-NEXT: store i16 [[CONV10]], ptr [[POUT_023]], align 2
46 ; CHECK-NEXT: [[DEC]] = add nsw i32 [[BLKCNT_025]], -1
47 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[DEC]], 0
48 ; CHECK-NEXT: br i1 [[CMP]], label [[WHILE_END_LOOPEXIT:%.*]], label [[WHILE_BODY]]
49 ; CHECK: while.end.loopexit:
50 ; CHECK-NEXT: br label [[WHILE_END]]
52 ; CHECK-NEXT: ret i32 0
55 %numRows = getelementptr inbounds %struct.arm_matrix_instance_q15, ptr %pSrcA, i32 0, i32 0
56 %i0 = load i16, ptr %numRows, align 4
57 %numCols = getelementptr inbounds %struct.arm_matrix_instance_q15, ptr %pSrcA, i32 0, i32 1
58 %i1 = load i16, ptr %numCols, align 2
59 %mul = mul i16 %i1, %i0
60 %cmp22 = icmp eq i16 %mul, 0
61 br i1 %cmp22, label %while.end, label %while.body.preheader
63 while.body.preheader: ; preds = %entry
64 %conv5 = zext i16 %mul to i32
65 %pData2 = getelementptr inbounds %struct.arm_matrix_instance_q15, ptr %pDst, i32 0, i32 2
66 %i2 = load ptr, ptr %pData2, align 4
67 %pData1 = getelementptr inbounds %struct.arm_matrix_instance_q15, ptr %pSrcB, i32 0, i32 2
68 %i3 = load ptr, ptr %pData1, align 4
69 %pData = getelementptr inbounds %struct.arm_matrix_instance_q15, ptr %pSrcA, i32 0, i32 2
70 %i4 = load ptr, ptr %pData, align 4
73 while.body: ; preds = %while.body.preheader, %while.body
74 %pInA.026 = phi ptr [ %incdec.ptr, %while.body ], [ %i4, %while.body.preheader ]
75 %blkCnt.025 = phi i32 [ %dec, %while.body ], [ %conv5, %while.body.preheader ]
76 %pInB.024 = phi ptr [ %incdec.ptr8, %while.body ], [ %i3, %while.body.preheader ]
77 %pOut.023 = phi ptr [ %incdec.ptr11, %while.body ], [ %i2, %while.body.preheader ]
78 %incdec.ptr = getelementptr inbounds i16, ptr %pInA.026, i32 1
79 %i5 = load i16, ptr %pInA.026, align 2
80 %conv7 = sext i16 %i5 to i32
81 %incdec.ptr8 = getelementptr inbounds i16, ptr %pInB.024, i32 1
82 %i6 = load i16, ptr %pInB.024, align 2
83 %conv9 = sext i16 %i6 to i32
84 %add = add nsw i32 %conv9, %conv7
85 %i7 = icmp sgt i32 %add, -32768
86 %spec.select.i = select i1 %i7, i32 %add, i32 -32768
87 %i8 = icmp slt i32 %spec.select.i, 32767
88 %call21 = select i1 %i8, i32 %spec.select.i, i32 32767
89 %conv10 = trunc i32 %call21 to i16
90 %incdec.ptr11 = getelementptr inbounds i16, ptr %pOut.023, i32 1
91 store i16 %conv10, ptr %pOut.023, align 2
92 %dec = add nsw i32 %blkCnt.025, -1
93 %cmp = icmp eq i32 %dec, 0
94 br i1 %cmp, label %while.end, label %while.body
96 while.end: ; preds = %while.body, %entry