Aart Bik | d14c595 | 2015-09-08 15:25:15 -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 | |
Aart Bik | d14c595 | 2015-09-08 15:25:15 -0700 | [diff] [blame] | 17 | #include "base/arena_allocator.h" |
| 18 | #include "builder.h" |
Aart Bik | d14c595 | 2015-09-08 15:25:15 -0700 | [diff] [blame] | 19 | #include "induction_var_analysis.h" |
| 20 | #include "induction_var_range.h" |
| 21 | #include "nodes.h" |
| 22 | #include "optimizing_unit_test.h" |
| 23 | |
| 24 | namespace art { |
| 25 | |
| 26 | using Value = InductionVarRange::Value; |
| 27 | |
| 28 | /** |
| 29 | * Fixture class for the InductionVarRange tests. |
| 30 | */ |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 31 | class InductionVarRangeTest : public CommonCompilerTest { |
Aart Bik | d14c595 | 2015-09-08 15:25:15 -0700 | [diff] [blame] | 32 | public: |
Aart Bik | 7d57d7f | 2015-12-09 14:39:48 -0800 | [diff] [blame] | 33 | InductionVarRangeTest() |
| 34 | : pool_(), |
| 35 | allocator_(&pool_), |
| 36 | graph_(CreateGraph(&allocator_)), |
| 37 | iva_(new (&allocator_) HInductionVarAnalysis(graph_)), |
| 38 | range_(iva_) { |
Aart Bik | d14c595 | 2015-09-08 15:25:15 -0700 | [diff] [blame] | 39 | BuildGraph(); |
| 40 | } |
| 41 | |
| 42 | ~InductionVarRangeTest() { } |
| 43 | |
| 44 | void ExpectEqual(Value v1, Value v2) { |
| 45 | EXPECT_EQ(v1.instruction, v2.instruction); |
| 46 | EXPECT_EQ(v1.a_constant, v2.a_constant); |
| 47 | EXPECT_EQ(v1.b_constant, v2.b_constant); |
Aart Bik | b3365e0 | 2015-09-21 14:45:05 -0700 | [diff] [blame] | 48 | EXPECT_EQ(v1.is_known, v2.is_known); |
Aart Bik | d14c595 | 2015-09-08 15:25:15 -0700 | [diff] [blame] | 49 | } |
| 50 | |
Aart Bik | 389b3db | 2015-10-28 14:23:40 -0700 | [diff] [blame] | 51 | // |
| 52 | // Construction methods. |
| 53 | // |
| 54 | |
Aart Bik | d14c595 | 2015-09-08 15:25:15 -0700 | [diff] [blame] | 55 | /** Constructs bare minimum graph. */ |
| 56 | void BuildGraph() { |
| 57 | graph_->SetNumberOfVRegs(1); |
Aart Bik | aec3cce | 2015-10-14 17:44:55 -0700 | [diff] [blame] | 58 | entry_block_ = new (&allocator_) HBasicBlock(graph_); |
| 59 | exit_block_ = new (&allocator_) HBasicBlock(graph_); |
| 60 | graph_->AddBlock(entry_block_); |
| 61 | graph_->AddBlock(exit_block_); |
| 62 | graph_->SetEntryBlock(entry_block_); |
| 63 | graph_->SetExitBlock(exit_block_); |
Aart Bik | 7d57d7f | 2015-12-09 14:39:48 -0800 | [diff] [blame] | 64 | // Two parameters. |
| 65 | x_ = new (&allocator_) HParameterValue(graph_->GetDexFile(), 0, 0, Primitive::kPrimInt); |
| 66 | entry_block_->AddInstruction(x_); |
| 67 | y_ = new (&allocator_) HParameterValue(graph_->GetDexFile(), 0, 0, Primitive::kPrimInt); |
| 68 | entry_block_->AddInstruction(y_); |
Aart Bik | 52be7e7 | 2016-06-23 11:20:41 -0700 | [diff] [blame] | 69 | // Set arbitrary range analysis hint while testing private methods. |
| 70 | SetHint(x_); |
Aart Bik | aec3cce | 2015-10-14 17:44:55 -0700 | [diff] [blame] | 71 | } |
| 72 | |
| 73 | /** Constructs loop with given upper bound. */ |
Aart Bik | 389b3db | 2015-10-28 14:23:40 -0700 | [diff] [blame] | 74 | void BuildLoop(int32_t lower, HInstruction* upper, int32_t stride) { |
Aart Bik | aec3cce | 2015-10-14 17:44:55 -0700 | [diff] [blame] | 75 | // Control flow. |
| 76 | loop_preheader_ = new (&allocator_) HBasicBlock(graph_); |
| 77 | graph_->AddBlock(loop_preheader_); |
| 78 | HBasicBlock* loop_header = new (&allocator_) HBasicBlock(graph_); |
| 79 | graph_->AddBlock(loop_header); |
| 80 | HBasicBlock* loop_body = new (&allocator_) HBasicBlock(graph_); |
| 81 | graph_->AddBlock(loop_body); |
David Brazdil | db51efb | 2015-11-06 01:36:20 +0000 | [diff] [blame] | 82 | HBasicBlock* return_block = new (&allocator_) HBasicBlock(graph_); |
| 83 | graph_->AddBlock(return_block); |
Aart Bik | aec3cce | 2015-10-14 17:44:55 -0700 | [diff] [blame] | 84 | entry_block_->AddSuccessor(loop_preheader_); |
| 85 | loop_preheader_->AddSuccessor(loop_header); |
| 86 | loop_header->AddSuccessor(loop_body); |
David Brazdil | db51efb | 2015-11-06 01:36:20 +0000 | [diff] [blame] | 87 | loop_header->AddSuccessor(return_block); |
Aart Bik | aec3cce | 2015-10-14 17:44:55 -0700 | [diff] [blame] | 88 | loop_body->AddSuccessor(loop_header); |
David Brazdil | db51efb | 2015-11-06 01:36:20 +0000 | [diff] [blame] | 89 | return_block->AddSuccessor(exit_block_); |
Aart Bik | aec3cce | 2015-10-14 17:44:55 -0700 | [diff] [blame] | 90 | // Instructions. |
Aart Bik | aec3cce | 2015-10-14 17:44:55 -0700 | [diff] [blame] | 91 | loop_preheader_->AddInstruction(new (&allocator_) HGoto()); |
David Brazdil | badd826 | 2016-02-02 16:28:56 +0000 | [diff] [blame] | 92 | HPhi* phi = new (&allocator_) HPhi(&allocator_, 0, 0, Primitive::kPrimInt); |
| 93 | loop_header->AddPhi(phi); |
| 94 | phi->AddInput(graph_->GetIntConstant(lower)); // i = l |
Aart Bik | 389b3db | 2015-10-28 14:23:40 -0700 | [diff] [blame] | 95 | if (stride > 0) { |
David Brazdil | badd826 | 2016-02-02 16:28:56 +0000 | [diff] [blame] | 96 | condition_ = new (&allocator_) HLessThan(phi, upper); // i < u |
Aart Bik | 389b3db | 2015-10-28 14:23:40 -0700 | [diff] [blame] | 97 | } else { |
David Brazdil | badd826 | 2016-02-02 16:28:56 +0000 | [diff] [blame] | 98 | condition_ = new (&allocator_) HGreaterThan(phi, upper); // i > u |
Aart Bik | 389b3db | 2015-10-28 14:23:40 -0700 | [diff] [blame] | 99 | } |
Aart Bik | aec3cce | 2015-10-14 17:44:55 -0700 | [diff] [blame] | 100 | loop_header->AddInstruction(condition_); |
Aart Bik | 389b3db | 2015-10-28 14:23:40 -0700 | [diff] [blame] | 101 | loop_header->AddInstruction(new (&allocator_) HIf(condition_)); |
David Brazdil | badd826 | 2016-02-02 16:28:56 +0000 | [diff] [blame] | 102 | increment_ = new (&allocator_) HAdd(Primitive::kPrimInt, phi, graph_->GetIntConstant(stride)); |
| 103 | loop_body->AddInstruction(increment_); // i += s |
| 104 | phi->AddInput(increment_); |
Aart Bik | aec3cce | 2015-10-14 17:44:55 -0700 | [diff] [blame] | 105 | loop_body->AddInstruction(new (&allocator_) HGoto()); |
David Brazdil | db51efb | 2015-11-06 01:36:20 +0000 | [diff] [blame] | 106 | return_block->AddInstruction(new (&allocator_) HReturnVoid()); |
| 107 | exit_block_->AddInstruction(new (&allocator_) HExit()); |
Aart Bik | aec3cce | 2015-10-14 17:44:55 -0700 | [diff] [blame] | 108 | } |
| 109 | |
Aart Bik | 7d57d7f | 2015-12-09 14:39:48 -0800 | [diff] [blame] | 110 | /** Constructs SSA and performs induction variable analysis. */ |
Aart Bik | aec3cce | 2015-10-14 17:44:55 -0700 | [diff] [blame] | 111 | void PerformInductionVarAnalysis() { |
David Brazdil | badd826 | 2016-02-02 16:28:56 +0000 | [diff] [blame] | 112 | graph_->BuildDominatorTree(); |
Aart Bik | aec3cce | 2015-10-14 17:44:55 -0700 | [diff] [blame] | 113 | iva_->Run(); |
Aart Bik | d14c595 | 2015-09-08 15:25:15 -0700 | [diff] [blame] | 114 | } |
| 115 | |
Aart Bik | 52be7e7 | 2016-06-23 11:20:41 -0700 | [diff] [blame] | 116 | /** Sets hint. */ |
| 117 | void SetHint(HInstruction* hint) { |
| 118 | range_.chase_hint_ = hint; |
| 119 | } |
| 120 | |
Aart Bik | d14c595 | 2015-09-08 15:25:15 -0700 | [diff] [blame] | 121 | /** Constructs an invariant. */ |
| 122 | HInductionVarAnalysis::InductionInfo* CreateInvariant(char opc, |
| 123 | HInductionVarAnalysis::InductionInfo* a, |
| 124 | HInductionVarAnalysis::InductionInfo* b) { |
| 125 | HInductionVarAnalysis::InductionOp op; |
| 126 | switch (opc) { |
| 127 | case '+': op = HInductionVarAnalysis::kAdd; break; |
| 128 | case '-': op = HInductionVarAnalysis::kSub; break; |
| 129 | case 'n': op = HInductionVarAnalysis::kNeg; break; |
| 130 | case '*': op = HInductionVarAnalysis::kMul; break; |
| 131 | case '/': op = HInductionVarAnalysis::kDiv; break; |
Aart Bik | 52be7e7 | 2016-06-23 11:20:41 -0700 | [diff] [blame] | 132 | case '<': op = HInductionVarAnalysis::kLT; break; |
Aart Bik | d14c595 | 2015-09-08 15:25:15 -0700 | [diff] [blame] | 133 | default: op = HInductionVarAnalysis::kNop; break; |
| 134 | } |
| 135 | return iva_->CreateInvariantOp(op, a, b); |
| 136 | } |
| 137 | |
| 138 | /** Constructs a fetch. */ |
| 139 | HInductionVarAnalysis::InductionInfo* CreateFetch(HInstruction* fetch) { |
| 140 | return iva_->CreateInvariantFetch(fetch); |
| 141 | } |
| 142 | |
| 143 | /** Constructs a constant. */ |
| 144 | HInductionVarAnalysis::InductionInfo* CreateConst(int32_t c) { |
| 145 | return CreateFetch(graph_->GetIntConstant(c)); |
| 146 | } |
| 147 | |
Aart Bik | 52be7e7 | 2016-06-23 11:20:41 -0700 | [diff] [blame] | 148 | /** Constructs a constant trip-count. */ |
Aart Bik | 389b3db | 2015-10-28 14:23:40 -0700 | [diff] [blame] | 149 | HInductionVarAnalysis::InductionInfo* CreateTripCount(int32_t tc, bool in_loop, bool safe) { |
Aart Bik | 52be7e7 | 2016-06-23 11:20:41 -0700 | [diff] [blame] | 150 | HInductionVarAnalysis::InductionOp op = HInductionVarAnalysis::kTripCountInBodyUnsafe; |
Aart Bik | 389b3db | 2015-10-28 14:23:40 -0700 | [diff] [blame] | 151 | if (in_loop && safe) { |
Aart Bik | 52be7e7 | 2016-06-23 11:20:41 -0700 | [diff] [blame] | 152 | op = HInductionVarAnalysis::kTripCountInLoop; |
Aart Bik | 389b3db | 2015-10-28 14:23:40 -0700 | [diff] [blame] | 153 | } else if (in_loop) { |
Aart Bik | 52be7e7 | 2016-06-23 11:20:41 -0700 | [diff] [blame] | 154 | op = HInductionVarAnalysis::kTripCountInLoopUnsafe; |
Aart Bik | 389b3db | 2015-10-28 14:23:40 -0700 | [diff] [blame] | 155 | } else if (safe) { |
Aart Bik | 52be7e7 | 2016-06-23 11:20:41 -0700 | [diff] [blame] | 156 | op = HInductionVarAnalysis::kTripCountInBody; |
Aart Bik | 389b3db | 2015-10-28 14:23:40 -0700 | [diff] [blame] | 157 | } |
Aart Bik | 52be7e7 | 2016-06-23 11:20:41 -0700 | [diff] [blame] | 158 | // Return TC with taken-test 0 < TC. |
| 159 | return iva_->CreateTripCount(op, |
| 160 | CreateConst(tc), |
| 161 | CreateInvariant('<', CreateConst(0), CreateConst(tc)), |
| 162 | Primitive::kPrimInt); |
Aart Bik | d14c595 | 2015-09-08 15:25:15 -0700 | [diff] [blame] | 163 | } |
| 164 | |
| 165 | /** Constructs a linear a * i + b induction. */ |
| 166 | HInductionVarAnalysis::InductionInfo* CreateLinear(int32_t a, int32_t b) { |
Aart Bik | 0d345cf | 2016-03-16 10:49:38 -0700 | [diff] [blame] | 167 | return iva_->CreateInduction( |
| 168 | HInductionVarAnalysis::kLinear, CreateConst(a), CreateConst(b), Primitive::kPrimInt); |
Aart Bik | d14c595 | 2015-09-08 15:25:15 -0700 | [diff] [blame] | 169 | } |
| 170 | |
| 171 | /** Constructs a range [lo, hi] using a periodic induction. */ |
| 172 | HInductionVarAnalysis::InductionInfo* CreateRange(int32_t lo, int32_t hi) { |
| 173 | return iva_->CreateInduction( |
Aart Bik | 0d345cf | 2016-03-16 10:49:38 -0700 | [diff] [blame] | 174 | HInductionVarAnalysis::kPeriodic, CreateConst(lo), CreateConst(hi), Primitive::kPrimInt); |
Aart Bik | d14c595 | 2015-09-08 15:25:15 -0700 | [diff] [blame] | 175 | } |
| 176 | |
Aart Bik | 389b3db | 2015-10-28 14:23:40 -0700 | [diff] [blame] | 177 | /** Constructs a wrap-around induction consisting of a constant, followed info */ |
| 178 | HInductionVarAnalysis::InductionInfo* CreateWrapAround( |
| 179 | int32_t initial, |
| 180 | HInductionVarAnalysis::InductionInfo* info) { |
Aart Bik | 0d345cf | 2016-03-16 10:49:38 -0700 | [diff] [blame] | 181 | return iva_->CreateInduction( |
| 182 | HInductionVarAnalysis::kWrapAround, CreateConst(initial), info, Primitive::kPrimInt); |
Aart Bik | 389b3db | 2015-10-28 14:23:40 -0700 | [diff] [blame] | 183 | } |
| 184 | |
Aart Bik | d14c595 | 2015-09-08 15:25:15 -0700 | [diff] [blame] | 185 | /** Constructs a wrap-around induction consisting of a constant, followed by a range. */ |
| 186 | HInductionVarAnalysis::InductionInfo* CreateWrapAround(int32_t initial, int32_t lo, int32_t hi) { |
Aart Bik | 389b3db | 2015-10-28 14:23:40 -0700 | [diff] [blame] | 187 | return CreateWrapAround(initial, CreateRange(lo, hi)); |
Aart Bik | d14c595 | 2015-09-08 15:25:15 -0700 | [diff] [blame] | 188 | } |
| 189 | |
| 190 | // |
| 191 | // Relay methods. |
| 192 | // |
| 193 | |
Aart Bik | 389b3db | 2015-10-28 14:23:40 -0700 | [diff] [blame] | 194 | bool NeedsTripCount(HInductionVarAnalysis::InductionInfo* info) { |
Aart Bik | 7d57d7f | 2015-12-09 14:39:48 -0800 | [diff] [blame] | 195 | return range_.NeedsTripCount(info); |
Aart Bik | 389b3db | 2015-10-28 14:23:40 -0700 | [diff] [blame] | 196 | } |
| 197 | |
| 198 | bool IsBodyTripCount(HInductionVarAnalysis::InductionInfo* trip) { |
Aart Bik | 7d57d7f | 2015-12-09 14:39:48 -0800 | [diff] [blame] | 199 | return range_.IsBodyTripCount(trip); |
Aart Bik | 389b3db | 2015-10-28 14:23:40 -0700 | [diff] [blame] | 200 | } |
| 201 | |
| 202 | bool IsUnsafeTripCount(HInductionVarAnalysis::InductionInfo* trip) { |
Aart Bik | 7d57d7f | 2015-12-09 14:39:48 -0800 | [diff] [blame] | 203 | return range_.IsUnsafeTripCount(trip); |
Aart Bik | 389b3db | 2015-10-28 14:23:40 -0700 | [diff] [blame] | 204 | } |
| 205 | |
Aart Bik | d14c595 | 2015-09-08 15:25:15 -0700 | [diff] [blame] | 206 | Value GetMin(HInductionVarAnalysis::InductionInfo* info, |
Aart Bik | 52be7e7 | 2016-06-23 11:20:41 -0700 | [diff] [blame] | 207 | HInductionVarAnalysis::InductionInfo* trip) { |
| 208 | return range_.GetVal(info, trip, /* in_body */ true, /* is_min */ true); |
Aart Bik | d14c595 | 2015-09-08 15:25:15 -0700 | [diff] [blame] | 209 | } |
| 210 | |
| 211 | Value GetMax(HInductionVarAnalysis::InductionInfo* info, |
Aart Bik | 52be7e7 | 2016-06-23 11:20:41 -0700 | [diff] [blame] | 212 | HInductionVarAnalysis::InductionInfo* trip) { |
| 213 | return range_.GetVal(info, trip, /* in_body */ true, /* is_min */ false); |
Aart Bik | d14c595 | 2015-09-08 15:25:15 -0700 | [diff] [blame] | 214 | } |
| 215 | |
| 216 | Value GetMul(HInductionVarAnalysis::InductionInfo* info1, |
Aart Bik | b3365e0 | 2015-09-21 14:45:05 -0700 | [diff] [blame] | 217 | HInductionVarAnalysis::InductionInfo* info2, |
| 218 | bool is_min) { |
Aart Bik | 7d57d7f | 2015-12-09 14:39:48 -0800 | [diff] [blame] | 219 | return range_.GetMul(info1, info2, nullptr, /* in_body */ true, is_min); |
Aart Bik | d14c595 | 2015-09-08 15:25:15 -0700 | [diff] [blame] | 220 | } |
| 221 | |
| 222 | Value GetDiv(HInductionVarAnalysis::InductionInfo* info1, |
Aart Bik | b3365e0 | 2015-09-21 14:45:05 -0700 | [diff] [blame] | 223 | HInductionVarAnalysis::InductionInfo* info2, |
| 224 | bool is_min) { |
Aart Bik | 7d57d7f | 2015-12-09 14:39:48 -0800 | [diff] [blame] | 225 | return range_.GetDiv(info1, info2, nullptr, /* in_body */ true, is_min); |
Aart Bik | 9401f53 | 2015-09-28 16:25:56 -0700 | [diff] [blame] | 226 | } |
| 227 | |
Aart Bik | 97412c92 | 2016-02-19 20:14:38 -0800 | [diff] [blame] | 228 | bool IsExact(HInductionVarAnalysis::InductionInfo* info, int64_t* value) { |
| 229 | return range_.IsConstant(info, InductionVarRange::kExact, value); |
| 230 | } |
| 231 | |
| 232 | bool IsAtMost(HInductionVarAnalysis::InductionInfo* info, int64_t* value) { |
| 233 | return range_.IsConstant(info, InductionVarRange::kAtMost, value); |
| 234 | } |
| 235 | |
| 236 | bool IsAtLeast(HInductionVarAnalysis::InductionInfo* info, int64_t* value) { |
| 237 | return range_.IsConstant(info, InductionVarRange::kAtLeast, value); |
Aart Bik | d14c595 | 2015-09-08 15:25:15 -0700 | [diff] [blame] | 238 | } |
| 239 | |
Aart Bik | 7d57d7f | 2015-12-09 14:39:48 -0800 | [diff] [blame] | 240 | Value AddValue(Value v1, Value v2) { return range_.AddValue(v1, v2); } |
| 241 | Value SubValue(Value v1, Value v2) { return range_.SubValue(v1, v2); } |
| 242 | Value MulValue(Value v1, Value v2) { return range_.MulValue(v1, v2); } |
| 243 | Value DivValue(Value v1, Value v2) { return range_.DivValue(v1, v2); } |
| 244 | Value MinValue(Value v1, Value v2) { return range_.MergeVal(v1, v2, true); } |
| 245 | Value MaxValue(Value v1, Value v2) { return range_.MergeVal(v1, v2, false); } |
Aart Bik | d14c595 | 2015-09-08 15:25:15 -0700 | [diff] [blame] | 246 | |
| 247 | // General building fields. |
| 248 | ArenaPool pool_; |
| 249 | ArenaAllocator allocator_; |
| 250 | HGraph* graph_; |
Aart Bik | aec3cce | 2015-10-14 17:44:55 -0700 | [diff] [blame] | 251 | HBasicBlock* entry_block_; |
| 252 | HBasicBlock* exit_block_; |
| 253 | HBasicBlock* loop_preheader_; |
Aart Bik | d14c595 | 2015-09-08 15:25:15 -0700 | [diff] [blame] | 254 | HInductionVarAnalysis* iva_; |
Aart Bik | 7d57d7f | 2015-12-09 14:39:48 -0800 | [diff] [blame] | 255 | InductionVarRange range_; |
Aart Bik | d14c595 | 2015-09-08 15:25:15 -0700 | [diff] [blame] | 256 | |
Aart Bik | aec3cce | 2015-10-14 17:44:55 -0700 | [diff] [blame] | 257 | // Instructions. |
| 258 | HInstruction* condition_; |
| 259 | HInstruction* increment_; |
Aart Bik | 7d57d7f | 2015-12-09 14:39:48 -0800 | [diff] [blame] | 260 | HInstruction* x_; |
| 261 | HInstruction* y_; |
Aart Bik | d14c595 | 2015-09-08 15:25:15 -0700 | [diff] [blame] | 262 | }; |
| 263 | |
| 264 | // |
Aart Bik | 7d57d7f | 2015-12-09 14:39:48 -0800 | [diff] [blame] | 265 | // Tests on private methods. |
Aart Bik | d14c595 | 2015-09-08 15:25:15 -0700 | [diff] [blame] | 266 | // |
| 267 | |
Aart Bik | 97412c92 | 2016-02-19 20:14:38 -0800 | [diff] [blame] | 268 | TEST_F(InductionVarRangeTest, IsConstant) { |
| 269 | int64_t value; |
| 270 | // Constant. |
| 271 | EXPECT_TRUE(IsExact(CreateConst(12345), &value)); |
| 272 | EXPECT_EQ(12345, value); |
| 273 | EXPECT_TRUE(IsAtMost(CreateConst(12345), &value)); |
| 274 | EXPECT_EQ(12345, value); |
| 275 | EXPECT_TRUE(IsAtLeast(CreateConst(12345), &value)); |
| 276 | EXPECT_EQ(12345, value); |
| 277 | // Constant trivial range. |
| 278 | EXPECT_TRUE(IsExact(CreateRange(111, 111), &value)); |
| 279 | EXPECT_EQ(111, value); |
| 280 | EXPECT_TRUE(IsAtMost(CreateRange(111, 111), &value)); |
| 281 | EXPECT_EQ(111, value); |
| 282 | EXPECT_TRUE(IsAtLeast(CreateRange(111, 111), &value)); |
| 283 | EXPECT_EQ(111, value); |
| 284 | // Constant non-trivial range. |
| 285 | EXPECT_FALSE(IsExact(CreateRange(11, 22), &value)); |
| 286 | EXPECT_TRUE(IsAtMost(CreateRange(11, 22), &value)); |
| 287 | EXPECT_EQ(22, value); |
| 288 | EXPECT_TRUE(IsAtLeast(CreateRange(11, 22), &value)); |
| 289 | EXPECT_EQ(11, value); |
| 290 | // Symbolic. |
| 291 | EXPECT_FALSE(IsExact(CreateFetch(x_), &value)); |
| 292 | EXPECT_FALSE(IsAtMost(CreateFetch(x_), &value)); |
| 293 | EXPECT_FALSE(IsAtLeast(CreateFetch(x_), &value)); |
| 294 | } |
| 295 | |
Aart Bik | 389b3db | 2015-10-28 14:23:40 -0700 | [diff] [blame] | 296 | TEST_F(InductionVarRangeTest, TripCountProperties) { |
| 297 | EXPECT_FALSE(NeedsTripCount(nullptr)); |
| 298 | EXPECT_FALSE(NeedsTripCount(CreateConst(1))); |
| 299 | EXPECT_TRUE(NeedsTripCount(CreateLinear(1, 1))); |
| 300 | EXPECT_FALSE(NeedsTripCount(CreateWrapAround(1, 2, 3))); |
| 301 | EXPECT_TRUE(NeedsTripCount(CreateWrapAround(1, CreateLinear(1, 1)))); |
| 302 | |
| 303 | EXPECT_FALSE(IsBodyTripCount(nullptr)); |
| 304 | EXPECT_FALSE(IsBodyTripCount(CreateTripCount(100, true, true))); |
| 305 | EXPECT_FALSE(IsBodyTripCount(CreateTripCount(100, true, false))); |
| 306 | EXPECT_TRUE(IsBodyTripCount(CreateTripCount(100, false, true))); |
| 307 | EXPECT_TRUE(IsBodyTripCount(CreateTripCount(100, false, false))); |
| 308 | |
| 309 | EXPECT_FALSE(IsUnsafeTripCount(nullptr)); |
| 310 | EXPECT_FALSE(IsUnsafeTripCount(CreateTripCount(100, true, true))); |
| 311 | EXPECT_TRUE(IsUnsafeTripCount(CreateTripCount(100, true, false))); |
| 312 | EXPECT_FALSE(IsUnsafeTripCount(CreateTripCount(100, false, true))); |
| 313 | EXPECT_TRUE(IsUnsafeTripCount(CreateTripCount(100, false, false))); |
| 314 | } |
| 315 | |
Aart Bik | d14c595 | 2015-09-08 15:25:15 -0700 | [diff] [blame] | 316 | TEST_F(InductionVarRangeTest, GetMinMaxNull) { |
Aart Bik | b3365e0 | 2015-09-21 14:45:05 -0700 | [diff] [blame] | 317 | ExpectEqual(Value(), GetMin(nullptr, nullptr)); |
| 318 | ExpectEqual(Value(), GetMax(nullptr, nullptr)); |
Aart Bik | d14c595 | 2015-09-08 15:25:15 -0700 | [diff] [blame] | 319 | } |
| 320 | |
| 321 | TEST_F(InductionVarRangeTest, GetMinMaxAdd) { |
| 322 | ExpectEqual(Value(12), |
| 323 | GetMin(CreateInvariant('+', CreateConst(2), CreateRange(10, 20)), nullptr)); |
| 324 | ExpectEqual(Value(22), |
| 325 | GetMax(CreateInvariant('+', CreateConst(2), CreateRange(10, 20)), nullptr)); |
Aart Bik | 7d57d7f | 2015-12-09 14:39:48 -0800 | [diff] [blame] | 326 | ExpectEqual(Value(x_, 1, -20), |
| 327 | GetMin(CreateInvariant('+', CreateFetch(x_), CreateRange(-20, -10)), nullptr)); |
| 328 | ExpectEqual(Value(x_, 1, -10), |
| 329 | GetMax(CreateInvariant('+', CreateFetch(x_), CreateRange(-20, -10)), nullptr)); |
| 330 | ExpectEqual(Value(x_, 1, 10), |
| 331 | GetMin(CreateInvariant('+', CreateRange(10, 20), CreateFetch(x_)), nullptr)); |
| 332 | ExpectEqual(Value(x_, 1, 20), |
| 333 | GetMax(CreateInvariant('+', CreateRange(10, 20), CreateFetch(x_)), nullptr)); |
Aart Bik | d14c595 | 2015-09-08 15:25:15 -0700 | [diff] [blame] | 334 | ExpectEqual(Value(5), |
| 335 | GetMin(CreateInvariant('+', CreateRange(-5, -1), CreateRange(10, 20)), nullptr)); |
| 336 | ExpectEqual(Value(19), |
| 337 | GetMax(CreateInvariant('+', CreateRange(-5, -1), CreateRange(10, 20)), nullptr)); |
| 338 | } |
| 339 | |
| 340 | TEST_F(InductionVarRangeTest, GetMinMaxSub) { |
| 341 | ExpectEqual(Value(-18), |
| 342 | GetMin(CreateInvariant('-', CreateConst(2), CreateRange(10, 20)), nullptr)); |
| 343 | ExpectEqual(Value(-8), |
| 344 | GetMax(CreateInvariant('-', CreateConst(2), CreateRange(10, 20)), nullptr)); |
Aart Bik | 7d57d7f | 2015-12-09 14:39:48 -0800 | [diff] [blame] | 345 | ExpectEqual(Value(x_, 1, 10), |
| 346 | GetMin(CreateInvariant('-', CreateFetch(x_), CreateRange(-20, -10)), nullptr)); |
| 347 | ExpectEqual(Value(x_, 1, 20), |
| 348 | GetMax(CreateInvariant('-', CreateFetch(x_), CreateRange(-20, -10)), nullptr)); |
| 349 | ExpectEqual(Value(x_, -1, 10), |
| 350 | GetMin(CreateInvariant('-', CreateRange(10, 20), CreateFetch(x_)), nullptr)); |
| 351 | ExpectEqual(Value(x_, -1, 20), |
| 352 | GetMax(CreateInvariant('-', CreateRange(10, 20), CreateFetch(x_)), nullptr)); |
Aart Bik | d14c595 | 2015-09-08 15:25:15 -0700 | [diff] [blame] | 353 | ExpectEqual(Value(-25), |
| 354 | GetMin(CreateInvariant('-', CreateRange(-5, -1), CreateRange(10, 20)), nullptr)); |
| 355 | ExpectEqual(Value(-11), |
| 356 | GetMax(CreateInvariant('-', CreateRange(-5, -1), CreateRange(10, 20)), nullptr)); |
| 357 | } |
| 358 | |
| 359 | TEST_F(InductionVarRangeTest, GetMinMaxNeg) { |
| 360 | ExpectEqual(Value(-20), GetMin(CreateInvariant('n', nullptr, CreateRange(10, 20)), nullptr)); |
| 361 | ExpectEqual(Value(-10), GetMax(CreateInvariant('n', nullptr, CreateRange(10, 20)), nullptr)); |
| 362 | ExpectEqual(Value(10), GetMin(CreateInvariant('n', nullptr, CreateRange(-20, -10)), nullptr)); |
| 363 | ExpectEqual(Value(20), GetMax(CreateInvariant('n', nullptr, CreateRange(-20, -10)), nullptr)); |
Aart Bik | 7d57d7f | 2015-12-09 14:39:48 -0800 | [diff] [blame] | 364 | ExpectEqual(Value(x_, -1, 0), GetMin(CreateInvariant('n', nullptr, CreateFetch(x_)), nullptr)); |
| 365 | ExpectEqual(Value(x_, -1, 0), GetMax(CreateInvariant('n', nullptr, CreateFetch(x_)), nullptr)); |
Aart Bik | d14c595 | 2015-09-08 15:25:15 -0700 | [diff] [blame] | 366 | } |
| 367 | |
| 368 | TEST_F(InductionVarRangeTest, GetMinMaxMul) { |
| 369 | ExpectEqual(Value(20), |
| 370 | GetMin(CreateInvariant('*', CreateConst(2), CreateRange(10, 20)), nullptr)); |
| 371 | ExpectEqual(Value(40), |
| 372 | GetMax(CreateInvariant('*', CreateConst(2), CreateRange(10, 20)), nullptr)); |
| 373 | } |
| 374 | |
| 375 | TEST_F(InductionVarRangeTest, GetMinMaxDiv) { |
| 376 | ExpectEqual(Value(3), |
| 377 | GetMin(CreateInvariant('/', CreateRange(12, 20), CreateConst(4)), nullptr)); |
| 378 | ExpectEqual(Value(5), |
| 379 | GetMax(CreateInvariant('/', CreateRange(12, 20), CreateConst(4)), nullptr)); |
| 380 | } |
| 381 | |
| 382 | TEST_F(InductionVarRangeTest, GetMinMaxConstant) { |
| 383 | ExpectEqual(Value(12345), GetMin(CreateConst(12345), nullptr)); |
| 384 | ExpectEqual(Value(12345), GetMax(CreateConst(12345), nullptr)); |
| 385 | } |
| 386 | |
| 387 | TEST_F(InductionVarRangeTest, GetMinMaxFetch) { |
Aart Bik | 7d57d7f | 2015-12-09 14:39:48 -0800 | [diff] [blame] | 388 | ExpectEqual(Value(x_, 1, 0), GetMin(CreateFetch(x_), nullptr)); |
| 389 | ExpectEqual(Value(x_, 1, 0), GetMax(CreateFetch(x_), nullptr)); |
Aart Bik | d14c595 | 2015-09-08 15:25:15 -0700 | [diff] [blame] | 390 | } |
| 391 | |
| 392 | TEST_F(InductionVarRangeTest, GetMinMaxLinear) { |
Aart Bik | 389b3db | 2015-10-28 14:23:40 -0700 | [diff] [blame] | 393 | ExpectEqual(Value(20), GetMin(CreateLinear(10, 20), CreateTripCount(100, true, true))); |
| 394 | ExpectEqual(Value(1010), GetMax(CreateLinear(10, 20), CreateTripCount(100, true, true))); |
| 395 | ExpectEqual(Value(-970), GetMin(CreateLinear(-10, 20), CreateTripCount(100, true, true))); |
| 396 | ExpectEqual(Value(20), GetMax(CreateLinear(-10, 20), CreateTripCount(100, true, true))); |
Aart Bik | d14c595 | 2015-09-08 15:25:15 -0700 | [diff] [blame] | 397 | } |
| 398 | |
| 399 | TEST_F(InductionVarRangeTest, GetMinMaxWrapAround) { |
| 400 | ExpectEqual(Value(-5), GetMin(CreateWrapAround(-5, -1, 10), nullptr)); |
| 401 | ExpectEqual(Value(10), GetMax(CreateWrapAround(-5, -1, 10), nullptr)); |
| 402 | ExpectEqual(Value(-1), GetMin(CreateWrapAround(2, -1, 10), nullptr)); |
| 403 | ExpectEqual(Value(10), GetMax(CreateWrapAround(2, -1, 10), nullptr)); |
| 404 | ExpectEqual(Value(-1), GetMin(CreateWrapAround(20, -1, 10), nullptr)); |
| 405 | ExpectEqual(Value(20), GetMax(CreateWrapAround(20, -1, 10), nullptr)); |
| 406 | } |
| 407 | |
| 408 | TEST_F(InductionVarRangeTest, GetMinMaxPeriodic) { |
| 409 | ExpectEqual(Value(-2), GetMin(CreateRange(-2, 99), nullptr)); |
| 410 | ExpectEqual(Value(99), GetMax(CreateRange(-2, 99), nullptr)); |
| 411 | } |
| 412 | |
| 413 | TEST_F(InductionVarRangeTest, GetMulMin) { |
Aart Bik | 97412c92 | 2016-02-19 20:14:38 -0800 | [diff] [blame] | 414 | ExpectEqual(Value(-14), GetMul(CreateConst(2), CreateRange(-7, 8), true)); |
| 415 | ExpectEqual(Value(-16), GetMul(CreateConst(-2), CreateRange(-7, 8), true)); |
| 416 | ExpectEqual(Value(-14), GetMul(CreateRange(-7, 8), CreateConst(2), true)); |
| 417 | ExpectEqual(Value(-16), GetMul(CreateRange(-7, 8), CreateConst(-2), true)); |
Aart Bik | b3365e0 | 2015-09-21 14:45:05 -0700 | [diff] [blame] | 418 | ExpectEqual(Value(6), GetMul(CreateRange(2, 10), CreateRange(3, 5), true)); |
| 419 | ExpectEqual(Value(-50), GetMul(CreateRange(2, 10), CreateRange(-5, -3), true)); |
Aart Bik | 7d57d7f | 2015-12-09 14:39:48 -0800 | [diff] [blame] | 420 | ExpectEqual(Value(), GetMul(CreateRange(2, 10), CreateRange(-1, 1), true)); |
Aart Bik | b3365e0 | 2015-09-21 14:45:05 -0700 | [diff] [blame] | 421 | ExpectEqual(Value(-50), GetMul(CreateRange(-10, -2), CreateRange(3, 5), true)); |
| 422 | ExpectEqual(Value(6), GetMul(CreateRange(-10, -2), CreateRange(-5, -3), true)); |
Aart Bik | 7d57d7f | 2015-12-09 14:39:48 -0800 | [diff] [blame] | 423 | ExpectEqual(Value(), GetMul(CreateRange(-10, -2), CreateRange(-1, 1), true)); |
| 424 | ExpectEqual(Value(), GetMul(CreateRange(-1, 1), CreateRange(2, 10), true)); |
| 425 | ExpectEqual(Value(), GetMul(CreateRange(-1, 1), CreateRange(-10, -2), true)); |
| 426 | ExpectEqual(Value(), GetMul(CreateRange(-1, 1), CreateRange(-1, 1), true)); |
Aart Bik | d14c595 | 2015-09-08 15:25:15 -0700 | [diff] [blame] | 427 | } |
| 428 | |
| 429 | TEST_F(InductionVarRangeTest, GetMulMax) { |
Aart Bik | 97412c92 | 2016-02-19 20:14:38 -0800 | [diff] [blame] | 430 | ExpectEqual(Value(16), GetMul(CreateConst(2), CreateRange(-7, 8), false)); |
| 431 | ExpectEqual(Value(14), GetMul(CreateConst(-2), CreateRange(-7, 8), false)); |
| 432 | ExpectEqual(Value(16), GetMul(CreateRange(-7, 8), CreateConst(2), false)); |
| 433 | ExpectEqual(Value(14), GetMul(CreateRange(-7, 8), CreateConst(-2), false)); |
Aart Bik | b3365e0 | 2015-09-21 14:45:05 -0700 | [diff] [blame] | 434 | ExpectEqual(Value(50), GetMul(CreateRange(2, 10), CreateRange(3, 5), false)); |
| 435 | ExpectEqual(Value(-6), GetMul(CreateRange(2, 10), CreateRange(-5, -3), false)); |
Aart Bik | 7d57d7f | 2015-12-09 14:39:48 -0800 | [diff] [blame] | 436 | ExpectEqual(Value(), GetMul(CreateRange(2, 10), CreateRange(-1, 1), false)); |
Aart Bik | b3365e0 | 2015-09-21 14:45:05 -0700 | [diff] [blame] | 437 | ExpectEqual(Value(-6), GetMul(CreateRange(-10, -2), CreateRange(3, 5), false)); |
| 438 | ExpectEqual(Value(50), GetMul(CreateRange(-10, -2), CreateRange(-5, -3), false)); |
Aart Bik | 7d57d7f | 2015-12-09 14:39:48 -0800 | [diff] [blame] | 439 | ExpectEqual(Value(), GetMul(CreateRange(-10, -2), CreateRange(-1, 1), false)); |
| 440 | ExpectEqual(Value(), GetMul(CreateRange(-1, 1), CreateRange(2, 10), false)); |
| 441 | ExpectEqual(Value(), GetMul(CreateRange(-1, 1), CreateRange(-10, -2), false)); |
| 442 | ExpectEqual(Value(), GetMul(CreateRange(-1, 1), CreateRange(-1, 1), false)); |
Aart Bik | d14c595 | 2015-09-08 15:25:15 -0700 | [diff] [blame] | 443 | } |
| 444 | |
| 445 | TEST_F(InductionVarRangeTest, GetDivMin) { |
Aart Bik | 97412c92 | 2016-02-19 20:14:38 -0800 | [diff] [blame] | 446 | ExpectEqual(Value(-5), GetDiv(CreateRange(-10, 20), CreateConst(2), true)); |
| 447 | ExpectEqual(Value(-10), GetDiv(CreateRange(-10, 20), CreateConst(-2), true)); |
Aart Bik | b3365e0 | 2015-09-21 14:45:05 -0700 | [diff] [blame] | 448 | ExpectEqual(Value(10), GetDiv(CreateRange(40, 1000), CreateRange(2, 4), true)); |
| 449 | ExpectEqual(Value(-500), GetDiv(CreateRange(40, 1000), CreateRange(-4, -2), true)); |
Aart Bik | 7d57d7f | 2015-12-09 14:39:48 -0800 | [diff] [blame] | 450 | ExpectEqual(Value(), GetDiv(CreateRange(40, 1000), CreateRange(-1, 1), true)); |
Aart Bik | b3365e0 | 2015-09-21 14:45:05 -0700 | [diff] [blame] | 451 | ExpectEqual(Value(-500), GetDiv(CreateRange(-1000, -40), CreateRange(2, 4), true)); |
| 452 | ExpectEqual(Value(10), GetDiv(CreateRange(-1000, -40), CreateRange(-4, -2), true)); |
Aart Bik | 7d57d7f | 2015-12-09 14:39:48 -0800 | [diff] [blame] | 453 | ExpectEqual(Value(), GetDiv(CreateRange(-1000, -40), CreateRange(-1, 1), true)); |
| 454 | ExpectEqual(Value(), GetDiv(CreateRange(-1, 1), CreateRange(40, 1000), true)); |
| 455 | ExpectEqual(Value(), GetDiv(CreateRange(-1, 1), CreateRange(-1000, -40), true)); |
| 456 | ExpectEqual(Value(), GetDiv(CreateRange(-1, 1), CreateRange(-1, 1), true)); |
Aart Bik | d14c595 | 2015-09-08 15:25:15 -0700 | [diff] [blame] | 457 | } |
| 458 | |
| 459 | TEST_F(InductionVarRangeTest, GetDivMax) { |
Aart Bik | 97412c92 | 2016-02-19 20:14:38 -0800 | [diff] [blame] | 460 | ExpectEqual(Value(10), GetDiv(CreateRange(-10, 20), CreateConst(2), false)); |
| 461 | ExpectEqual(Value(5), GetDiv(CreateRange(-10, 20), CreateConst(-2), false)); |
Aart Bik | b3365e0 | 2015-09-21 14:45:05 -0700 | [diff] [blame] | 462 | ExpectEqual(Value(500), GetDiv(CreateRange(40, 1000), CreateRange(2, 4), false)); |
| 463 | ExpectEqual(Value(-10), GetDiv(CreateRange(40, 1000), CreateRange(-4, -2), false)); |
Aart Bik | 7d57d7f | 2015-12-09 14:39:48 -0800 | [diff] [blame] | 464 | ExpectEqual(Value(), GetDiv(CreateRange(40, 1000), CreateRange(-1, 1), false)); |
Aart Bik | b3365e0 | 2015-09-21 14:45:05 -0700 | [diff] [blame] | 465 | ExpectEqual(Value(-10), GetDiv(CreateRange(-1000, -40), CreateRange(2, 4), false)); |
| 466 | ExpectEqual(Value(500), GetDiv(CreateRange(-1000, -40), CreateRange(-4, -2), false)); |
Aart Bik | 7d57d7f | 2015-12-09 14:39:48 -0800 | [diff] [blame] | 467 | ExpectEqual(Value(), GetDiv(CreateRange(-1000, -40), CreateRange(-1, 1), false)); |
| 468 | ExpectEqual(Value(), GetDiv(CreateRange(-1, 1), CreateRange(40, 1000), false)); |
| 469 | ExpectEqual(Value(), GetDiv(CreateRange(-1, 1), CreateRange(-1000, 40), false)); |
| 470 | ExpectEqual(Value(), GetDiv(CreateRange(-1, 1), CreateRange(-1, 1), false)); |
Aart Bik | d14c595 | 2015-09-08 15:25:15 -0700 | [diff] [blame] | 471 | } |
| 472 | |
| 473 | TEST_F(InductionVarRangeTest, AddValue) { |
| 474 | ExpectEqual(Value(110), AddValue(Value(10), Value(100))); |
Aart Bik | 7d57d7f | 2015-12-09 14:39:48 -0800 | [diff] [blame] | 475 | ExpectEqual(Value(-5), AddValue(Value(x_, 1, -4), Value(x_, -1, -1))); |
| 476 | ExpectEqual(Value(x_, 3, -5), AddValue(Value(x_, 2, -4), Value(x_, 1, -1))); |
| 477 | ExpectEqual(Value(), AddValue(Value(x_, 1, 5), Value(y_, 1, -7))); |
| 478 | ExpectEqual(Value(x_, 1, 23), AddValue(Value(x_, 1, 20), Value(3))); |
| 479 | ExpectEqual(Value(y_, 1, 5), AddValue(Value(55), Value(y_, 1, -50))); |
Aart Bik | cd26feb | 2015-09-23 17:50:50 -0700 | [diff] [blame] | 480 | const int32_t max_value = std::numeric_limits<int32_t>::max(); |
| 481 | ExpectEqual(Value(max_value), AddValue(Value(max_value - 5), Value(5))); |
| 482 | ExpectEqual(Value(), AddValue(Value(max_value - 5), Value(6))); // unsafe |
Aart Bik | d14c595 | 2015-09-08 15:25:15 -0700 | [diff] [blame] | 483 | } |
| 484 | |
| 485 | TEST_F(InductionVarRangeTest, SubValue) { |
| 486 | ExpectEqual(Value(-90), SubValue(Value(10), Value(100))); |
Aart Bik | 7d57d7f | 2015-12-09 14:39:48 -0800 | [diff] [blame] | 487 | ExpectEqual(Value(-3), SubValue(Value(x_, 1, -4), Value(x_, 1, -1))); |
| 488 | ExpectEqual(Value(x_, 2, -3), SubValue(Value(x_, 3, -4), Value(x_, 1, -1))); |
| 489 | ExpectEqual(Value(), SubValue(Value(x_, 1, 5), Value(y_, 1, -7))); |
| 490 | ExpectEqual(Value(x_, 1, 17), SubValue(Value(x_, 1, 20), Value(3))); |
| 491 | ExpectEqual(Value(y_, -4, 105), SubValue(Value(55), Value(y_, 4, -50))); |
Aart Bik | cd26feb | 2015-09-23 17:50:50 -0700 | [diff] [blame] | 492 | const int32_t min_value = std::numeric_limits<int32_t>::min(); |
| 493 | ExpectEqual(Value(min_value), SubValue(Value(min_value + 5), Value(5))); |
| 494 | ExpectEqual(Value(), SubValue(Value(min_value + 5), Value(6))); // unsafe |
Aart Bik | d14c595 | 2015-09-08 15:25:15 -0700 | [diff] [blame] | 495 | } |
| 496 | |
| 497 | TEST_F(InductionVarRangeTest, MulValue) { |
| 498 | ExpectEqual(Value(1000), MulValue(Value(10), Value(100))); |
Aart Bik | 7d57d7f | 2015-12-09 14:39:48 -0800 | [diff] [blame] | 499 | ExpectEqual(Value(), MulValue(Value(x_, 1, -4), Value(x_, 1, -1))); |
| 500 | ExpectEqual(Value(), MulValue(Value(x_, 1, 5), Value(y_, 1, -7))); |
| 501 | ExpectEqual(Value(x_, 9, 60), MulValue(Value(x_, 3, 20), Value(3))); |
| 502 | ExpectEqual(Value(y_, 55, -110), MulValue(Value(55), Value(y_, 1, -2))); |
Aart Bik | b3365e0 | 2015-09-21 14:45:05 -0700 | [diff] [blame] | 503 | ExpectEqual(Value(), MulValue(Value(90000), Value(-90000))); // unsafe |
Aart Bik | d14c595 | 2015-09-08 15:25:15 -0700 | [diff] [blame] | 504 | } |
| 505 | |
Aart Bik | 97412c92 | 2016-02-19 20:14:38 -0800 | [diff] [blame] | 506 | TEST_F(InductionVarRangeTest, MulValueSpecial) { |
| 507 | const int32_t min_value = std::numeric_limits<int32_t>::min(); |
| 508 | const int32_t max_value = std::numeric_limits<int32_t>::max(); |
| 509 | |
| 510 | // Unsafe. |
| 511 | ExpectEqual(Value(), MulValue(Value(min_value), Value(min_value))); |
| 512 | ExpectEqual(Value(), MulValue(Value(min_value), Value(-1))); |
| 513 | ExpectEqual(Value(), MulValue(Value(min_value), Value(max_value))); |
| 514 | ExpectEqual(Value(), MulValue(Value(max_value), Value(max_value))); |
| 515 | |
| 516 | // Safe. |
| 517 | ExpectEqual(Value(min_value), MulValue(Value(min_value), Value(1))); |
| 518 | ExpectEqual(Value(max_value), MulValue(Value(max_value), Value(1))); |
| 519 | ExpectEqual(Value(-max_value), MulValue(Value(max_value), Value(-1))); |
| 520 | ExpectEqual(Value(-1), MulValue(Value(1), Value(-1))); |
| 521 | ExpectEqual(Value(1), MulValue(Value(-1), Value(-1))); |
| 522 | } |
| 523 | |
Aart Bik | d14c595 | 2015-09-08 15:25:15 -0700 | [diff] [blame] | 524 | TEST_F(InductionVarRangeTest, DivValue) { |
| 525 | ExpectEqual(Value(25), DivValue(Value(100), Value(4))); |
Aart Bik | 7d57d7f | 2015-12-09 14:39:48 -0800 | [diff] [blame] | 526 | ExpectEqual(Value(), DivValue(Value(x_, 1, -4), Value(x_, 1, -1))); |
| 527 | ExpectEqual(Value(), DivValue(Value(x_, 1, 5), Value(y_, 1, -7))); |
| 528 | ExpectEqual(Value(), DivValue(Value(x_, 12, 24), Value(3))); |
| 529 | ExpectEqual(Value(), DivValue(Value(55), Value(y_, 1, -50))); |
Aart Bik | b3365e0 | 2015-09-21 14:45:05 -0700 | [diff] [blame] | 530 | ExpectEqual(Value(), DivValue(Value(1), Value(0))); // unsafe |
Aart Bik | d14c595 | 2015-09-08 15:25:15 -0700 | [diff] [blame] | 531 | } |
| 532 | |
Aart Bik | 97412c92 | 2016-02-19 20:14:38 -0800 | [diff] [blame] | 533 | TEST_F(InductionVarRangeTest, DivValueSpecial) { |
| 534 | const int32_t min_value = std::numeric_limits<int32_t>::min(); |
| 535 | const int32_t max_value = std::numeric_limits<int32_t>::max(); |
| 536 | |
| 537 | // Unsafe. |
| 538 | ExpectEqual(Value(), DivValue(Value(min_value), Value(-1))); |
| 539 | |
| 540 | // Safe. |
| 541 | ExpectEqual(Value(1), DivValue(Value(min_value), Value(min_value))); |
| 542 | ExpectEqual(Value(1), DivValue(Value(max_value), Value(max_value))); |
| 543 | ExpectEqual(Value(min_value), DivValue(Value(min_value), Value(1))); |
| 544 | ExpectEqual(Value(max_value), DivValue(Value(max_value), Value(1))); |
| 545 | ExpectEqual(Value(-max_value), DivValue(Value(max_value), Value(-1))); |
| 546 | ExpectEqual(Value(-1), DivValue(Value(1), Value(-1))); |
| 547 | ExpectEqual(Value(1), DivValue(Value(-1), Value(-1))); |
| 548 | } |
| 549 | |
Aart Bik | d14c595 | 2015-09-08 15:25:15 -0700 | [diff] [blame] | 550 | TEST_F(InductionVarRangeTest, MinValue) { |
| 551 | ExpectEqual(Value(10), MinValue(Value(10), Value(100))); |
Aart Bik | 7d57d7f | 2015-12-09 14:39:48 -0800 | [diff] [blame] | 552 | ExpectEqual(Value(x_, 1, -4), MinValue(Value(x_, 1, -4), Value(x_, 1, -1))); |
| 553 | ExpectEqual(Value(x_, 4, -4), MinValue(Value(x_, 4, -4), Value(x_, 4, -1))); |
| 554 | ExpectEqual(Value(), MinValue(Value(x_, 1, 5), Value(y_, 1, -7))); |
| 555 | ExpectEqual(Value(), MinValue(Value(x_, 1, 20), Value(3))); |
| 556 | ExpectEqual(Value(), MinValue(Value(55), Value(y_, 1, -50))); |
Aart Bik | d14c595 | 2015-09-08 15:25:15 -0700 | [diff] [blame] | 557 | } |
| 558 | |
| 559 | TEST_F(InductionVarRangeTest, MaxValue) { |
| 560 | ExpectEqual(Value(100), MaxValue(Value(10), Value(100))); |
Aart Bik | 7d57d7f | 2015-12-09 14:39:48 -0800 | [diff] [blame] | 561 | ExpectEqual(Value(x_, 1, -1), MaxValue(Value(x_, 1, -4), Value(x_, 1, -1))); |
| 562 | ExpectEqual(Value(x_, 4, -1), MaxValue(Value(x_, 4, -4), Value(x_, 4, -1))); |
| 563 | ExpectEqual(Value(), MaxValue(Value(x_, 1, 5), Value(y_, 1, -7))); |
| 564 | ExpectEqual(Value(), MaxValue(Value(x_, 1, 20), Value(3))); |
| 565 | ExpectEqual(Value(), MaxValue(Value(55), Value(y_, 1, -50))); |
Aart Bik | d14c595 | 2015-09-08 15:25:15 -0700 | [diff] [blame] | 566 | } |
| 567 | |
Aart Bik | 52be7e7 | 2016-06-23 11:20:41 -0700 | [diff] [blame] | 568 | TEST_F(InductionVarRangeTest, ArrayLengthAndHints) { |
| 569 | HInstruction* new_array = new (&allocator_) |
| 570 | HNewArray(x_, |
| 571 | graph_->GetCurrentMethod(), |
| 572 | 0, Primitive::kPrimInt, |
| 573 | graph_->GetDexFile(), |
| 574 | kQuickAllocArray); |
| 575 | entry_block_->AddInstruction(new_array); |
| 576 | HInstruction* array_length = new (&allocator_) HArrayLength(new_array, 0); |
| 577 | entry_block_->AddInstruction(array_length); |
| 578 | // With null hint: yields extreme constants. |
| 579 | const int32_t max_value = std::numeric_limits<int32_t>::max(); |
| 580 | SetHint(nullptr); |
| 581 | ExpectEqual(Value(0), GetMin(CreateFetch(array_length), nullptr)); |
| 582 | ExpectEqual(Value(max_value), GetMax(CreateFetch(array_length), nullptr)); |
| 583 | // With explicit hint: yields the length instruction. |
| 584 | SetHint(array_length); |
| 585 | ExpectEqual(Value(array_length, 1, 0), GetMin(CreateFetch(array_length), nullptr)); |
| 586 | ExpectEqual(Value(array_length, 1, 0), GetMax(CreateFetch(array_length), nullptr)); |
| 587 | // With any non-null hint: chases beyond the length instruction. |
| 588 | SetHint(x_); |
| 589 | ExpectEqual(Value(x_, 1, 0), GetMin(CreateFetch(array_length), nullptr)); |
| 590 | ExpectEqual(Value(x_, 1, 0), GetMax(CreateFetch(array_length), nullptr)); |
| 591 | } |
| 592 | |
Aart Bik | aec3cce | 2015-10-14 17:44:55 -0700 | [diff] [blame] | 593 | // |
Aart Bik | 7d57d7f | 2015-12-09 14:39:48 -0800 | [diff] [blame] | 594 | // Tests on public methods. |
Aart Bik | aec3cce | 2015-10-14 17:44:55 -0700 | [diff] [blame] | 595 | // |
| 596 | |
Aart Bik | 389b3db | 2015-10-28 14:23:40 -0700 | [diff] [blame] | 597 | TEST_F(InductionVarRangeTest, ConstantTripCountUp) { |
| 598 | BuildLoop(0, graph_->GetIntConstant(1000), 1); |
Aart Bik | aec3cce | 2015-10-14 17:44:55 -0700 | [diff] [blame] | 599 | PerformInductionVarAnalysis(); |
Aart Bik | aec3cce | 2015-10-14 17:44:55 -0700 | [diff] [blame] | 600 | |
Aart Bik | 389b3db | 2015-10-28 14:23:40 -0700 | [diff] [blame] | 601 | Value v1, v2; |
| 602 | bool needs_finite_test = true; |
| 603 | |
Aart Bik | aec3cce | 2015-10-14 17:44:55 -0700 | [diff] [blame] | 604 | // In context of header: known. |
Aart Bik | 52be7e7 | 2016-06-23 11:20:41 -0700 | [diff] [blame] | 605 | range_.GetInductionRange(condition_, condition_->InputAt(0), x_, &v1, &v2, &needs_finite_test); |
Aart Bik | 389b3db | 2015-10-28 14:23:40 -0700 | [diff] [blame] | 606 | EXPECT_FALSE(needs_finite_test); |
| 607 | ExpectEqual(Value(0), v1); |
| 608 | ExpectEqual(Value(1000), v2); |
Aart Bik | aec3cce | 2015-10-14 17:44:55 -0700 | [diff] [blame] | 609 | |
| 610 | // In context of loop-body: known. |
Aart Bik | 52be7e7 | 2016-06-23 11:20:41 -0700 | [diff] [blame] | 611 | range_.GetInductionRange(increment_, condition_->InputAt(0), x_, &v1, &v2, &needs_finite_test); |
Aart Bik | 389b3db | 2015-10-28 14:23:40 -0700 | [diff] [blame] | 612 | EXPECT_FALSE(needs_finite_test); |
| 613 | ExpectEqual(Value(0), v1); |
| 614 | ExpectEqual(Value(999), v2); |
Aart Bik | 52be7e7 | 2016-06-23 11:20:41 -0700 | [diff] [blame] | 615 | range_.GetInductionRange(increment_, increment_, x_, &v1, &v2, &needs_finite_test); |
Aart Bik | 389b3db | 2015-10-28 14:23:40 -0700 | [diff] [blame] | 616 | EXPECT_FALSE(needs_finite_test); |
| 617 | ExpectEqual(Value(1), v1); |
| 618 | ExpectEqual(Value(1000), v2); |
Aart Bik | aec3cce | 2015-10-14 17:44:55 -0700 | [diff] [blame] | 619 | } |
| 620 | |
Aart Bik | 389b3db | 2015-10-28 14:23:40 -0700 | [diff] [blame] | 621 | TEST_F(InductionVarRangeTest, ConstantTripCountDown) { |
| 622 | BuildLoop(1000, graph_->GetIntConstant(0), -1); |
Aart Bik | aec3cce | 2015-10-14 17:44:55 -0700 | [diff] [blame] | 623 | PerformInductionVarAnalysis(); |
Aart Bik | aec3cce | 2015-10-14 17:44:55 -0700 | [diff] [blame] | 624 | |
Aart Bik | 389b3db | 2015-10-28 14:23:40 -0700 | [diff] [blame] | 625 | Value v1, v2; |
| 626 | bool needs_finite_test = true; |
| 627 | |
| 628 | // In context of header: known. |
Aart Bik | 52be7e7 | 2016-06-23 11:20:41 -0700 | [diff] [blame] | 629 | range_.GetInductionRange(condition_, condition_->InputAt(0), x_, &v1, &v2, &needs_finite_test); |
Aart Bik | 389b3db | 2015-10-28 14:23:40 -0700 | [diff] [blame] | 630 | EXPECT_FALSE(needs_finite_test); |
| 631 | ExpectEqual(Value(0), v1); |
| 632 | ExpectEqual(Value(1000), v2); |
Aart Bik | aec3cce | 2015-10-14 17:44:55 -0700 | [diff] [blame] | 633 | |
| 634 | // In context of loop-body: known. |
Aart Bik | 52be7e7 | 2016-06-23 11:20:41 -0700 | [diff] [blame] | 635 | range_.GetInductionRange(increment_, condition_->InputAt(0), x_, &v1, &v2, &needs_finite_test); |
Aart Bik | 389b3db | 2015-10-28 14:23:40 -0700 | [diff] [blame] | 636 | EXPECT_FALSE(needs_finite_test); |
| 637 | ExpectEqual(Value(1), v1); |
| 638 | ExpectEqual(Value(1000), v2); |
Aart Bik | 52be7e7 | 2016-06-23 11:20:41 -0700 | [diff] [blame] | 639 | range_.GetInductionRange(increment_, increment_, x_, &v1, &v2, &needs_finite_test); |
Aart Bik | 389b3db | 2015-10-28 14:23:40 -0700 | [diff] [blame] | 640 | EXPECT_FALSE(needs_finite_test); |
| 641 | ExpectEqual(Value(0), v1); |
| 642 | ExpectEqual(Value(999), v2); |
Aart Bik | aec3cce | 2015-10-14 17:44:55 -0700 | [diff] [blame] | 643 | } |
| 644 | |
Aart Bik | 389b3db | 2015-10-28 14:23:40 -0700 | [diff] [blame] | 645 | TEST_F(InductionVarRangeTest, SymbolicTripCountUp) { |
Aart Bik | 7d57d7f | 2015-12-09 14:39:48 -0800 | [diff] [blame] | 646 | BuildLoop(0, x_, 1); |
Aart Bik | aec3cce | 2015-10-14 17:44:55 -0700 | [diff] [blame] | 647 | PerformInductionVarAnalysis(); |
Aart Bik | aec3cce | 2015-10-14 17:44:55 -0700 | [diff] [blame] | 648 | |
Aart Bik | 389b3db | 2015-10-28 14:23:40 -0700 | [diff] [blame] | 649 | Value v1, v2; |
| 650 | bool needs_finite_test = true; |
| 651 | bool needs_taken_test = true; |
| 652 | |
| 653 | // In context of header: upper unknown. |
Aart Bik | 52be7e7 | 2016-06-23 11:20:41 -0700 | [diff] [blame] | 654 | range_.GetInductionRange(condition_, condition_->InputAt(0), x_, &v1, &v2, &needs_finite_test); |
Aart Bik | 389b3db | 2015-10-28 14:23:40 -0700 | [diff] [blame] | 655 | EXPECT_FALSE(needs_finite_test); |
| 656 | ExpectEqual(Value(0), v1); |
| 657 | ExpectEqual(Value(), v2); |
| 658 | |
| 659 | // In context of loop-body: known. |
Aart Bik | 52be7e7 | 2016-06-23 11:20:41 -0700 | [diff] [blame] | 660 | range_.GetInductionRange(increment_, condition_->InputAt(0), x_, &v1, &v2, &needs_finite_test); |
Aart Bik | 389b3db | 2015-10-28 14:23:40 -0700 | [diff] [blame] | 661 | EXPECT_FALSE(needs_finite_test); |
| 662 | ExpectEqual(Value(0), v1); |
Aart Bik | 7d57d7f | 2015-12-09 14:39:48 -0800 | [diff] [blame] | 663 | ExpectEqual(Value(x_, 1, -1), v2); |
Aart Bik | 52be7e7 | 2016-06-23 11:20:41 -0700 | [diff] [blame] | 664 | range_.GetInductionRange(increment_, increment_, x_, &v1, &v2, &needs_finite_test); |
Aart Bik | 389b3db | 2015-10-28 14:23:40 -0700 | [diff] [blame] | 665 | EXPECT_FALSE(needs_finite_test); |
| 666 | ExpectEqual(Value(1), v1); |
Aart Bik | 7d57d7f | 2015-12-09 14:39:48 -0800 | [diff] [blame] | 667 | ExpectEqual(Value(x_, 1, 0), v2); |
Aart Bik | 389b3db | 2015-10-28 14:23:40 -0700 | [diff] [blame] | 668 | |
Aart Bik | aec3cce | 2015-10-14 17:44:55 -0700 | [diff] [blame] | 669 | HInstruction* lower = nullptr; |
| 670 | HInstruction* upper = nullptr; |
Aart Bik | 389b3db | 2015-10-28 14:23:40 -0700 | [diff] [blame] | 671 | HInstruction* taken = nullptr; |
Aart Bik | aec3cce | 2015-10-14 17:44:55 -0700 | [diff] [blame] | 672 | |
| 673 | // Can generate code in context of loop-body only. |
Aart Bik | 7d57d7f | 2015-12-09 14:39:48 -0800 | [diff] [blame] | 674 | EXPECT_FALSE(range_.CanGenerateCode( |
Aart Bik | 389b3db | 2015-10-28 14:23:40 -0700 | [diff] [blame] | 675 | condition_, condition_->InputAt(0), &needs_finite_test, &needs_taken_test)); |
Aart Bik | 7d57d7f | 2015-12-09 14:39:48 -0800 | [diff] [blame] | 676 | ASSERT_TRUE(range_.CanGenerateCode( |
Aart Bik | 389b3db | 2015-10-28 14:23:40 -0700 | [diff] [blame] | 677 | increment_, condition_->InputAt(0), &needs_finite_test, &needs_taken_test)); |
| 678 | EXPECT_FALSE(needs_finite_test); |
| 679 | EXPECT_TRUE(needs_taken_test); |
Aart Bik | aec3cce | 2015-10-14 17:44:55 -0700 | [diff] [blame] | 680 | |
| 681 | // Generates code. |
Aart Bik | 7d57d7f | 2015-12-09 14:39:48 -0800 | [diff] [blame] | 682 | range_.GenerateRangeCode( |
| 683 | increment_, condition_->InputAt(0), graph_, loop_preheader_, &lower, &upper); |
Aart Bik | aec3cce | 2015-10-14 17:44:55 -0700 | [diff] [blame] | 684 | |
| 685 | // Verify lower is 0+0. |
| 686 | ASSERT_TRUE(lower != nullptr); |
| 687 | ASSERT_TRUE(lower->IsAdd()); |
| 688 | ASSERT_TRUE(lower->InputAt(0)->IsIntConstant()); |
| 689 | EXPECT_EQ(0, lower->InputAt(0)->AsIntConstant()->GetValue()); |
| 690 | ASSERT_TRUE(lower->InputAt(1)->IsIntConstant()); |
| 691 | EXPECT_EQ(0, lower->InputAt(1)->AsIntConstant()->GetValue()); |
| 692 | |
Aart Bik | 389b3db | 2015-10-28 14:23:40 -0700 | [diff] [blame] | 693 | // Verify upper is (V-1)+0. |
Aart Bik | aec3cce | 2015-10-14 17:44:55 -0700 | [diff] [blame] | 694 | ASSERT_TRUE(upper != nullptr); |
| 695 | ASSERT_TRUE(upper->IsAdd()); |
| 696 | ASSERT_TRUE(upper->InputAt(0)->IsSub()); |
| 697 | EXPECT_TRUE(upper->InputAt(0)->InputAt(0)->IsParameterValue()); |
| 698 | ASSERT_TRUE(upper->InputAt(0)->InputAt(1)->IsIntConstant()); |
| 699 | EXPECT_EQ(1, upper->InputAt(0)->InputAt(1)->AsIntConstant()->GetValue()); |
| 700 | ASSERT_TRUE(upper->InputAt(1)->IsIntConstant()); |
| 701 | EXPECT_EQ(0, upper->InputAt(1)->AsIntConstant()->GetValue()); |
Aart Bik | 389b3db | 2015-10-28 14:23:40 -0700 | [diff] [blame] | 702 | |
| 703 | // Verify taken-test is 0<V. |
Aart Bik | 7d57d7f | 2015-12-09 14:39:48 -0800 | [diff] [blame] | 704 | range_.GenerateTakenTest(increment_, graph_, loop_preheader_, &taken); |
Aart Bik | 389b3db | 2015-10-28 14:23:40 -0700 | [diff] [blame] | 705 | ASSERT_TRUE(taken != nullptr); |
| 706 | ASSERT_TRUE(taken->IsLessThan()); |
| 707 | ASSERT_TRUE(taken->InputAt(0)->IsIntConstant()); |
| 708 | EXPECT_EQ(0, taken->InputAt(0)->AsIntConstant()->GetValue()); |
| 709 | EXPECT_TRUE(taken->InputAt(1)->IsParameterValue()); |
| 710 | } |
| 711 | |
| 712 | TEST_F(InductionVarRangeTest, SymbolicTripCountDown) { |
Aart Bik | 7d57d7f | 2015-12-09 14:39:48 -0800 | [diff] [blame] | 713 | BuildLoop(1000, x_, -1); |
Aart Bik | 389b3db | 2015-10-28 14:23:40 -0700 | [diff] [blame] | 714 | PerformInductionVarAnalysis(); |
Aart Bik | 389b3db | 2015-10-28 14:23:40 -0700 | [diff] [blame] | 715 | |
| 716 | Value v1, v2; |
| 717 | bool needs_finite_test = true; |
| 718 | bool needs_taken_test = true; |
| 719 | |
| 720 | // In context of header: lower unknown. |
Aart Bik | 52be7e7 | 2016-06-23 11:20:41 -0700 | [diff] [blame] | 721 | range_.GetInductionRange(condition_, condition_->InputAt(0), x_, &v1, &v2, &needs_finite_test); |
Aart Bik | 389b3db | 2015-10-28 14:23:40 -0700 | [diff] [blame] | 722 | EXPECT_FALSE(needs_finite_test); |
| 723 | ExpectEqual(Value(), v1); |
| 724 | ExpectEqual(Value(1000), v2); |
| 725 | |
| 726 | // In context of loop-body: known. |
Aart Bik | 52be7e7 | 2016-06-23 11:20:41 -0700 | [diff] [blame] | 727 | range_.GetInductionRange(increment_, condition_->InputAt(0), x_, &v1, &v2, &needs_finite_test); |
Aart Bik | 389b3db | 2015-10-28 14:23:40 -0700 | [diff] [blame] | 728 | EXPECT_FALSE(needs_finite_test); |
Aart Bik | 7d57d7f | 2015-12-09 14:39:48 -0800 | [diff] [blame] | 729 | ExpectEqual(Value(x_, 1, 1), v1); |
Aart Bik | 389b3db | 2015-10-28 14:23:40 -0700 | [diff] [blame] | 730 | ExpectEqual(Value(1000), v2); |
Aart Bik | 52be7e7 | 2016-06-23 11:20:41 -0700 | [diff] [blame] | 731 | range_.GetInductionRange(increment_, increment_, x_, &v1, &v2, &needs_finite_test); |
Aart Bik | 389b3db | 2015-10-28 14:23:40 -0700 | [diff] [blame] | 732 | EXPECT_FALSE(needs_finite_test); |
Aart Bik | 7d57d7f | 2015-12-09 14:39:48 -0800 | [diff] [blame] | 733 | ExpectEqual(Value(x_, 1, 0), v1); |
Aart Bik | 389b3db | 2015-10-28 14:23:40 -0700 | [diff] [blame] | 734 | ExpectEqual(Value(999), v2); |
| 735 | |
| 736 | HInstruction* lower = nullptr; |
| 737 | HInstruction* upper = nullptr; |
| 738 | HInstruction* taken = nullptr; |
| 739 | |
| 740 | // Can generate code in context of loop-body only. |
Aart Bik | 7d57d7f | 2015-12-09 14:39:48 -0800 | [diff] [blame] | 741 | EXPECT_FALSE(range_.CanGenerateCode( |
Aart Bik | 389b3db | 2015-10-28 14:23:40 -0700 | [diff] [blame] | 742 | condition_, condition_->InputAt(0), &needs_finite_test, &needs_taken_test)); |
Aart Bik | 7d57d7f | 2015-12-09 14:39:48 -0800 | [diff] [blame] | 743 | ASSERT_TRUE(range_.CanGenerateCode( |
Aart Bik | 389b3db | 2015-10-28 14:23:40 -0700 | [diff] [blame] | 744 | increment_, condition_->InputAt(0), &needs_finite_test, &needs_taken_test)); |
| 745 | EXPECT_FALSE(needs_finite_test); |
| 746 | EXPECT_TRUE(needs_taken_test); |
| 747 | |
| 748 | // Generates code. |
Aart Bik | 7d57d7f | 2015-12-09 14:39:48 -0800 | [diff] [blame] | 749 | range_.GenerateRangeCode( |
| 750 | increment_, condition_->InputAt(0), graph_, loop_preheader_, &lower, &upper); |
Aart Bik | 389b3db | 2015-10-28 14:23:40 -0700 | [diff] [blame] | 751 | |
Aart Bik | 7d57d7f | 2015-12-09 14:39:48 -0800 | [diff] [blame] | 752 | // Verify lower is 1000-((1000-V)-1). |
Aart Bik | 389b3db | 2015-10-28 14:23:40 -0700 | [diff] [blame] | 753 | ASSERT_TRUE(lower != nullptr); |
| 754 | ASSERT_TRUE(lower->IsSub()); |
| 755 | ASSERT_TRUE(lower->InputAt(0)->IsIntConstant()); |
| 756 | EXPECT_EQ(1000, lower->InputAt(0)->AsIntConstant()->GetValue()); |
| 757 | lower = lower->InputAt(1); |
| 758 | ASSERT_TRUE(lower->IsSub()); |
| 759 | ASSERT_TRUE(lower->InputAt(1)->IsIntConstant()); |
| 760 | EXPECT_EQ(1, lower->InputAt(1)->AsIntConstant()->GetValue()); |
| 761 | lower = lower->InputAt(0); |
Aart Bik | 389b3db | 2015-10-28 14:23:40 -0700 | [diff] [blame] | 762 | ASSERT_TRUE(lower->IsSub()); |
Aart Bik | 7d57d7f | 2015-12-09 14:39:48 -0800 | [diff] [blame] | 763 | ASSERT_TRUE(lower->InputAt(0)->IsIntConstant()); |
| 764 | EXPECT_EQ(1000, lower->InputAt(0)->AsIntConstant()->GetValue()); |
| 765 | EXPECT_TRUE(lower->InputAt(1)->IsParameterValue()); |
Aart Bik | 389b3db | 2015-10-28 14:23:40 -0700 | [diff] [blame] | 766 | |
| 767 | // Verify upper is 1000-0. |
| 768 | ASSERT_TRUE(upper != nullptr); |
| 769 | ASSERT_TRUE(upper->IsSub()); |
| 770 | ASSERT_TRUE(upper->InputAt(0)->IsIntConstant()); |
| 771 | EXPECT_EQ(1000, upper->InputAt(0)->AsIntConstant()->GetValue()); |
| 772 | ASSERT_TRUE(upper->InputAt(1)->IsIntConstant()); |
| 773 | EXPECT_EQ(0, upper->InputAt(1)->AsIntConstant()->GetValue()); |
| 774 | |
| 775 | // Verify taken-test is 1000>V. |
Aart Bik | 7d57d7f | 2015-12-09 14:39:48 -0800 | [diff] [blame] | 776 | range_.GenerateTakenTest(increment_, graph_, loop_preheader_, &taken); |
Aart Bik | 389b3db | 2015-10-28 14:23:40 -0700 | [diff] [blame] | 777 | ASSERT_TRUE(taken != nullptr); |
| 778 | ASSERT_TRUE(taken->IsGreaterThan()); |
| 779 | ASSERT_TRUE(taken->InputAt(0)->IsIntConstant()); |
| 780 | EXPECT_EQ(1000, taken->InputAt(0)->AsIntConstant()->GetValue()); |
| 781 | EXPECT_TRUE(taken->InputAt(1)->IsParameterValue()); |
Aart Bik | aec3cce | 2015-10-14 17:44:55 -0700 | [diff] [blame] | 782 | } |
| 783 | |
Aart Bik | d14c595 | 2015-09-08 15:25:15 -0700 | [diff] [blame] | 784 | } // namespace art |