# Copyright (c) 2023-2024 Huawei Device Co., Ltd. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # Checks that the loop with the constant trip # count gets unrolled without side exits #! CHECKER Loop unrolled w/o side exits #! RUN force_jit: true, options: "--compiler-enable-events=true --compiler-events-path=./events.csv", entry: "_GLOBAL::main" #! METHOD "_GLOBAL::main" #! PASS_BEFORE "LoopUnroll" #! INST_COUNT "IfImm", 2 #! INST_COUNT "Shl", 1 #! PASS_AFTER "LoopUnroll" #! EVENT /_GLOBAL::main,loop-unroll,.*without side exits/ #! INST_COUNT "IfImm", 2 #! # trip count=99, unroll_factor=6 and 99%6=3 iterations left #! INST_COUNT "Shl", 9 #! CHECKER Loop unrolled w/o side exits (AOT) #! RUN_PAOC options: "--compiler-enable-events=true --compiler-events-path=./events.csv --compiler-regex=_GLOBAL::main" #! METHOD "_GLOBAL::main" #! PASS_BEFORE "LoopUnroll" #! INST_COUNT "IfImm", 2 #! INST_COUNT "Shl", 1 #! PASS_AFTER "LoopUnroll" #! EVENT /_GLOBAL::main,loop-unroll,.*without side exits/ #! INST_COUNT "IfImm", 2 #! INST_COUNT "Shl", 9 #! RUN options: "", entry: "_GLOBAL::main" #! CHECKER Loop unrolled w/o control flow #! RUN force_jit: true, options: "--compiler-enable-events=true --compiler-events-path=./events.csv", entry: "_GLOBAL::main2" #! METHOD "_GLOBAL::main2" #! PASS_BEFORE "LoopUnroll" #! INST_COUNT "IfImm", 2 #! INST_COUNT "Mul", 1 #! PASS_AFTER "LoopUnroll" #! EVENT /_GLOBAL::main2,loop-unroll,.*without branching/ #! INST_NOT "IfImm" #! INST_COUNT "Mul", 5 #! PASS_AFTER "Codegen" #! # only return 0 should remain after constant folding #! TRUE BLOCK_COUNT() == 3 #! INST /ReturnI.*0x0/ #! CHECKER Loop unrolled w/o control flow (AOT) #! RUN_PAOC options: "--compiler-enable-events=true --compiler-events-path=./events.csv --compiler-regex=_GLOBAL::main2" #! METHOD "_GLOBAL::main2" #! PASS_BEFORE "LoopUnroll" #! INST_COUNT "IfImm", 2 #! INST_COUNT "Mul", 1 #! PASS_AFTER "LoopUnroll" #! EVENT /_GLOBAL::main2,loop-unroll,.*without branching/ #! INST_NOT "IfImm" #! INST_COUNT "Mul", 5 #! PASS_AFTER "Codegen" #! TRUE BLOCK_COUNT() == 3 #! INST /ReturnI.*0x0/ #! RUN options: "", entry: "_GLOBAL::main" .language PandaAssembly .function u1 main() { movi v0, 0x64 movi v1, 0x1 movi v2, 0xa mov v3, v1 jump_label_1: lda v3 jge v0, jump_label_0 lda v3 shli 0x1 sta v4 lda v3 addi 0x1 sta v3 and2 v4 add2 v2 sta v2 jmp jump_label_1 jump_label_0: movi v0, 0x0 ldai 0x640 jeq v2, jump_label_2 movi v0, 0x1 jump_label_2: lda v0 return } .function u1 main2() { movi v0, 0x6 movi v1, 0x1 movi v2, 0x0 mov v3, v1 jump_label_1: lda v3 jge v0, jump_label_0 lda v3 mul2 v3 add2 v2 sta v2 lda v3 addi 0x1 sta v3 jmp jump_label_1 jump_label_0: movi v0, 0x0 ldai 0x37 jeq v2, jump_label_2 movi v0, 0x1 jump_label_2: lda v0 return }