• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright (c) 2023-2024 Huawei Device Co., Ltd.
2# Licensed under the Apache License, Version 2.0 (the "License");
3# you may not use this file except in compliance with the License.
4# You may obtain a copy of the License at
5#
6# http://www.apache.org/licenses/LICENSE-2.0
7#
8# Unless required by applicable law or agreed to in writing, software
9# distributed under the License is distributed on an "AS IS" BASIS,
10# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11# See the License for the specific language governing permissions and
12# limitations under the License.
13
14# Checks that the loop with the constant trip
15# count gets unrolled without side exits
16
17#! CHECKER      Loop unrolled w/o side exits
18#! RUN          force_jit: true, options: "--compiler-enable-events=true --compiler-events-path=./events.csv", entry: "_GLOBAL::main"
19#! METHOD       "_GLOBAL::main"
20#! PASS_BEFORE  "LoopUnroll"
21#! INST_COUNT   "IfImm", 2
22#! INST_COUNT   "Shl", 1
23#! PASS_AFTER   "LoopUnroll"
24#! EVENT        /_GLOBAL::main,loop-unroll,.*without side exits/
25#! INST_COUNT   "IfImm", 2
26#! # trip count=99, unroll_factor=6 and 99%6=3 iterations left
27#! INST_COUNT   "Shl", 9
28
29#! CHECKER      Loop unrolled w/o side exits (AOT)
30#! RUN_PAOC     options: "--compiler-enable-events=true --compiler-events-path=./events.csv --compiler-regex=_GLOBAL::main"
31#! METHOD       "_GLOBAL::main"
32#! PASS_BEFORE  "LoopUnroll"
33#! INST_COUNT   "IfImm", 2
34#! INST_COUNT   "Shl", 1
35#! PASS_AFTER   "LoopUnroll"
36#! EVENT        /_GLOBAL::main,loop-unroll,.*without side exits/
37#! INST_COUNT   "IfImm", 2
38#! INST_COUNT   "Shl", 9
39#! RUN          options: "", entry: "_GLOBAL::main"
40
41#! CHECKER      Loop unrolled w/o control flow
42#! RUN          force_jit: true, options: "--compiler-enable-events=true --compiler-events-path=./events.csv", entry: "_GLOBAL::main2"
43#! METHOD       "_GLOBAL::main2"
44#! PASS_BEFORE  "LoopUnroll"
45#! INST_COUNT   "IfImm", 2
46#! INST_COUNT   "Mul", 1
47#! PASS_AFTER   "LoopUnroll"
48#! EVENT        /_GLOBAL::main2,loop-unroll,.*without branching/
49#! INST_NOT     "IfImm"
50#! INST_COUNT   "Mul", 5
51#! PASS_AFTER   "Codegen"
52#! # only return 0 should remain after constant folding
53#! TRUE         BLOCK_COUNT() == 3
54#! INST         /ReturnI.*0x0/
55
56#! CHECKER      Loop unrolled w/o control flow (AOT)
57#! RUN_PAOC     options: "--compiler-enable-events=true --compiler-events-path=./events.csv --compiler-regex=_GLOBAL::main2"
58#! METHOD       "_GLOBAL::main2"
59#! PASS_BEFORE  "LoopUnroll"
60#! INST_COUNT   "IfImm", 2
61#! INST_COUNT   "Mul", 1
62#! PASS_AFTER   "LoopUnroll"
63#! EVENT        /_GLOBAL::main2,loop-unroll,.*without branching/
64#! INST_NOT     "IfImm"
65#! INST_COUNT   "Mul", 5
66#! PASS_AFTER   "Codegen"
67#! TRUE         BLOCK_COUNT() == 3
68#! INST         /ReturnI.*0x0/
69#! RUN          options: "", entry: "_GLOBAL::main"
70
71.language PandaAssembly
72
73.function u1 main() <static> {
74    movi v0, 0x64
75    movi v1, 0x1
76    movi v2, 0xa
77    mov v3, v1
78
79jump_label_1:
80    lda v3
81    jge v0, jump_label_0
82    lda v3
83    shli 0x1
84    sta v4
85    lda v3
86    addi 0x1
87    sta v3
88    and2 v4
89    add2 v2
90    sta v2
91    jmp jump_label_1
92
93jump_label_0:
94    movi v0, 0x0
95    ldai 0x640
96    jeq v2, jump_label_2
97    movi v0, 0x1
98
99jump_label_2:
100    lda v0
101    return
102}
103
104.function u1 main2() <static> {
105    movi v0, 0x6
106    movi v1, 0x1
107    movi v2, 0x0
108    mov v3, v1
109
110jump_label_1:
111    lda v3
112    jge v0, jump_label_0
113    lda v3
114    mul2 v3
115    add2 v2
116    sta v2
117    lda v3
118    addi 0x1
119    sta v3
120    jmp jump_label_1
121
122jump_label_0:
123    movi v0, 0x0
124    ldai 0x37
125    jeq v2, jump_label_2
126    movi v0, 0x1
127
128jump_label_2:
129    lda v0
130    return
131}
132