1 /**
2 * Copyright (c) 2021-2022 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include "canonicalization.h"
17 #include "common.h"
18
19 namespace panda::bytecodeopt::test {
20
TEST_F(CommonTest,CanonicalizationSwapCompareInputs)21 TEST_F(CommonTest, CanonicalizationSwapCompareInputs)
22 {
23 auto graph = CreateEmptyGraph();
24 GRAPH(graph)
25 {
26 CONSTANT(0, 0).s32();
27 CONSTANT(1, 0).s32();
28
29 BASIC_BLOCK(2, -1)
30 {
31 INST(2, Opcode::Add).s32().Inputs(0, 1);
32 INST(3, Opcode::Compare).b().Inputs(0, 2);
33 INST(4, Opcode::Return).b().Inputs(3);
34 }
35 }
36
37 graph->RunPass<Canonicalization>();
38
39 auto expected = CreateEmptyGraph();
40 GRAPH(expected)
41 {
42 CONSTANT(0, 0).s32();
43 CONSTANT(1, 0).s32();
44
45 BASIC_BLOCK(2, -1)
46 {
47 INST(2, Opcode::Add).s32().Inputs(0, 1);
48 INST(3, Opcode::Compare).b().Inputs(2, 0);
49 INST(4, Opcode::Return).b().Inputs(3);
50 }
51 }
52
53 EXPECT_TRUE(GraphComparator().Compare(graph, expected));
54 }
55
56 } // namespace panda::bytecodeopt::test
57