Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014 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 "instruction_simplifier.h" |
| 18 | |
Nicolas Geoffray | a83a54d | 2015-10-02 17:30:26 +0100 | [diff] [blame] | 19 | #include "intrinsics.h" |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 20 | #include "mirror/class-inl.h" |
| 21 | #include "scoped_thread_state_change.h" |
| 22 | |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 23 | namespace art { |
| 24 | |
Nicolas Geoffray | a83a54d | 2015-10-02 17:30:26 +0100 | [diff] [blame] | 25 | class InstructionSimplifierVisitor : public HGraphDelegateVisitor { |
Nicolas Geoffray | 5e6916c | 2014-11-18 16:53:35 +0000 | [diff] [blame] | 26 | public: |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 27 | InstructionSimplifierVisitor(HGraph* graph, OptimizingCompilerStats* stats) |
Nicolas Geoffray | a83a54d | 2015-10-02 17:30:26 +0100 | [diff] [blame] | 28 | : HGraphDelegateVisitor(graph), |
Alexandre Rames | 188d431 | 2015-04-09 18:30:21 +0100 | [diff] [blame] | 29 | stats_(stats) {} |
| 30 | |
| 31 | void Run(); |
Nicolas Geoffray | 5e6916c | 2014-11-18 16:53:35 +0000 | [diff] [blame] | 32 | |
| 33 | private: |
Alexandre Rames | 188d431 | 2015-04-09 18:30:21 +0100 | [diff] [blame] | 34 | void RecordSimplification() { |
| 35 | simplification_occurred_ = true; |
| 36 | simplifications_at_current_position_++; |
| 37 | if (stats_) { |
| 38 | stats_->RecordStat(kInstructionSimplifications); |
| 39 | } |
| 40 | } |
| 41 | |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 42 | bool ReplaceRotateWithRor(HBinaryOperation* op, HUShr* ushr, HShl* shl); |
| 43 | bool TryReplaceWithRotate(HBinaryOperation* instruction); |
| 44 | bool TryReplaceWithRotateConstantPattern(HBinaryOperation* op, HUShr* ushr, HShl* shl); |
| 45 | bool TryReplaceWithRotateRegisterNegPattern(HBinaryOperation* op, HUShr* ushr, HShl* shl); |
| 46 | bool TryReplaceWithRotateRegisterSubPattern(HBinaryOperation* op, HUShr* ushr, HShl* shl); |
| 47 | |
Alexandre Rames | 188d431 | 2015-04-09 18:30:21 +0100 | [diff] [blame] | 48 | bool TryMoveNegOnInputsAfterBinop(HBinaryOperation* binop); |
Kevin Brodsky | 9679849 | 2016-01-15 09:49:20 +0000 | [diff] [blame^] | 49 | // `op` should be either HOr or HAnd. |
| 50 | // De Morgan's laws: |
| 51 | // ~a & ~b = ~(a | b) and ~a | ~b = ~(a & b) |
| 52 | bool TryApplyDeMorgan(HBinaryOperation* op); |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 53 | void VisitShift(HBinaryOperation* shift); |
| 54 | |
Nicolas Geoffray | 5e6916c | 2014-11-18 16:53:35 +0000 | [diff] [blame] | 55 | void VisitSuspendCheck(HSuspendCheck* check) OVERRIDE; |
| 56 | void VisitEqual(HEqual* equal) OVERRIDE; |
David Brazdil | 0d13fee | 2015-04-17 14:52:19 +0100 | [diff] [blame] | 57 | void VisitNotEqual(HNotEqual* equal) OVERRIDE; |
| 58 | void VisitBooleanNot(HBooleanNot* bool_not) OVERRIDE; |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 59 | void VisitInstanceFieldSet(HInstanceFieldSet* equal) OVERRIDE; |
| 60 | void VisitStaticFieldSet(HStaticFieldSet* equal) OVERRIDE; |
Nicolas Geoffray | 5e6916c | 2014-11-18 16:53:35 +0000 | [diff] [blame] | 61 | void VisitArraySet(HArraySet* equal) OVERRIDE; |
Nicolas Geoffray | 01fcc9e | 2014-12-01 14:16:20 +0000 | [diff] [blame] | 62 | void VisitTypeConversion(HTypeConversion* instruction) OVERRIDE; |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 63 | void VisitNullCheck(HNullCheck* instruction) OVERRIDE; |
Mingyao Yang | 0304e18 | 2015-01-30 16:41:29 -0800 | [diff] [blame] | 64 | void VisitArrayLength(HArrayLength* instruction) OVERRIDE; |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 65 | void VisitCheckCast(HCheckCast* instruction) OVERRIDE; |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 66 | void VisitAdd(HAdd* instruction) OVERRIDE; |
| 67 | void VisitAnd(HAnd* instruction) OVERRIDE; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 68 | void VisitCondition(HCondition* instruction) OVERRIDE; |
| 69 | void VisitGreaterThan(HGreaterThan* condition) OVERRIDE; |
| 70 | void VisitGreaterThanOrEqual(HGreaterThanOrEqual* condition) OVERRIDE; |
| 71 | void VisitLessThan(HLessThan* condition) OVERRIDE; |
| 72 | void VisitLessThanOrEqual(HLessThanOrEqual* condition) OVERRIDE; |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 73 | void VisitDiv(HDiv* instruction) OVERRIDE; |
| 74 | void VisitMul(HMul* instruction) OVERRIDE; |
Alexandre Rames | 188d431 | 2015-04-09 18:30:21 +0100 | [diff] [blame] | 75 | void VisitNeg(HNeg* instruction) OVERRIDE; |
| 76 | void VisitNot(HNot* instruction) OVERRIDE; |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 77 | void VisitOr(HOr* instruction) OVERRIDE; |
| 78 | void VisitShl(HShl* instruction) OVERRIDE; |
| 79 | void VisitShr(HShr* instruction) OVERRIDE; |
| 80 | void VisitSub(HSub* instruction) OVERRIDE; |
| 81 | void VisitUShr(HUShr* instruction) OVERRIDE; |
| 82 | void VisitXor(HXor* instruction) OVERRIDE; |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 83 | void VisitInstanceOf(HInstanceOf* instruction) OVERRIDE; |
Nicolas Geoffray | a83a54d | 2015-10-02 17:30:26 +0100 | [diff] [blame] | 84 | void VisitInvoke(HInvoke* invoke) OVERRIDE; |
Aart Bik | bb245d1 | 2015-10-19 11:05:03 -0700 | [diff] [blame] | 85 | void VisitDeoptimize(HDeoptimize* deoptimize) OVERRIDE; |
Nicolas Geoffray | 6e7455e | 2015-09-28 16:25:37 +0100 | [diff] [blame] | 86 | |
| 87 | bool CanEnsureNotNullAt(HInstruction* instr, HInstruction* at) const; |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 88 | |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 89 | void SimplifyRotate(HInvoke* invoke, bool is_left); |
Nicolas Geoffray | ee3cf07 | 2015-10-06 11:45:02 +0100 | [diff] [blame] | 90 | void SimplifySystemArrayCopy(HInvoke* invoke); |
| 91 | void SimplifyStringEquals(HInvoke* invoke); |
| 92 | |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 93 | OptimizingCompilerStats* stats_; |
Alexandre Rames | 188d431 | 2015-04-09 18:30:21 +0100 | [diff] [blame] | 94 | bool simplification_occurred_ = false; |
| 95 | int simplifications_at_current_position_ = 0; |
| 96 | // We ensure we do not loop infinitely. The value is a finger in the air guess |
| 97 | // that should allow enough simplification. |
| 98 | static constexpr int kMaxSamePositionSimplifications = 10; |
Nicolas Geoffray | 5e6916c | 2014-11-18 16:53:35 +0000 | [diff] [blame] | 99 | }; |
| 100 | |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 101 | void InstructionSimplifier::Run() { |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 102 | InstructionSimplifierVisitor visitor(graph_, stats_); |
Alexandre Rames | 188d431 | 2015-04-09 18:30:21 +0100 | [diff] [blame] | 103 | visitor.Run(); |
| 104 | } |
| 105 | |
| 106 | void InstructionSimplifierVisitor::Run() { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 107 | // Iterate in reverse post order to open up more simplifications to users |
| 108 | // of instructions that got simplified. |
Alexandre Rames | 188d431 | 2015-04-09 18:30:21 +0100 | [diff] [blame] | 109 | for (HReversePostOrderIterator it(*GetGraph()); !it.Done();) { |
| 110 | // The simplification of an instruction to another instruction may yield |
| 111 | // possibilities for other simplifications. So although we perform a reverse |
| 112 | // post order visit, we sometimes need to revisit an instruction index. |
| 113 | simplification_occurred_ = false; |
| 114 | VisitBasicBlock(it.Current()); |
| 115 | if (simplification_occurred_ && |
| 116 | (simplifications_at_current_position_ < kMaxSamePositionSimplifications)) { |
| 117 | // New simplifications may be applicable to the instruction at the |
| 118 | // current index, so don't advance the iterator. |
| 119 | continue; |
| 120 | } |
Alexandre Rames | 188d431 | 2015-04-09 18:30:21 +0100 | [diff] [blame] | 121 | simplifications_at_current_position_ = 0; |
| 122 | it.Advance(); |
| 123 | } |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 124 | } |
| 125 | |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 126 | namespace { |
| 127 | |
| 128 | bool AreAllBitsSet(HConstant* constant) { |
| 129 | return Int64FromConstant(constant) == -1; |
| 130 | } |
| 131 | |
| 132 | } // namespace |
| 133 | |
Alexandre Rames | 188d431 | 2015-04-09 18:30:21 +0100 | [diff] [blame] | 134 | // Returns true if the code was simplified to use only one negation operation |
| 135 | // after the binary operation instead of one on each of the inputs. |
| 136 | bool InstructionSimplifierVisitor::TryMoveNegOnInputsAfterBinop(HBinaryOperation* binop) { |
| 137 | DCHECK(binop->IsAdd() || binop->IsSub()); |
| 138 | DCHECK(binop->GetLeft()->IsNeg() && binop->GetRight()->IsNeg()); |
| 139 | HNeg* left_neg = binop->GetLeft()->AsNeg(); |
| 140 | HNeg* right_neg = binop->GetRight()->AsNeg(); |
| 141 | if (!left_neg->HasOnlyOneNonEnvironmentUse() || |
| 142 | !right_neg->HasOnlyOneNonEnvironmentUse()) { |
| 143 | return false; |
| 144 | } |
| 145 | // Replace code looking like |
| 146 | // NEG tmp1, a |
| 147 | // NEG tmp2, b |
| 148 | // ADD dst, tmp1, tmp2 |
| 149 | // with |
| 150 | // ADD tmp, a, b |
| 151 | // NEG dst, tmp |
Serdjuk, Nikolay Y | aae9e66 | 2015-08-21 13:26:34 +0600 | [diff] [blame] | 152 | // Note that we cannot optimize `(-a) + (-b)` to `-(a + b)` for floating-point. |
| 153 | // When `a` is `-0.0` and `b` is `0.0`, the former expression yields `0.0`, |
| 154 | // while the later yields `-0.0`. |
| 155 | if (!Primitive::IsIntegralType(binop->GetType())) { |
| 156 | return false; |
| 157 | } |
Alexandre Rames | 188d431 | 2015-04-09 18:30:21 +0100 | [diff] [blame] | 158 | binop->ReplaceInput(left_neg->GetInput(), 0); |
| 159 | binop->ReplaceInput(right_neg->GetInput(), 1); |
| 160 | left_neg->GetBlock()->RemoveInstruction(left_neg); |
| 161 | right_neg->GetBlock()->RemoveInstruction(right_neg); |
| 162 | HNeg* neg = new (GetGraph()->GetArena()) HNeg(binop->GetType(), binop); |
| 163 | binop->GetBlock()->InsertInstructionBefore(neg, binop->GetNext()); |
| 164 | binop->ReplaceWithExceptInReplacementAtIndex(neg, 0); |
| 165 | RecordSimplification(); |
| 166 | return true; |
| 167 | } |
| 168 | |
Kevin Brodsky | 9679849 | 2016-01-15 09:49:20 +0000 | [diff] [blame^] | 169 | bool InstructionSimplifierVisitor::TryApplyDeMorgan(HBinaryOperation* op) { |
| 170 | DCHECK(op->IsAnd() || op->IsOr()); |
| 171 | Primitive::Type type = op->GetType(); |
| 172 | HInstruction* left = op->GetLeft(); |
| 173 | HInstruction* right = op->GetRight(); |
| 174 | |
| 175 | // We can apply De Morgan's laws if both inputs are Not's and are only used |
| 176 | // by `op`. |
| 177 | if (left->IsNot() && |
| 178 | right->IsNot() && |
| 179 | left->HasOnlyOneNonEnvironmentUse() && |
| 180 | right->HasOnlyOneNonEnvironmentUse()) { |
| 181 | // Replace code looking like |
| 182 | // NOT nota, a |
| 183 | // NOT notb, b |
| 184 | // AND dst, nota, notb (respectively OR) |
| 185 | // with |
| 186 | // OR or, a, b (respectively AND) |
| 187 | // NOT dest, or |
| 188 | HInstruction* src_left = left->AsNot()->GetInput(); |
| 189 | HInstruction* src_right = right->AsNot()->GetInput(); |
| 190 | uint32_t dex_pc = op->GetDexPc(); |
| 191 | |
| 192 | HBinaryOperation* hbin; |
| 193 | if (op->IsAnd()) { |
| 194 | hbin = new (GetGraph()->GetArena()) HOr(type, src_left, src_right, dex_pc); |
| 195 | } else { |
| 196 | hbin = new (GetGraph()->GetArena()) HAnd(type, src_left, src_right, dex_pc); |
| 197 | } |
| 198 | // Step 1: replace left Not by new binary operation (this is arbitrary, |
| 199 | // the right one could have been used instead). |
| 200 | // SL SR SL SR |
| 201 | // | | | / | |
| 202 | // Not Not NewBin Not |
| 203 | // \ / -> \ / |
| 204 | // OldBin OldBin |
| 205 | // | | |
| 206 | left->GetBlock()->ReplaceAndRemoveInstructionWith(left, hbin); |
| 207 | |
| 208 | HNot* hnot = new (GetGraph()->GetArena()) HNot(type, hbin, dex_pc); |
| 209 | // Step 2: replace old binary operation by a new Not, and remove |
| 210 | // the now disconnected right Not. |
| 211 | // SL SR SL SR |
| 212 | // | / | | / | |
| 213 | // NewBin Not NewBin Not [removed] |
| 214 | // \ / -> \ x |
| 215 | // OldBin Not |
| 216 | // | | |
| 217 | op->GetBlock()->ReplaceAndRemoveInstructionWith(op, hnot); |
| 218 | right->GetBlock()->RemoveInstruction(right); |
| 219 | |
| 220 | RecordSimplification(); |
| 221 | return true; |
| 222 | } |
| 223 | |
| 224 | return false; |
| 225 | } |
| 226 | |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 227 | void InstructionSimplifierVisitor::VisitShift(HBinaryOperation* instruction) { |
| 228 | DCHECK(instruction->IsShl() || instruction->IsShr() || instruction->IsUShr()); |
| 229 | HConstant* input_cst = instruction->GetConstantRight(); |
| 230 | HInstruction* input_other = instruction->GetLeastConstantLeft(); |
| 231 | |
Mark Mendell | ba56d06 | 2015-05-05 21:34:03 -0400 | [diff] [blame] | 232 | if (input_cst != nullptr) { |
| 233 | if (input_cst->IsZero()) { |
| 234 | // Replace code looking like |
| 235 | // SHL dst, src, 0 |
| 236 | // with |
| 237 | // src |
| 238 | instruction->ReplaceWith(input_other); |
| 239 | instruction->GetBlock()->RemoveInstruction(instruction); |
Mark Mendell | ba56d06 | 2015-05-05 21:34:03 -0400 | [diff] [blame] | 240 | } |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 241 | } |
| 242 | } |
| 243 | |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 244 | static bool IsSubRegBitsMinusOther(HSub* sub, size_t reg_bits, HInstruction* other) { |
| 245 | return (sub->GetRight() == other && |
| 246 | sub->GetLeft()->IsConstant() && |
| 247 | (Int64FromConstant(sub->GetLeft()->AsConstant()) & (reg_bits - 1)) == 0); |
| 248 | } |
| 249 | |
| 250 | bool InstructionSimplifierVisitor::ReplaceRotateWithRor(HBinaryOperation* op, |
| 251 | HUShr* ushr, |
| 252 | HShl* shl) { |
| 253 | DCHECK(op->IsAdd() || op->IsXor() || op->IsOr()); |
| 254 | HRor* ror = new (GetGraph()->GetArena()) HRor(ushr->GetType(), |
| 255 | ushr->GetLeft(), |
| 256 | ushr->GetRight()); |
| 257 | op->GetBlock()->ReplaceAndRemoveInstructionWith(op, ror); |
| 258 | if (!ushr->HasUses()) { |
| 259 | ushr->GetBlock()->RemoveInstruction(ushr); |
| 260 | } |
| 261 | if (!ushr->GetRight()->HasUses()) { |
| 262 | ushr->GetRight()->GetBlock()->RemoveInstruction(ushr->GetRight()); |
| 263 | } |
| 264 | if (!shl->HasUses()) { |
| 265 | shl->GetBlock()->RemoveInstruction(shl); |
| 266 | } |
| 267 | if (!shl->GetRight()->HasUses()) { |
| 268 | shl->GetRight()->GetBlock()->RemoveInstruction(shl->GetRight()); |
| 269 | } |
| 270 | return true; |
| 271 | } |
| 272 | |
| 273 | // Try to replace a binary operation flanked by one UShr and one Shl with a bitfield rotation. |
| 274 | bool InstructionSimplifierVisitor::TryReplaceWithRotate(HBinaryOperation* op) { |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 275 | DCHECK(op->IsAdd() || op->IsXor() || op->IsOr()); |
| 276 | HInstruction* left = op->GetLeft(); |
| 277 | HInstruction* right = op->GetRight(); |
| 278 | // If we have an UShr and a Shl (in either order). |
| 279 | if ((left->IsUShr() && right->IsShl()) || (left->IsShl() && right->IsUShr())) { |
| 280 | HUShr* ushr = left->IsUShr() ? left->AsUShr() : right->AsUShr(); |
| 281 | HShl* shl = left->IsShl() ? left->AsShl() : right->AsShl(); |
| 282 | DCHECK(Primitive::IsIntOrLongType(ushr->GetType())); |
| 283 | if (ushr->GetType() == shl->GetType() && |
| 284 | ushr->GetLeft() == shl->GetLeft()) { |
| 285 | if (ushr->GetRight()->IsConstant() && shl->GetRight()->IsConstant()) { |
| 286 | // Shift distances are both constant, try replacing with Ror if they |
| 287 | // add up to the register size. |
| 288 | return TryReplaceWithRotateConstantPattern(op, ushr, shl); |
| 289 | } else if (ushr->GetRight()->IsSub() || shl->GetRight()->IsSub()) { |
| 290 | // Shift distances are potentially of the form x and (reg_size - x). |
| 291 | return TryReplaceWithRotateRegisterSubPattern(op, ushr, shl); |
| 292 | } else if (ushr->GetRight()->IsNeg() || shl->GetRight()->IsNeg()) { |
| 293 | // Shift distances are potentially of the form d and -d. |
| 294 | return TryReplaceWithRotateRegisterNegPattern(op, ushr, shl); |
| 295 | } |
| 296 | } |
| 297 | } |
| 298 | return false; |
| 299 | } |
| 300 | |
| 301 | // Try replacing code looking like (x >>> #rdist OP x << #ldist): |
| 302 | // UShr dst, x, #rdist |
| 303 | // Shl tmp, x, #ldist |
| 304 | // OP dst, dst, tmp |
| 305 | // or like (x >>> #rdist OP x << #-ldist): |
| 306 | // UShr dst, x, #rdist |
| 307 | // Shl tmp, x, #-ldist |
| 308 | // OP dst, dst, tmp |
| 309 | // with |
| 310 | // Ror dst, x, #rdist |
| 311 | bool InstructionSimplifierVisitor::TryReplaceWithRotateConstantPattern(HBinaryOperation* op, |
| 312 | HUShr* ushr, |
| 313 | HShl* shl) { |
| 314 | DCHECK(op->IsAdd() || op->IsXor() || op->IsOr()); |
| 315 | size_t reg_bits = Primitive::ComponentSize(ushr->GetType()) * kBitsPerByte; |
| 316 | size_t rdist = Int64FromConstant(ushr->GetRight()->AsConstant()); |
| 317 | size_t ldist = Int64FromConstant(shl->GetRight()->AsConstant()); |
| 318 | if (((ldist + rdist) & (reg_bits - 1)) == 0) { |
| 319 | ReplaceRotateWithRor(op, ushr, shl); |
| 320 | return true; |
| 321 | } |
| 322 | return false; |
| 323 | } |
| 324 | |
| 325 | // Replace code looking like (x >>> -d OP x << d): |
| 326 | // Neg neg, d |
| 327 | // UShr dst, x, neg |
| 328 | // Shl tmp, x, d |
| 329 | // OP dst, dst, tmp |
| 330 | // with |
| 331 | // Neg neg, d |
| 332 | // Ror dst, x, neg |
| 333 | // *** OR *** |
| 334 | // Replace code looking like (x >>> d OP x << -d): |
| 335 | // UShr dst, x, d |
| 336 | // Neg neg, d |
| 337 | // Shl tmp, x, neg |
| 338 | // OP dst, dst, tmp |
| 339 | // with |
| 340 | // Ror dst, x, d |
| 341 | bool InstructionSimplifierVisitor::TryReplaceWithRotateRegisterNegPattern(HBinaryOperation* op, |
| 342 | HUShr* ushr, |
| 343 | HShl* shl) { |
| 344 | DCHECK(op->IsAdd() || op->IsXor() || op->IsOr()); |
| 345 | DCHECK(ushr->GetRight()->IsNeg() || shl->GetRight()->IsNeg()); |
| 346 | bool neg_is_left = shl->GetRight()->IsNeg(); |
| 347 | HNeg* neg = neg_is_left ? shl->GetRight()->AsNeg() : ushr->GetRight()->AsNeg(); |
| 348 | // And the shift distance being negated is the distance being shifted the other way. |
| 349 | if (neg->InputAt(0) == (neg_is_left ? ushr->GetRight() : shl->GetRight())) { |
| 350 | ReplaceRotateWithRor(op, ushr, shl); |
| 351 | } |
| 352 | return false; |
| 353 | } |
| 354 | |
| 355 | // Try replacing code looking like (x >>> d OP x << (#bits - d)): |
| 356 | // UShr dst, x, d |
| 357 | // Sub ld, #bits, d |
| 358 | // Shl tmp, x, ld |
| 359 | // OP dst, dst, tmp |
| 360 | // with |
| 361 | // Ror dst, x, d |
| 362 | // *** OR *** |
| 363 | // Replace code looking like (x >>> (#bits - d) OP x << d): |
| 364 | // Sub rd, #bits, d |
| 365 | // UShr dst, x, rd |
| 366 | // Shl tmp, x, d |
| 367 | // OP dst, dst, tmp |
| 368 | // with |
| 369 | // Neg neg, d |
| 370 | // Ror dst, x, neg |
| 371 | bool InstructionSimplifierVisitor::TryReplaceWithRotateRegisterSubPattern(HBinaryOperation* op, |
| 372 | HUShr* ushr, |
| 373 | HShl* shl) { |
| 374 | DCHECK(op->IsAdd() || op->IsXor() || op->IsOr()); |
| 375 | DCHECK(ushr->GetRight()->IsSub() || shl->GetRight()->IsSub()); |
| 376 | size_t reg_bits = Primitive::ComponentSize(ushr->GetType()) * kBitsPerByte; |
| 377 | HInstruction* shl_shift = shl->GetRight(); |
| 378 | HInstruction* ushr_shift = ushr->GetRight(); |
| 379 | if ((shl_shift->IsSub() && IsSubRegBitsMinusOther(shl_shift->AsSub(), reg_bits, ushr_shift)) || |
| 380 | (ushr_shift->IsSub() && IsSubRegBitsMinusOther(ushr_shift->AsSub(), reg_bits, shl_shift))) { |
| 381 | return ReplaceRotateWithRor(op, ushr, shl); |
| 382 | } |
| 383 | return false; |
| 384 | } |
| 385 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 386 | void InstructionSimplifierVisitor::VisitNullCheck(HNullCheck* null_check) { |
| 387 | HInstruction* obj = null_check->InputAt(0); |
| 388 | if (!obj->CanBeNull()) { |
| 389 | null_check->ReplaceWith(obj); |
| 390 | null_check->GetBlock()->RemoveInstruction(null_check); |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 391 | if (stats_ != nullptr) { |
| 392 | stats_->RecordStat(MethodCompilationStat::kRemovedNullCheck); |
| 393 | } |
| 394 | } |
| 395 | } |
| 396 | |
Nicolas Geoffray | 6e7455e | 2015-09-28 16:25:37 +0100 | [diff] [blame] | 397 | bool InstructionSimplifierVisitor::CanEnsureNotNullAt(HInstruction* input, HInstruction* at) const { |
| 398 | if (!input->CanBeNull()) { |
| 399 | return true; |
| 400 | } |
| 401 | |
Guillaume "Vermeille" Sanchez | 8909baf | 2015-04-23 21:35:11 +0100 | [diff] [blame] | 402 | for (HUseIterator<HInstruction*> it(input->GetUses()); !it.Done(); it.Advance()) { |
| 403 | HInstruction* use = it.Current()->GetUser(); |
Nicolas Geoffray | 6e7455e | 2015-09-28 16:25:37 +0100 | [diff] [blame] | 404 | if (use->IsNullCheck() && use->StrictlyDominates(at)) { |
Guillaume "Vermeille" Sanchez | 8909baf | 2015-04-23 21:35:11 +0100 | [diff] [blame] | 405 | return true; |
| 406 | } |
| 407 | } |
Nicolas Geoffray | 6e7455e | 2015-09-28 16:25:37 +0100 | [diff] [blame] | 408 | |
Guillaume "Vermeille" Sanchez | 8909baf | 2015-04-23 21:35:11 +0100 | [diff] [blame] | 409 | return false; |
| 410 | } |
| 411 | |
Guillaume Sanchez | 222862c | 2015-06-09 18:33:02 +0100 | [diff] [blame] | 412 | // Returns whether doing a type test between the class of `object` against `klass` has |
| 413 | // a statically known outcome. The result of the test is stored in `outcome`. |
| 414 | static bool TypeCheckHasKnownOutcome(HLoadClass* klass, HInstruction* object, bool* outcome) { |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 415 | DCHECK(!object->IsNullConstant()) << "Null constants should be special cased"; |
| 416 | ReferenceTypeInfo obj_rti = object->GetReferenceTypeInfo(); |
| 417 | ScopedObjectAccess soa(Thread::Current()); |
| 418 | if (!obj_rti.IsValid()) { |
| 419 | // We run the simplifier before the reference type propagation so type info might not be |
| 420 | // available. |
Guillaume Sanchez | 222862c | 2015-06-09 18:33:02 +0100 | [diff] [blame] | 421 | return false; |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 422 | } |
Guillaume Sanchez | 222862c | 2015-06-09 18:33:02 +0100 | [diff] [blame] | 423 | |
Guillaume Sanchez | 222862c | 2015-06-09 18:33:02 +0100 | [diff] [blame] | 424 | ReferenceTypeInfo class_rti = klass->GetLoadedClassRTI(); |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 425 | if (!class_rti.IsValid()) { |
| 426 | // Happens when the loaded class is unresolved. |
| 427 | return false; |
| 428 | } |
| 429 | DCHECK(class_rti.IsExact()); |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 430 | if (class_rti.IsSupertypeOf(obj_rti)) { |
Guillaume Sanchez | 222862c | 2015-06-09 18:33:02 +0100 | [diff] [blame] | 431 | *outcome = true; |
| 432 | return true; |
| 433 | } else if (obj_rti.IsExact()) { |
| 434 | // The test failed at compile time so will also fail at runtime. |
| 435 | *outcome = false; |
| 436 | return true; |
Nicolas Geoffray | 7cb499b | 2015-06-17 11:35:11 +0100 | [diff] [blame] | 437 | } else if (!class_rti.IsInterface() |
| 438 | && !obj_rti.IsInterface() |
| 439 | && !obj_rti.IsSupertypeOf(class_rti)) { |
Guillaume Sanchez | 222862c | 2015-06-09 18:33:02 +0100 | [diff] [blame] | 440 | // Different type hierarchy. The test will fail. |
| 441 | *outcome = false; |
| 442 | return true; |
| 443 | } |
| 444 | return false; |
| 445 | } |
| 446 | |
| 447 | void InstructionSimplifierVisitor::VisitCheckCast(HCheckCast* check_cast) { |
| 448 | HInstruction* object = check_cast->InputAt(0); |
Calin Juravle | e53fb55 | 2015-10-07 17:51:52 +0100 | [diff] [blame] | 449 | HLoadClass* load_class = check_cast->InputAt(1)->AsLoadClass(); |
| 450 | if (load_class->NeedsAccessCheck()) { |
| 451 | // If we need to perform an access check we cannot remove the instruction. |
| 452 | return; |
| 453 | } |
| 454 | |
Nicolas Geoffray | 6e7455e | 2015-09-28 16:25:37 +0100 | [diff] [blame] | 455 | if (CanEnsureNotNullAt(object, check_cast)) { |
Guillaume Sanchez | 222862c | 2015-06-09 18:33:02 +0100 | [diff] [blame] | 456 | check_cast->ClearMustDoNullCheck(); |
| 457 | } |
| 458 | |
| 459 | if (object->IsNullConstant()) { |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 460 | check_cast->GetBlock()->RemoveInstruction(check_cast); |
| 461 | if (stats_ != nullptr) { |
| 462 | stats_->RecordStat(MethodCompilationStat::kRemovedCheckedCast); |
| 463 | } |
Guillaume Sanchez | 222862c | 2015-06-09 18:33:02 +0100 | [diff] [blame] | 464 | return; |
| 465 | } |
| 466 | |
| 467 | bool outcome; |
Nicolas Geoffray | efa8468 | 2015-08-12 18:28:14 -0700 | [diff] [blame] | 468 | if (TypeCheckHasKnownOutcome(load_class, object, &outcome)) { |
Guillaume Sanchez | 222862c | 2015-06-09 18:33:02 +0100 | [diff] [blame] | 469 | if (outcome) { |
| 470 | check_cast->GetBlock()->RemoveInstruction(check_cast); |
| 471 | if (stats_ != nullptr) { |
| 472 | stats_->RecordStat(MethodCompilationStat::kRemovedCheckedCast); |
| 473 | } |
Nicolas Geoffray | efa8468 | 2015-08-12 18:28:14 -0700 | [diff] [blame] | 474 | if (!load_class->HasUses()) { |
| 475 | // We cannot rely on DCE to remove the class because the `HLoadClass` thinks it can throw. |
| 476 | // However, here we know that it cannot because the checkcast was successfull, hence |
| 477 | // the class was already loaded. |
| 478 | load_class->GetBlock()->RemoveInstruction(load_class); |
| 479 | } |
Guillaume Sanchez | 222862c | 2015-06-09 18:33:02 +0100 | [diff] [blame] | 480 | } else { |
| 481 | // Don't do anything for exceptional cases for now. Ideally we should remove |
| 482 | // all instructions and blocks this instruction dominates. |
| 483 | } |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 484 | } |
| 485 | } |
| 486 | |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 487 | void InstructionSimplifierVisitor::VisitInstanceOf(HInstanceOf* instruction) { |
Guillaume Sanchez | 222862c | 2015-06-09 18:33:02 +0100 | [diff] [blame] | 488 | HInstruction* object = instruction->InputAt(0); |
Calin Juravle | e53fb55 | 2015-10-07 17:51:52 +0100 | [diff] [blame] | 489 | HLoadClass* load_class = instruction->InputAt(1)->AsLoadClass(); |
| 490 | if (load_class->NeedsAccessCheck()) { |
| 491 | // If we need to perform an access check we cannot remove the instruction. |
| 492 | return; |
| 493 | } |
| 494 | |
Guillaume Sanchez | 222862c | 2015-06-09 18:33:02 +0100 | [diff] [blame] | 495 | bool can_be_null = true; |
Nicolas Geoffray | 6e7455e | 2015-09-28 16:25:37 +0100 | [diff] [blame] | 496 | if (CanEnsureNotNullAt(object, instruction)) { |
Guillaume Sanchez | 222862c | 2015-06-09 18:33:02 +0100 | [diff] [blame] | 497 | can_be_null = false; |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 498 | instruction->ClearMustDoNullCheck(); |
| 499 | } |
Guillaume Sanchez | 222862c | 2015-06-09 18:33:02 +0100 | [diff] [blame] | 500 | |
| 501 | HGraph* graph = GetGraph(); |
| 502 | if (object->IsNullConstant()) { |
| 503 | instruction->ReplaceWith(graph->GetIntConstant(0)); |
| 504 | instruction->GetBlock()->RemoveInstruction(instruction); |
| 505 | RecordSimplification(); |
| 506 | return; |
| 507 | } |
| 508 | |
| 509 | bool outcome; |
Nicolas Geoffray | efa8468 | 2015-08-12 18:28:14 -0700 | [diff] [blame] | 510 | if (TypeCheckHasKnownOutcome(load_class, object, &outcome)) { |
Guillaume Sanchez | 222862c | 2015-06-09 18:33:02 +0100 | [diff] [blame] | 511 | if (outcome && can_be_null) { |
| 512 | // Type test will succeed, we just need a null test. |
| 513 | HNotEqual* test = new (graph->GetArena()) HNotEqual(graph->GetNullConstant(), object); |
| 514 | instruction->GetBlock()->InsertInstructionBefore(test, instruction); |
| 515 | instruction->ReplaceWith(test); |
| 516 | } else { |
| 517 | // We've statically determined the result of the instanceof. |
| 518 | instruction->ReplaceWith(graph->GetIntConstant(outcome)); |
| 519 | } |
| 520 | RecordSimplification(); |
| 521 | instruction->GetBlock()->RemoveInstruction(instruction); |
Nicolas Geoffray | efa8468 | 2015-08-12 18:28:14 -0700 | [diff] [blame] | 522 | if (outcome && !load_class->HasUses()) { |
| 523 | // We cannot rely on DCE to remove the class because the `HLoadClass` thinks it can throw. |
| 524 | // However, here we know that it cannot because the instanceof check was successfull, hence |
| 525 | // the class was already loaded. |
| 526 | load_class->GetBlock()->RemoveInstruction(load_class); |
| 527 | } |
Guillaume Sanchez | 222862c | 2015-06-09 18:33:02 +0100 | [diff] [blame] | 528 | } |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 529 | } |
| 530 | |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 531 | void InstructionSimplifierVisitor::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
| 532 | if ((instruction->GetValue()->GetType() == Primitive::kPrimNot) |
Nicolas Geoffray | 6e7455e | 2015-09-28 16:25:37 +0100 | [diff] [blame] | 533 | && CanEnsureNotNullAt(instruction->GetValue(), instruction)) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 534 | instruction->ClearValueCanBeNull(); |
| 535 | } |
| 536 | } |
| 537 | |
| 538 | void InstructionSimplifierVisitor::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
| 539 | if ((instruction->GetValue()->GetType() == Primitive::kPrimNot) |
Nicolas Geoffray | 6e7455e | 2015-09-28 16:25:37 +0100 | [diff] [blame] | 540 | && CanEnsureNotNullAt(instruction->GetValue(), instruction)) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 541 | instruction->ClearValueCanBeNull(); |
| 542 | } |
| 543 | } |
| 544 | |
Nicolas Geoffray | 5e6916c | 2014-11-18 16:53:35 +0000 | [diff] [blame] | 545 | void InstructionSimplifierVisitor::VisitSuspendCheck(HSuspendCheck* check) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 546 | HBasicBlock* block = check->GetBlock(); |
| 547 | // Currently always keep the suspend check at entry. |
| 548 | if (block->IsEntryBlock()) return; |
| 549 | |
| 550 | // Currently always keep suspend checks at loop entry. |
| 551 | if (block->IsLoopHeader() && block->GetFirstInstruction() == check) { |
| 552 | DCHECK(block->GetLoopInformation()->GetSuspendCheck() == check); |
| 553 | return; |
| 554 | } |
| 555 | |
| 556 | // Remove the suspend check that was added at build time for the baseline |
| 557 | // compiler. |
| 558 | block->RemoveInstruction(check); |
| 559 | } |
| 560 | |
Nicolas Geoffray | 5e6916c | 2014-11-18 16:53:35 +0000 | [diff] [blame] | 561 | void InstructionSimplifierVisitor::VisitEqual(HEqual* equal) { |
David Brazdil | 0d13fee | 2015-04-17 14:52:19 +0100 | [diff] [blame] | 562 | HInstruction* input_const = equal->GetConstantRight(); |
| 563 | if (input_const != nullptr) { |
| 564 | HInstruction* input_value = equal->GetLeastConstantLeft(); |
| 565 | if (input_value->GetType() == Primitive::kPrimBoolean && input_const->IsIntConstant()) { |
| 566 | HBasicBlock* block = equal->GetBlock(); |
Nicolas Geoffray | 3c4ab80 | 2015-06-19 11:42:07 +0100 | [diff] [blame] | 567 | // We are comparing the boolean to a constant which is of type int and can |
| 568 | // be any constant. |
David Brazdil | 0d13fee | 2015-04-17 14:52:19 +0100 | [diff] [blame] | 569 | if (input_const->AsIntConstant()->IsOne()) { |
| 570 | // Replace (bool_value == true) with bool_value |
| 571 | equal->ReplaceWith(input_value); |
| 572 | block->RemoveInstruction(equal); |
| 573 | RecordSimplification(); |
Nicolas Geoffray | 3c4ab80 | 2015-06-19 11:42:07 +0100 | [diff] [blame] | 574 | } else if (input_const->AsIntConstant()->IsZero()) { |
Mark Mendell | f652917 | 2015-11-17 11:16:56 -0500 | [diff] [blame] | 575 | equal->ReplaceWith(GetGraph()->InsertOppositeCondition(input_value, equal)); |
| 576 | block->RemoveInstruction(equal); |
David Brazdil | 0d13fee | 2015-04-17 14:52:19 +0100 | [diff] [blame] | 577 | RecordSimplification(); |
David Brazdil | 1e9ec05 | 2015-06-22 10:26:45 +0100 | [diff] [blame] | 578 | } else { |
| 579 | // Replace (bool_value == integer_not_zero_nor_one_constant) with false |
| 580 | equal->ReplaceWith(GetGraph()->GetIntConstant(0)); |
| 581 | block->RemoveInstruction(equal); |
| 582 | RecordSimplification(); |
David Brazdil | 0d13fee | 2015-04-17 14:52:19 +0100 | [diff] [blame] | 583 | } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 584 | } else { |
| 585 | VisitCondition(equal); |
Nicolas Geoffray | 01ef345 | 2014-10-01 11:32:17 +0100 | [diff] [blame] | 586 | } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 587 | } else { |
| 588 | VisitCondition(equal); |
Nicolas Geoffray | 01ef345 | 2014-10-01 11:32:17 +0100 | [diff] [blame] | 589 | } |
| 590 | } |
| 591 | |
David Brazdil | 0d13fee | 2015-04-17 14:52:19 +0100 | [diff] [blame] | 592 | void InstructionSimplifierVisitor::VisitNotEqual(HNotEqual* not_equal) { |
| 593 | HInstruction* input_const = not_equal->GetConstantRight(); |
| 594 | if (input_const != nullptr) { |
| 595 | HInstruction* input_value = not_equal->GetLeastConstantLeft(); |
| 596 | if (input_value->GetType() == Primitive::kPrimBoolean && input_const->IsIntConstant()) { |
| 597 | HBasicBlock* block = not_equal->GetBlock(); |
Nicolas Geoffray | 3c4ab80 | 2015-06-19 11:42:07 +0100 | [diff] [blame] | 598 | // We are comparing the boolean to a constant which is of type int and can |
| 599 | // be any constant. |
David Brazdil | 0d13fee | 2015-04-17 14:52:19 +0100 | [diff] [blame] | 600 | if (input_const->AsIntConstant()->IsOne()) { |
Mark Mendell | f652917 | 2015-11-17 11:16:56 -0500 | [diff] [blame] | 601 | not_equal->ReplaceWith(GetGraph()->InsertOppositeCondition(input_value, not_equal)); |
| 602 | block->RemoveInstruction(not_equal); |
David Brazdil | 0d13fee | 2015-04-17 14:52:19 +0100 | [diff] [blame] | 603 | RecordSimplification(); |
Nicolas Geoffray | 3c4ab80 | 2015-06-19 11:42:07 +0100 | [diff] [blame] | 604 | } else if (input_const->AsIntConstant()->IsZero()) { |
David Brazdil | 0d13fee | 2015-04-17 14:52:19 +0100 | [diff] [blame] | 605 | // Replace (bool_value != false) with bool_value |
David Brazdil | 0d13fee | 2015-04-17 14:52:19 +0100 | [diff] [blame] | 606 | not_equal->ReplaceWith(input_value); |
| 607 | block->RemoveInstruction(not_equal); |
| 608 | RecordSimplification(); |
David Brazdil | 1e9ec05 | 2015-06-22 10:26:45 +0100 | [diff] [blame] | 609 | } else { |
| 610 | // Replace (bool_value != integer_not_zero_nor_one_constant) with true |
| 611 | not_equal->ReplaceWith(GetGraph()->GetIntConstant(1)); |
| 612 | block->RemoveInstruction(not_equal); |
| 613 | RecordSimplification(); |
David Brazdil | 0d13fee | 2015-04-17 14:52:19 +0100 | [diff] [blame] | 614 | } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 615 | } else { |
| 616 | VisitCondition(not_equal); |
David Brazdil | 0d13fee | 2015-04-17 14:52:19 +0100 | [diff] [blame] | 617 | } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 618 | } else { |
| 619 | VisitCondition(not_equal); |
David Brazdil | 0d13fee | 2015-04-17 14:52:19 +0100 | [diff] [blame] | 620 | } |
| 621 | } |
| 622 | |
| 623 | void InstructionSimplifierVisitor::VisitBooleanNot(HBooleanNot* bool_not) { |
| 624 | HInstruction* parent = bool_not->InputAt(0); |
| 625 | if (parent->IsBooleanNot()) { |
| 626 | HInstruction* value = parent->InputAt(0); |
| 627 | // Replace (!(!bool_value)) with bool_value |
| 628 | bool_not->ReplaceWith(value); |
| 629 | bool_not->GetBlock()->RemoveInstruction(bool_not); |
| 630 | // It is possible that `parent` is dead at this point but we leave |
| 631 | // its removal to DCE for simplicity. |
| 632 | RecordSimplification(); |
| 633 | } |
| 634 | } |
| 635 | |
Mingyao Yang | 0304e18 | 2015-01-30 16:41:29 -0800 | [diff] [blame] | 636 | void InstructionSimplifierVisitor::VisitArrayLength(HArrayLength* instruction) { |
| 637 | HInstruction* input = instruction->InputAt(0); |
| 638 | // If the array is a NewArray with constant size, replace the array length |
| 639 | // with the constant instruction. This helps the bounds check elimination phase. |
| 640 | if (input->IsNewArray()) { |
| 641 | input = input->InputAt(0); |
| 642 | if (input->IsIntConstant()) { |
| 643 | instruction->ReplaceWith(input); |
| 644 | } |
| 645 | } |
| 646 | } |
| 647 | |
Nicolas Geoffray | 5e6916c | 2014-11-18 16:53:35 +0000 | [diff] [blame] | 648 | void InstructionSimplifierVisitor::VisitArraySet(HArraySet* instruction) { |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 649 | HInstruction* value = instruction->GetValue(); |
| 650 | if (value->GetType() != Primitive::kPrimNot) return; |
| 651 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 652 | if (CanEnsureNotNullAt(value, instruction)) { |
| 653 | instruction->ClearValueCanBeNull(); |
| 654 | } |
| 655 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 656 | if (value->IsArrayGet()) { |
| 657 | if (value->AsArrayGet()->GetArray() == instruction->GetArray()) { |
| 658 | // If the code is just swapping elements in the array, no need for a type check. |
| 659 | instruction->ClearNeedsTypeCheck(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 660 | return; |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 661 | } |
| 662 | } |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 663 | |
Nicolas Geoffray | 9fdb31e | 2015-07-01 12:56:46 +0100 | [diff] [blame] | 664 | if (value->IsNullConstant()) { |
| 665 | instruction->ClearNeedsTypeCheck(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 666 | return; |
Nicolas Geoffray | 9fdb31e | 2015-07-01 12:56:46 +0100 | [diff] [blame] | 667 | } |
| 668 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 669 | ScopedObjectAccess soa(Thread::Current()); |
| 670 | ReferenceTypeInfo array_rti = instruction->GetArray()->GetReferenceTypeInfo(); |
| 671 | ReferenceTypeInfo value_rti = value->GetReferenceTypeInfo(); |
| 672 | if (!array_rti.IsValid()) { |
| 673 | return; |
| 674 | } |
| 675 | |
| 676 | if (value_rti.IsValid() && array_rti.CanArrayHold(value_rti)) { |
| 677 | instruction->ClearNeedsTypeCheck(); |
| 678 | return; |
| 679 | } |
| 680 | |
| 681 | if (array_rti.IsObjectArray()) { |
| 682 | if (array_rti.IsExact()) { |
| 683 | instruction->ClearNeedsTypeCheck(); |
| 684 | return; |
| 685 | } |
| 686 | instruction->SetStaticTypeOfArrayIsObjectArray(); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 687 | } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 688 | } |
| 689 | |
Nicolas Geoffray | 01fcc9e | 2014-12-01 14:16:20 +0000 | [diff] [blame] | 690 | void InstructionSimplifierVisitor::VisitTypeConversion(HTypeConversion* instruction) { |
| 691 | if (instruction->GetResultType() == instruction->GetInputType()) { |
| 692 | // Remove the instruction if it's converting to the same type. |
| 693 | instruction->ReplaceWith(instruction->GetInput()); |
| 694 | instruction->GetBlock()->RemoveInstruction(instruction); |
| 695 | } |
| 696 | } |
| 697 | |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 698 | void InstructionSimplifierVisitor::VisitAdd(HAdd* instruction) { |
| 699 | HConstant* input_cst = instruction->GetConstantRight(); |
| 700 | HInstruction* input_other = instruction->GetLeastConstantLeft(); |
| 701 | if ((input_cst != nullptr) && input_cst->IsZero()) { |
| 702 | // Replace code looking like |
| 703 | // ADD dst, src, 0 |
| 704 | // with |
| 705 | // src |
Serguei Katkov | 115b53f | 2015-08-05 17:03:30 +0600 | [diff] [blame] | 706 | // Note that we cannot optimize `x + 0.0` to `x` for floating-point. When |
| 707 | // `x` is `-0.0`, the former expression yields `0.0`, while the later |
| 708 | // yields `-0.0`. |
| 709 | if (Primitive::IsIntegralType(instruction->GetType())) { |
| 710 | instruction->ReplaceWith(input_other); |
| 711 | instruction->GetBlock()->RemoveInstruction(instruction); |
| 712 | return; |
| 713 | } |
Alexandre Rames | 188d431 | 2015-04-09 18:30:21 +0100 | [diff] [blame] | 714 | } |
| 715 | |
| 716 | HInstruction* left = instruction->GetLeft(); |
| 717 | HInstruction* right = instruction->GetRight(); |
| 718 | bool left_is_neg = left->IsNeg(); |
| 719 | bool right_is_neg = right->IsNeg(); |
| 720 | |
| 721 | if (left_is_neg && right_is_neg) { |
| 722 | if (TryMoveNegOnInputsAfterBinop(instruction)) { |
| 723 | return; |
| 724 | } |
| 725 | } |
| 726 | |
| 727 | HNeg* neg = left_is_neg ? left->AsNeg() : right->AsNeg(); |
| 728 | if ((left_is_neg ^ right_is_neg) && neg->HasOnlyOneNonEnvironmentUse()) { |
| 729 | // Replace code looking like |
| 730 | // NEG tmp, b |
| 731 | // ADD dst, a, tmp |
| 732 | // with |
| 733 | // SUB dst, a, b |
| 734 | // We do not perform the optimization if the input negation has environment |
| 735 | // uses or multiple non-environment uses as it could lead to worse code. In |
| 736 | // particular, we do not want the live range of `b` to be extended if we are |
| 737 | // not sure the initial 'NEG' instruction can be removed. |
| 738 | HInstruction* other = left_is_neg ? right : left; |
| 739 | HSub* sub = new(GetGraph()->GetArena()) HSub(instruction->GetType(), other, neg->GetInput()); |
| 740 | instruction->GetBlock()->ReplaceAndRemoveInstructionWith(instruction, sub); |
| 741 | RecordSimplification(); |
| 742 | neg->GetBlock()->RemoveInstruction(neg); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 743 | return; |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 744 | } |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 745 | |
| 746 | TryReplaceWithRotate(instruction); |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 747 | } |
| 748 | |
| 749 | void InstructionSimplifierVisitor::VisitAnd(HAnd* instruction) { |
| 750 | HConstant* input_cst = instruction->GetConstantRight(); |
| 751 | HInstruction* input_other = instruction->GetLeastConstantLeft(); |
| 752 | |
Vladimir Marko | 452c1b6 | 2015-09-25 14:44:17 +0100 | [diff] [blame] | 753 | if (input_cst != nullptr) { |
| 754 | int64_t value = Int64FromConstant(input_cst); |
| 755 | if (value == -1) { |
| 756 | // Replace code looking like |
| 757 | // AND dst, src, 0xFFF...FF |
| 758 | // with |
| 759 | // src |
| 760 | instruction->ReplaceWith(input_other); |
| 761 | instruction->GetBlock()->RemoveInstruction(instruction); |
| 762 | RecordSimplification(); |
| 763 | return; |
| 764 | } |
| 765 | // Eliminate And from UShr+And if the And-mask contains all the bits that |
| 766 | // can be non-zero after UShr. Transform Shr+And to UShr if the And-mask |
| 767 | // precisely clears the shifted-in sign bits. |
| 768 | if ((input_other->IsUShr() || input_other->IsShr()) && input_other->InputAt(1)->IsConstant()) { |
| 769 | size_t reg_bits = (instruction->GetResultType() == Primitive::kPrimLong) ? 64 : 32; |
| 770 | size_t shift = Int64FromConstant(input_other->InputAt(1)->AsConstant()) & (reg_bits - 1); |
| 771 | size_t num_tail_bits_set = CTZ(value + 1); |
| 772 | if ((num_tail_bits_set >= reg_bits - shift) && input_other->IsUShr()) { |
| 773 | // This AND clears only bits known to be clear, for example "(x >>> 24) & 0xff". |
| 774 | instruction->ReplaceWith(input_other); |
| 775 | instruction->GetBlock()->RemoveInstruction(instruction); |
| 776 | RecordSimplification(); |
| 777 | return; |
| 778 | } else if ((num_tail_bits_set == reg_bits - shift) && IsPowerOfTwo(value + 1) && |
| 779 | input_other->HasOnlyOneNonEnvironmentUse()) { |
| 780 | DCHECK(input_other->IsShr()); // For UShr, we would have taken the branch above. |
| 781 | // Replace SHR+AND with USHR, for example "(x >> 24) & 0xff" -> "x >>> 24". |
| 782 | HUShr* ushr = new (GetGraph()->GetArena()) HUShr(instruction->GetType(), |
| 783 | input_other->InputAt(0), |
| 784 | input_other->InputAt(1), |
| 785 | input_other->GetDexPc()); |
| 786 | instruction->GetBlock()->ReplaceAndRemoveInstructionWith(instruction, ushr); |
| 787 | input_other->GetBlock()->RemoveInstruction(input_other); |
| 788 | RecordSimplification(); |
| 789 | return; |
| 790 | } |
| 791 | } |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 792 | } |
| 793 | |
| 794 | // We assume that GVN has run before, so we only perform a pointer comparison. |
| 795 | // If for some reason the values are equal but the pointers are different, we |
Alexandre Rames | 188d431 | 2015-04-09 18:30:21 +0100 | [diff] [blame] | 796 | // are still correct and only miss an optimization opportunity. |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 797 | if (instruction->GetLeft() == instruction->GetRight()) { |
| 798 | // Replace code looking like |
| 799 | // AND dst, src, src |
| 800 | // with |
| 801 | // src |
| 802 | instruction->ReplaceWith(instruction->GetLeft()); |
| 803 | instruction->GetBlock()->RemoveInstruction(instruction); |
Kevin Brodsky | 9679849 | 2016-01-15 09:49:20 +0000 | [diff] [blame^] | 804 | return; |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 805 | } |
Kevin Brodsky | 9679849 | 2016-01-15 09:49:20 +0000 | [diff] [blame^] | 806 | |
| 807 | TryApplyDeMorgan(instruction); |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 808 | } |
| 809 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 810 | void InstructionSimplifierVisitor::VisitGreaterThan(HGreaterThan* condition) { |
| 811 | VisitCondition(condition); |
| 812 | } |
| 813 | |
| 814 | void InstructionSimplifierVisitor::VisitGreaterThanOrEqual(HGreaterThanOrEqual* condition) { |
| 815 | VisitCondition(condition); |
| 816 | } |
| 817 | |
| 818 | void InstructionSimplifierVisitor::VisitLessThan(HLessThan* condition) { |
| 819 | VisitCondition(condition); |
| 820 | } |
| 821 | |
| 822 | void InstructionSimplifierVisitor::VisitLessThanOrEqual(HLessThanOrEqual* condition) { |
| 823 | VisitCondition(condition); |
| 824 | } |
| 825 | |
Nicolas Geoffray | d4aee94 | 2016-01-22 12:35:26 +0000 | [diff] [blame] | 826 | // TODO: unsigned comparisons too? |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 827 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 828 | void InstructionSimplifierVisitor::VisitCondition(HCondition* condition) { |
Nicolas Geoffray | d4aee94 | 2016-01-22 12:35:26 +0000 | [diff] [blame] | 829 | // Try to fold an HCompare into this HCondition. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 830 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 831 | HInstruction* left = condition->GetLeft(); |
| 832 | HInstruction* right = condition->GetRight(); |
| 833 | // We can only replace an HCondition which compares a Compare to 0. |
| 834 | // Both 'dx' and 'jack' generate a compare to 0 when compiling a |
| 835 | // condition with a long, float or double comparison as input. |
| 836 | if (!left->IsCompare() || !right->IsConstant() || right->AsIntConstant()->GetValue() != 0) { |
| 837 | // Conversion is not possible. |
| 838 | return; |
| 839 | } |
| 840 | |
| 841 | // Is the Compare only used for this purpose? |
| 842 | if (!left->GetUses().HasOnlyOneUse()) { |
| 843 | // Someone else also wants the result of the compare. |
| 844 | return; |
| 845 | } |
| 846 | |
| 847 | if (!left->GetEnvUses().IsEmpty()) { |
| 848 | // There is a reference to the compare result in an environment. Do we really need it? |
| 849 | if (GetGraph()->IsDebuggable()) { |
| 850 | return; |
| 851 | } |
| 852 | |
| 853 | // We have to ensure that there are no deopt points in the sequence. |
| 854 | if (left->HasAnyEnvironmentUseBefore(condition)) { |
| 855 | return; |
| 856 | } |
| 857 | } |
| 858 | |
| 859 | // Clean up any environment uses from the HCompare, if any. |
| 860 | left->RemoveEnvironmentUsers(); |
| 861 | |
| 862 | // We have decided to fold the HCompare into the HCondition. Transfer the information. |
| 863 | condition->SetBias(left->AsCompare()->GetBias()); |
| 864 | |
| 865 | // Replace the operands of the HCondition. |
| 866 | condition->ReplaceInput(left->InputAt(0), 0); |
| 867 | condition->ReplaceInput(left->InputAt(1), 1); |
| 868 | |
| 869 | // Remove the HCompare. |
| 870 | left->GetBlock()->RemoveInstruction(left); |
| 871 | |
| 872 | RecordSimplification(); |
| 873 | } |
| 874 | |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 875 | void InstructionSimplifierVisitor::VisitDiv(HDiv* instruction) { |
| 876 | HConstant* input_cst = instruction->GetConstantRight(); |
| 877 | HInstruction* input_other = instruction->GetLeastConstantLeft(); |
| 878 | Primitive::Type type = instruction->GetType(); |
| 879 | |
| 880 | if ((input_cst != nullptr) && input_cst->IsOne()) { |
| 881 | // Replace code looking like |
| 882 | // DIV dst, src, 1 |
| 883 | // with |
| 884 | // src |
| 885 | instruction->ReplaceWith(input_other); |
| 886 | instruction->GetBlock()->RemoveInstruction(instruction); |
| 887 | return; |
| 888 | } |
| 889 | |
Nicolas Geoffray | 0d22184 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 890 | if ((input_cst != nullptr) && input_cst->IsMinusOne()) { |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 891 | // Replace code looking like |
| 892 | // DIV dst, src, -1 |
| 893 | // with |
| 894 | // NEG dst, src |
| 895 | instruction->GetBlock()->ReplaceAndRemoveInstructionWith( |
Nicolas Geoffray | 0d22184 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 896 | instruction, new (GetGraph()->GetArena()) HNeg(type, input_other)); |
Alexandre Rames | 188d431 | 2015-04-09 18:30:21 +0100 | [diff] [blame] | 897 | RecordSimplification(); |
Nicolas Geoffray | 0d22184 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 898 | return; |
| 899 | } |
| 900 | |
| 901 | if ((input_cst != nullptr) && Primitive::IsFloatingPointType(type)) { |
| 902 | // Try replacing code looking like |
| 903 | // DIV dst, src, constant |
| 904 | // with |
| 905 | // MUL dst, src, 1 / constant |
| 906 | HConstant* reciprocal = nullptr; |
| 907 | if (type == Primitive::Primitive::kPrimDouble) { |
| 908 | double value = input_cst->AsDoubleConstant()->GetValue(); |
| 909 | if (CanDivideByReciprocalMultiplyDouble(bit_cast<int64_t, double>(value))) { |
| 910 | reciprocal = GetGraph()->GetDoubleConstant(1.0 / value); |
| 911 | } |
| 912 | } else { |
| 913 | DCHECK_EQ(type, Primitive::kPrimFloat); |
| 914 | float value = input_cst->AsFloatConstant()->GetValue(); |
| 915 | if (CanDivideByReciprocalMultiplyFloat(bit_cast<int32_t, float>(value))) { |
| 916 | reciprocal = GetGraph()->GetFloatConstant(1.0f / value); |
| 917 | } |
| 918 | } |
| 919 | |
| 920 | if (reciprocal != nullptr) { |
| 921 | instruction->GetBlock()->ReplaceAndRemoveInstructionWith( |
| 922 | instruction, new (GetGraph()->GetArena()) HMul(type, input_other, reciprocal)); |
| 923 | RecordSimplification(); |
| 924 | return; |
| 925 | } |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 926 | } |
| 927 | } |
| 928 | |
| 929 | void InstructionSimplifierVisitor::VisitMul(HMul* instruction) { |
| 930 | HConstant* input_cst = instruction->GetConstantRight(); |
| 931 | HInstruction* input_other = instruction->GetLeastConstantLeft(); |
| 932 | Primitive::Type type = instruction->GetType(); |
| 933 | HBasicBlock* block = instruction->GetBlock(); |
| 934 | ArenaAllocator* allocator = GetGraph()->GetArena(); |
| 935 | |
| 936 | if (input_cst == nullptr) { |
| 937 | return; |
| 938 | } |
| 939 | |
| 940 | if (input_cst->IsOne()) { |
| 941 | // Replace code looking like |
| 942 | // MUL dst, src, 1 |
| 943 | // with |
| 944 | // src |
| 945 | instruction->ReplaceWith(input_other); |
| 946 | instruction->GetBlock()->RemoveInstruction(instruction); |
| 947 | return; |
| 948 | } |
| 949 | |
| 950 | if (input_cst->IsMinusOne() && |
| 951 | (Primitive::IsFloatingPointType(type) || Primitive::IsIntOrLongType(type))) { |
| 952 | // Replace code looking like |
| 953 | // MUL dst, src, -1 |
| 954 | // with |
| 955 | // NEG dst, src |
| 956 | HNeg* neg = new (allocator) HNeg(type, input_other); |
| 957 | block->ReplaceAndRemoveInstructionWith(instruction, neg); |
Alexandre Rames | 188d431 | 2015-04-09 18:30:21 +0100 | [diff] [blame] | 958 | RecordSimplification(); |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 959 | return; |
| 960 | } |
| 961 | |
| 962 | if (Primitive::IsFloatingPointType(type) && |
| 963 | ((input_cst->IsFloatConstant() && input_cst->AsFloatConstant()->GetValue() == 2.0f) || |
| 964 | (input_cst->IsDoubleConstant() && input_cst->AsDoubleConstant()->GetValue() == 2.0))) { |
| 965 | // Replace code looking like |
| 966 | // FP_MUL dst, src, 2.0 |
| 967 | // with |
| 968 | // FP_ADD dst, src, src |
| 969 | // The 'int' and 'long' cases are handled below. |
| 970 | block->ReplaceAndRemoveInstructionWith(instruction, |
| 971 | new (allocator) HAdd(type, input_other, input_other)); |
Alexandre Rames | 188d431 | 2015-04-09 18:30:21 +0100 | [diff] [blame] | 972 | RecordSimplification(); |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 973 | return; |
| 974 | } |
| 975 | |
| 976 | if (Primitive::IsIntOrLongType(type)) { |
| 977 | int64_t factor = Int64FromConstant(input_cst); |
Serguei Katkov | 5384919 | 2015-04-20 14:22:27 +0600 | [diff] [blame] | 978 | // Even though constant propagation also takes care of the zero case, other |
| 979 | // optimizations can lead to having a zero multiplication. |
| 980 | if (factor == 0) { |
| 981 | // Replace code looking like |
| 982 | // MUL dst, src, 0 |
| 983 | // with |
| 984 | // 0 |
| 985 | instruction->ReplaceWith(input_cst); |
| 986 | instruction->GetBlock()->RemoveInstruction(instruction); |
| 987 | } else if (IsPowerOfTwo(factor)) { |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 988 | // Replace code looking like |
| 989 | // MUL dst, src, pow_of_2 |
| 990 | // with |
| 991 | // SHL dst, src, log2(pow_of_2) |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 992 | HIntConstant* shift = GetGraph()->GetIntConstant(WhichPowerOf2(factor)); |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 993 | HShl* shl = new(allocator) HShl(type, input_other, shift); |
| 994 | block->ReplaceAndRemoveInstructionWith(instruction, shl); |
Alexandre Rames | 188d431 | 2015-04-09 18:30:21 +0100 | [diff] [blame] | 995 | RecordSimplification(); |
Alexandre Rames | 38db785 | 2015-11-20 15:02:45 +0000 | [diff] [blame] | 996 | } else if (IsPowerOfTwo(factor - 1)) { |
| 997 | // Transform code looking like |
| 998 | // MUL dst, src, (2^n + 1) |
| 999 | // into |
| 1000 | // SHL tmp, src, n |
| 1001 | // ADD dst, src, tmp |
| 1002 | HShl* shl = new (allocator) HShl(type, |
| 1003 | input_other, |
| 1004 | GetGraph()->GetIntConstant(WhichPowerOf2(factor - 1))); |
| 1005 | HAdd* add = new (allocator) HAdd(type, input_other, shl); |
| 1006 | |
| 1007 | block->InsertInstructionBefore(shl, instruction); |
| 1008 | block->ReplaceAndRemoveInstructionWith(instruction, add); |
| 1009 | RecordSimplification(); |
| 1010 | } else if (IsPowerOfTwo(factor + 1)) { |
| 1011 | // Transform code looking like |
| 1012 | // MUL dst, src, (2^n - 1) |
| 1013 | // into |
| 1014 | // SHL tmp, src, n |
| 1015 | // SUB dst, tmp, src |
| 1016 | HShl* shl = new (allocator) HShl(type, |
| 1017 | input_other, |
| 1018 | GetGraph()->GetIntConstant(WhichPowerOf2(factor + 1))); |
| 1019 | HSub* sub = new (allocator) HSub(type, shl, input_other); |
| 1020 | |
| 1021 | block->InsertInstructionBefore(shl, instruction); |
| 1022 | block->ReplaceAndRemoveInstructionWith(instruction, sub); |
| 1023 | RecordSimplification(); |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 1024 | } |
| 1025 | } |
| 1026 | } |
| 1027 | |
Alexandre Rames | 188d431 | 2015-04-09 18:30:21 +0100 | [diff] [blame] | 1028 | void InstructionSimplifierVisitor::VisitNeg(HNeg* instruction) { |
| 1029 | HInstruction* input = instruction->GetInput(); |
| 1030 | if (input->IsNeg()) { |
| 1031 | // Replace code looking like |
| 1032 | // NEG tmp, src |
| 1033 | // NEG dst, tmp |
| 1034 | // with |
| 1035 | // src |
| 1036 | HNeg* previous_neg = input->AsNeg(); |
| 1037 | instruction->ReplaceWith(previous_neg->GetInput()); |
| 1038 | instruction->GetBlock()->RemoveInstruction(instruction); |
| 1039 | // We perform the optimization even if the input negation has environment |
| 1040 | // uses since it allows removing the current instruction. But we only delete |
| 1041 | // the input negation only if it is does not have any uses left. |
| 1042 | if (!previous_neg->HasUses()) { |
| 1043 | previous_neg->GetBlock()->RemoveInstruction(previous_neg); |
| 1044 | } |
| 1045 | RecordSimplification(); |
| 1046 | return; |
| 1047 | } |
| 1048 | |
Serguei Katkov | 339dfc2 | 2015-04-20 12:29:32 +0600 | [diff] [blame] | 1049 | if (input->IsSub() && input->HasOnlyOneNonEnvironmentUse() && |
| 1050 | !Primitive::IsFloatingPointType(input->GetType())) { |
Alexandre Rames | 188d431 | 2015-04-09 18:30:21 +0100 | [diff] [blame] | 1051 | // Replace code looking like |
| 1052 | // SUB tmp, a, b |
| 1053 | // NEG dst, tmp |
| 1054 | // with |
| 1055 | // SUB dst, b, a |
| 1056 | // We do not perform the optimization if the input subtraction has |
| 1057 | // environment uses or multiple non-environment uses as it could lead to |
| 1058 | // worse code. In particular, we do not want the live ranges of `a` and `b` |
| 1059 | // to be extended if we are not sure the initial 'SUB' instruction can be |
| 1060 | // removed. |
Serguei Katkov | 339dfc2 | 2015-04-20 12:29:32 +0600 | [diff] [blame] | 1061 | // We do not perform optimization for fp because we could lose the sign of zero. |
Alexandre Rames | 188d431 | 2015-04-09 18:30:21 +0100 | [diff] [blame] | 1062 | HSub* sub = input->AsSub(); |
| 1063 | HSub* new_sub = |
| 1064 | new (GetGraph()->GetArena()) HSub(instruction->GetType(), sub->GetRight(), sub->GetLeft()); |
| 1065 | instruction->GetBlock()->ReplaceAndRemoveInstructionWith(instruction, new_sub); |
| 1066 | if (!sub->HasUses()) { |
| 1067 | sub->GetBlock()->RemoveInstruction(sub); |
| 1068 | } |
| 1069 | RecordSimplification(); |
| 1070 | } |
| 1071 | } |
| 1072 | |
| 1073 | void InstructionSimplifierVisitor::VisitNot(HNot* instruction) { |
| 1074 | HInstruction* input = instruction->GetInput(); |
| 1075 | if (input->IsNot()) { |
| 1076 | // Replace code looking like |
| 1077 | // NOT tmp, src |
| 1078 | // NOT dst, tmp |
| 1079 | // with |
| 1080 | // src |
| 1081 | // We perform the optimization even if the input negation has environment |
| 1082 | // uses since it allows removing the current instruction. But we only delete |
| 1083 | // the input negation only if it is does not have any uses left. |
| 1084 | HNot* previous_not = input->AsNot(); |
| 1085 | instruction->ReplaceWith(previous_not->GetInput()); |
| 1086 | instruction->GetBlock()->RemoveInstruction(instruction); |
| 1087 | if (!previous_not->HasUses()) { |
| 1088 | previous_not->GetBlock()->RemoveInstruction(previous_not); |
| 1089 | } |
| 1090 | RecordSimplification(); |
| 1091 | } |
| 1092 | } |
| 1093 | |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 1094 | void InstructionSimplifierVisitor::VisitOr(HOr* instruction) { |
| 1095 | HConstant* input_cst = instruction->GetConstantRight(); |
| 1096 | HInstruction* input_other = instruction->GetLeastConstantLeft(); |
| 1097 | |
| 1098 | if ((input_cst != nullptr) && input_cst->IsZero()) { |
| 1099 | // Replace code looking like |
| 1100 | // OR dst, src, 0 |
| 1101 | // with |
| 1102 | // src |
| 1103 | instruction->ReplaceWith(input_other); |
| 1104 | instruction->GetBlock()->RemoveInstruction(instruction); |
| 1105 | return; |
| 1106 | } |
| 1107 | |
| 1108 | // We assume that GVN has run before, so we only perform a pointer comparison. |
| 1109 | // If for some reason the values are equal but the pointers are different, we |
Alexandre Rames | 188d431 | 2015-04-09 18:30:21 +0100 | [diff] [blame] | 1110 | // are still correct and only miss an optimization opportunity. |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 1111 | if (instruction->GetLeft() == instruction->GetRight()) { |
| 1112 | // Replace code looking like |
| 1113 | // OR dst, src, src |
| 1114 | // with |
| 1115 | // src |
| 1116 | instruction->ReplaceWith(instruction->GetLeft()); |
| 1117 | instruction->GetBlock()->RemoveInstruction(instruction); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 1118 | return; |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 1119 | } |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 1120 | |
Kevin Brodsky | 9679849 | 2016-01-15 09:49:20 +0000 | [diff] [blame^] | 1121 | if (TryApplyDeMorgan(instruction)) return; |
| 1122 | |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 1123 | TryReplaceWithRotate(instruction); |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 1124 | } |
| 1125 | |
| 1126 | void InstructionSimplifierVisitor::VisitShl(HShl* instruction) { |
| 1127 | VisitShift(instruction); |
| 1128 | } |
| 1129 | |
| 1130 | void InstructionSimplifierVisitor::VisitShr(HShr* instruction) { |
| 1131 | VisitShift(instruction); |
| 1132 | } |
| 1133 | |
| 1134 | void InstructionSimplifierVisitor::VisitSub(HSub* instruction) { |
| 1135 | HConstant* input_cst = instruction->GetConstantRight(); |
| 1136 | HInstruction* input_other = instruction->GetLeastConstantLeft(); |
| 1137 | |
Serguei Katkov | 115b53f | 2015-08-05 17:03:30 +0600 | [diff] [blame] | 1138 | Primitive::Type type = instruction->GetType(); |
| 1139 | if (Primitive::IsFloatingPointType(type)) { |
| 1140 | return; |
| 1141 | } |
| 1142 | |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 1143 | if ((input_cst != nullptr) && input_cst->IsZero()) { |
| 1144 | // Replace code looking like |
| 1145 | // SUB dst, src, 0 |
| 1146 | // with |
| 1147 | // src |
Serguei Katkov | 115b53f | 2015-08-05 17:03:30 +0600 | [diff] [blame] | 1148 | // Note that we cannot optimize `x - 0.0` to `x` for floating-point. When |
| 1149 | // `x` is `-0.0`, the former expression yields `0.0`, while the later |
| 1150 | // yields `-0.0`. |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 1151 | instruction->ReplaceWith(input_other); |
| 1152 | instruction->GetBlock()->RemoveInstruction(instruction); |
| 1153 | return; |
| 1154 | } |
| 1155 | |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 1156 | HBasicBlock* block = instruction->GetBlock(); |
| 1157 | ArenaAllocator* allocator = GetGraph()->GetArena(); |
| 1158 | |
Alexandre Rames | 188d431 | 2015-04-09 18:30:21 +0100 | [diff] [blame] | 1159 | HInstruction* left = instruction->GetLeft(); |
| 1160 | HInstruction* right = instruction->GetRight(); |
| 1161 | if (left->IsConstant()) { |
| 1162 | if (Int64FromConstant(left->AsConstant()) == 0) { |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 1163 | // Replace code looking like |
| 1164 | // SUB dst, 0, src |
| 1165 | // with |
| 1166 | // NEG dst, src |
Alexandre Rames | 188d431 | 2015-04-09 18:30:21 +0100 | [diff] [blame] | 1167 | // Note that we cannot optimize `0.0 - x` to `-x` for floating-point. When |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 1168 | // `x` is `0.0`, the former expression yields `0.0`, while the later |
| 1169 | // yields `-0.0`. |
Alexandre Rames | 188d431 | 2015-04-09 18:30:21 +0100 | [diff] [blame] | 1170 | HNeg* neg = new (allocator) HNeg(type, right); |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 1171 | block->ReplaceAndRemoveInstructionWith(instruction, neg); |
Alexandre Rames | 188d431 | 2015-04-09 18:30:21 +0100 | [diff] [blame] | 1172 | RecordSimplification(); |
| 1173 | return; |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 1174 | } |
| 1175 | } |
Alexandre Rames | 188d431 | 2015-04-09 18:30:21 +0100 | [diff] [blame] | 1176 | |
| 1177 | if (left->IsNeg() && right->IsNeg()) { |
| 1178 | if (TryMoveNegOnInputsAfterBinop(instruction)) { |
| 1179 | return; |
| 1180 | } |
| 1181 | } |
| 1182 | |
| 1183 | if (right->IsNeg() && right->HasOnlyOneNonEnvironmentUse()) { |
| 1184 | // Replace code looking like |
| 1185 | // NEG tmp, b |
| 1186 | // SUB dst, a, tmp |
| 1187 | // with |
| 1188 | // ADD dst, a, b |
| 1189 | HAdd* add = new(GetGraph()->GetArena()) HAdd(type, left, right->AsNeg()->GetInput()); |
| 1190 | instruction->GetBlock()->ReplaceAndRemoveInstructionWith(instruction, add); |
| 1191 | RecordSimplification(); |
| 1192 | right->GetBlock()->RemoveInstruction(right); |
| 1193 | return; |
| 1194 | } |
| 1195 | |
| 1196 | if (left->IsNeg() && left->HasOnlyOneNonEnvironmentUse()) { |
| 1197 | // Replace code looking like |
| 1198 | // NEG tmp, a |
| 1199 | // SUB dst, tmp, b |
| 1200 | // with |
| 1201 | // ADD tmp, a, b |
| 1202 | // NEG dst, tmp |
| 1203 | // The second version is not intrinsically better, but enables more |
| 1204 | // transformations. |
| 1205 | HAdd* add = new(GetGraph()->GetArena()) HAdd(type, left->AsNeg()->GetInput(), right); |
| 1206 | instruction->GetBlock()->InsertInstructionBefore(add, instruction); |
| 1207 | HNeg* neg = new (GetGraph()->GetArena()) HNeg(instruction->GetType(), add); |
| 1208 | instruction->GetBlock()->InsertInstructionBefore(neg, instruction); |
| 1209 | instruction->ReplaceWith(neg); |
| 1210 | instruction->GetBlock()->RemoveInstruction(instruction); |
| 1211 | RecordSimplification(); |
| 1212 | left->GetBlock()->RemoveInstruction(left); |
| 1213 | } |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 1214 | } |
| 1215 | |
| 1216 | void InstructionSimplifierVisitor::VisitUShr(HUShr* instruction) { |
| 1217 | VisitShift(instruction); |
| 1218 | } |
| 1219 | |
| 1220 | void InstructionSimplifierVisitor::VisitXor(HXor* instruction) { |
| 1221 | HConstant* input_cst = instruction->GetConstantRight(); |
| 1222 | HInstruction* input_other = instruction->GetLeastConstantLeft(); |
| 1223 | |
| 1224 | if ((input_cst != nullptr) && input_cst->IsZero()) { |
| 1225 | // Replace code looking like |
| 1226 | // XOR dst, src, 0 |
| 1227 | // with |
| 1228 | // src |
| 1229 | instruction->ReplaceWith(input_other); |
| 1230 | instruction->GetBlock()->RemoveInstruction(instruction); |
| 1231 | return; |
| 1232 | } |
| 1233 | |
| 1234 | if ((input_cst != nullptr) && AreAllBitsSet(input_cst)) { |
| 1235 | // Replace code looking like |
| 1236 | // XOR dst, src, 0xFFF...FF |
| 1237 | // with |
| 1238 | // NOT dst, src |
| 1239 | HNot* bitwise_not = new (GetGraph()->GetArena()) HNot(instruction->GetType(), input_other); |
| 1240 | instruction->GetBlock()->ReplaceAndRemoveInstructionWith(instruction, bitwise_not); |
Alexandre Rames | 188d431 | 2015-04-09 18:30:21 +0100 | [diff] [blame] | 1241 | RecordSimplification(); |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 1242 | return; |
| 1243 | } |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 1244 | |
Kevin Brodsky | 9679849 | 2016-01-15 09:49:20 +0000 | [diff] [blame^] | 1245 | HInstruction* left = instruction->GetLeft(); |
| 1246 | HInstruction* right = instruction->GetRight(); |
| 1247 | if (left->IsNot() && |
| 1248 | right->IsNot() && |
| 1249 | left->HasOnlyOneNonEnvironmentUse() && |
| 1250 | right->HasOnlyOneNonEnvironmentUse()) { |
| 1251 | // Replace code looking like |
| 1252 | // NOT nota, a |
| 1253 | // NOT notb, b |
| 1254 | // XOR dst, nota, notb |
| 1255 | // with |
| 1256 | // XOR dst, a, b |
| 1257 | instruction->ReplaceInput(left->AsNot()->GetInput(), 0); |
| 1258 | instruction->ReplaceInput(right->AsNot()->GetInput(), 1); |
| 1259 | left->GetBlock()->RemoveInstruction(left); |
| 1260 | right->GetBlock()->RemoveInstruction(right); |
| 1261 | RecordSimplification(); |
| 1262 | return; |
| 1263 | } |
| 1264 | |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 1265 | TryReplaceWithRotate(instruction); |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 1266 | } |
| 1267 | |
Nicolas Geoffray | ee3cf07 | 2015-10-06 11:45:02 +0100 | [diff] [blame] | 1268 | void InstructionSimplifierVisitor::SimplifyStringEquals(HInvoke* instruction) { |
| 1269 | HInstruction* argument = instruction->InputAt(1); |
| 1270 | HInstruction* receiver = instruction->InputAt(0); |
| 1271 | if (receiver == argument) { |
| 1272 | // Because String.equals is an instance call, the receiver is |
| 1273 | // a null check if we don't know it's null. The argument however, will |
| 1274 | // be the actual object. So we cannot end up in a situation where both |
| 1275 | // are equal but could be null. |
| 1276 | DCHECK(CanEnsureNotNullAt(argument, instruction)); |
| 1277 | instruction->ReplaceWith(GetGraph()->GetIntConstant(1)); |
| 1278 | instruction->GetBlock()->RemoveInstruction(instruction); |
| 1279 | } else { |
| 1280 | StringEqualsOptimizations optimizations(instruction); |
| 1281 | if (CanEnsureNotNullAt(argument, instruction)) { |
| 1282 | optimizations.SetArgumentNotNull(); |
| 1283 | } |
| 1284 | ScopedObjectAccess soa(Thread::Current()); |
| 1285 | ReferenceTypeInfo argument_rti = argument->GetReferenceTypeInfo(); |
| 1286 | if (argument_rti.IsValid() && argument_rti.IsStringClass()) { |
| 1287 | optimizations.SetArgumentIsString(); |
| 1288 | } |
| 1289 | } |
| 1290 | } |
| 1291 | |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 1292 | void InstructionSimplifierVisitor::SimplifyRotate(HInvoke* invoke, bool is_left) { |
| 1293 | DCHECK(invoke->IsInvokeStaticOrDirect()); |
| 1294 | DCHECK_EQ(invoke->GetOriginalInvokeType(), InvokeType::kStatic); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 1295 | HInstruction* value = invoke->InputAt(0); |
| 1296 | HInstruction* distance = invoke->InputAt(1); |
| 1297 | // Replace the invoke with an HRor. |
| 1298 | if (is_left) { |
| 1299 | distance = new (GetGraph()->GetArena()) HNeg(distance->GetType(), distance); |
| 1300 | invoke->GetBlock()->InsertInstructionBefore(distance, invoke); |
| 1301 | } |
| 1302 | HRor* ror = new (GetGraph()->GetArena()) HRor(value->GetType(), value, distance); |
| 1303 | invoke->GetBlock()->ReplaceAndRemoveInstructionWith(invoke, ror); |
| 1304 | // Remove ClinitCheck and LoadClass, if possible. |
| 1305 | HInstruction* clinit = invoke->InputAt(invoke->InputCount() - 1); |
| 1306 | if (clinit->IsClinitCheck() && !clinit->HasUses()) { |
| 1307 | clinit->GetBlock()->RemoveInstruction(clinit); |
| 1308 | HInstruction* ldclass = clinit->InputAt(0); |
| 1309 | if (ldclass->IsLoadClass() && !ldclass->HasUses()) { |
| 1310 | ldclass->GetBlock()->RemoveInstruction(ldclass); |
| 1311 | } |
| 1312 | } |
| 1313 | } |
| 1314 | |
Nicolas Geoffray | ee3cf07 | 2015-10-06 11:45:02 +0100 | [diff] [blame] | 1315 | static bool IsArrayLengthOf(HInstruction* potential_length, HInstruction* potential_array) { |
| 1316 | if (potential_length->IsArrayLength()) { |
| 1317 | return potential_length->InputAt(0) == potential_array; |
| 1318 | } |
| 1319 | |
| 1320 | if (potential_array->IsNewArray()) { |
| 1321 | return potential_array->InputAt(0) == potential_length; |
| 1322 | } |
| 1323 | |
| 1324 | return false; |
| 1325 | } |
| 1326 | |
| 1327 | void InstructionSimplifierVisitor::SimplifySystemArrayCopy(HInvoke* instruction) { |
| 1328 | HInstruction* source = instruction->InputAt(0); |
| 1329 | HInstruction* destination = instruction->InputAt(2); |
| 1330 | HInstruction* count = instruction->InputAt(4); |
| 1331 | SystemArrayCopyOptimizations optimizations(instruction); |
| 1332 | if (CanEnsureNotNullAt(source, instruction)) { |
| 1333 | optimizations.SetSourceIsNotNull(); |
| 1334 | } |
| 1335 | if (CanEnsureNotNullAt(destination, instruction)) { |
| 1336 | optimizations.SetDestinationIsNotNull(); |
| 1337 | } |
| 1338 | if (destination == source) { |
| 1339 | optimizations.SetDestinationIsSource(); |
| 1340 | } |
| 1341 | |
| 1342 | if (IsArrayLengthOf(count, source)) { |
| 1343 | optimizations.SetCountIsSourceLength(); |
| 1344 | } |
| 1345 | |
| 1346 | if (IsArrayLengthOf(count, destination)) { |
| 1347 | optimizations.SetCountIsDestinationLength(); |
| 1348 | } |
| 1349 | |
| 1350 | { |
| 1351 | ScopedObjectAccess soa(Thread::Current()); |
| 1352 | ReferenceTypeInfo destination_rti = destination->GetReferenceTypeInfo(); |
| 1353 | if (destination_rti.IsValid()) { |
| 1354 | if (destination_rti.IsObjectArray()) { |
| 1355 | if (destination_rti.IsExact()) { |
| 1356 | optimizations.SetDoesNotNeedTypeCheck(); |
| 1357 | } |
| 1358 | optimizations.SetDestinationIsTypedObjectArray(); |
Nicolas Geoffray | a83a54d | 2015-10-02 17:30:26 +0100 | [diff] [blame] | 1359 | } |
Nicolas Geoffray | ee3cf07 | 2015-10-06 11:45:02 +0100 | [diff] [blame] | 1360 | if (destination_rti.IsPrimitiveArrayClass()) { |
| 1361 | optimizations.SetDestinationIsPrimitiveArray(); |
| 1362 | } else if (destination_rti.IsNonPrimitiveArrayClass()) { |
| 1363 | optimizations.SetDestinationIsNonPrimitiveArray(); |
Nicolas Geoffray | a83a54d | 2015-10-02 17:30:26 +0100 | [diff] [blame] | 1364 | } |
| 1365 | } |
Nicolas Geoffray | ee3cf07 | 2015-10-06 11:45:02 +0100 | [diff] [blame] | 1366 | ReferenceTypeInfo source_rti = source->GetReferenceTypeInfo(); |
| 1367 | if (source_rti.IsValid()) { |
| 1368 | if (destination_rti.IsValid() && destination_rti.CanArrayHoldValuesOf(source_rti)) { |
| 1369 | optimizations.SetDoesNotNeedTypeCheck(); |
| 1370 | } |
| 1371 | if (source_rti.IsPrimitiveArrayClass()) { |
| 1372 | optimizations.SetSourceIsPrimitiveArray(); |
| 1373 | } else if (source_rti.IsNonPrimitiveArrayClass()) { |
| 1374 | optimizations.SetSourceIsNonPrimitiveArray(); |
| 1375 | } |
| 1376 | } |
| 1377 | } |
| 1378 | } |
| 1379 | |
| 1380 | void InstructionSimplifierVisitor::VisitInvoke(HInvoke* instruction) { |
| 1381 | if (instruction->GetIntrinsic() == Intrinsics::kStringEquals) { |
| 1382 | SimplifyStringEquals(instruction); |
| 1383 | } else if (instruction->GetIntrinsic() == Intrinsics::kSystemArrayCopy) { |
| 1384 | SimplifySystemArrayCopy(instruction); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 1385 | } else if (instruction->GetIntrinsic() == Intrinsics::kIntegerRotateRight || |
| 1386 | instruction->GetIntrinsic() == Intrinsics::kLongRotateRight) { |
| 1387 | SimplifyRotate(instruction, false); |
| 1388 | } else if (instruction->GetIntrinsic() == Intrinsics::kIntegerRotateLeft || |
| 1389 | instruction->GetIntrinsic() == Intrinsics::kLongRotateLeft) { |
| 1390 | SimplifyRotate(instruction, true); |
Nicolas Geoffray | a83a54d | 2015-10-02 17:30:26 +0100 | [diff] [blame] | 1391 | } |
| 1392 | } |
| 1393 | |
Aart Bik | bb245d1 | 2015-10-19 11:05:03 -0700 | [diff] [blame] | 1394 | void InstructionSimplifierVisitor::VisitDeoptimize(HDeoptimize* deoptimize) { |
| 1395 | HInstruction* cond = deoptimize->InputAt(0); |
| 1396 | if (cond->IsConstant()) { |
| 1397 | if (cond->AsIntConstant()->IsZero()) { |
| 1398 | // Never deopt: instruction can be removed. |
| 1399 | deoptimize->GetBlock()->RemoveInstruction(deoptimize); |
| 1400 | } else { |
| 1401 | // Always deopt. |
| 1402 | } |
| 1403 | } |
| 1404 | } |
| 1405 | |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1406 | } // namespace art |