1c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray/* 2c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray * Copyright (C) 2014 The Android Open Source Project 3c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray * 4c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray * Licensed under the Apache License, Version 2.0 (the "License"); 5c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray * you may not use this file except in compliance with the License. 6c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray * You may obtain a copy of the License at 7c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray * 8c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray * http://www.apache.org/licenses/LICENSE-2.0 9c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray * 10c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray * Unless required by applicable law or agreed to in writing, software 11c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray * distributed under the License is distributed on an "AS IS" BASIS, 12c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray * See the License for the specific language governing permissions and 14c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray * limitations under the License. 15c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray */ 16c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray 17b666f4805c8ae707ea6fd7f6c7f375e0b000dba8Mathieu Chartier#include "base/arena_allocator.h" 18c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray#include "base/stringprintf.h" 19c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray#include "builder.h" 20c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray#include "dex_file.h" 21c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray#include "dex_instruction.h" 22c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray#include "nodes.h" 23c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray#include "optimizing_unit_test.h" 24c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray#include "pretty_printer.h" 25c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray#include "ssa_builder.h" 26c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray 27c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray#include "gtest/gtest.h" 28c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray 29c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffraynamespace art { 30c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray 314833f5a1990c76bc2be89504225fb13cca22bedfDavid Brazdilclass SsaTest : public CommonCompilerTest {}; 324833f5a1990c76bc2be89504225fb13cca22bedfDavid Brazdil 330d3f578909d0d1ea072ca68d78301b6fb7a44451Nicolas Geoffrayclass SsaPrettyPrinter : public HPrettyPrinter { 34c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray public: 350d3f578909d0d1ea072ca68d78301b6fb7a44451Nicolas Geoffray explicit SsaPrettyPrinter(HGraph* graph) : HPrettyPrinter(graph), str_("") {} 36c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray 372ed20afc6a1032e9e0cf919cb8d1b2b41e147182Alexandre Rames void PrintInt(int value) OVERRIDE { 38c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray str_ += StringPrintf("%d", value); 39c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray } 40c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray 412ed20afc6a1032e9e0cf919cb8d1b2b41e147182Alexandre Rames void PrintString(const char* value) OVERRIDE { 42c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray str_ += value; 43c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray } 44c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray 452ed20afc6a1032e9e0cf919cb8d1b2b41e147182Alexandre Rames void PrintNewLine() OVERRIDE { 46c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray str_ += '\n'; 47c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray } 48c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray 49c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray void Clear() { str_.clear(); } 50c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray 51c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray std::string str() const { return str_; } 52c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray 532ed20afc6a1032e9e0cf919cb8d1b2b41e147182Alexandre Rames void VisitIntConstant(HIntConstant* constant) OVERRIDE { 54c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray PrintPreInstruction(constant); 55c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray str_ += constant->DebugName(); 56c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray str_ += " "; 57c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray PrintInt(constant->GetValue()); 58c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray PrintPostInstruction(constant); 59c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray } 60c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray 61c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray private: 62c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray std::string str_; 63c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray 640d3f578909d0d1ea072ca68d78301b6fb7a44451Nicolas Geoffray DISALLOW_COPY_AND_ASSIGN(SsaPrettyPrinter); 65c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray}; 66c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray 67c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffraystatic void ReNumberInstructions(HGraph* graph) { 68c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray int id = 0; 69fa6b93c4b69e6d7ddfa2a4ed0aff01b0608c5a3aVladimir Marko for (HBasicBlock* block : graph->GetBlocks()) { 70f635e63318447ca04731b265a86a573c9ed1737cNicolas Geoffray for (HInstructionIterator it(block->GetPhis()); !it.Done(); it.Advance()) { 71c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray it.Current()->SetId(id++); 72c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray } 73f635e63318447ca04731b265a86a573c9ed1737cNicolas Geoffray for (HInstructionIterator it(block->GetInstructions()); !it.Done(); it.Advance()) { 74c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray it.Current()->SetId(id++); 75c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray } 76c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray } 77c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray} 78c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray 79c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffraystatic void TestCode(const uint16_t* data, const char* expected) { 80c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray ArenaPool pool; 81c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray ArenaAllocator allocator(&pool); 82badd826664896d4a9628a5a89b78016894aa414bDavid Brazdil HGraph* graph = CreateCFG(&allocator, data); 83fbc695f9b8e2084697e19c1355ab925f99f0d235Nicolas Geoffray // Suspend checks implementation may change in the future, and this test relies 84fbc695f9b8e2084697e19c1355ab925f99f0d235Nicolas Geoffray // on how instructions are ordered. 85fbc695f9b8e2084697e19c1355ab925f99f0d235Nicolas Geoffray RemoveSuspendChecks(graph); 86c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray ReNumberInstructions(graph); 87c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray 88184d640d2a3ac86d871dab58386a50cc9bb973f9Nicolas Geoffray // Test that phis had their type set. 89fa6b93c4b69e6d7ddfa2a4ed0aff01b0608c5a3aVladimir Marko for (HBasicBlock* block : graph->GetBlocks()) { 90fa6b93c4b69e6d7ddfa2a4ed0aff01b0608c5a3aVladimir Marko for (HInstructionIterator it(block->GetPhis()); !it.Done(); it.Advance()) { 91184d640d2a3ac86d871dab58386a50cc9bb973f9Nicolas Geoffray ASSERT_NE(it.Current()->GetType(), Primitive::kPrimVoid); 92184d640d2a3ac86d871dab58386a50cc9bb973f9Nicolas Geoffray } 93184d640d2a3ac86d871dab58386a50cc9bb973f9Nicolas Geoffray } 94184d640d2a3ac86d871dab58386a50cc9bb973f9Nicolas Geoffray 950d3f578909d0d1ea072ca68d78301b6fb7a44451Nicolas Geoffray SsaPrettyPrinter printer(graph); 96c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray printer.VisitInsertionOrder(); 97c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray 98c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray ASSERT_STREQ(expected, printer.str().c_str()); 99c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray} 100c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray 1014833f5a1990c76bc2be89504225fb13cca22bedfDavid BrazdilTEST_F(SsaTest, CFG1) { 102c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray // Test that we get rid of loads and stores. 103c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray const char* expected = 104c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray "BasicBlock 0, succ: 1\n" 105c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray " 0: IntConstant 0 [2, 2]\n" 106c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray " 1: Goto\n" 107ec7e4727e99aa1416398ac5a684f5024817a25c7Nicolas Geoffray "BasicBlock 1, pred: 0, succ: 5, 2\n" 108c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray " 2: Equal(0, 0) [3]\n" 109c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray " 3: If(2)\n" 110c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray "BasicBlock 2, pred: 1, succ: 3\n" 111c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray " 4: Goto\n" 1128b20f88b0a8d1b374dd5eaae289d19734c77b8f8Nicolas Geoffray "BasicBlock 3, pred: 5, 2, succ: 4\n" 113c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray " 5: ReturnVoid\n" 114c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray "BasicBlock 4, pred: 3\n" 115622d9c31febd950255b36a48b47e1f630197c5feNicolas Geoffray " 6: Exit\n" 116622d9c31febd950255b36a48b47e1f630197c5feNicolas Geoffray // Synthesized block to avoid critical edge. 117622d9c31febd950255b36a48b47e1f630197c5feNicolas Geoffray "BasicBlock 5, pred: 1, succ: 3\n" 118622d9c31febd950255b36a48b47e1f630197c5feNicolas Geoffray " 7: Goto\n"; 119c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray 120c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray const uint16_t data[] = ONE_REGISTER_CODE_ITEM( 121c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray Instruction::CONST_4 | 0 | 0, 122c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray Instruction::IF_EQ, 3, 123c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray Instruction::GOTO | 0x100, 124c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray Instruction::RETURN_VOID); 125c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray 126c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray TestCode(data, expected); 127c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray} 128c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray 1294833f5a1990c76bc2be89504225fb13cca22bedfDavid BrazdilTEST_F(SsaTest, CFG2) { 130c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray // Test that we create a phi for the join block of an if control flow instruction 131c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray // when there is only code in the else branch. 132c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray const char* expected = 133c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray "BasicBlock 0, succ: 1\n" 134c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray " 0: IntConstant 0 [6, 3, 3]\n" 135c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray " 1: IntConstant 4 [6]\n" 136c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray " 2: Goto\n" 137ec7e4727e99aa1416398ac5a684f5024817a25c7Nicolas Geoffray "BasicBlock 1, pred: 0, succ: 5, 2\n" 138c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray " 3: Equal(0, 0) [4]\n" 139c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray " 4: If(3)\n" 140c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray "BasicBlock 2, pred: 1, succ: 3\n" 141c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray " 5: Goto\n" 1428b20f88b0a8d1b374dd5eaae289d19734c77b8f8Nicolas Geoffray "BasicBlock 3, pred: 5, 2, succ: 4\n" 1438b20f88b0a8d1b374dd5eaae289d19734c77b8f8Nicolas Geoffray " 6: Phi(0, 1) [7]\n" 144c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray " 7: Return(6)\n" 145c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray "BasicBlock 4, pred: 3\n" 146622d9c31febd950255b36a48b47e1f630197c5feNicolas Geoffray " 8: Exit\n" 147622d9c31febd950255b36a48b47e1f630197c5feNicolas Geoffray // Synthesized block to avoid critical edge. 148622d9c31febd950255b36a48b47e1f630197c5feNicolas Geoffray "BasicBlock 5, pred: 1, succ: 3\n" 149622d9c31febd950255b36a48b47e1f630197c5feNicolas Geoffray " 9: Goto\n"; 150c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray 151c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray const uint16_t data[] = ONE_REGISTER_CODE_ITEM( 152c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray Instruction::CONST_4 | 0 | 0, 153c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray Instruction::IF_EQ, 3, 154c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray Instruction::CONST_4 | 4 << 12 | 0, 155c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray Instruction::RETURN | 0 << 8); 156c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray 157c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray TestCode(data, expected); 158c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray} 159c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray 1604833f5a1990c76bc2be89504225fb13cca22bedfDavid BrazdilTEST_F(SsaTest, CFG3) { 161c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray // Test that we create a phi for the join block of an if control flow instruction 162804d09372cc3d80d537da1489da4a45e0e19aa5dNicolas Geoffray // when both branches update a local. 163c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray const char* expected = 164c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray "BasicBlock 0, succ: 1\n" 165c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray " 0: IntConstant 0 [4, 4]\n" 166dee58d6bb6d567fcd0c4f39d8d690c3acaf0e432David Brazdil " 1: IntConstant 5 [8]\n" 167dee58d6bb6d567fcd0c4f39d8d690c3acaf0e432David Brazdil " 2: IntConstant 4 [8]\n" 168c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray " 3: Goto\n" 169c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray "BasicBlock 1, pred: 0, succ: 3, 2\n" 170c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray " 4: Equal(0, 0) [5]\n" 171c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray " 5: If(4)\n" 172c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray "BasicBlock 2, pred: 1, succ: 4\n" 173c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray " 6: Goto\n" 174c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray "BasicBlock 3, pred: 1, succ: 4\n" 175c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray " 7: Goto\n" 176c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray "BasicBlock 4, pred: 2, 3, succ: 5\n" 177dee58d6bb6d567fcd0c4f39d8d690c3acaf0e432David Brazdil " 8: Phi(2, 1) [9]\n" 178c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray " 9: Return(8)\n" 179c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray "BasicBlock 5, pred: 4\n" 180c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray " 10: Exit\n"; 181c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray 182c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray const uint16_t data[] = ONE_REGISTER_CODE_ITEM( 183c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray Instruction::CONST_4 | 0 | 0, 184c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray Instruction::IF_EQ, 4, 185c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray Instruction::CONST_4 | 4 << 12 | 0, 186c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray Instruction::GOTO | 0x200, 187c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray Instruction::CONST_4 | 5 << 12 | 0, 188c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray Instruction::RETURN | 0 << 8); 189c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray 190c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray TestCode(data, expected); 191c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray} 192c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray 1934833f5a1990c76bc2be89504225fb13cca22bedfDavid BrazdilTEST_F(SsaTest, Loop1) { 194c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray // Test that we create a phi for an initialized local at entry of a loop. 195c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray const char* expected = 196c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray "BasicBlock 0, succ: 1\n" 197a3c00e54f9b711bf3fc55ce5e7d4f8765e2ea9faNicolas Geoffray " 0: IntConstant 0 [6, 3, 3]\n" 198a3c00e54f9b711bf3fc55ce5e7d4f8765e2ea9faNicolas Geoffray " 1: IntConstant 4 [6]\n" 199a3c00e54f9b711bf3fc55ce5e7d4f8765e2ea9faNicolas Geoffray " 2: Goto\n" 200a3c00e54f9b711bf3fc55ce5e7d4f8765e2ea9faNicolas Geoffray "BasicBlock 1, pred: 0, succ: 4, 2\n" 201a3c00e54f9b711bf3fc55ce5e7d4f8765e2ea9faNicolas Geoffray " 3: Equal(0, 0) [4]\n" 202a3c00e54f9b711bf3fc55ce5e7d4f8765e2ea9faNicolas Geoffray " 4: If(3)\n" 203a3c00e54f9b711bf3fc55ce5e7d4f8765e2ea9faNicolas Geoffray "BasicBlock 2, pred: 1, succ: 3\n" 204c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray " 5: Goto\n" 205a3c00e54f9b711bf3fc55ce5e7d4f8765e2ea9faNicolas Geoffray "BasicBlock 3, pred: 2, 4, succ: 5\n" 206a3c00e54f9b711bf3fc55ce5e7d4f8765e2ea9faNicolas Geoffray " 6: Phi(1, 0) [9]\n" 207c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray " 7: Goto\n" 208a3c00e54f9b711bf3fc55ce5e7d4f8765e2ea9faNicolas Geoffray "BasicBlock 4, pred: 1, succ: 3\n" 209622d9c31febd950255b36a48b47e1f630197c5feNicolas Geoffray " 8: Goto\n" 210a3c00e54f9b711bf3fc55ce5e7d4f8765e2ea9faNicolas Geoffray "BasicBlock 5, pred: 3, succ: 6\n" 211a3c00e54f9b711bf3fc55ce5e7d4f8765e2ea9faNicolas Geoffray " 9: Return(6)\n" 212a3c00e54f9b711bf3fc55ce5e7d4f8765e2ea9faNicolas Geoffray "BasicBlock 6, pred: 5\n" 213a3c00e54f9b711bf3fc55ce5e7d4f8765e2ea9faNicolas Geoffray " 10: Exit\n"; 214c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray 215c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray const uint16_t data[] = ONE_REGISTER_CODE_ITEM( 216c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray Instruction::CONST_4 | 0 | 0, 217a3c00e54f9b711bf3fc55ce5e7d4f8765e2ea9faNicolas Geoffray Instruction::IF_EQ, 4, 218a3c00e54f9b711bf3fc55ce5e7d4f8765e2ea9faNicolas Geoffray Instruction::CONST_4 | 4 << 12 | 0, 219a3c00e54f9b711bf3fc55ce5e7d4f8765e2ea9faNicolas Geoffray Instruction::GOTO | 0x200, 220a3c00e54f9b711bf3fc55ce5e7d4f8765e2ea9faNicolas Geoffray Instruction::GOTO | 0xFF00, 221a3c00e54f9b711bf3fc55ce5e7d4f8765e2ea9faNicolas Geoffray Instruction::RETURN | 0 << 8); 222c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray 223c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray TestCode(data, expected); 224c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray} 225c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray 2264833f5a1990c76bc2be89504225fb13cca22bedfDavid BrazdilTEST_F(SsaTest, Loop2) { 227c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray // Simple loop with one preheader and one back edge. 228c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray const char* expected = 229c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray "BasicBlock 0, succ: 1\n" 230c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray " 0: IntConstant 0 [4]\n" 231c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray " 1: IntConstant 4 [4]\n" 232c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray " 2: Goto\n" 233c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray "BasicBlock 1, pred: 0, succ: 2\n" 234c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray " 3: Goto\n" 235c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray "BasicBlock 2, pred: 1, 3, succ: 4, 3\n" 236c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray " 4: Phi(0, 1) [5, 5]\n" 237c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray " 5: Equal(4, 4) [6]\n" 238c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray " 6: If(5)\n" 239c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray "BasicBlock 3, pred: 2, succ: 2\n" 240c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray " 7: Goto\n" 241c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray "BasicBlock 4, pred: 2, succ: 5\n" 242c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray " 8: ReturnVoid\n" 243c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray "BasicBlock 5, pred: 4\n" 244c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray " 9: Exit\n"; 245c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray 246c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray const uint16_t data[] = ONE_REGISTER_CODE_ITEM( 247c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray Instruction::CONST_4 | 0 | 0, 248c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray Instruction::IF_EQ, 4, 249c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray Instruction::CONST_4 | 4 << 12 | 0, 250c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray Instruction::GOTO | 0xFD00, 251c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray Instruction::RETURN_VOID); 252c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray 253c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray TestCode(data, expected); 254c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray} 255c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray 2564833f5a1990c76bc2be89504225fb13cca22bedfDavid BrazdilTEST_F(SsaTest, Loop3) { 257c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray // Test that a local not yet defined at the entry of a loop is handled properly. 258c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray const char* expected = 259c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray "BasicBlock 0, succ: 1\n" 260c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray " 0: IntConstant 0 [5]\n" 261dee58d6bb6d567fcd0c4f39d8d690c3acaf0e432David Brazdil " 1: IntConstant 5 [9]\n" 262dee58d6bb6d567fcd0c4f39d8d690c3acaf0e432David Brazdil " 2: IntConstant 4 [5]\n" 263c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray " 3: Goto\n" 264c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray "BasicBlock 1, pred: 0, succ: 2\n" 265c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray " 4: Goto\n" 266c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray "BasicBlock 2, pred: 1, 3, succ: 4, 3\n" 267dee58d6bb6d567fcd0c4f39d8d690c3acaf0e432David Brazdil " 5: Phi(0, 2) [6, 6]\n" 268c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray " 6: Equal(5, 5) [7]\n" 269c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray " 7: If(6)\n" 270c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray "BasicBlock 3, pred: 2, succ: 2\n" 271c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray " 8: Goto\n" 272c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray "BasicBlock 4, pred: 2, succ: 5\n" 273dee58d6bb6d567fcd0c4f39d8d690c3acaf0e432David Brazdil " 9: Return(1)\n" 274c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray "BasicBlock 5, pred: 4\n" 275c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray " 10: Exit\n"; 276c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray 277c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray const uint16_t data[] = TWO_REGISTERS_CODE_ITEM( 278c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray Instruction::CONST_4 | 0 | 0, 279c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray Instruction::IF_EQ, 4, 280c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray Instruction::CONST_4 | 4 << 12 | 0, 281c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray Instruction::GOTO | 0xFD00, 282c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray Instruction::CONST_4 | 5 << 12 | 1 << 8, 283c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray Instruction::RETURN | 1 << 8); 284c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray 285c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray TestCode(data, expected); 286c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray} 287c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray 2884833f5a1990c76bc2be89504225fb13cca22bedfDavid BrazdilTEST_F(SsaTest, Loop4) { 289c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray // Make sure we support a preheader of a loop not being the first predecessor 290c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray // in the predecessor list of the header. 291c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray const char* expected = 292c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray "BasicBlock 0, succ: 1\n" 293c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray " 0: IntConstant 0 [4]\n" 294c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray " 1: IntConstant 4 [4]\n" 295c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray " 2: Goto\n" 296c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray "BasicBlock 1, pred: 0, succ: 4\n" 297c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray " 3: Goto\n" 298c83d441a722f0afb510c9cd0e69e09d65652143cNicolas Geoffray "BasicBlock 2, pred: 4, 3, succ: 5, 3\n" 299c83d441a722f0afb510c9cd0e69e09d65652143cNicolas Geoffray " 4: Phi(0, 1) [9, 5, 5]\n" 300c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray " 5: Equal(4, 4) [6]\n" 301c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray " 6: If(5)\n" 302c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray "BasicBlock 3, pred: 2, succ: 2\n" 303c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray " 7: Goto\n" 304c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray "BasicBlock 4, pred: 1, succ: 2\n" 305c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray " 8: Goto\n" 306c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray "BasicBlock 5, pred: 2, succ: 6\n" 307c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray " 9: Return(4)\n" 308c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray "BasicBlock 6, pred: 5\n" 309c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray " 10: Exit\n"; 310c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray 311c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray const uint16_t data[] = ONE_REGISTER_CODE_ITEM( 312c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray Instruction::CONST_4 | 0 | 0, 313c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray Instruction::GOTO | 0x500, 314c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray Instruction::IF_EQ, 5, 315c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray Instruction::CONST_4 | 4 << 12 | 0, 316c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray Instruction::GOTO | 0xFD00, 317c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray Instruction::GOTO | 0xFC00, 318c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray Instruction::RETURN | 0 << 8); 319c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray 320c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray TestCode(data, expected); 321c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray} 322c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray 3234833f5a1990c76bc2be89504225fb13cca22bedfDavid BrazdilTEST_F(SsaTest, Loop5) { 324c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray // Make sure we create a preheader of a loop when a header originally has two 325c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray // incoming blocks and one back edge. 326c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray const char* expected = 327c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray "BasicBlock 0, succ: 1\n" 328c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray " 0: IntConstant 0 [4, 4]\n" 329dee58d6bb6d567fcd0c4f39d8d690c3acaf0e432David Brazdil " 1: IntConstant 5 [13]\n" 330dee58d6bb6d567fcd0c4f39d8d690c3acaf0e432David Brazdil " 2: IntConstant 4 [13]\n" 331c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray " 3: Goto\n" 332c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray "BasicBlock 1, pred: 0, succ: 3, 2\n" 333c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray " 4: Equal(0, 0) [5]\n" 334c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray " 5: If(4)\n" 335c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray "BasicBlock 2, pred: 1, succ: 8\n" 336c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray " 6: Goto\n" 337c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray "BasicBlock 3, pred: 1, succ: 8\n" 338c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray " 7: Goto\n" 339c83d441a722f0afb510c9cd0e69e09d65652143cNicolas Geoffray "BasicBlock 4, pred: 8, 5, succ: 6, 5\n" 3403afca781086699e60a8941fb9474d4607c5909cbNicolas Geoffray " 8: Equal(13, 13) [9]\n" 3413afca781086699e60a8941fb9474d4607c5909cbNicolas Geoffray " 9: If(8)\n" 342c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray "BasicBlock 5, pred: 4, succ: 4\n" 3433afca781086699e60a8941fb9474d4607c5909cbNicolas Geoffray " 10: Goto\n" 344c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray "BasicBlock 6, pred: 4, succ: 7\n" 3453afca781086699e60a8941fb9474d4607c5909cbNicolas Geoffray " 11: Return(13)\n" 346c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray "BasicBlock 7, pred: 6\n" 3473afca781086699e60a8941fb9474d4607c5909cbNicolas Geoffray " 12: Exit\n" 348c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray "BasicBlock 8, pred: 2, 3, succ: 4\n" 349fa7f58935491fad5cb8e5af9ee38d1a4f73e872dVladimir Marko " 13: Phi(2, 1) [11, 8, 8]\n" 3503afca781086699e60a8941fb9474d4607c5909cbNicolas Geoffray " 14: Goto\n"; 351c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray 352c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray const uint16_t data[] = ONE_REGISTER_CODE_ITEM( 353c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray Instruction::CONST_4 | 0 | 0, 354c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray Instruction::IF_EQ, 4, 355c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray Instruction::CONST_4 | 4 << 12 | 0, 356c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray Instruction::GOTO | 0x200, 357c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray Instruction::CONST_4 | 5 << 12 | 0, 358c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray Instruction::IF_EQ, 3, 359c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray Instruction::GOTO | 0xFE00, 360c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray Instruction::RETURN | 0 << 8); 361c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray 362c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray TestCode(data, expected); 363c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray} 364c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray 3654833f5a1990c76bc2be89504225fb13cca22bedfDavid BrazdilTEST_F(SsaTest, Loop6) { 366c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray // Test a loop with one preheader and two back edges (e.g. continue). 367c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray const char* expected = 368c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray "BasicBlock 0, succ: 1\n" 369c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray " 0: IntConstant 0 [5]\n" 370db216f4d49ea1561a74261c29f1264952232728aNicolas Geoffray " 1: IntConstant 4 [5, 8, 8]\n" 371db216f4d49ea1561a74261c29f1264952232728aNicolas Geoffray " 2: IntConstant 5 [5]\n" 372c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray " 3: Goto\n" 373c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray "BasicBlock 1, pred: 0, succ: 2\n" 374c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray " 4: Goto\n" 375db216f4d49ea1561a74261c29f1264952232728aNicolas Geoffray "BasicBlock 2, pred: 1, 4, 5, succ: 6, 3\n" 376db216f4d49ea1561a74261c29f1264952232728aNicolas Geoffray " 5: Phi(0, 2, 1) [12, 6, 6]\n" 377c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray " 6: Equal(5, 5) [7]\n" 378c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray " 7: If(6)\n" 379c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray "BasicBlock 3, pred: 2, succ: 5, 4\n" 380c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray " 8: Equal(1, 1) [9]\n" 381c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray " 9: If(8)\n" 382db216f4d49ea1561a74261c29f1264952232728aNicolas Geoffray "BasicBlock 4, pred: 3, succ: 2\n" 383c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray " 10: Goto\n" 384db216f4d49ea1561a74261c29f1264952232728aNicolas Geoffray "BasicBlock 5, pred: 3, succ: 2\n" 385c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray " 11: Goto\n" 386c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray "BasicBlock 6, pred: 2, succ: 7\n" 387c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray " 12: Return(5)\n" 388c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray "BasicBlock 7, pred: 6\n" 389db216f4d49ea1561a74261c29f1264952232728aNicolas Geoffray " 13: Exit\n"; 390c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray 391c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray const uint16_t data[] = ONE_REGISTER_CODE_ITEM( 392c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray Instruction::CONST_4 | 0 | 0, 393c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray Instruction::IF_EQ, 8, 394c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray Instruction::CONST_4 | 4 << 12 | 0, 395c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray Instruction::IF_EQ, 4, 396c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray Instruction::CONST_4 | 5 << 12 | 0, 397c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray Instruction::GOTO | 0xFA00, 398c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray Instruction::GOTO | 0xF900, 399c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray Instruction::RETURN | 0 << 8); 400c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray 401c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray TestCode(data, expected); 402c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray} 403c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray 4044833f5a1990c76bc2be89504225fb13cca22bedfDavid BrazdilTEST_F(SsaTest, Loop7) { 405c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray // Test a loop with one preheader, one back edge, and two exit edges (e.g. break). 406c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray const char* expected = 407c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray "BasicBlock 0, succ: 1\n" 408c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray " 0: IntConstant 0 [5]\n" 409c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray " 1: IntConstant 4 [5, 8, 8]\n" 410c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray " 2: IntConstant 5 [12]\n" 411c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray " 3: Goto\n" 412c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray "BasicBlock 1, pred: 0, succ: 2\n" 413c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray " 4: Goto\n" 414ec7e4727e99aa1416398ac5a684f5024817a25c7Nicolas Geoffray "BasicBlock 2, pred: 1, 5, succ: 8, 3\n" 415c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray " 5: Phi(0, 1) [12, 6, 6]\n" 416c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray " 6: Equal(5, 5) [7]\n" 417c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray " 7: If(6)\n" 418c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray "BasicBlock 3, pred: 2, succ: 5, 4\n" 419c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray " 8: Equal(1, 1) [9]\n" 420c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray " 9: If(8)\n" 421c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray "BasicBlock 4, pred: 3, succ: 6\n" 422c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray " 10: Goto\n" 423c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray "BasicBlock 5, pred: 3, succ: 2\n" 424c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray " 11: Goto\n" 4258b20f88b0a8d1b374dd5eaae289d19734c77b8f8Nicolas Geoffray "BasicBlock 6, pred: 8, 4, succ: 7\n" 4268b20f88b0a8d1b374dd5eaae289d19734c77b8f8Nicolas Geoffray " 12: Phi(5, 2) [13]\n" 427c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray " 13: Return(12)\n" 428c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray "BasicBlock 7, pred: 6\n" 429622d9c31febd950255b36a48b47e1f630197c5feNicolas Geoffray " 14: Exit\n" 430622d9c31febd950255b36a48b47e1f630197c5feNicolas Geoffray "BasicBlock 8, pred: 2, succ: 6\n" 431622d9c31febd950255b36a48b47e1f630197c5feNicolas Geoffray " 15: Goto\n"; 432c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray 433c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray const uint16_t data[] = ONE_REGISTER_CODE_ITEM( 434c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray Instruction::CONST_4 | 0 | 0, 435c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray Instruction::IF_EQ, 8, 436c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray Instruction::CONST_4 | 4 << 12 | 0, 437c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray Instruction::IF_EQ, 4, 438c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray Instruction::CONST_4 | 5 << 12 | 0, 439c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray Instruction::GOTO | 0x0200, 440c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray Instruction::GOTO | 0xF900, 441c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray Instruction::RETURN | 0 << 8); 442c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray 443c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray TestCode(data, expected); 444c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray} 445c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray 4464833f5a1990c76bc2be89504225fb13cca22bedfDavid BrazdilTEST_F(SsaTest, DeadLocal) { 447c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray // Test that we correctly handle a local not being used. 448c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray const char* expected = 449c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray "BasicBlock 0, succ: 1\n" 450c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray " 0: IntConstant 0\n" 451c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray " 1: Goto\n" 452c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray "BasicBlock 1, pred: 0, succ: 2\n" 453c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray " 2: ReturnVoid\n" 454c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray "BasicBlock 2, pred: 1\n" 455c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray " 3: Exit\n"; 456c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray 457c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray const uint16_t data[] = ONE_REGISTER_CODE_ITEM( 458c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray Instruction::CONST_4 | 0 | 0, 459c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray Instruction::RETURN_VOID); 460c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray 461c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray TestCode(data, expected); 462c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray} 463c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray 4644833f5a1990c76bc2be89504225fb13cca22bedfDavid BrazdilTEST_F(SsaTest, LocalInIf) { 4657c3560f2ce0ec9484004d05a94bfaa6e02f5a96aNicolas Geoffray // Test that we do not create a phi in the join block when one predecessor 4667c3560f2ce0ec9484004d05a94bfaa6e02f5a96aNicolas Geoffray // does not update the local. 4677c3560f2ce0ec9484004d05a94bfaa6e02f5a96aNicolas Geoffray const char* expected = 4687c3560f2ce0ec9484004d05a94bfaa6e02f5a96aNicolas Geoffray "BasicBlock 0, succ: 1\n" 4697c3560f2ce0ec9484004d05a94bfaa6e02f5a96aNicolas Geoffray " 0: IntConstant 0 [3, 3]\n" 4707c3560f2ce0ec9484004d05a94bfaa6e02f5a96aNicolas Geoffray " 1: IntConstant 4\n" 4717c3560f2ce0ec9484004d05a94bfaa6e02f5a96aNicolas Geoffray " 2: Goto\n" 472ec7e4727e99aa1416398ac5a684f5024817a25c7Nicolas Geoffray "BasicBlock 1, pred: 0, succ: 5, 2\n" 4737c3560f2ce0ec9484004d05a94bfaa6e02f5a96aNicolas Geoffray " 3: Equal(0, 0) [4]\n" 4747c3560f2ce0ec9484004d05a94bfaa6e02f5a96aNicolas Geoffray " 4: If(3)\n" 4757c3560f2ce0ec9484004d05a94bfaa6e02f5a96aNicolas Geoffray "BasicBlock 2, pred: 1, succ: 3\n" 4767c3560f2ce0ec9484004d05a94bfaa6e02f5a96aNicolas Geoffray " 5: Goto\n" 4778b20f88b0a8d1b374dd5eaae289d19734c77b8f8Nicolas Geoffray "BasicBlock 3, pred: 5, 2, succ: 4\n" 4787c3560f2ce0ec9484004d05a94bfaa6e02f5a96aNicolas Geoffray " 6: ReturnVoid\n" 4797c3560f2ce0ec9484004d05a94bfaa6e02f5a96aNicolas Geoffray "BasicBlock 4, pred: 3\n" 4807c3560f2ce0ec9484004d05a94bfaa6e02f5a96aNicolas Geoffray " 7: Exit\n" 4817c3560f2ce0ec9484004d05a94bfaa6e02f5a96aNicolas Geoffray // Synthesized block to avoid critical edge. 4827c3560f2ce0ec9484004d05a94bfaa6e02f5a96aNicolas Geoffray "BasicBlock 5, pred: 1, succ: 3\n" 4837c3560f2ce0ec9484004d05a94bfaa6e02f5a96aNicolas Geoffray " 8: Goto\n"; 4847c3560f2ce0ec9484004d05a94bfaa6e02f5a96aNicolas Geoffray 4857c3560f2ce0ec9484004d05a94bfaa6e02f5a96aNicolas Geoffray const uint16_t data[] = TWO_REGISTERS_CODE_ITEM( 4867c3560f2ce0ec9484004d05a94bfaa6e02f5a96aNicolas Geoffray Instruction::CONST_4 | 0 | 0, 4877c3560f2ce0ec9484004d05a94bfaa6e02f5a96aNicolas Geoffray Instruction::IF_EQ, 3, 4887c3560f2ce0ec9484004d05a94bfaa6e02f5a96aNicolas Geoffray Instruction::CONST_4 | 4 << 12 | 1 << 8, 4897c3560f2ce0ec9484004d05a94bfaa6e02f5a96aNicolas Geoffray Instruction::RETURN_VOID); 4907c3560f2ce0ec9484004d05a94bfaa6e02f5a96aNicolas Geoffray 4917c3560f2ce0ec9484004d05a94bfaa6e02f5a96aNicolas Geoffray TestCode(data, expected); 4927c3560f2ce0ec9484004d05a94bfaa6e02f5a96aNicolas Geoffray} 4937c3560f2ce0ec9484004d05a94bfaa6e02f5a96aNicolas Geoffray 4944833f5a1990c76bc2be89504225fb13cca22bedfDavid BrazdilTEST_F(SsaTest, MultiplePredecessors) { 495ec7e4727e99aa1416398ac5a684f5024817a25c7Nicolas Geoffray // Test that we do not create a phi when one predecessor 496ec7e4727e99aa1416398ac5a684f5024817a25c7Nicolas Geoffray // does not update the local. 497ec7e4727e99aa1416398ac5a684f5024817a25c7Nicolas Geoffray const char* expected = 498ec7e4727e99aa1416398ac5a684f5024817a25c7Nicolas Geoffray "BasicBlock 0, succ: 1\n" 499dee58d6bb6d567fcd0c4f39d8d690c3acaf0e432David Brazdil " 0: IntConstant 0 [4, 4, 8, 8, 6, 6, 2, 2]\n" 500ec7e4727e99aa1416398ac5a684f5024817a25c7Nicolas Geoffray " 1: Goto\n" 501ec7e4727e99aa1416398ac5a684f5024817a25c7Nicolas Geoffray "BasicBlock 1, pred: 0, succ: 3, 2\n" 502ec7e4727e99aa1416398ac5a684f5024817a25c7Nicolas Geoffray " 2: Equal(0, 0) [3]\n" 503ec7e4727e99aa1416398ac5a684f5024817a25c7Nicolas Geoffray " 3: If(2)\n" 504ec7e4727e99aa1416398ac5a684f5024817a25c7Nicolas Geoffray "BasicBlock 2, pred: 1, succ: 5\n" 505ec7e4727e99aa1416398ac5a684f5024817a25c7Nicolas Geoffray " 4: Add(0, 0)\n" 506ec7e4727e99aa1416398ac5a684f5024817a25c7Nicolas Geoffray " 5: Goto\n" 507ec7e4727e99aa1416398ac5a684f5024817a25c7Nicolas Geoffray "BasicBlock 3, pred: 1, succ: 7, 4\n" 508ec7e4727e99aa1416398ac5a684f5024817a25c7Nicolas Geoffray " 6: Equal(0, 0) [7]\n" 509ec7e4727e99aa1416398ac5a684f5024817a25c7Nicolas Geoffray " 7: If(6)\n" 510ec7e4727e99aa1416398ac5a684f5024817a25c7Nicolas Geoffray "BasicBlock 4, pred: 3, succ: 5\n" 511ec7e4727e99aa1416398ac5a684f5024817a25c7Nicolas Geoffray " 8: Add(0, 0)\n" 512ec7e4727e99aa1416398ac5a684f5024817a25c7Nicolas Geoffray " 9: Goto\n" 513ec7e4727e99aa1416398ac5a684f5024817a25c7Nicolas Geoffray // This block should not get a phi for local 1. 5148b20f88b0a8d1b374dd5eaae289d19734c77b8f8Nicolas Geoffray "BasicBlock 5, pred: 2, 7, 4, succ: 6\n" 515ec7e4727e99aa1416398ac5a684f5024817a25c7Nicolas Geoffray " 10: ReturnVoid\n" 516ec7e4727e99aa1416398ac5a684f5024817a25c7Nicolas Geoffray "BasicBlock 6, pred: 5\n" 517ec7e4727e99aa1416398ac5a684f5024817a25c7Nicolas Geoffray " 11: Exit\n" 518ec7e4727e99aa1416398ac5a684f5024817a25c7Nicolas Geoffray "BasicBlock 7, pred: 3, succ: 5\n" 519ec7e4727e99aa1416398ac5a684f5024817a25c7Nicolas Geoffray " 12: Goto\n"; 520ec7e4727e99aa1416398ac5a684f5024817a25c7Nicolas Geoffray 521ec7e4727e99aa1416398ac5a684f5024817a25c7Nicolas Geoffray const uint16_t data[] = TWO_REGISTERS_CODE_ITEM( 522ec7e4727e99aa1416398ac5a684f5024817a25c7Nicolas Geoffray Instruction::CONST_4 | 0 | 0, 523ec7e4727e99aa1416398ac5a684f5024817a25c7Nicolas Geoffray Instruction::IF_EQ, 5, 524ec7e4727e99aa1416398ac5a684f5024817a25c7Nicolas Geoffray Instruction::ADD_INT_LIT8 | 1 << 8, 0 << 8, 525ec7e4727e99aa1416398ac5a684f5024817a25c7Nicolas Geoffray Instruction::GOTO | 0x0500, 526ec7e4727e99aa1416398ac5a684f5024817a25c7Nicolas Geoffray Instruction::IF_EQ, 4, 527ec7e4727e99aa1416398ac5a684f5024817a25c7Nicolas Geoffray Instruction::ADD_INT_LIT8 | 1 << 8, 0 << 8, 528ec7e4727e99aa1416398ac5a684f5024817a25c7Nicolas Geoffray Instruction::RETURN_VOID); 529ec7e4727e99aa1416398ac5a684f5024817a25c7Nicolas Geoffray 530ec7e4727e99aa1416398ac5a684f5024817a25c7Nicolas Geoffray TestCode(data, expected); 531ec7e4727e99aa1416398ac5a684f5024817a25c7Nicolas Geoffray} 532ec7e4727e99aa1416398ac5a684f5024817a25c7Nicolas Geoffray 533c32e770f21540e4e9eda6dc7f770e745d33f1b9fNicolas Geoffray} // namespace art 534