OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. |
| 4 |
| 5 // Regression test for dartbug.com/29620: check that decision to deoptimize |
| 6 // and decisions which parts of the instruction to emit use the same |
| 7 // range information for instruction inputs. |
| 8 |
| 9 // VMOptions=--enable-inlining-annotations --optimization_counter_threshold=10 -
-no-use-osr --no-background-compilation |
| 10 |
| 11 import "package:expect/expect.dart"; |
| 12 |
| 13 const alwaysInline = "AlwaysInline"; |
| 14 const neverInline = "NeverInline"; |
| 15 |
| 16 class Flag { |
| 17 var value; |
| 18 Flag(this.value); |
| 19 |
| 20 static final FLAG = new Flag(0); |
| 21 } |
| 22 |
| 23 @alwaysInline |
| 24 void checkRange(bit) { |
| 25 if (bit < 0 || bit > 31) { |
| 26 throw "bit must be in [0, 31]"; |
| 27 } |
| 28 } |
| 29 |
| 30 @alwaysInline |
| 31 bool isSet(flags, bit) { |
| 32 checkRange(bit); |
| 33 // Note: > 0 here instead of == 0 to prevent merging into |
| 34 // TestSmi instruction. |
| 35 return (flags & (1 << bit)) > 0; |
| 36 } |
| 37 |
| 38 @neverInline |
| 39 bool bug(flags) { |
| 40 var bit = Flag.FLAG.value; |
| 41 checkRange(bit); |
| 42 for (var i = 0; i < 1; i++) { |
| 43 bit = Flag.FLAG.value; |
| 44 checkRange(bit); |
| 45 } |
| 46 |
| 47 // In early optimization stages `bit` would be a Phi(...). This Phi would be |
| 48 // dominated by checkRange and thus range analysis will infer [0, 31] range |
| 49 // for it - and thus a EliminateEnvironment will make decision that |
| 50 // (1 << bit) can't deoptimize and will detach environment from it. Later |
| 51 // passes will eliminate Phi for `bit` as it is redundant and as a result we |
| 52 // will loose precise range information for `bit` and backend will try |
| 53 // to emit a range check and a deoptimization. |
| 54 return isSet(flags, bit); |
| 55 } |
| 56 |
| 57 main() { |
| 58 for (var i = 0; i < 100; i++) { |
| 59 bug(1); |
| 60 } |
| 61 } |
OLD | NEW |