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" |
| 19 | #include "gtest/gtest.h" |
| 20 | #include "induction_var_analysis.h" |
| 21 | #include "induction_var_range.h" |
| 22 | #include "nodes.h" |
| 23 | #include "optimizing_unit_test.h" |
| 24 | |
| 25 | namespace art { |
| 26 | |
| 27 | using Value = InductionVarRange::Value; |
| 28 | |
| 29 | /** |
| 30 | * Fixture class for the InductionVarRange tests. |
| 31 | */ |
| 32 | class InductionVarRangeTest : public testing::Test { |
| 33 | public: |
| 34 | InductionVarRangeTest() : pool_(), allocator_(&pool_) { |
| 35 | graph_ = CreateGraph(&allocator_); |
| 36 | iva_ = new (&allocator_) HInductionVarAnalysis(graph_); |
| 37 | BuildGraph(); |
| 38 | } |
| 39 | |
| 40 | ~InductionVarRangeTest() { } |
| 41 | |
| 42 | void ExpectEqual(Value v1, Value v2) { |
| 43 | EXPECT_EQ(v1.instruction, v2.instruction); |
| 44 | EXPECT_EQ(v1.a_constant, v2.a_constant); |
| 45 | EXPECT_EQ(v1.b_constant, v2.b_constant); |
Aart Bik | b3365e0 | 2015-09-21 14:45:05 -0700 | [diff] [blame] | 46 | EXPECT_EQ(v1.is_known, v2.is_known); |
Aart Bik | d14c595 | 2015-09-08 15:25:15 -0700 | [diff] [blame] | 47 | } |
| 48 | |
| 49 | /** Constructs bare minimum graph. */ |
| 50 | void BuildGraph() { |
| 51 | graph_->SetNumberOfVRegs(1); |
| 52 | HBasicBlock* entry_block = new (&allocator_) HBasicBlock(graph_); |
| 53 | HBasicBlock* exit_block = new (&allocator_) HBasicBlock(graph_); |
| 54 | graph_->AddBlock(entry_block); |
| 55 | graph_->AddBlock(exit_block); |
| 56 | graph_->SetEntryBlock(entry_block); |
| 57 | graph_->SetExitBlock(exit_block); |
| 58 | } |
| 59 | |
| 60 | /** Constructs an invariant. */ |
| 61 | HInductionVarAnalysis::InductionInfo* CreateInvariant(char opc, |
| 62 | HInductionVarAnalysis::InductionInfo* a, |
| 63 | HInductionVarAnalysis::InductionInfo* b) { |
| 64 | HInductionVarAnalysis::InductionOp op; |
| 65 | switch (opc) { |
| 66 | case '+': op = HInductionVarAnalysis::kAdd; break; |
| 67 | case '-': op = HInductionVarAnalysis::kSub; break; |
| 68 | case 'n': op = HInductionVarAnalysis::kNeg; break; |
| 69 | case '*': op = HInductionVarAnalysis::kMul; break; |
| 70 | case '/': op = HInductionVarAnalysis::kDiv; break; |
| 71 | default: op = HInductionVarAnalysis::kNop; break; |
| 72 | } |
| 73 | return iva_->CreateInvariantOp(op, a, b); |
| 74 | } |
| 75 | |
| 76 | /** Constructs a fetch. */ |
| 77 | HInductionVarAnalysis::InductionInfo* CreateFetch(HInstruction* fetch) { |
| 78 | return iva_->CreateInvariantFetch(fetch); |
| 79 | } |
| 80 | |
| 81 | /** Constructs a constant. */ |
| 82 | HInductionVarAnalysis::InductionInfo* CreateConst(int32_t c) { |
| 83 | return CreateFetch(graph_->GetIntConstant(c)); |
| 84 | } |
| 85 | |
| 86 | /** Constructs a trip-count. */ |
| 87 | HInductionVarAnalysis::InductionInfo* CreateTripCount(int32_t tc) { |
Aart Bik | 9401f53 | 2015-09-28 16:25:56 -0700 | [diff] [blame^] | 88 | return iva_->CreateTripCount(HInductionVarAnalysis::kTripCountInLoop, CreateConst(tc)); |
Aart Bik | d14c595 | 2015-09-08 15:25:15 -0700 | [diff] [blame] | 89 | } |
| 90 | |
| 91 | /** Constructs a linear a * i + b induction. */ |
| 92 | HInductionVarAnalysis::InductionInfo* CreateLinear(int32_t a, int32_t b) { |
| 93 | return iva_->CreateInduction(HInductionVarAnalysis::kLinear, CreateConst(a), CreateConst(b)); |
| 94 | } |
| 95 | |
| 96 | /** Constructs a range [lo, hi] using a periodic induction. */ |
| 97 | HInductionVarAnalysis::InductionInfo* CreateRange(int32_t lo, int32_t hi) { |
| 98 | return iva_->CreateInduction( |
| 99 | HInductionVarAnalysis::kPeriodic, CreateConst(lo), CreateConst(hi)); |
| 100 | } |
| 101 | |
| 102 | /** Constructs a wrap-around induction consisting of a constant, followed by a range. */ |
| 103 | HInductionVarAnalysis::InductionInfo* CreateWrapAround(int32_t initial, int32_t lo, int32_t hi) { |
| 104 | return iva_->CreateInduction( |
| 105 | HInductionVarAnalysis::kWrapAround, CreateConst(initial), CreateRange(lo, hi)); |
| 106 | } |
| 107 | |
| 108 | // |
| 109 | // Relay methods. |
| 110 | // |
| 111 | |
| 112 | Value GetMin(HInductionVarAnalysis::InductionInfo* info, |
| 113 | HInductionVarAnalysis::InductionInfo* induc) { |
Aart Bik | 9401f53 | 2015-09-28 16:25:56 -0700 | [diff] [blame^] | 114 | return InductionVarRange::GetVal(info, induc, /* in_body */ true, /* is_min */ true); |
Aart Bik | d14c595 | 2015-09-08 15:25:15 -0700 | [diff] [blame] | 115 | } |
| 116 | |
| 117 | Value GetMax(HInductionVarAnalysis::InductionInfo* info, |
| 118 | HInductionVarAnalysis::InductionInfo* induc) { |
Aart Bik | 9401f53 | 2015-09-28 16:25:56 -0700 | [diff] [blame^] | 119 | return InductionVarRange::GetVal(info, induc, /* in_body */ true, /* is_min */ false); |
Aart Bik | d14c595 | 2015-09-08 15:25:15 -0700 | [diff] [blame] | 120 | } |
| 121 | |
| 122 | Value GetMul(HInductionVarAnalysis::InductionInfo* info1, |
Aart Bik | b3365e0 | 2015-09-21 14:45:05 -0700 | [diff] [blame] | 123 | HInductionVarAnalysis::InductionInfo* info2, |
| 124 | bool is_min) { |
Aart Bik | 9401f53 | 2015-09-28 16:25:56 -0700 | [diff] [blame^] | 125 | return InductionVarRange::GetMul(info1, info2, nullptr, /* in_body */ true, is_min); |
Aart Bik | d14c595 | 2015-09-08 15:25:15 -0700 | [diff] [blame] | 126 | } |
| 127 | |
| 128 | Value GetDiv(HInductionVarAnalysis::InductionInfo* info1, |
Aart Bik | b3365e0 | 2015-09-21 14:45:05 -0700 | [diff] [blame] | 129 | HInductionVarAnalysis::InductionInfo* info2, |
| 130 | bool is_min) { |
Aart Bik | 9401f53 | 2015-09-28 16:25:56 -0700 | [diff] [blame^] | 131 | return InductionVarRange::GetDiv(info1, info2, nullptr, /* in_body */ true, is_min); |
| 132 | } |
| 133 | |
| 134 | bool GetConstant(HInductionVarAnalysis::InductionInfo* info, int32_t* value) { |
| 135 | return InductionVarRange::GetConstant(info, value); |
Aart Bik | d14c595 | 2015-09-08 15:25:15 -0700 | [diff] [blame] | 136 | } |
| 137 | |
Aart Bik | b3365e0 | 2015-09-21 14:45:05 -0700 | [diff] [blame] | 138 | Value AddValue(Value v1, Value v2) { return InductionVarRange::AddValue(v1, v2); } |
| 139 | Value SubValue(Value v1, Value v2) { return InductionVarRange::SubValue(v1, v2); } |
| 140 | Value MulValue(Value v1, Value v2) { return InductionVarRange::MulValue(v1, v2); } |
| 141 | Value DivValue(Value v1, Value v2) { return InductionVarRange::DivValue(v1, v2); } |
Aart Bik | cd26feb | 2015-09-23 17:50:50 -0700 | [diff] [blame] | 142 | Value MinValue(Value v1, Value v2) { return InductionVarRange::MergeVal(v1, v2, true); } |
| 143 | Value MaxValue(Value v1, Value v2) { return InductionVarRange::MergeVal(v1, v2, false); } |
Aart Bik | d14c595 | 2015-09-08 15:25:15 -0700 | [diff] [blame] | 144 | |
| 145 | // General building fields. |
| 146 | ArenaPool pool_; |
| 147 | ArenaAllocator allocator_; |
| 148 | HGraph* graph_; |
| 149 | HInductionVarAnalysis* iva_; |
| 150 | |
| 151 | // Two dummy instructions. |
| 152 | HReturnVoid x_; |
| 153 | HReturnVoid y_; |
| 154 | }; |
| 155 | |
| 156 | // |
| 157 | // The actual InductionVarRange tests. |
| 158 | // |
| 159 | |
| 160 | TEST_F(InductionVarRangeTest, GetMinMaxNull) { |
Aart Bik | b3365e0 | 2015-09-21 14:45:05 -0700 | [diff] [blame] | 161 | ExpectEqual(Value(), GetMin(nullptr, nullptr)); |
| 162 | ExpectEqual(Value(), GetMax(nullptr, nullptr)); |
Aart Bik | d14c595 | 2015-09-08 15:25:15 -0700 | [diff] [blame] | 163 | } |
| 164 | |
| 165 | TEST_F(InductionVarRangeTest, GetMinMaxAdd) { |
| 166 | ExpectEqual(Value(12), |
| 167 | GetMin(CreateInvariant('+', CreateConst(2), CreateRange(10, 20)), nullptr)); |
| 168 | ExpectEqual(Value(22), |
| 169 | GetMax(CreateInvariant('+', CreateConst(2), CreateRange(10, 20)), nullptr)); |
| 170 | ExpectEqual(Value(&x_, 1, -20), |
| 171 | GetMin(CreateInvariant('+', CreateFetch(&x_), CreateRange(-20, -10)), nullptr)); |
| 172 | ExpectEqual(Value(&x_, 1, -10), |
| 173 | GetMax(CreateInvariant('+', CreateFetch(&x_), CreateRange(-20, -10)), nullptr)); |
| 174 | ExpectEqual(Value(&x_, 1, 10), |
| 175 | GetMin(CreateInvariant('+', CreateRange(10, 20), CreateFetch(&x_)), nullptr)); |
| 176 | ExpectEqual(Value(&x_, 1, 20), |
| 177 | GetMax(CreateInvariant('+', CreateRange(10, 20), CreateFetch(&x_)), nullptr)); |
| 178 | ExpectEqual(Value(5), |
| 179 | GetMin(CreateInvariant('+', CreateRange(-5, -1), CreateRange(10, 20)), nullptr)); |
| 180 | ExpectEqual(Value(19), |
| 181 | GetMax(CreateInvariant('+', CreateRange(-5, -1), CreateRange(10, 20)), nullptr)); |
| 182 | } |
| 183 | |
| 184 | TEST_F(InductionVarRangeTest, GetMinMaxSub) { |
| 185 | ExpectEqual(Value(-18), |
| 186 | GetMin(CreateInvariant('-', CreateConst(2), CreateRange(10, 20)), nullptr)); |
| 187 | ExpectEqual(Value(-8), |
| 188 | GetMax(CreateInvariant('-', CreateConst(2), CreateRange(10, 20)), nullptr)); |
| 189 | ExpectEqual(Value(&x_, 1, 10), |
| 190 | GetMin(CreateInvariant('-', CreateFetch(&x_), CreateRange(-20, -10)), nullptr)); |
| 191 | ExpectEqual(Value(&x_, 1, 20), |
| 192 | GetMax(CreateInvariant('-', CreateFetch(&x_), CreateRange(-20, -10)), nullptr)); |
| 193 | ExpectEqual(Value(&x_, -1, 10), |
| 194 | GetMin(CreateInvariant('-', CreateRange(10, 20), CreateFetch(&x_)), nullptr)); |
| 195 | ExpectEqual(Value(&x_, -1, 20), |
| 196 | GetMax(CreateInvariant('-', CreateRange(10, 20), CreateFetch(&x_)), nullptr)); |
| 197 | ExpectEqual(Value(-25), |
| 198 | GetMin(CreateInvariant('-', CreateRange(-5, -1), CreateRange(10, 20)), nullptr)); |
| 199 | ExpectEqual(Value(-11), |
| 200 | GetMax(CreateInvariant('-', CreateRange(-5, -1), CreateRange(10, 20)), nullptr)); |
| 201 | } |
| 202 | |
| 203 | TEST_F(InductionVarRangeTest, GetMinMaxNeg) { |
| 204 | ExpectEqual(Value(-20), GetMin(CreateInvariant('n', nullptr, CreateRange(10, 20)), nullptr)); |
| 205 | ExpectEqual(Value(-10), GetMax(CreateInvariant('n', nullptr, CreateRange(10, 20)), nullptr)); |
| 206 | ExpectEqual(Value(10), GetMin(CreateInvariant('n', nullptr, CreateRange(-20, -10)), nullptr)); |
| 207 | ExpectEqual(Value(20), GetMax(CreateInvariant('n', nullptr, CreateRange(-20, -10)), nullptr)); |
| 208 | ExpectEqual(Value(&x_, -1, 0), GetMin(CreateInvariant('n', nullptr, CreateFetch(&x_)), nullptr)); |
| 209 | ExpectEqual(Value(&x_, -1, 0), GetMax(CreateInvariant('n', nullptr, CreateFetch(&x_)), nullptr)); |
| 210 | } |
| 211 | |
| 212 | TEST_F(InductionVarRangeTest, GetMinMaxMul) { |
| 213 | ExpectEqual(Value(20), |
| 214 | GetMin(CreateInvariant('*', CreateConst(2), CreateRange(10, 20)), nullptr)); |
| 215 | ExpectEqual(Value(40), |
| 216 | GetMax(CreateInvariant('*', CreateConst(2), CreateRange(10, 20)), nullptr)); |
| 217 | } |
| 218 | |
| 219 | TEST_F(InductionVarRangeTest, GetMinMaxDiv) { |
| 220 | ExpectEqual(Value(3), |
| 221 | GetMin(CreateInvariant('/', CreateRange(12, 20), CreateConst(4)), nullptr)); |
| 222 | ExpectEqual(Value(5), |
| 223 | GetMax(CreateInvariant('/', CreateRange(12, 20), CreateConst(4)), nullptr)); |
| 224 | } |
| 225 | |
| 226 | TEST_F(InductionVarRangeTest, GetMinMaxConstant) { |
| 227 | ExpectEqual(Value(12345), GetMin(CreateConst(12345), nullptr)); |
| 228 | ExpectEqual(Value(12345), GetMax(CreateConst(12345), nullptr)); |
| 229 | } |
| 230 | |
| 231 | TEST_F(InductionVarRangeTest, GetMinMaxFetch) { |
| 232 | ExpectEqual(Value(&x_, 1, 0), GetMin(CreateFetch(&x_), nullptr)); |
| 233 | ExpectEqual(Value(&x_, 1, 0), GetMax(CreateFetch(&x_), nullptr)); |
| 234 | } |
| 235 | |
| 236 | TEST_F(InductionVarRangeTest, GetMinMaxLinear) { |
| 237 | ExpectEqual(Value(20), GetMin(CreateLinear(10, 20), CreateTripCount(100))); |
| 238 | ExpectEqual(Value(1010), GetMax(CreateLinear(10, 20), CreateTripCount(100))); |
| 239 | ExpectEqual(Value(-970), GetMin(CreateLinear(-10, 20), CreateTripCount(100))); |
| 240 | ExpectEqual(Value(20), GetMax(CreateLinear(-10, 20), CreateTripCount(100))); |
| 241 | } |
| 242 | |
| 243 | TEST_F(InductionVarRangeTest, GetMinMaxWrapAround) { |
| 244 | ExpectEqual(Value(-5), GetMin(CreateWrapAround(-5, -1, 10), nullptr)); |
| 245 | ExpectEqual(Value(10), GetMax(CreateWrapAround(-5, -1, 10), nullptr)); |
| 246 | ExpectEqual(Value(-1), GetMin(CreateWrapAround(2, -1, 10), nullptr)); |
| 247 | ExpectEqual(Value(10), GetMax(CreateWrapAround(2, -1, 10), nullptr)); |
| 248 | ExpectEqual(Value(-1), GetMin(CreateWrapAround(20, -1, 10), nullptr)); |
| 249 | ExpectEqual(Value(20), GetMax(CreateWrapAround(20, -1, 10), nullptr)); |
| 250 | } |
| 251 | |
| 252 | TEST_F(InductionVarRangeTest, GetMinMaxPeriodic) { |
| 253 | ExpectEqual(Value(-2), GetMin(CreateRange(-2, 99), nullptr)); |
| 254 | ExpectEqual(Value(99), GetMax(CreateRange(-2, 99), nullptr)); |
| 255 | } |
| 256 | |
| 257 | TEST_F(InductionVarRangeTest, GetMulMin) { |
Aart Bik | b3365e0 | 2015-09-21 14:45:05 -0700 | [diff] [blame] | 258 | ExpectEqual(Value(6), GetMul(CreateRange(2, 10), CreateRange(3, 5), true)); |
| 259 | ExpectEqual(Value(-50), GetMul(CreateRange(2, 10), CreateRange(-5, -3), true)); |
| 260 | ExpectEqual(Value(-50), GetMul(CreateRange(-10, -2), CreateRange(3, 5), true)); |
| 261 | ExpectEqual(Value(6), GetMul(CreateRange(-10, -2), CreateRange(-5, -3), true)); |
Aart Bik | d14c595 | 2015-09-08 15:25:15 -0700 | [diff] [blame] | 262 | } |
| 263 | |
| 264 | TEST_F(InductionVarRangeTest, GetMulMax) { |
Aart Bik | b3365e0 | 2015-09-21 14:45:05 -0700 | [diff] [blame] | 265 | ExpectEqual(Value(50), GetMul(CreateRange(2, 10), CreateRange(3, 5), false)); |
| 266 | ExpectEqual(Value(-6), GetMul(CreateRange(2, 10), CreateRange(-5, -3), false)); |
| 267 | ExpectEqual(Value(-6), GetMul(CreateRange(-10, -2), CreateRange(3, 5), false)); |
| 268 | ExpectEqual(Value(50), GetMul(CreateRange(-10, -2), CreateRange(-5, -3), false)); |
Aart Bik | d14c595 | 2015-09-08 15:25:15 -0700 | [diff] [blame] | 269 | } |
| 270 | |
| 271 | TEST_F(InductionVarRangeTest, GetDivMin) { |
Aart Bik | b3365e0 | 2015-09-21 14:45:05 -0700 | [diff] [blame] | 272 | ExpectEqual(Value(10), GetDiv(CreateRange(40, 1000), CreateRange(2, 4), true)); |
| 273 | ExpectEqual(Value(-500), GetDiv(CreateRange(40, 1000), CreateRange(-4, -2), true)); |
| 274 | ExpectEqual(Value(-500), GetDiv(CreateRange(-1000, -40), CreateRange(2, 4), true)); |
| 275 | ExpectEqual(Value(10), GetDiv(CreateRange(-1000, -40), CreateRange(-4, -2), true)); |
Aart Bik | d14c595 | 2015-09-08 15:25:15 -0700 | [diff] [blame] | 276 | } |
| 277 | |
| 278 | TEST_F(InductionVarRangeTest, GetDivMax) { |
Aart Bik | b3365e0 | 2015-09-21 14:45:05 -0700 | [diff] [blame] | 279 | ExpectEqual(Value(500), GetDiv(CreateRange(40, 1000), CreateRange(2, 4), false)); |
| 280 | ExpectEqual(Value(-10), GetDiv(CreateRange(40, 1000), CreateRange(-4, -2), false)); |
| 281 | ExpectEqual(Value(-10), GetDiv(CreateRange(-1000, -40), CreateRange(2, 4), false)); |
| 282 | ExpectEqual(Value(500), GetDiv(CreateRange(-1000, -40), CreateRange(-4, -2), false)); |
Aart Bik | d14c595 | 2015-09-08 15:25:15 -0700 | [diff] [blame] | 283 | } |
| 284 | |
Aart Bik | 9401f53 | 2015-09-28 16:25:56 -0700 | [diff] [blame^] | 285 | TEST_F(InductionVarRangeTest, GetConstant) { |
| 286 | int32_t value; |
| 287 | ASSERT_TRUE(GetConstant(CreateConst(12345), &value)); |
| 288 | EXPECT_EQ(12345, value); |
| 289 | EXPECT_FALSE(GetConstant(CreateRange(1, 2), &value)); |
| 290 | } |
| 291 | |
Aart Bik | d14c595 | 2015-09-08 15:25:15 -0700 | [diff] [blame] | 292 | TEST_F(InductionVarRangeTest, AddValue) { |
| 293 | ExpectEqual(Value(110), AddValue(Value(10), Value(100))); |
| 294 | ExpectEqual(Value(-5), AddValue(Value(&x_, 1, -4), Value(&x_, -1, -1))); |
| 295 | ExpectEqual(Value(&x_, 3, -5), AddValue(Value(&x_, 2, -4), Value(&x_, 1, -1))); |
Aart Bik | b3365e0 | 2015-09-21 14:45:05 -0700 | [diff] [blame] | 296 | ExpectEqual(Value(), AddValue(Value(&x_, 1, 5), Value(&y_, 1, -7))); |
Aart Bik | d14c595 | 2015-09-08 15:25:15 -0700 | [diff] [blame] | 297 | ExpectEqual(Value(&x_, 1, 23), AddValue(Value(&x_, 1, 20), Value(3))); |
| 298 | ExpectEqual(Value(&y_, 1, 5), AddValue(Value(55), Value(&y_, 1, -50))); |
Aart Bik | cd26feb | 2015-09-23 17:50:50 -0700 | [diff] [blame] | 299 | const int32_t max_value = std::numeric_limits<int32_t>::max(); |
| 300 | ExpectEqual(Value(max_value), AddValue(Value(max_value - 5), Value(5))); |
| 301 | ExpectEqual(Value(), AddValue(Value(max_value - 5), Value(6))); // unsafe |
Aart Bik | d14c595 | 2015-09-08 15:25:15 -0700 | [diff] [blame] | 302 | } |
| 303 | |
| 304 | TEST_F(InductionVarRangeTest, SubValue) { |
| 305 | ExpectEqual(Value(-90), SubValue(Value(10), Value(100))); |
| 306 | ExpectEqual(Value(-3), SubValue(Value(&x_, 1, -4), Value(&x_, 1, -1))); |
| 307 | ExpectEqual(Value(&x_, 2, -3), SubValue(Value(&x_, 3, -4), Value(&x_, 1, -1))); |
Aart Bik | b3365e0 | 2015-09-21 14:45:05 -0700 | [diff] [blame] | 308 | ExpectEqual(Value(), SubValue(Value(&x_, 1, 5), Value(&y_, 1, -7))); |
Aart Bik | d14c595 | 2015-09-08 15:25:15 -0700 | [diff] [blame] | 309 | ExpectEqual(Value(&x_, 1, 17), SubValue(Value(&x_, 1, 20), Value(3))); |
| 310 | ExpectEqual(Value(&y_, -4, 105), SubValue(Value(55), Value(&y_, 4, -50))); |
Aart Bik | cd26feb | 2015-09-23 17:50:50 -0700 | [diff] [blame] | 311 | const int32_t min_value = std::numeric_limits<int32_t>::min(); |
| 312 | ExpectEqual(Value(min_value), SubValue(Value(min_value + 5), Value(5))); |
| 313 | ExpectEqual(Value(), SubValue(Value(min_value + 5), Value(6))); // unsafe |
Aart Bik | d14c595 | 2015-09-08 15:25:15 -0700 | [diff] [blame] | 314 | } |
| 315 | |
| 316 | TEST_F(InductionVarRangeTest, MulValue) { |
| 317 | ExpectEqual(Value(1000), MulValue(Value(10), Value(100))); |
Aart Bik | b3365e0 | 2015-09-21 14:45:05 -0700 | [diff] [blame] | 318 | ExpectEqual(Value(), MulValue(Value(&x_, 1, -4), Value(&x_, 1, -1))); |
| 319 | ExpectEqual(Value(), MulValue(Value(&x_, 1, 5), Value(&y_, 1, -7))); |
Aart Bik | d14c595 | 2015-09-08 15:25:15 -0700 | [diff] [blame] | 320 | ExpectEqual(Value(&x_, 9, 60), MulValue(Value(&x_, 3, 20), Value(3))); |
| 321 | ExpectEqual(Value(&y_, 55, -110), MulValue(Value(55), Value(&y_, 1, -2))); |
Aart Bik | b3365e0 | 2015-09-21 14:45:05 -0700 | [diff] [blame] | 322 | ExpectEqual(Value(), MulValue(Value(90000), Value(-90000))); // unsafe |
Aart Bik | d14c595 | 2015-09-08 15:25:15 -0700 | [diff] [blame] | 323 | } |
| 324 | |
| 325 | TEST_F(InductionVarRangeTest, DivValue) { |
| 326 | ExpectEqual(Value(25), DivValue(Value(100), Value(4))); |
Aart Bik | b3365e0 | 2015-09-21 14:45:05 -0700 | [diff] [blame] | 327 | ExpectEqual(Value(), DivValue(Value(&x_, 1, -4), Value(&x_, 1, -1))); |
| 328 | ExpectEqual(Value(), DivValue(Value(&x_, 1, 5), Value(&y_, 1, -7))); |
| 329 | ExpectEqual(Value(), DivValue(Value(&x_, 12, 24), Value(3))); |
| 330 | ExpectEqual(Value(), DivValue(Value(55), Value(&y_, 1, -50))); |
| 331 | ExpectEqual(Value(), DivValue(Value(1), Value(0))); // unsafe |
Aart Bik | d14c595 | 2015-09-08 15:25:15 -0700 | [diff] [blame] | 332 | } |
| 333 | |
| 334 | TEST_F(InductionVarRangeTest, MinValue) { |
| 335 | ExpectEqual(Value(10), MinValue(Value(10), Value(100))); |
| 336 | ExpectEqual(Value(&x_, 1, -4), MinValue(Value(&x_, 1, -4), Value(&x_, 1, -1))); |
| 337 | ExpectEqual(Value(&x_, 4, -4), MinValue(Value(&x_, 4, -4), Value(&x_, 4, -1))); |
Aart Bik | b3365e0 | 2015-09-21 14:45:05 -0700 | [diff] [blame] | 338 | ExpectEqual(Value(), MinValue(Value(&x_, 1, 5), Value(&y_, 1, -7))); |
| 339 | ExpectEqual(Value(), MinValue(Value(&x_, 1, 20), Value(3))); |
| 340 | ExpectEqual(Value(), MinValue(Value(55), Value(&y_, 1, -50))); |
Aart Bik | d14c595 | 2015-09-08 15:25:15 -0700 | [diff] [blame] | 341 | } |
| 342 | |
| 343 | TEST_F(InductionVarRangeTest, MaxValue) { |
| 344 | ExpectEqual(Value(100), MaxValue(Value(10), Value(100))); |
| 345 | ExpectEqual(Value(&x_, 1, -1), MaxValue(Value(&x_, 1, -4), Value(&x_, 1, -1))); |
| 346 | ExpectEqual(Value(&x_, 4, -1), MaxValue(Value(&x_, 4, -4), Value(&x_, 4, -1))); |
Aart Bik | b3365e0 | 2015-09-21 14:45:05 -0700 | [diff] [blame] | 347 | ExpectEqual(Value(), MaxValue(Value(&x_, 1, 5), Value(&y_, 1, -7))); |
| 348 | ExpectEqual(Value(), MaxValue(Value(&x_, 1, 20), Value(3))); |
| 349 | ExpectEqual(Value(), MaxValue(Value(55), Value(&y_, 1, -50))); |
Aart Bik | d14c595 | 2015-09-08 15:25:15 -0700 | [diff] [blame] | 350 | } |
| 351 | |
| 352 | } // namespace art |