Skip to content

Commit c12ef07

Browse files
Abnikant Singhabnikant
authored andcommitted
[AIE] Add loopsize + ZOLSetupSize checks for NumOfLoopBundles < 7
1 parent 1f60c54 commit c12ef07

File tree

5 files changed

+774
-5
lines changed

5 files changed

+774
-5
lines changed

llvm/lib/Target/AIE/AIEBaseInstrInfo.cpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1175,14 +1175,19 @@ AIEBaseInstrInfo::getAlignmentBoundaries(MachineBasicBlock &MBB) const {
11751175
// must be a 112-byte gap (in PM address space) between writing to the ls,
11761176
// le, and lc registers and the LoopEnd instruction.
11771177
ZOLBundlesCount = getZOLBundlesCount(MBB) - 1;
1178-
if (ZOLBundlesCount < ZOLSetupToLoopEndDist)
1179-
LoopSetupDistance = ZOLBundlesCount;
1180-
else {
1178+
const unsigned LoopSetupSizeInBytes = 16 * ZOLSetupToLoopEndDist;
1179+
const unsigned LoopSize = LoopSizeExcludingLastBundle(MBB);
1180+
if (ZOLBundlesCount < ZOLSetupToLoopEndDist) {
1181+
// We have already elongated the bundles in the preheader.
1182+
// getPostZOLSetupRegionSize should return the elongated size in bytes.
1183+
const unsigned PostZOLRegionSize = getPostZOLSetupRegionSize(MBB);
1184+
const bool DistanceConstraintMet =
1185+
(LoopSize + PostZOLRegionSize) >= LoopSetupSizeInBytes;
1186+
LoopSetupDistance = DistanceConstraintMet ? 0 : ZOLBundlesCount;
1187+
} else {
11811188
// Elongate the ZOL loop body only if the distance from the end of the
11821189
// ZOL setup instruction to the last bundle in the loop (excluding the
11831190
// final bundle) is less than 112 bytes.
1184-
const unsigned LoopSetupSizeInBytes = 16 * ZOLSetupToLoopEndDist;
1185-
const unsigned LoopSize = LoopSizeExcludingLastBundle(MBB);
11861191
if (LoopSize >= LoopSetupSizeInBytes)
11871192
LoopSetupDistance = 0;
11881193
else {
Lines changed: 202 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,202 @@
1+
# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py
2+
#
3+
# This file is licensed under the Apache License v2.0 with LLVM Exceptions.
4+
# See https://llvm.org/LICENSE.txt for license information.
5+
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
#
7+
# (c) Copyright 2025 Advanced Micro Devices, Inc. or its affiliates
8+
9+
# RUN: llc -mtriple aie2p -run-pass=aie-machine-alignment %s -verify-machineinstrs -o - | FileCheck %s
10+
11+
---
12+
name: zol_elongated_preheader_plus_1_LoopBundles_ge112bytes
13+
alignment: 16
14+
body: |
15+
; CHECK-LABEL: name: zol_elongated_preheader_plus_1_LoopBundles_ge112bytes
16+
; CHECK: bb.0.entry (align 16):
17+
; CHECK-NEXT: successors: %bb.1(0x80000000)
18+
; CHECK-NEXT: liveins: $p0, $r0
19+
; CHECK-NEXT: {{ $}}
20+
; CHECK-NEXT: BUNDLE implicit-def $x6, implicit-def $wl6, implicit-def $wh6, implicit-def $p0, implicit killed $p0 {
21+
; CHECK-NEXT: NOPA
22+
; CHECK-NEXT: renamable $x6, renamable $p0 = VLDB_dmx_ldb_x_pstm_nrm_imm killed renamable $p0, 0 :: (load (<32 x s16>))
23+
; CHECK-NEXT: NOPXM
24+
; CHECK-NEXT: }
25+
; CHECK-NEXT: BUNDLE implicit-def $r0, implicit-def dead $srcarry, implicit killed $r0 {
26+
; CHECK-NEXT: renamable $r0 = ADD_add_r_ri killed renamable $r0, -1, implicit-def dead $srcarry
27+
; CHECK-NEXT: }
28+
; CHECK-NEXT: BUNDLE implicit-def $lc, implicit $r0 {
29+
; CHECK-NEXT: NOPB
30+
; CHECK-NEXT: $lc = ADD_NC_mv_add_ri $r0, -3
31+
; CHECK-NEXT: }
32+
; CHECK-NEXT: BUNDLE implicit-def $x0, implicit-def $wl0, implicit-def $wh0, implicit-def $p0, implicit-def $r0, implicit-def dead $srcarry, implicit killed $p0, implicit killed $r0 {
33+
; CHECK-NEXT: renamable $x0, renamable $p0 = VLDB_dmx_ldb_x_pstm_nrm_imm killed renamable $p0, 64 :: (load (<32 x s16>))
34+
; CHECK-NEXT: renamable $r0 = ADD_add_r_ri killed renamable $r0, -1, implicit-def dead $srcarry
35+
; CHECK-NEXT: }
36+
; CHECK-NEXT: BUNDLE implicit-def $x2, implicit-def $wl2, implicit-def $wh2, implicit-def $p0, implicit-def $ls, implicit killed $p0 {
37+
; CHECK-NEXT: renamable $x2, renamable $p0 = VLDB_dmx_ldb_x_pstm_nrm_imm killed renamable $p0, 64 :: (load (<32 x s16>))
38+
; CHECK-NEXT: $ls = MOVXM %bb.1
39+
; CHECK-NEXT: }
40+
; CHECK-NEXT: BUNDLE implicit-def $x1, implicit-def $wl1, implicit-def $wh1, implicit-def $p0, implicit-def $le, implicit killed $p0 {
41+
; CHECK-NEXT: renamable $x1, renamable $p0 = VLDB_dmx_ldb_x_pstm_nrm_imm killed renamable $p0, 128 :: (load (<32 x s16>))
42+
; CHECK-NEXT: $le = MOVXM <mcsymbol .L_LEnd0>
43+
; CHECK-NEXT: }
44+
; CHECK-NEXT: BUNDLE implicit-def $x0, implicit-def $wl0, implicit-def $wh0, implicit-def $p0, implicit-def $r0, implicit-def dead $srcarry, implicit killed $p0, implicit killed $r0 {
45+
; CHECK-NEXT: NOPA
46+
; CHECK-NEXT: renamable $x0, renamable $p0 = VLDB_dmx_ldb_x_pstm_nrm_imm killed renamable $p0, 64 :: (load (<32 x s16>))
47+
; CHECK-NEXT: NOPS
48+
; CHECK-NEXT: renamable $r0 = ADD_add_r_ri killed renamable $r0, -1, implicit-def dead $srcarry
49+
; CHECK-NEXT: NOPM
50+
; CHECK-NEXT: NOPV
51+
; CHECK-NEXT: }
52+
; CHECK-NEXT: BUNDLE implicit-def $x2, implicit-def $wl2, implicit-def $wh2, implicit-def $p0, implicit killed $p0 {
53+
; CHECK-NEXT: NOPA
54+
; CHECK-NEXT: renamable $x2, renamable $p0 = VLDB_dmx_ldb_x_pstm_nrm_imm killed renamable $p0, 64 :: (load (<32 x s16>))
55+
; CHECK-NEXT: NOPS
56+
; CHECK-NEXT: NOPXM
57+
; CHECK-NEXT: NOPV
58+
; CHECK-NEXT: }
59+
; CHECK-NEXT: BUNDLE implicit-def $x1, implicit-def $wl1, implicit-def $wh1, implicit-def $p0, implicit killed $p0 {
60+
; CHECK-NEXT: NOPA
61+
; CHECK-NEXT: renamable $x1, renamable $p0 = VLDB_dmx_ldb_x_pstm_nrm_imm killed renamable $p0, 128 :: (load (<32 x s16>))
62+
; CHECK-NEXT: NOPS
63+
; CHECK-NEXT: NOPXM
64+
; CHECK-NEXT: NOPV
65+
; CHECK-NEXT: }
66+
; CHECK-NEXT: BUNDLE implicit-def $x0, implicit-def $wl0, implicit-def $wh0, implicit-def $p0, implicit-def $r0, implicit-def dead $srcarry, implicit killed $p0, implicit killed $r0 {
67+
; CHECK-NEXT: NOPA
68+
; CHECK-NEXT: renamable $x0, renamable $p0 = VLDB_dmx_ldb_x_pstm_nrm_imm killed renamable $p0, 64 :: (load (<32 x s16>))
69+
; CHECK-NEXT: NOPS
70+
; CHECK-NEXT: renamable $r0 = ADD_add_r_ri killed renamable $r0, -1, implicit-def dead $srcarry
71+
; CHECK-NEXT: NOPM
72+
; CHECK-NEXT: NOPV
73+
; CHECK-NEXT: }
74+
; CHECK-NEXT: BUNDLE implicit-def $x2, implicit-def $wl2, implicit-def $wh2, implicit-def $p0, implicit-def $x4, implicit-def $wl4, implicit-def $wh4, implicit killed $p0, implicit $x6, implicit killed $x0 {
75+
; CHECK-NEXT: NOPA
76+
; CHECK-NEXT: renamable $x2, renamable $p0 = VLDB_dmx_ldb_x_pstm_nrm_imm killed renamable $p0, 64 :: (load (<32 x s16>))
77+
; CHECK-NEXT: NOPS
78+
; CHECK-NEXT: NOPX
79+
; CHECK-NEXT: renamable $x4 = VADD_16 renamable $x6, killed renamable $x0
80+
; CHECK-NEXT: NOPV
81+
; CHECK-NEXT: }
82+
; CHECK-NEXT: BUNDLE implicit-def $x1, implicit-def $wl1, implicit-def $wh1, implicit-def $p0, implicit killed $p0 {
83+
; CHECK-NEXT: renamable $x1, renamable $p0 = VLDB_dmx_ldb_x_pstm_nrm_imm killed renamable $p0, 128 :: (load (<32 x s16>))
84+
; CHECK-NEXT: }
85+
; CHECK-NEXT: BUNDLE implicit-def $r23, implicit-def $p0, implicit-def $r24, implicit-def $s0, implicit $p1 {
86+
; CHECK-NEXT: renamable $r23 = MOVA 0
87+
; CHECK-NEXT: $p1 = MOVS $p0
88+
; CHECK-NEXT: renamable $r0 = MOVX_alu_cg 64
89+
; CHECK-NEXT: $s0 = MOV_alu_mv_mv_mv_scl internal $r0
90+
; CHECK-NEXT: }
91+
; CHECK-NEXT: {{ $}}
92+
; CHECK-NEXT: bb.1 (align 16):
93+
; CHECK-NEXT: successors: %bb.1(0x7c000000), %bb.2(0x04000000)
94+
; CHECK-NEXT: liveins: $p1, $r0, $s0, $r5, $x6
95+
; CHECK-NEXT: {{ $}}
96+
; CHECK-NEXT: BUNDLE implicit-def $x0, implicit-def $wl0, implicit-def $wh0, implicit-def $p1, implicit-def $r0, implicit-def dead $srcarry, implicit-def $x6, implicit-def $wl6, implicit-def $wh6, implicit killed $p1, implicit killed $r0, implicit killed $x4, implicit killed $x1 {
97+
; CHECK-NEXT: renamable $x0, renamable $p1 = VLDB_dmx_ldb_x_pstm_nrm_imm killed renamable $p1, 64 :: (load (<32 x s16>))
98+
; CHECK-NEXT: renamable $r0 = ADD_add_r_ri killed renamable $r0, -1, implicit-def dead $srcarry
99+
; CHECK-NEXT: renamable $x6 = VADD_16 killed renamable $x4, killed renamable $x1
100+
; CHECK-NEXT: }
101+
; CHECK-NEXT: BUNDLE implicit-def $x2, implicit-def $wl2, implicit-def $wh2, implicit-def $p1, implicit-def $x4, implicit-def $wl4, implicit-def $wh4, implicit killed $p1, implicit $x6, implicit killed $x0 {
102+
; CHECK-NEXT: renamable $x2, renamable $p1 = VLDB_dmx_ldb_x_pstm_nrm_imm killed renamable $p1, 64 :: (load (<32 x s16>))
103+
; CHECK-NEXT: renamable $x4 = VADD_16 renamable $x6, killed renamable $x0
104+
; CHECK-NEXT: }
105+
; CHECK-NEXT: BUNDLE implicit-def $x1, implicit-def $wl1, implicit-def $wh1, implicit-def $p1, implicit killed $p1 {
106+
; CHECK-NEXT: NOPA
107+
; CHECK-NEXT: renamable $x1, renamable $p1 = VLDB_dmx_ldb_x_pstm_nrm_imm killed renamable $p1, 128 :: (load (<32 x s16>))
108+
; CHECK-NEXT: NOPS
109+
; CHECK-NEXT: NOPXM
110+
; CHECK-NEXT: NOPV
111+
; CHECK-NEXT: }
112+
; CHECK-NEXT: PseudoLoopEnd <mcsymbol .L_LEnd0>, %bb.1
113+
; CHECK-NEXT: {{ $}}
114+
; CHECK-NEXT: bb.2:
115+
; CHECK-NEXT: BUNDLE implicit $lr {
116+
; CHECK-NEXT: NOPA
117+
; CHECK-NEXT: NOPB
118+
; CHECK-NEXT: NOPS
119+
; CHECK-NEXT: RET implicit $lr
120+
; CHECK-NEXT: NOPM
121+
; CHECK-NEXT: NOPV
122+
; CHECK-NEXT: }
123+
; CHECK-NEXT: DelayedSchedBarrier implicit killed $x0
124+
bb.0.entry (align 16):
125+
successors: %bb.1(0x80000000)
126+
liveins: $p0, $r0
127+
128+
BUNDLE implicit-def $x6, implicit-def $wl6, implicit-def $wh6, implicit-def $p0, implicit killed $p0 {
129+
renamable $x6, renamable $p0 = VLDB_dmx_ldb_x_pstm_nrm_imm killed renamable $p0, 0 :: (load (<32 x s16>))
130+
}
131+
BUNDLE implicit-def $r0, implicit-def dead $srcarry, implicit killed $r0 {
132+
renamable $r0 = ADD_add_r_ri killed renamable $r0, -1, implicit-def dead $srcarry
133+
}
134+
BUNDLE implicit-def $lc, implicit $r0 {
135+
NOPB
136+
$lc = ADD_NC_mv_add_ri $r0, -3
137+
}
138+
BUNDLE implicit-def $x0, implicit-def $wl0, implicit-def $wh0, implicit-def $p0, implicit-def $r0, implicit-def dead $srcarry, implicit killed $p0, implicit killed $r0 {
139+
renamable $x0, renamable $p0 = VLDB_dmx_ldb_x_pstm_nrm_imm killed renamable $p0, 64 :: (load (<32 x s16>))
140+
renamable $r0 = ADD_add_r_ri killed renamable $r0, -1, implicit-def dead $srcarry
141+
}
142+
BUNDLE implicit-def $x2, implicit-def $wl2, implicit-def $wh2, implicit-def $p0, implicit-def $ls, implicit killed $p0 {
143+
renamable $x2, renamable $p0 = VLDB_dmx_ldb_x_pstm_nrm_imm killed renamable $p0, 64 :: (load (<32 x s16>))
144+
$ls = MOVXM %bb.1
145+
}
146+
BUNDLE implicit-def $x1, implicit-def $wl1, implicit-def $wh1, implicit-def $p0, implicit-def $le, implicit killed $p0 {
147+
renamable $x1, renamable $p0 = VLDB_dmx_ldb_x_pstm_nrm_imm killed renamable $p0, 128 :: (load (<32 x s16>))
148+
$le = MOVXM <mcsymbol .L_LEnd0>
149+
}
150+
BUNDLE implicit-def $x0, implicit-def $wl0, implicit-def $wh0, implicit-def $p0, implicit-def $r0, implicit-def dead $srcarry, implicit killed $p0, implicit killed $r0 {
151+
renamable $x0, renamable $p0 = VLDB_dmx_ldb_x_pstm_nrm_imm killed renamable $p0, 64 :: (load (<32 x s16>))
152+
renamable $r0 = ADD_add_r_ri killed renamable $r0, -1, implicit-def dead $srcarry
153+
}
154+
BUNDLE implicit-def $x2, implicit-def $wl2, implicit-def $wh2, implicit-def $p0, implicit killed $p0 {
155+
renamable $x2, renamable $p0 = VLDB_dmx_ldb_x_pstm_nrm_imm killed renamable $p0, 64 :: (load (<32 x s16>))
156+
}
157+
BUNDLE implicit-def $x1, implicit-def $wl1, implicit-def $wh1, implicit-def $p0, implicit killed $p0 {
158+
renamable $x1, renamable $p0 = VLDB_dmx_ldb_x_pstm_nrm_imm killed renamable $p0, 128 :: (load (<32 x s16>))
159+
}
160+
BUNDLE implicit-def $x0, implicit-def $wl0, implicit-def $wh0, implicit-def $p0, implicit-def $r0, implicit-def dead $srcarry, implicit killed $p0, implicit killed $r0 {
161+
renamable $x0, renamable $p0 = VLDB_dmx_ldb_x_pstm_nrm_imm killed renamable $p0, 64 :: (load (<32 x s16>))
162+
renamable $r0 = ADD_add_r_ri killed renamable $r0, -1, implicit-def dead $srcarry
163+
}
164+
BUNDLE implicit-def $x2, implicit-def $wl2, implicit-def $wh2, implicit-def $p0, implicit-def $x4, implicit-def $wl4, implicit-def $wh4, implicit killed $p0, implicit $x6, implicit killed $x0 {
165+
renamable $x2, renamable $p0 = VLDB_dmx_ldb_x_pstm_nrm_imm killed renamable $p0, 64 :: (load (<32 x s16>))
166+
renamable $x4 = VADD_16 renamable $x6, killed renamable $x0
167+
}
168+
BUNDLE implicit-def $x1, implicit-def $wl1, implicit-def $wh1, implicit-def $p0, implicit killed $p0 {
169+
renamable $x1, renamable $p0 = VLDB_dmx_ldb_x_pstm_nrm_imm killed renamable $p0, 128 :: (load (<32 x s16>))
170+
}
171+
BUNDLE implicit-def $r23, implicit-def $p0, implicit-def $r24, implicit-def $s0, implicit $p1 {
172+
renamable $r23 = MOVA 0
173+
$p1 = MOVS $p0
174+
renamable $r0 = MOVX_alu_cg 64
175+
$s0 = MOV_alu_mv_mv_mv_scl internal $r0
176+
}
177+
178+
bb.1 (align 16):
179+
successors: %bb.1(0x7c000000), %bb.2(0x04000000)
180+
liveins: $p1, $r0, $s0, $r5, $x6
181+
182+
BUNDLE implicit-def $x0, implicit-def $wl0, implicit-def $wh0, implicit-def $p1, implicit-def $r0, implicit-def dead $srcarry, implicit-def $x6, implicit-def $wl6, implicit-def $wh6, implicit killed $p1, implicit killed $r0, implicit killed $x4, implicit killed $x1 {
183+
renamable $x0, renamable $p1 = VLDB_dmx_ldb_x_pstm_nrm_imm killed renamable $p1, 64 :: (load (<32 x s16>))
184+
renamable $r0 = ADD_add_r_ri killed renamable $r0, -1, implicit-def dead $srcarry
185+
renamable $x6 = VADD_16 killed renamable $x4, killed renamable $x1
186+
}
187+
BUNDLE implicit-def $x2, implicit-def $wl2, implicit-def $wh2, implicit-def $p1, implicit-def $x4, implicit-def $wl4, implicit-def $wh4, implicit killed $p1, implicit $x6, implicit killed $x0 {
188+
renamable $x2, renamable $p1 = VLDB_dmx_ldb_x_pstm_nrm_imm killed renamable $p1, 64 :: (load (<32 x s16>))
189+
renamable $x4 = VADD_16 renamable $x6, killed renamable $x0
190+
}
191+
BUNDLE implicit-def $x1, implicit-def $wl1, implicit-def $wh1, implicit-def $p1, implicit killed $p1 {
192+
renamable $x1, renamable $p1 = VLDB_dmx_ldb_x_pstm_nrm_imm killed renamable $p1, 128 :: (load (<32 x s16>))
193+
}
194+
PseudoLoopEnd <mcsymbol .L_LEnd0>, %bb.1
195+
196+
bb.2:
197+
BUNDLE implicit $lr {
198+
RET implicit $lr
199+
}
200+
DelayedSchedBarrier implicit killed $x0
201+
202+
...

0 commit comments

Comments
 (0)