Aart Bik | 30efb4e | 2015-07-30 12:14:31 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2015 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #include <regex> |
| 18 | |
| 19 | #include "base/arena_allocator.h" |
| 20 | #include "builder.h" |
Aart Bik | 30efb4e | 2015-07-30 12:14:31 -0700 | [diff] [blame] | 21 | #include "induction_var_analysis.h" |
| 22 | #include "nodes.h" |
| 23 | #include "optimizing_unit_test.h" |
| 24 | |
| 25 | namespace art { |
| 26 | |
| 27 | /** |
| 28 | * Fixture class for the InductionVarAnalysis tests. |
| 29 | */ |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 30 | class InductionVarAnalysisTest : public CommonCompilerTest { |
Aart Bik | 30efb4e | 2015-07-30 12:14:31 -0700 | [diff] [blame] | 31 | public: |
| 32 | InductionVarAnalysisTest() : pool_(), allocator_(&pool_) { |
| 33 | graph_ = CreateGraph(&allocator_); |
| 34 | } |
| 35 | |
| 36 | ~InductionVarAnalysisTest() { } |
| 37 | |
| 38 | // Builds single for-loop at depth d. |
| 39 | void BuildForLoop(int d, int n) { |
| 40 | ASSERT_LT(d, n); |
| 41 | loop_preheader_[d] = new (&allocator_) HBasicBlock(graph_); |
| 42 | graph_->AddBlock(loop_preheader_[d]); |
| 43 | loop_header_[d] = new (&allocator_) HBasicBlock(graph_); |
| 44 | graph_->AddBlock(loop_header_[d]); |
| 45 | loop_preheader_[d]->AddSuccessor(loop_header_[d]); |
| 46 | if (d < (n - 1)) { |
| 47 | BuildForLoop(d + 1, n); |
| 48 | } |
| 49 | loop_body_[d] = new (&allocator_) HBasicBlock(graph_); |
| 50 | graph_->AddBlock(loop_body_[d]); |
| 51 | loop_body_[d]->AddSuccessor(loop_header_[d]); |
| 52 | if (d < (n - 1)) { |
| 53 | loop_header_[d]->AddSuccessor(loop_preheader_[d + 1]); |
| 54 | loop_header_[d + 1]->AddSuccessor(loop_body_[d]); |
| 55 | } else { |
| 56 | loop_header_[d]->AddSuccessor(loop_body_[d]); |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | // Builds a n-nested loop in CFG where each loop at depth 0 <= d < n |
| 61 | // is defined as "for (int i_d = 0; i_d < 100; i_d++)". Tests can further |
| 62 | // populate the loop with instructions to set up interesting scenarios. |
| 63 | void BuildLoopNest(int n) { |
| 64 | ASSERT_LE(n, 10); |
Aart Bik | e609b7c | 2015-08-27 13:46:58 -0700 | [diff] [blame] | 65 | graph_->SetNumberOfVRegs(n + 3); |
Aart Bik | 30efb4e | 2015-07-30 12:14:31 -0700 | [diff] [blame] | 66 | |
| 67 | // Build basic blocks with entry, nested loop, exit. |
| 68 | entry_ = new (&allocator_) HBasicBlock(graph_); |
| 69 | graph_->AddBlock(entry_); |
| 70 | BuildForLoop(0, n); |
David Brazdil | db51efb | 2015-11-06 01:36:20 +0000 | [diff] [blame] | 71 | return_ = new (&allocator_) HBasicBlock(graph_); |
| 72 | graph_->AddBlock(return_); |
Aart Bik | 30efb4e | 2015-07-30 12:14:31 -0700 | [diff] [blame] | 73 | exit_ = new (&allocator_) HBasicBlock(graph_); |
| 74 | graph_->AddBlock(exit_); |
| 75 | entry_->AddSuccessor(loop_preheader_[0]); |
David Brazdil | db51efb | 2015-11-06 01:36:20 +0000 | [diff] [blame] | 76 | loop_header_[0]->AddSuccessor(return_); |
| 77 | return_->AddSuccessor(exit_); |
Aart Bik | 30efb4e | 2015-07-30 12:14:31 -0700 | [diff] [blame] | 78 | graph_->SetEntryBlock(entry_); |
| 79 | graph_->SetExitBlock(exit_); |
| 80 | |
| 81 | // Provide entry and exit instructions. |
Calin Juravle | e6e3bea | 2015-10-14 13:53:10 +0000 | [diff] [blame] | 82 | parameter_ = new (&allocator_) HParameterValue( |
| 83 | graph_->GetDexFile(), 0, 0, Primitive::kPrimNot, true); |
Aart Bik | 30efb4e | 2015-07-30 12:14:31 -0700 | [diff] [blame] | 84 | entry_->AddInstruction(parameter_); |
Aart Bik | e609b7c | 2015-08-27 13:46:58 -0700 | [diff] [blame] | 85 | constant0_ = graph_->GetIntConstant(0); |
| 86 | constant1_ = graph_->GetIntConstant(1); |
| 87 | constant100_ = graph_->GetIntConstant(100); |
David Brazdil | 15693bf | 2015-12-16 10:30:45 +0000 | [diff] [blame] | 88 | float_constant0_ = graph_->GetFloatConstant(0.0f); |
David Brazdil | db51efb | 2015-11-06 01:36:20 +0000 | [diff] [blame] | 89 | return_->AddInstruction(new (&allocator_) HReturnVoid()); |
Aart Bik | e609b7c | 2015-08-27 13:46:58 -0700 | [diff] [blame] | 90 | exit_->AddInstruction(new (&allocator_) HExit()); |
Aart Bik | 30efb4e | 2015-07-30 12:14:31 -0700 | [diff] [blame] | 91 | |
| 92 | // Provide loop instructions. |
| 93 | for (int d = 0; d < n; d++) { |
David Brazdil | badd826 | 2016-02-02 16:28:56 +0000 | [diff] [blame] | 94 | basic_[d] = new (&allocator_) HPhi(&allocator_, d, 0, Primitive::kPrimInt); |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 95 | loop_preheader_[d]->AddInstruction(new (&allocator_) HGoto()); |
David Brazdil | badd826 | 2016-02-02 16:28:56 +0000 | [diff] [blame] | 96 | loop_header_[d]->AddPhi(basic_[d]); |
| 97 | HInstruction* compare = new (&allocator_) HLessThan(basic_[d], constant100_); |
Aart Bik | 30efb4e | 2015-07-30 12:14:31 -0700 | [diff] [blame] | 98 | loop_header_[d]->AddInstruction(compare); |
| 99 | loop_header_[d]->AddInstruction(new (&allocator_) HIf(compare)); |
David Brazdil | badd826 | 2016-02-02 16:28:56 +0000 | [diff] [blame] | 100 | increment_[d] = new (&allocator_) HAdd(Primitive::kPrimInt, basic_[d], constant1_); |
Aart Bik | 30efb4e | 2015-07-30 12:14:31 -0700 | [diff] [blame] | 101 | loop_body_[d]->AddInstruction(increment_[d]); |
Aart Bik | 30efb4e | 2015-07-30 12:14:31 -0700 | [diff] [blame] | 102 | loop_body_[d]->AddInstruction(new (&allocator_) HGoto()); |
David Brazdil | badd826 | 2016-02-02 16:28:56 +0000 | [diff] [blame] | 103 | |
| 104 | basic_[d]->AddInput(constant0_); |
| 105 | basic_[d]->AddInput(increment_[d]); |
Aart Bik | 30efb4e | 2015-07-30 12:14:31 -0700 | [diff] [blame] | 106 | } |
| 107 | } |
| 108 | |
| 109 | // Builds if-statement at depth d. |
David Brazdil | badd826 | 2016-02-02 16:28:56 +0000 | [diff] [blame] | 110 | HPhi* BuildIf(int d, HBasicBlock** ifT, HBasicBlock **ifF) { |
Aart Bik | 30efb4e | 2015-07-30 12:14:31 -0700 | [diff] [blame] | 111 | HBasicBlock* cond = new (&allocator_) HBasicBlock(graph_); |
| 112 | HBasicBlock* ifTrue = new (&allocator_) HBasicBlock(graph_); |
| 113 | HBasicBlock* ifFalse = new (&allocator_) HBasicBlock(graph_); |
| 114 | graph_->AddBlock(cond); |
| 115 | graph_->AddBlock(ifTrue); |
| 116 | graph_->AddBlock(ifFalse); |
| 117 | // Conditional split. |
| 118 | loop_header_[d]->ReplaceSuccessor(loop_body_[d], cond); |
| 119 | cond->AddSuccessor(ifTrue); |
| 120 | cond->AddSuccessor(ifFalse); |
| 121 | ifTrue->AddSuccessor(loop_body_[d]); |
| 122 | ifFalse->AddSuccessor(loop_body_[d]); |
| 123 | cond->AddInstruction(new (&allocator_) HIf(parameter_)); |
| 124 | *ifT = ifTrue; |
| 125 | *ifF = ifFalse; |
David Brazdil | badd826 | 2016-02-02 16:28:56 +0000 | [diff] [blame] | 126 | |
| 127 | HPhi* select_phi = new (&allocator_) HPhi(&allocator_, -1, 0, Primitive::kPrimInt); |
| 128 | loop_body_[d]->AddPhi(select_phi); |
| 129 | return select_phi; |
Aart Bik | 30efb4e | 2015-07-30 12:14:31 -0700 | [diff] [blame] | 130 | } |
| 131 | |
| 132 | // Inserts instruction right before increment at depth d. |
| 133 | HInstruction* InsertInstruction(HInstruction* instruction, int d) { |
| 134 | loop_body_[d]->InsertInstructionBefore(instruction, increment_[d]); |
| 135 | return instruction; |
| 136 | } |
| 137 | |
David Brazdil | badd826 | 2016-02-02 16:28:56 +0000 | [diff] [blame] | 138 | // Inserts a phi to loop header at depth d and returns it. |
| 139 | HPhi* InsertLoopPhi(int vreg, int d) { |
| 140 | HPhi* phi = new (&allocator_) HPhi(&allocator_, vreg, 0, Primitive::kPrimInt); |
| 141 | loop_header_[d]->AddPhi(phi); |
| 142 | return phi; |
Aart Bik | 30efb4e | 2015-07-30 12:14:31 -0700 | [diff] [blame] | 143 | } |
| 144 | |
David Brazdil | badd826 | 2016-02-02 16:28:56 +0000 | [diff] [blame] | 145 | // Inserts an array store with given `subscript` at depth d to |
Aart Bik | 30efb4e | 2015-07-30 12:14:31 -0700 | [diff] [blame] | 146 | // enable tests to inspect the computed induction at that point easily. |
David Brazdil | badd826 | 2016-02-02 16:28:56 +0000 | [diff] [blame] | 147 | HInstruction* InsertArrayStore(HInstruction* subscript, int d) { |
David Brazdil | 15693bf | 2015-12-16 10:30:45 +0000 | [diff] [blame] | 148 | // ArraySet is given a float value in order to avoid SsaBuilder typing |
| 149 | // it from the array's non-existent reference type info. |
Aart Bik | 30efb4e | 2015-07-30 12:14:31 -0700 | [diff] [blame] | 150 | return InsertInstruction(new (&allocator_) HArraySet( |
David Brazdil | badd826 | 2016-02-02 16:28:56 +0000 | [diff] [blame] | 151 | parameter_, subscript, float_constant0_, Primitive::kPrimFloat, 0), d); |
Aart Bik | 30efb4e | 2015-07-30 12:14:31 -0700 | [diff] [blame] | 152 | } |
| 153 | |
Aart Bik | e609b7c | 2015-08-27 13:46:58 -0700 | [diff] [blame] | 154 | // Returns induction information of instruction in loop at depth d. |
| 155 | std::string GetInductionInfo(HInstruction* instruction, int d) { |
| 156 | return HInductionVarAnalysis::InductionToString( |
| 157 | iva_->LookupInfo(loop_body_[d]->GetLoopInformation(), instruction)); |
Aart Bik | 30efb4e | 2015-07-30 12:14:31 -0700 | [diff] [blame] | 158 | } |
| 159 | |
| 160 | // Performs InductionVarAnalysis (after proper set up). |
| 161 | void PerformInductionVarAnalysis() { |
David Brazdil | badd826 | 2016-02-02 16:28:56 +0000 | [diff] [blame] | 162 | graph_->BuildDominatorTree(); |
Aart Bik | 30efb4e | 2015-07-30 12:14:31 -0700 | [diff] [blame] | 163 | iva_ = new (&allocator_) HInductionVarAnalysis(graph_); |
| 164 | iva_->Run(); |
| 165 | } |
| 166 | |
| 167 | // General building fields. |
| 168 | ArenaPool pool_; |
| 169 | ArenaAllocator allocator_; |
| 170 | HGraph* graph_; |
| 171 | HInductionVarAnalysis* iva_; |
| 172 | |
| 173 | // Fixed basic blocks and instructions. |
| 174 | HBasicBlock* entry_; |
David Brazdil | db51efb | 2015-11-06 01:36:20 +0000 | [diff] [blame] | 175 | HBasicBlock* return_; |
Aart Bik | 30efb4e | 2015-07-30 12:14:31 -0700 | [diff] [blame] | 176 | HBasicBlock* exit_; |
| 177 | HInstruction* parameter_; // "this" |
| 178 | HInstruction* constant0_; |
| 179 | HInstruction* constant1_; |
| 180 | HInstruction* constant100_; |
David Brazdil | 15693bf | 2015-12-16 10:30:45 +0000 | [diff] [blame] | 181 | HInstruction* float_constant0_; |
Aart Bik | 30efb4e | 2015-07-30 12:14:31 -0700 | [diff] [blame] | 182 | |
| 183 | // Loop specifics. |
| 184 | HBasicBlock* loop_preheader_[10]; |
| 185 | HBasicBlock* loop_header_[10]; |
| 186 | HBasicBlock* loop_body_[10]; |
| 187 | HInstruction* increment_[10]; |
David Brazdil | badd826 | 2016-02-02 16:28:56 +0000 | [diff] [blame] | 188 | HPhi* basic_[10]; // "vreg_d", the "i_d" |
Aart Bik | 30efb4e | 2015-07-30 12:14:31 -0700 | [diff] [blame] | 189 | }; |
| 190 | |
| 191 | // |
| 192 | // The actual InductionVarAnalysis tests. |
| 193 | // |
| 194 | |
| 195 | TEST_F(InductionVarAnalysisTest, ProperLoopSetup) { |
| 196 | // Setup: |
| 197 | // for (int i_0 = 0; i_0 < 100; i_0++) { |
| 198 | // .. |
| 199 | // for (int i_9 = 0; i_9 < 100; i_9++) { |
| 200 | // } |
| 201 | // .. |
| 202 | // } |
| 203 | BuildLoopNest(10); |
David Brazdil | badd826 | 2016-02-02 16:28:56 +0000 | [diff] [blame] | 204 | graph_->BuildDominatorTree(); |
Aart Bik | 30efb4e | 2015-07-30 12:14:31 -0700 | [diff] [blame] | 205 | ASSERT_EQ(entry_->GetLoopInformation(), nullptr); |
| 206 | for (int d = 0; d < 1; d++) { |
| 207 | ASSERT_EQ(loop_preheader_[d]->GetLoopInformation(), |
| 208 | (d == 0) ? nullptr |
| 209 | : loop_header_[d - 1]->GetLoopInformation()); |
| 210 | ASSERT_NE(loop_header_[d]->GetLoopInformation(), nullptr); |
| 211 | ASSERT_NE(loop_body_[d]->GetLoopInformation(), nullptr); |
| 212 | ASSERT_EQ(loop_header_[d]->GetLoopInformation(), |
| 213 | loop_body_[d]->GetLoopInformation()); |
| 214 | } |
| 215 | ASSERT_EQ(exit_->GetLoopInformation(), nullptr); |
| 216 | } |
| 217 | |
Aart Bik | e609b7c | 2015-08-27 13:46:58 -0700 | [diff] [blame] | 218 | TEST_F(InductionVarAnalysisTest, FindBasicInduction) { |
Aart Bik | 30efb4e | 2015-07-30 12:14:31 -0700 | [diff] [blame] | 219 | // Setup: |
| 220 | // for (int i = 0; i < 100; i++) { |
Aart Bik | e609b7c | 2015-08-27 13:46:58 -0700 | [diff] [blame] | 221 | // a[i] = 0; |
Aart Bik | 30efb4e | 2015-07-30 12:14:31 -0700 | [diff] [blame] | 222 | // } |
| 223 | BuildLoopNest(1); |
| 224 | HInstruction* store = InsertArrayStore(basic_[0], 0); |
| 225 | PerformInductionVarAnalysis(); |
| 226 | |
Aart Bik | e609b7c | 2015-08-27 13:46:58 -0700 | [diff] [blame] | 227 | EXPECT_STREQ("((1) * i + (0))", GetInductionInfo(store->InputAt(1), 0).c_str()); |
Aart Bik | 471a203 | 2015-09-04 18:22:11 -0700 | [diff] [blame] | 228 | EXPECT_STREQ("((1) * i + (1))", GetInductionInfo(increment_[0], 0).c_str()); |
Aart Bik | d14c595 | 2015-09-08 15:25:15 -0700 | [diff] [blame] | 229 | |
| 230 | // Trip-count. |
Aart Bik | 22f0587 | 2015-10-27 15:56:28 -0700 | [diff] [blame] | 231 | EXPECT_STREQ("((100) (TC-loop) ((0) < (100)))", |
Aart Bik | 9401f53 | 2015-09-28 16:25:56 -0700 | [diff] [blame] | 232 | GetInductionInfo(loop_header_[0]->GetLastInstruction(), 0).c_str()); |
Aart Bik | 30efb4e | 2015-07-30 12:14:31 -0700 | [diff] [blame] | 233 | } |
| 234 | |
Aart Bik | e609b7c | 2015-08-27 13:46:58 -0700 | [diff] [blame] | 235 | TEST_F(InductionVarAnalysisTest, FindDerivedInduction) { |
Aart Bik | 30efb4e | 2015-07-30 12:14:31 -0700 | [diff] [blame] | 236 | // Setup: |
| 237 | // for (int i = 0; i < 100; i++) { |
Aart Bik | e609b7c | 2015-08-27 13:46:58 -0700 | [diff] [blame] | 238 | // k = 100 + i; |
| 239 | // k = 100 - i; |
| 240 | // k = 100 * i; |
| 241 | // k = i << 1; |
| 242 | // k = - i; |
Aart Bik | 30efb4e | 2015-07-30 12:14:31 -0700 | [diff] [blame] | 243 | // } |
| 244 | BuildLoopNest(1); |
| 245 | HInstruction *add = InsertInstruction( |
David Brazdil | badd826 | 2016-02-02 16:28:56 +0000 | [diff] [blame] | 246 | new (&allocator_) HAdd(Primitive::kPrimInt, constant100_, basic_[0]), 0); |
Aart Bik | 30efb4e | 2015-07-30 12:14:31 -0700 | [diff] [blame] | 247 | HInstruction *sub = InsertInstruction( |
David Brazdil | badd826 | 2016-02-02 16:28:56 +0000 | [diff] [blame] | 248 | new (&allocator_) HSub(Primitive::kPrimInt, constant100_, basic_[0]), 0); |
Aart Bik | 30efb4e | 2015-07-30 12:14:31 -0700 | [diff] [blame] | 249 | HInstruction *mul = InsertInstruction( |
David Brazdil | badd826 | 2016-02-02 16:28:56 +0000 | [diff] [blame] | 250 | new (&allocator_) HMul(Primitive::kPrimInt, constant100_, basic_[0]), 0); |
Aart Bik | e609b7c | 2015-08-27 13:46:58 -0700 | [diff] [blame] | 251 | HInstruction *shl = InsertInstruction( |
David Brazdil | badd826 | 2016-02-02 16:28:56 +0000 | [diff] [blame] | 252 | new (&allocator_) HShl(Primitive::kPrimInt, basic_[0], constant1_), 0); |
Aart Bik | 30efb4e | 2015-07-30 12:14:31 -0700 | [diff] [blame] | 253 | HInstruction *neg = InsertInstruction( |
David Brazdil | badd826 | 2016-02-02 16:28:56 +0000 | [diff] [blame] | 254 | new (&allocator_) HNeg(Primitive::kPrimInt, basic_[0]), 0); |
Aart Bik | 30efb4e | 2015-07-30 12:14:31 -0700 | [diff] [blame] | 255 | PerformInductionVarAnalysis(); |
| 256 | |
Aart Bik | 471a203 | 2015-09-04 18:22:11 -0700 | [diff] [blame] | 257 | EXPECT_STREQ("((1) * i + (100))", GetInductionInfo(add, 0).c_str()); |
| 258 | EXPECT_STREQ("(( - (1)) * i + (100))", GetInductionInfo(sub, 0).c_str()); |
| 259 | EXPECT_STREQ("((100) * i + (0))", GetInductionInfo(mul, 0).c_str()); |
| 260 | EXPECT_STREQ("((2) * i + (0))", GetInductionInfo(shl, 0).c_str()); |
| 261 | EXPECT_STREQ("(( - (1)) * i + (0))", GetInductionInfo(neg, 0).c_str()); |
Aart Bik | 30efb4e | 2015-07-30 12:14:31 -0700 | [diff] [blame] | 262 | } |
| 263 | |
| 264 | TEST_F(InductionVarAnalysisTest, FindChainInduction) { |
| 265 | // Setup: |
| 266 | // k = 0; |
| 267 | // for (int i = 0; i < 100; i++) { |
Aart Bik | e609b7c | 2015-08-27 13:46:58 -0700 | [diff] [blame] | 268 | // k = k + 100; |
| 269 | // a[k] = 0; |
| 270 | // k = k - 1; |
| 271 | // a[k] = 0; |
Aart Bik | 30efb4e | 2015-07-30 12:14:31 -0700 | [diff] [blame] | 272 | // } |
| 273 | BuildLoopNest(1); |
David Brazdil | badd826 | 2016-02-02 16:28:56 +0000 | [diff] [blame] | 274 | HPhi* k = InsertLoopPhi(0, 0); |
| 275 | k->AddInput(constant0_); |
| 276 | |
Aart Bik | 30efb4e | 2015-07-30 12:14:31 -0700 | [diff] [blame] | 277 | HInstruction *add = InsertInstruction( |
David Brazdil | badd826 | 2016-02-02 16:28:56 +0000 | [diff] [blame] | 278 | new (&allocator_) HAdd(Primitive::kPrimInt, k, constant100_), 0); |
| 279 | HInstruction* store1 = InsertArrayStore(add, 0); |
Aart Bik | 30efb4e | 2015-07-30 12:14:31 -0700 | [diff] [blame] | 280 | HInstruction *sub = InsertInstruction( |
David Brazdil | badd826 | 2016-02-02 16:28:56 +0000 | [diff] [blame] | 281 | new (&allocator_) HSub(Primitive::kPrimInt, add, constant1_), 0); |
| 282 | HInstruction* store2 = InsertArrayStore(sub, 0); |
| 283 | k->AddInput(sub); |
Aart Bik | 30efb4e | 2015-07-30 12:14:31 -0700 | [diff] [blame] | 284 | PerformInductionVarAnalysis(); |
| 285 | |
Aart Bik | 471a203 | 2015-09-04 18:22:11 -0700 | [diff] [blame] | 286 | EXPECT_STREQ("(((100) - (1)) * i + (100))", |
Aart Bik | e609b7c | 2015-08-27 13:46:58 -0700 | [diff] [blame] | 287 | GetInductionInfo(store1->InputAt(1), 0).c_str()); |
Aart Bik | 471a203 | 2015-09-04 18:22:11 -0700 | [diff] [blame] | 288 | EXPECT_STREQ("(((100) - (1)) * i + ((100) - (1)))", |
Aart Bik | e609b7c | 2015-08-27 13:46:58 -0700 | [diff] [blame] | 289 | GetInductionInfo(store2->InputAt(1), 0).c_str()); |
Aart Bik | 30efb4e | 2015-07-30 12:14:31 -0700 | [diff] [blame] | 290 | } |
| 291 | |
| 292 | TEST_F(InductionVarAnalysisTest, FindTwoWayBasicInduction) { |
| 293 | // Setup: |
| 294 | // k = 0; |
| 295 | // for (int i = 0; i < 100; i++) { |
Aart Bik | e609b7c | 2015-08-27 13:46:58 -0700 | [diff] [blame] | 296 | // if () k = k + 1; |
| 297 | // else k = k + 1; |
| 298 | // a[k] = 0; |
Aart Bik | 30efb4e | 2015-07-30 12:14:31 -0700 | [diff] [blame] | 299 | // } |
| 300 | BuildLoopNest(1); |
David Brazdil | badd826 | 2016-02-02 16:28:56 +0000 | [diff] [blame] | 301 | HPhi* k_header = InsertLoopPhi(0, 0); |
| 302 | k_header->AddInput(constant0_); |
| 303 | |
Aart Bik | 30efb4e | 2015-07-30 12:14:31 -0700 | [diff] [blame] | 304 | HBasicBlock* ifTrue; |
| 305 | HBasicBlock* ifFalse; |
David Brazdil | badd826 | 2016-02-02 16:28:56 +0000 | [diff] [blame] | 306 | HPhi* k_body = BuildIf(0, &ifTrue, &ifFalse); |
| 307 | |
Aart Bik | 30efb4e | 2015-07-30 12:14:31 -0700 | [diff] [blame] | 308 | // True-branch. |
David Brazdil | badd826 | 2016-02-02 16:28:56 +0000 | [diff] [blame] | 309 | HInstruction* inc1 = new (&allocator_) HAdd(Primitive::kPrimInt, k_header, constant1_); |
Aart Bik | 30efb4e | 2015-07-30 12:14:31 -0700 | [diff] [blame] | 310 | ifTrue->AddInstruction(inc1); |
David Brazdil | badd826 | 2016-02-02 16:28:56 +0000 | [diff] [blame] | 311 | k_body->AddInput(inc1); |
Aart Bik | 30efb4e | 2015-07-30 12:14:31 -0700 | [diff] [blame] | 312 | // False-branch. |
David Brazdil | badd826 | 2016-02-02 16:28:56 +0000 | [diff] [blame] | 313 | HInstruction* inc2 = new (&allocator_) HAdd(Primitive::kPrimInt, k_header, constant1_); |
Aart Bik | 30efb4e | 2015-07-30 12:14:31 -0700 | [diff] [blame] | 314 | ifFalse->AddInstruction(inc2); |
David Brazdil | badd826 | 2016-02-02 16:28:56 +0000 | [diff] [blame] | 315 | k_body->AddInput(inc2); |
Aart Bik | 30efb4e | 2015-07-30 12:14:31 -0700 | [diff] [blame] | 316 | // Merge over a phi. |
David Brazdil | badd826 | 2016-02-02 16:28:56 +0000 | [diff] [blame] | 317 | HInstruction* store = InsertArrayStore(k_body, 0); |
| 318 | k_header->AddInput(k_body); |
Aart Bik | 30efb4e | 2015-07-30 12:14:31 -0700 | [diff] [blame] | 319 | PerformInductionVarAnalysis(); |
| 320 | |
Aart Bik | 471a203 | 2015-09-04 18:22:11 -0700 | [diff] [blame] | 321 | EXPECT_STREQ("((1) * i + (1))", GetInductionInfo(store->InputAt(1), 0).c_str()); |
Aart Bik | 30efb4e | 2015-07-30 12:14:31 -0700 | [diff] [blame] | 322 | } |
| 323 | |
| 324 | TEST_F(InductionVarAnalysisTest, FindTwoWayDerivedInduction) { |
| 325 | // Setup: |
| 326 | // for (int i = 0; i < 100; i++) { |
Aart Bik | e609b7c | 2015-08-27 13:46:58 -0700 | [diff] [blame] | 327 | // if () k = i + 1; |
| 328 | // else k = i + 1; |
| 329 | // a[k] = 0; |
Aart Bik | 30efb4e | 2015-07-30 12:14:31 -0700 | [diff] [blame] | 330 | // } |
| 331 | BuildLoopNest(1); |
| 332 | HBasicBlock* ifTrue; |
| 333 | HBasicBlock* ifFalse; |
David Brazdil | badd826 | 2016-02-02 16:28:56 +0000 | [diff] [blame] | 334 | HPhi* k = BuildIf(0, &ifTrue, &ifFalse); |
| 335 | |
Aart Bik | 30efb4e | 2015-07-30 12:14:31 -0700 | [diff] [blame] | 336 | // True-branch. |
David Brazdil | badd826 | 2016-02-02 16:28:56 +0000 | [diff] [blame] | 337 | HInstruction* inc1 = new (&allocator_) HAdd(Primitive::kPrimInt, basic_[0], constant1_); |
Aart Bik | 30efb4e | 2015-07-30 12:14:31 -0700 | [diff] [blame] | 338 | ifTrue->AddInstruction(inc1); |
David Brazdil | badd826 | 2016-02-02 16:28:56 +0000 | [diff] [blame] | 339 | k->AddInput(inc1); |
Aart Bik | 30efb4e | 2015-07-30 12:14:31 -0700 | [diff] [blame] | 340 | // False-branch. |
David Brazdil | badd826 | 2016-02-02 16:28:56 +0000 | [diff] [blame] | 341 | HInstruction* inc2 = new (&allocator_) HAdd(Primitive::kPrimInt, basic_[0], constant1_); |
Aart Bik | 30efb4e | 2015-07-30 12:14:31 -0700 | [diff] [blame] | 342 | ifFalse->AddInstruction(inc2); |
David Brazdil | badd826 | 2016-02-02 16:28:56 +0000 | [diff] [blame] | 343 | k->AddInput(inc2); |
Aart Bik | 30efb4e | 2015-07-30 12:14:31 -0700 | [diff] [blame] | 344 | // Merge over a phi. |
David Brazdil | badd826 | 2016-02-02 16:28:56 +0000 | [diff] [blame] | 345 | HInstruction* store = InsertArrayStore(k, 0); |
Aart Bik | 30efb4e | 2015-07-30 12:14:31 -0700 | [diff] [blame] | 346 | PerformInductionVarAnalysis(); |
| 347 | |
Aart Bik | 471a203 | 2015-09-04 18:22:11 -0700 | [diff] [blame] | 348 | EXPECT_STREQ("((1) * i + (1))", GetInductionInfo(store->InputAt(1), 0).c_str()); |
Aart Bik | 30efb4e | 2015-07-30 12:14:31 -0700 | [diff] [blame] | 349 | } |
| 350 | |
| 351 | TEST_F(InductionVarAnalysisTest, FindFirstOrderWrapAroundInduction) { |
| 352 | // Setup: |
| 353 | // k = 0; |
| 354 | // for (int i = 0; i < 100; i++) { |
Aart Bik | e609b7c | 2015-08-27 13:46:58 -0700 | [diff] [blame] | 355 | // a[k] = 0; |
| 356 | // k = 100 - i; |
Aart Bik | 30efb4e | 2015-07-30 12:14:31 -0700 | [diff] [blame] | 357 | // } |
| 358 | BuildLoopNest(1); |
David Brazdil | badd826 | 2016-02-02 16:28:56 +0000 | [diff] [blame] | 359 | HPhi* k = InsertLoopPhi(0, 0); |
| 360 | k->AddInput(constant0_); |
| 361 | |
| 362 | HInstruction* store = InsertArrayStore(k, 0); |
Aart Bik | 30efb4e | 2015-07-30 12:14:31 -0700 | [diff] [blame] | 363 | HInstruction *sub = InsertInstruction( |
David Brazdil | badd826 | 2016-02-02 16:28:56 +0000 | [diff] [blame] | 364 | new (&allocator_) HSub(Primitive::kPrimInt, constant100_, basic_[0]), 0); |
| 365 | k->AddInput(sub); |
Aart Bik | 30efb4e | 2015-07-30 12:14:31 -0700 | [diff] [blame] | 366 | PerformInductionVarAnalysis(); |
| 367 | |
Aart Bik | 471a203 | 2015-09-04 18:22:11 -0700 | [diff] [blame] | 368 | EXPECT_STREQ("wrap((0), (( - (1)) * i + (100)))", |
Aart Bik | e609b7c | 2015-08-27 13:46:58 -0700 | [diff] [blame] | 369 | GetInductionInfo(store->InputAt(1), 0).c_str()); |
Aart Bik | 30efb4e | 2015-07-30 12:14:31 -0700 | [diff] [blame] | 370 | } |
| 371 | |
| 372 | TEST_F(InductionVarAnalysisTest, FindSecondOrderWrapAroundInduction) { |
| 373 | // Setup: |
| 374 | // k = 0; |
| 375 | // t = 100; |
| 376 | // for (int i = 0; i < 100; i++) { |
Aart Bik | e609b7c | 2015-08-27 13:46:58 -0700 | [diff] [blame] | 377 | // a[k] = 0; |
| 378 | // k = t; |
| 379 | // t = 100 - i; |
Aart Bik | 30efb4e | 2015-07-30 12:14:31 -0700 | [diff] [blame] | 380 | // } |
| 381 | BuildLoopNest(1); |
David Brazdil | badd826 | 2016-02-02 16:28:56 +0000 | [diff] [blame] | 382 | HPhi* k = InsertLoopPhi(0, 0); |
| 383 | k->AddInput(constant0_); |
| 384 | HPhi* t = InsertLoopPhi(1, 0); |
| 385 | t->AddInput(constant100_); |
| 386 | |
| 387 | HInstruction* store = InsertArrayStore(k, 0); |
| 388 | k->AddInput(t); |
Aart Bik | 30efb4e | 2015-07-30 12:14:31 -0700 | [diff] [blame] | 389 | HInstruction *sub = InsertInstruction( |
David Brazdil | badd826 | 2016-02-02 16:28:56 +0000 | [diff] [blame] | 390 | new (&allocator_) HSub(Primitive::kPrimInt, constant100_, basic_[0], 0), 0); |
| 391 | t->AddInput(sub); |
Aart Bik | 30efb4e | 2015-07-30 12:14:31 -0700 | [diff] [blame] | 392 | PerformInductionVarAnalysis(); |
| 393 | |
Aart Bik | 471a203 | 2015-09-04 18:22:11 -0700 | [diff] [blame] | 394 | EXPECT_STREQ("wrap((0), wrap((100), (( - (1)) * i + (100))))", |
Aart Bik | e609b7c | 2015-08-27 13:46:58 -0700 | [diff] [blame] | 395 | GetInductionInfo(store->InputAt(1), 0).c_str()); |
| 396 | } |
| 397 | |
| 398 | TEST_F(InductionVarAnalysisTest, FindWrapAroundDerivedInduction) { |
| 399 | // Setup: |
| 400 | // k = 0; |
| 401 | // for (int i = 0; i < 100; i++) { |
| 402 | // t = k + 100; |
| 403 | // t = k - 100; |
| 404 | // t = k * 100; |
| 405 | // t = k << 1; |
| 406 | // t = - k; |
| 407 | // k = i << 1; |
| 408 | // } |
| 409 | BuildLoopNest(1); |
David Brazdil | badd826 | 2016-02-02 16:28:56 +0000 | [diff] [blame] | 410 | HPhi* k = InsertLoopPhi(0, 0); |
| 411 | k->AddInput(constant0_); |
| 412 | |
Aart Bik | e609b7c | 2015-08-27 13:46:58 -0700 | [diff] [blame] | 413 | HInstruction *add = InsertInstruction( |
David Brazdil | badd826 | 2016-02-02 16:28:56 +0000 | [diff] [blame] | 414 | new (&allocator_) HAdd(Primitive::kPrimInt, k, constant100_), 0); |
Aart Bik | e609b7c | 2015-08-27 13:46:58 -0700 | [diff] [blame] | 415 | HInstruction *sub = InsertInstruction( |
David Brazdil | badd826 | 2016-02-02 16:28:56 +0000 | [diff] [blame] | 416 | new (&allocator_) HSub(Primitive::kPrimInt, k, constant100_), 0); |
Aart Bik | e609b7c | 2015-08-27 13:46:58 -0700 | [diff] [blame] | 417 | HInstruction *mul = InsertInstruction( |
David Brazdil | badd826 | 2016-02-02 16:28:56 +0000 | [diff] [blame] | 418 | new (&allocator_) HMul(Primitive::kPrimInt, k, constant100_), 0); |
Aart Bik | e609b7c | 2015-08-27 13:46:58 -0700 | [diff] [blame] | 419 | HInstruction *shl = InsertInstruction( |
David Brazdil | badd826 | 2016-02-02 16:28:56 +0000 | [diff] [blame] | 420 | new (&allocator_) HShl(Primitive::kPrimInt, k, constant1_), 0); |
Aart Bik | e609b7c | 2015-08-27 13:46:58 -0700 | [diff] [blame] | 421 | HInstruction *neg = InsertInstruction( |
David Brazdil | badd826 | 2016-02-02 16:28:56 +0000 | [diff] [blame] | 422 | new (&allocator_) HNeg(Primitive::kPrimInt, k), 0); |
| 423 | k->AddInput( |
| 424 | InsertInstruction(new (&allocator_) HShl(Primitive::kPrimInt, basic_[0], constant1_), 0)); |
Aart Bik | e609b7c | 2015-08-27 13:46:58 -0700 | [diff] [blame] | 425 | PerformInductionVarAnalysis(); |
| 426 | |
Aart Bik | 471a203 | 2015-09-04 18:22:11 -0700 | [diff] [blame] | 427 | EXPECT_STREQ("wrap((100), ((2) * i + (100)))", GetInductionInfo(add, 0).c_str()); |
| 428 | EXPECT_STREQ("wrap(((0) - (100)), ((2) * i + ((0) - (100))))", GetInductionInfo(sub, 0).c_str()); |
| 429 | EXPECT_STREQ("wrap((0), (((2) * (100)) * i + (0)))", GetInductionInfo(mul, 0).c_str()); |
| 430 | EXPECT_STREQ("wrap((0), (((2) * (2)) * i + (0)))", GetInductionInfo(shl, 0).c_str()); |
| 431 | EXPECT_STREQ("wrap((0), (( - (2)) * i + (0)))", GetInductionInfo(neg, 0).c_str()); |
Aart Bik | e609b7c | 2015-08-27 13:46:58 -0700 | [diff] [blame] | 432 | } |
| 433 | |
| 434 | TEST_F(InductionVarAnalysisTest, FindPeriodicInduction) { |
| 435 | // Setup: |
| 436 | // k = 0; |
| 437 | // t = 100; |
| 438 | // for (int i = 0; i < 100; i++) { |
| 439 | // a[k] = 0; |
| 440 | // a[t] = 0; |
| 441 | // // Swap t <-> k. |
| 442 | // d = t; |
| 443 | // t = k; |
| 444 | // k = d; |
| 445 | // } |
| 446 | BuildLoopNest(1); |
David Brazdil | badd826 | 2016-02-02 16:28:56 +0000 | [diff] [blame] | 447 | HPhi* k = InsertLoopPhi(0, 0); |
| 448 | k->AddInput(constant0_); |
| 449 | HPhi* t = InsertLoopPhi(1, 0); |
| 450 | t->AddInput(constant100_); |
| 451 | |
| 452 | HInstruction* store1 = InsertArrayStore(k, 0); |
| 453 | HInstruction* store2 = InsertArrayStore(t, 0); |
| 454 | k->AddInput(t); |
| 455 | t->AddInput(k); |
Aart Bik | e609b7c | 2015-08-27 13:46:58 -0700 | [diff] [blame] | 456 | PerformInductionVarAnalysis(); |
| 457 | |
| 458 | EXPECT_STREQ("periodic((0), (100))", GetInductionInfo(store1->InputAt(1), 0).c_str()); |
| 459 | EXPECT_STREQ("periodic((100), (0))", GetInductionInfo(store2->InputAt(1), 0).c_str()); |
| 460 | } |
| 461 | |
| 462 | TEST_F(InductionVarAnalysisTest, FindIdiomaticPeriodicInduction) { |
| 463 | // Setup: |
| 464 | // k = 0; |
| 465 | // for (int i = 0; i < 100; i++) { |
| 466 | // a[k] = 0; |
| 467 | // k = 1 - k; |
| 468 | // } |
| 469 | BuildLoopNest(1); |
David Brazdil | badd826 | 2016-02-02 16:28:56 +0000 | [diff] [blame] | 470 | HPhi* k = InsertLoopPhi(0, 0); |
| 471 | k->AddInput(constant0_); |
| 472 | |
| 473 | HInstruction* store = InsertArrayStore(k, 0); |
Aart Bik | e609b7c | 2015-08-27 13:46:58 -0700 | [diff] [blame] | 474 | HInstruction *sub = InsertInstruction( |
David Brazdil | badd826 | 2016-02-02 16:28:56 +0000 | [diff] [blame] | 475 | new (&allocator_) HSub(Primitive::kPrimInt, constant1_, k), 0); |
| 476 | k->AddInput(sub); |
Aart Bik | e609b7c | 2015-08-27 13:46:58 -0700 | [diff] [blame] | 477 | PerformInductionVarAnalysis(); |
| 478 | |
Aart Bik | 471a203 | 2015-09-04 18:22:11 -0700 | [diff] [blame] | 479 | EXPECT_STREQ("periodic((0), (1))", GetInductionInfo(store->InputAt(1), 0).c_str()); |
| 480 | EXPECT_STREQ("periodic((1), (0))", GetInductionInfo(sub, 0).c_str()); |
Aart Bik | e609b7c | 2015-08-27 13:46:58 -0700 | [diff] [blame] | 481 | } |
| 482 | |
| 483 | TEST_F(InductionVarAnalysisTest, FindDerivedPeriodicInduction) { |
| 484 | // Setup: |
| 485 | // k = 0; |
| 486 | // for (int i = 0; i < 100; i++) { |
| 487 | // k = 1 - k; |
| 488 | // t = k + 100; |
| 489 | // t = k - 100; |
| 490 | // t = k * 100; |
| 491 | // t = k << 1; |
| 492 | // t = - k; |
| 493 | // } |
| 494 | BuildLoopNest(1); |
David Brazdil | badd826 | 2016-02-02 16:28:56 +0000 | [diff] [blame] | 495 | HPhi* k_header = InsertLoopPhi(0, 0); |
| 496 | k_header->AddInput(constant0_); |
| 497 | |
| 498 | HInstruction* k_body = InsertInstruction( |
| 499 | new (&allocator_) HSub(Primitive::kPrimInt, constant1_, k_header), 0); |
| 500 | k_header->AddInput(k_body); |
| 501 | |
Aart Bik | e609b7c | 2015-08-27 13:46:58 -0700 | [diff] [blame] | 502 | // Derived expressions. |
| 503 | HInstruction *add = InsertInstruction( |
David Brazdil | badd826 | 2016-02-02 16:28:56 +0000 | [diff] [blame] | 504 | new (&allocator_) HAdd(Primitive::kPrimInt, k_body, constant100_), 0); |
Aart Bik | e609b7c | 2015-08-27 13:46:58 -0700 | [diff] [blame] | 505 | HInstruction *sub = InsertInstruction( |
David Brazdil | badd826 | 2016-02-02 16:28:56 +0000 | [diff] [blame] | 506 | new (&allocator_) HSub(Primitive::kPrimInt, k_body, constant100_), 0); |
Aart Bik | e609b7c | 2015-08-27 13:46:58 -0700 | [diff] [blame] | 507 | HInstruction *mul = InsertInstruction( |
David Brazdil | badd826 | 2016-02-02 16:28:56 +0000 | [diff] [blame] | 508 | new (&allocator_) HMul(Primitive::kPrimInt, k_body, constant100_), 0); |
Aart Bik | e609b7c | 2015-08-27 13:46:58 -0700 | [diff] [blame] | 509 | HInstruction *shl = InsertInstruction( |
David Brazdil | badd826 | 2016-02-02 16:28:56 +0000 | [diff] [blame] | 510 | new (&allocator_) HShl(Primitive::kPrimInt, k_body, constant1_), 0); |
Aart Bik | e609b7c | 2015-08-27 13:46:58 -0700 | [diff] [blame] | 511 | HInstruction *neg = InsertInstruction( |
David Brazdil | badd826 | 2016-02-02 16:28:56 +0000 | [diff] [blame] | 512 | new (&allocator_) HNeg(Primitive::kPrimInt, k_body), 0); |
Aart Bik | e609b7c | 2015-08-27 13:46:58 -0700 | [diff] [blame] | 513 | PerformInductionVarAnalysis(); |
| 514 | |
Aart Bik | 471a203 | 2015-09-04 18:22:11 -0700 | [diff] [blame] | 515 | EXPECT_STREQ("periodic(((1) + (100)), (100))", GetInductionInfo(add, 0).c_str()); |
| 516 | EXPECT_STREQ("periodic(((1) - (100)), ((0) - (100)))", GetInductionInfo(sub, 0).c_str()); |
| 517 | EXPECT_STREQ("periodic((100), (0))", GetInductionInfo(mul, 0).c_str()); |
| 518 | EXPECT_STREQ("periodic((2), (0))", GetInductionInfo(shl, 0).c_str()); |
| 519 | EXPECT_STREQ("periodic(( - (1)), (0))", GetInductionInfo(neg, 0).c_str()); |
Aart Bik | 30efb4e | 2015-07-30 12:14:31 -0700 | [diff] [blame] | 520 | } |
| 521 | |
| 522 | TEST_F(InductionVarAnalysisTest, FindDeepLoopInduction) { |
| 523 | // Setup: |
| 524 | // k = 0; |
| 525 | // for (int i_0 = 0; i_0 < 100; i_0++) { |
| 526 | // .. |
| 527 | // for (int i_9 = 0; i_9 < 100; i_9++) { |
| 528 | // k = 1 + k; |
| 529 | // a[k] = 0; |
| 530 | // } |
| 531 | // .. |
| 532 | // } |
| 533 | BuildLoopNest(10); |
David Brazdil | badd826 | 2016-02-02 16:28:56 +0000 | [diff] [blame] | 534 | |
| 535 | HPhi* k[10]; |
| 536 | for (int d = 0; d < 10; d++) { |
| 537 | k[d] = InsertLoopPhi(0, d); |
| 538 | } |
| 539 | |
Aart Bik | 30efb4e | 2015-07-30 12:14:31 -0700 | [diff] [blame] | 540 | HInstruction *inc = InsertInstruction( |
David Brazdil | badd826 | 2016-02-02 16:28:56 +0000 | [diff] [blame] | 541 | new (&allocator_) HAdd(Primitive::kPrimInt, constant1_, k[9]), 9); |
| 542 | HInstruction* store = InsertArrayStore(inc, 9); |
| 543 | |
| 544 | for (int d = 0; d < 10; d++) { |
David Brazdil | 6dd10fa | 2016-02-15 17:14:31 +0000 | [diff] [blame] | 545 | k[d]->AddInput((d != 0) ? k[d - 1] : constant0_); |
David Brazdil | badd826 | 2016-02-02 16:28:56 +0000 | [diff] [blame] | 546 | k[d]->AddInput((d != 9) ? k[d + 1] : inc); |
| 547 | } |
Aart Bik | 30efb4e | 2015-07-30 12:14:31 -0700 | [diff] [blame] | 548 | PerformInductionVarAnalysis(); |
| 549 | |
Aart Bik | e609b7c | 2015-08-27 13:46:58 -0700 | [diff] [blame] | 550 | // Avoid exact phi number, since that depends on the SSA building phase. |
| 551 | std::regex r("\\(\\(1\\) \\* i \\+ " |
| 552 | "\\(\\(1\\) \\+ \\(\\d+:Phi\\)\\)\\)"); |
Aart Bik | 30efb4e | 2015-07-30 12:14:31 -0700 | [diff] [blame] | 553 | |
| 554 | for (int d = 0; d < 10; d++) { |
| 555 | if (d == 9) { |
Aart Bik | e609b7c | 2015-08-27 13:46:58 -0700 | [diff] [blame] | 556 | EXPECT_TRUE(std::regex_match(GetInductionInfo(store->InputAt(1), d), r)); |
Aart Bik | 30efb4e | 2015-07-30 12:14:31 -0700 | [diff] [blame] | 557 | } else { |
Aart Bik | e609b7c | 2015-08-27 13:46:58 -0700 | [diff] [blame] | 558 | EXPECT_STREQ("", GetInductionInfo(store->InputAt(1), d).c_str()); |
Aart Bik | 30efb4e | 2015-07-30 12:14:31 -0700 | [diff] [blame] | 559 | } |
Aart Bik | 471a203 | 2015-09-04 18:22:11 -0700 | [diff] [blame] | 560 | EXPECT_STREQ("((1) * i + (1))", GetInductionInfo(increment_[d], d).c_str()); |
Aart Bik | d14c595 | 2015-09-08 15:25:15 -0700 | [diff] [blame] | 561 | // Trip-count. |
Aart Bik | 22f0587 | 2015-10-27 15:56:28 -0700 | [diff] [blame] | 562 | EXPECT_STREQ("((100) (TC-loop) ((0) < (100)))", |
Aart Bik | 9401f53 | 2015-09-28 16:25:56 -0700 | [diff] [blame] | 563 | GetInductionInfo(loop_header_[d]->GetLastInstruction(), d).c_str()); |
Aart Bik | 30efb4e | 2015-07-30 12:14:31 -0700 | [diff] [blame] | 564 | } |
| 565 | } |
| 566 | |
| 567 | } // namespace art |