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