blob: b90afb1d731d78934f856b4b834e6c1f6909fc05 [file] [log] [blame]
Nicolas Geoffray3c049742014-09-24 18:10:46 +01001/*
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 Geoffraya83a54d2015-10-02 17:30:26 +010019#include "intrinsics.h"
Calin Juravleacf735c2015-02-12 15:25:22 +000020#include "mirror/class-inl.h"
21#include "scoped_thread_state_change.h"
22
Nicolas Geoffray3c049742014-09-24 18:10:46 +010023namespace art {
24
Nicolas Geoffraya83a54d2015-10-02 17:30:26 +010025class InstructionSimplifierVisitor : public HGraphDelegateVisitor {
Nicolas Geoffray5e6916c2014-11-18 16:53:35 +000026 public:
Calin Juravleacf735c2015-02-12 15:25:22 +000027 InstructionSimplifierVisitor(HGraph* graph, OptimizingCompilerStats* stats)
Nicolas Geoffraya83a54d2015-10-02 17:30:26 +010028 : HGraphDelegateVisitor(graph),
Alexandre Rames188d4312015-04-09 18:30:21 +010029 stats_(stats) {}
30
31 void Run();
Nicolas Geoffray5e6916c2014-11-18 16:53:35 +000032
33 private:
Alexandre Rames188d4312015-04-09 18:30:21 +010034 void RecordSimplification() {
35 simplification_occurred_ = true;
36 simplifications_at_current_position_++;
37 if (stats_) {
38 stats_->RecordStat(kInstructionSimplifications);
39 }
40 }
41
Scott Wakeling40a04bf2015-12-11 09:50:36 +000042 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 Rames188d4312015-04-09 18:30:21 +010048 bool TryMoveNegOnInputsAfterBinop(HBinaryOperation* binop);
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +000049 void VisitShift(HBinaryOperation* shift);
50
Nicolas Geoffray5e6916c2014-11-18 16:53:35 +000051 void VisitSuspendCheck(HSuspendCheck* check) OVERRIDE;
52 void VisitEqual(HEqual* equal) OVERRIDE;
David Brazdil0d13fee2015-04-17 14:52:19 +010053 void VisitNotEqual(HNotEqual* equal) OVERRIDE;
54 void VisitBooleanNot(HBooleanNot* bool_not) OVERRIDE;
Nicolas Geoffray07276db2015-05-18 14:22:09 +010055 void VisitInstanceFieldSet(HInstanceFieldSet* equal) OVERRIDE;
56 void VisitStaticFieldSet(HStaticFieldSet* equal) OVERRIDE;
Nicolas Geoffray5e6916c2014-11-18 16:53:35 +000057 void VisitArraySet(HArraySet* equal) OVERRIDE;
Nicolas Geoffray01fcc9e2014-12-01 14:16:20 +000058 void VisitTypeConversion(HTypeConversion* instruction) OVERRIDE;
Calin Juravle10e244f2015-01-26 18:54:32 +000059 void VisitNullCheck(HNullCheck* instruction) OVERRIDE;
Mingyao Yang0304e182015-01-30 16:41:29 -080060 void VisitArrayLength(HArrayLength* instruction) OVERRIDE;
Calin Juravleacf735c2015-02-12 15:25:22 +000061 void VisitCheckCast(HCheckCast* instruction) OVERRIDE;
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +000062 void VisitAdd(HAdd* instruction) OVERRIDE;
63 void VisitAnd(HAnd* instruction) OVERRIDE;
Mark Mendellc4701932015-04-10 13:18:51 -040064 void VisitCondition(HCondition* instruction) OVERRIDE;
65 void VisitGreaterThan(HGreaterThan* condition) OVERRIDE;
66 void VisitGreaterThanOrEqual(HGreaterThanOrEqual* condition) OVERRIDE;
67 void VisitLessThan(HLessThan* condition) OVERRIDE;
68 void VisitLessThanOrEqual(HLessThanOrEqual* condition) OVERRIDE;
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +000069 void VisitDiv(HDiv* instruction) OVERRIDE;
70 void VisitMul(HMul* instruction) OVERRIDE;
Alexandre Rames188d4312015-04-09 18:30:21 +010071 void VisitNeg(HNeg* instruction) OVERRIDE;
72 void VisitNot(HNot* instruction) OVERRIDE;
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +000073 void VisitOr(HOr* instruction) OVERRIDE;
74 void VisitShl(HShl* instruction) OVERRIDE;
75 void VisitShr(HShr* instruction) OVERRIDE;
76 void VisitSub(HSub* instruction) OVERRIDE;
77 void VisitUShr(HUShr* instruction) OVERRIDE;
78 void VisitXor(HXor* instruction) OVERRIDE;
Guillaume "Vermeille" Sanchezaf888352015-04-20 14:41:30 +010079 void VisitInstanceOf(HInstanceOf* instruction) OVERRIDE;
Nicolas Geoffray2e7cd752015-07-10 11:38:52 +010080 void VisitFakeString(HFakeString* fake_string) OVERRIDE;
Nicolas Geoffraya83a54d2015-10-02 17:30:26 +010081 void VisitInvoke(HInvoke* invoke) OVERRIDE;
Aart Bikbb245d12015-10-19 11:05:03 -070082 void VisitDeoptimize(HDeoptimize* deoptimize) OVERRIDE;
Nicolas Geoffray6e7455e2015-09-28 16:25:37 +010083
84 bool CanEnsureNotNullAt(HInstruction* instr, HInstruction* at) const;
Calin Juravleacf735c2015-02-12 15:25:22 +000085
Scott Wakeling40a04bf2015-12-11 09:50:36 +000086 void SimplifyRotate(HInvoke* invoke, bool is_left);
Nicolas Geoffrayee3cf072015-10-06 11:45:02 +010087 void SimplifySystemArrayCopy(HInvoke* invoke);
88 void SimplifyStringEquals(HInvoke* invoke);
89
Calin Juravleacf735c2015-02-12 15:25:22 +000090 OptimizingCompilerStats* stats_;
Alexandre Rames188d4312015-04-09 18:30:21 +010091 bool simplification_occurred_ = false;
92 int simplifications_at_current_position_ = 0;
93 // We ensure we do not loop infinitely. The value is a finger in the air guess
94 // that should allow enough simplification.
95 static constexpr int kMaxSamePositionSimplifications = 10;
Nicolas Geoffray5e6916c2014-11-18 16:53:35 +000096};
97
Nicolas Geoffray3c049742014-09-24 18:10:46 +010098void InstructionSimplifier::Run() {
Calin Juravleacf735c2015-02-12 15:25:22 +000099 InstructionSimplifierVisitor visitor(graph_, stats_);
Alexandre Rames188d4312015-04-09 18:30:21 +0100100 visitor.Run();
101}
102
103void InstructionSimplifierVisitor::Run() {
Nicolas Geoffray07276db2015-05-18 14:22:09 +0100104 // Iterate in reverse post order to open up more simplifications to users
105 // of instructions that got simplified.
Alexandre Rames188d4312015-04-09 18:30:21 +0100106 for (HReversePostOrderIterator it(*GetGraph()); !it.Done();) {
107 // The simplification of an instruction to another instruction may yield
108 // possibilities for other simplifications. So although we perform a reverse
109 // post order visit, we sometimes need to revisit an instruction index.
110 simplification_occurred_ = false;
111 VisitBasicBlock(it.Current());
112 if (simplification_occurred_ &&
113 (simplifications_at_current_position_ < kMaxSamePositionSimplifications)) {
114 // New simplifications may be applicable to the instruction at the
115 // current index, so don't advance the iterator.
116 continue;
117 }
Alexandre Rames188d4312015-04-09 18:30:21 +0100118 simplifications_at_current_position_ = 0;
119 it.Advance();
120 }
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100121}
122
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000123namespace {
124
125bool AreAllBitsSet(HConstant* constant) {
126 return Int64FromConstant(constant) == -1;
127}
128
129} // namespace
130
Alexandre Rames188d4312015-04-09 18:30:21 +0100131// Returns true if the code was simplified to use only one negation operation
132// after the binary operation instead of one on each of the inputs.
133bool InstructionSimplifierVisitor::TryMoveNegOnInputsAfterBinop(HBinaryOperation* binop) {
134 DCHECK(binop->IsAdd() || binop->IsSub());
135 DCHECK(binop->GetLeft()->IsNeg() && binop->GetRight()->IsNeg());
136 HNeg* left_neg = binop->GetLeft()->AsNeg();
137 HNeg* right_neg = binop->GetRight()->AsNeg();
138 if (!left_neg->HasOnlyOneNonEnvironmentUse() ||
139 !right_neg->HasOnlyOneNonEnvironmentUse()) {
140 return false;
141 }
142 // Replace code looking like
143 // NEG tmp1, a
144 // NEG tmp2, b
145 // ADD dst, tmp1, tmp2
146 // with
147 // ADD tmp, a, b
148 // NEG dst, tmp
Serdjuk, Nikolay Yaae9e662015-08-21 13:26:34 +0600149 // Note that we cannot optimize `(-a) + (-b)` to `-(a + b)` for floating-point.
150 // When `a` is `-0.0` and `b` is `0.0`, the former expression yields `0.0`,
151 // while the later yields `-0.0`.
152 if (!Primitive::IsIntegralType(binop->GetType())) {
153 return false;
154 }
Alexandre Rames188d4312015-04-09 18:30:21 +0100155 binop->ReplaceInput(left_neg->GetInput(), 0);
156 binop->ReplaceInput(right_neg->GetInput(), 1);
157 left_neg->GetBlock()->RemoveInstruction(left_neg);
158 right_neg->GetBlock()->RemoveInstruction(right_neg);
159 HNeg* neg = new (GetGraph()->GetArena()) HNeg(binop->GetType(), binop);
160 binop->GetBlock()->InsertInstructionBefore(neg, binop->GetNext());
161 binop->ReplaceWithExceptInReplacementAtIndex(neg, 0);
162 RecordSimplification();
163 return true;
164}
165
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000166void InstructionSimplifierVisitor::VisitShift(HBinaryOperation* instruction) {
167 DCHECK(instruction->IsShl() || instruction->IsShr() || instruction->IsUShr());
168 HConstant* input_cst = instruction->GetConstantRight();
169 HInstruction* input_other = instruction->GetLeastConstantLeft();
170
Mark Mendellba56d062015-05-05 21:34:03 -0400171 if (input_cst != nullptr) {
172 if (input_cst->IsZero()) {
173 // Replace code looking like
174 // SHL dst, src, 0
175 // with
176 // src
177 instruction->ReplaceWith(input_other);
178 instruction->GetBlock()->RemoveInstruction(instruction);
Mark Mendellba56d062015-05-05 21:34:03 -0400179 }
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000180 }
181}
182
Scott Wakeling40a04bf2015-12-11 09:50:36 +0000183static bool IsSubRegBitsMinusOther(HSub* sub, size_t reg_bits, HInstruction* other) {
184 return (sub->GetRight() == other &&
185 sub->GetLeft()->IsConstant() &&
186 (Int64FromConstant(sub->GetLeft()->AsConstant()) & (reg_bits - 1)) == 0);
187}
188
189bool InstructionSimplifierVisitor::ReplaceRotateWithRor(HBinaryOperation* op,
190 HUShr* ushr,
191 HShl* shl) {
192 DCHECK(op->IsAdd() || op->IsXor() || op->IsOr());
193 HRor* ror = new (GetGraph()->GetArena()) HRor(ushr->GetType(),
194 ushr->GetLeft(),
195 ushr->GetRight());
196 op->GetBlock()->ReplaceAndRemoveInstructionWith(op, ror);
197 if (!ushr->HasUses()) {
198 ushr->GetBlock()->RemoveInstruction(ushr);
199 }
200 if (!ushr->GetRight()->HasUses()) {
201 ushr->GetRight()->GetBlock()->RemoveInstruction(ushr->GetRight());
202 }
203 if (!shl->HasUses()) {
204 shl->GetBlock()->RemoveInstruction(shl);
205 }
206 if (!shl->GetRight()->HasUses()) {
207 shl->GetRight()->GetBlock()->RemoveInstruction(shl->GetRight());
208 }
209 return true;
210}
211
212// Try to replace a binary operation flanked by one UShr and one Shl with a bitfield rotation.
213bool InstructionSimplifierVisitor::TryReplaceWithRotate(HBinaryOperation* op) {
Scott Wakeling40a04bf2015-12-11 09:50:36 +0000214 DCHECK(op->IsAdd() || op->IsXor() || op->IsOr());
215 HInstruction* left = op->GetLeft();
216 HInstruction* right = op->GetRight();
217 // If we have an UShr and a Shl (in either order).
218 if ((left->IsUShr() && right->IsShl()) || (left->IsShl() && right->IsUShr())) {
219 HUShr* ushr = left->IsUShr() ? left->AsUShr() : right->AsUShr();
220 HShl* shl = left->IsShl() ? left->AsShl() : right->AsShl();
221 DCHECK(Primitive::IsIntOrLongType(ushr->GetType()));
222 if (ushr->GetType() == shl->GetType() &&
223 ushr->GetLeft() == shl->GetLeft()) {
224 if (ushr->GetRight()->IsConstant() && shl->GetRight()->IsConstant()) {
225 // Shift distances are both constant, try replacing with Ror if they
226 // add up to the register size.
227 return TryReplaceWithRotateConstantPattern(op, ushr, shl);
228 } else if (ushr->GetRight()->IsSub() || shl->GetRight()->IsSub()) {
229 // Shift distances are potentially of the form x and (reg_size - x).
230 return TryReplaceWithRotateRegisterSubPattern(op, ushr, shl);
231 } else if (ushr->GetRight()->IsNeg() || shl->GetRight()->IsNeg()) {
232 // Shift distances are potentially of the form d and -d.
233 return TryReplaceWithRotateRegisterNegPattern(op, ushr, shl);
234 }
235 }
236 }
237 return false;
238}
239
240// Try replacing code looking like (x >>> #rdist OP x << #ldist):
241// UShr dst, x, #rdist
242// Shl tmp, x, #ldist
243// OP dst, dst, tmp
244// or like (x >>> #rdist OP x << #-ldist):
245// UShr dst, x, #rdist
246// Shl tmp, x, #-ldist
247// OP dst, dst, tmp
248// with
249// Ror dst, x, #rdist
250bool InstructionSimplifierVisitor::TryReplaceWithRotateConstantPattern(HBinaryOperation* op,
251 HUShr* ushr,
252 HShl* shl) {
253 DCHECK(op->IsAdd() || op->IsXor() || op->IsOr());
254 size_t reg_bits = Primitive::ComponentSize(ushr->GetType()) * kBitsPerByte;
255 size_t rdist = Int64FromConstant(ushr->GetRight()->AsConstant());
256 size_t ldist = Int64FromConstant(shl->GetRight()->AsConstant());
257 if (((ldist + rdist) & (reg_bits - 1)) == 0) {
258 ReplaceRotateWithRor(op, ushr, shl);
259 return true;
260 }
261 return false;
262}
263
264// Replace code looking like (x >>> -d OP x << d):
265// Neg neg, d
266// UShr dst, x, neg
267// Shl tmp, x, d
268// OP dst, dst, tmp
269// with
270// Neg neg, d
271// Ror dst, x, neg
272// *** OR ***
273// Replace code looking like (x >>> d OP x << -d):
274// UShr dst, x, d
275// Neg neg, d
276// Shl tmp, x, neg
277// OP dst, dst, tmp
278// with
279// Ror dst, x, d
280bool InstructionSimplifierVisitor::TryReplaceWithRotateRegisterNegPattern(HBinaryOperation* op,
281 HUShr* ushr,
282 HShl* shl) {
283 DCHECK(op->IsAdd() || op->IsXor() || op->IsOr());
284 DCHECK(ushr->GetRight()->IsNeg() || shl->GetRight()->IsNeg());
285 bool neg_is_left = shl->GetRight()->IsNeg();
286 HNeg* neg = neg_is_left ? shl->GetRight()->AsNeg() : ushr->GetRight()->AsNeg();
287 // And the shift distance being negated is the distance being shifted the other way.
288 if (neg->InputAt(0) == (neg_is_left ? ushr->GetRight() : shl->GetRight())) {
289 ReplaceRotateWithRor(op, ushr, shl);
290 }
291 return false;
292}
293
294// Try replacing code looking like (x >>> d OP x << (#bits - d)):
295// UShr dst, x, d
296// Sub ld, #bits, d
297// Shl tmp, x, ld
298// OP dst, dst, tmp
299// with
300// Ror dst, x, d
301// *** OR ***
302// Replace code looking like (x >>> (#bits - d) OP x << d):
303// Sub rd, #bits, d
304// UShr dst, x, rd
305// Shl tmp, x, d
306// OP dst, dst, tmp
307// with
308// Neg neg, d
309// Ror dst, x, neg
310bool InstructionSimplifierVisitor::TryReplaceWithRotateRegisterSubPattern(HBinaryOperation* op,
311 HUShr* ushr,
312 HShl* shl) {
313 DCHECK(op->IsAdd() || op->IsXor() || op->IsOr());
314 DCHECK(ushr->GetRight()->IsSub() || shl->GetRight()->IsSub());
315 size_t reg_bits = Primitive::ComponentSize(ushr->GetType()) * kBitsPerByte;
316 HInstruction* shl_shift = shl->GetRight();
317 HInstruction* ushr_shift = ushr->GetRight();
318 if ((shl_shift->IsSub() && IsSubRegBitsMinusOther(shl_shift->AsSub(), reg_bits, ushr_shift)) ||
319 (ushr_shift->IsSub() && IsSubRegBitsMinusOther(ushr_shift->AsSub(), reg_bits, shl_shift))) {
320 return ReplaceRotateWithRor(op, ushr, shl);
321 }
322 return false;
323}
324
Calin Juravle10e244f2015-01-26 18:54:32 +0000325void InstructionSimplifierVisitor::VisitNullCheck(HNullCheck* null_check) {
326 HInstruction* obj = null_check->InputAt(0);
327 if (!obj->CanBeNull()) {
328 null_check->ReplaceWith(obj);
329 null_check->GetBlock()->RemoveInstruction(null_check);
Calin Juravleacf735c2015-02-12 15:25:22 +0000330 if (stats_ != nullptr) {
331 stats_->RecordStat(MethodCompilationStat::kRemovedNullCheck);
332 }
333 }
334}
335
Nicolas Geoffray6e7455e2015-09-28 16:25:37 +0100336bool InstructionSimplifierVisitor::CanEnsureNotNullAt(HInstruction* input, HInstruction* at) const {
337 if (!input->CanBeNull()) {
338 return true;
339 }
340
Guillaume "Vermeille" Sanchez8909baf2015-04-23 21:35:11 +0100341 for (HUseIterator<HInstruction*> it(input->GetUses()); !it.Done(); it.Advance()) {
342 HInstruction* use = it.Current()->GetUser();
Nicolas Geoffray6e7455e2015-09-28 16:25:37 +0100343 if (use->IsNullCheck() && use->StrictlyDominates(at)) {
Guillaume "Vermeille" Sanchez8909baf2015-04-23 21:35:11 +0100344 return true;
345 }
346 }
Nicolas Geoffray6e7455e2015-09-28 16:25:37 +0100347
Guillaume "Vermeille" Sanchez8909baf2015-04-23 21:35:11 +0100348 return false;
349}
350
Guillaume Sanchez222862c2015-06-09 18:33:02 +0100351// Returns whether doing a type test between the class of `object` against `klass` has
352// a statically known outcome. The result of the test is stored in `outcome`.
353static bool TypeCheckHasKnownOutcome(HLoadClass* klass, HInstruction* object, bool* outcome) {
Calin Juravle2e768302015-07-28 14:41:11 +0000354 DCHECK(!object->IsNullConstant()) << "Null constants should be special cased";
355 ReferenceTypeInfo obj_rti = object->GetReferenceTypeInfo();
356 ScopedObjectAccess soa(Thread::Current());
357 if (!obj_rti.IsValid()) {
358 // We run the simplifier before the reference type propagation so type info might not be
359 // available.
Guillaume Sanchez222862c2015-06-09 18:33:02 +0100360 return false;
Calin Juravleacf735c2015-02-12 15:25:22 +0000361 }
Guillaume Sanchez222862c2015-06-09 18:33:02 +0100362
Guillaume Sanchez222862c2015-06-09 18:33:02 +0100363 ReferenceTypeInfo class_rti = klass->GetLoadedClassRTI();
Calin Juravle98893e12015-10-02 21:05:03 +0100364 if (!class_rti.IsValid()) {
365 // Happens when the loaded class is unresolved.
366 return false;
367 }
368 DCHECK(class_rti.IsExact());
Calin Juravleacf735c2015-02-12 15:25:22 +0000369 if (class_rti.IsSupertypeOf(obj_rti)) {
Guillaume Sanchez222862c2015-06-09 18:33:02 +0100370 *outcome = true;
371 return true;
372 } else if (obj_rti.IsExact()) {
373 // The test failed at compile time so will also fail at runtime.
374 *outcome = false;
375 return true;
Nicolas Geoffray7cb499b2015-06-17 11:35:11 +0100376 } else if (!class_rti.IsInterface()
377 && !obj_rti.IsInterface()
378 && !obj_rti.IsSupertypeOf(class_rti)) {
Guillaume Sanchez222862c2015-06-09 18:33:02 +0100379 // Different type hierarchy. The test will fail.
380 *outcome = false;
381 return true;
382 }
383 return false;
384}
385
386void InstructionSimplifierVisitor::VisitCheckCast(HCheckCast* check_cast) {
387 HInstruction* object = check_cast->InputAt(0);
Calin Juravlee53fb552015-10-07 17:51:52 +0100388 HLoadClass* load_class = check_cast->InputAt(1)->AsLoadClass();
389 if (load_class->NeedsAccessCheck()) {
390 // If we need to perform an access check we cannot remove the instruction.
391 return;
392 }
393
Nicolas Geoffray6e7455e2015-09-28 16:25:37 +0100394 if (CanEnsureNotNullAt(object, check_cast)) {
Guillaume Sanchez222862c2015-06-09 18:33:02 +0100395 check_cast->ClearMustDoNullCheck();
396 }
397
398 if (object->IsNullConstant()) {
Calin Juravleacf735c2015-02-12 15:25:22 +0000399 check_cast->GetBlock()->RemoveInstruction(check_cast);
400 if (stats_ != nullptr) {
401 stats_->RecordStat(MethodCompilationStat::kRemovedCheckedCast);
402 }
Guillaume Sanchez222862c2015-06-09 18:33:02 +0100403 return;
404 }
405
406 bool outcome;
Nicolas Geoffrayefa84682015-08-12 18:28:14 -0700407 if (TypeCheckHasKnownOutcome(load_class, object, &outcome)) {
Guillaume Sanchez222862c2015-06-09 18:33:02 +0100408 if (outcome) {
409 check_cast->GetBlock()->RemoveInstruction(check_cast);
410 if (stats_ != nullptr) {
411 stats_->RecordStat(MethodCompilationStat::kRemovedCheckedCast);
412 }
Nicolas Geoffrayefa84682015-08-12 18:28:14 -0700413 if (!load_class->HasUses()) {
414 // We cannot rely on DCE to remove the class because the `HLoadClass` thinks it can throw.
415 // However, here we know that it cannot because the checkcast was successfull, hence
416 // the class was already loaded.
417 load_class->GetBlock()->RemoveInstruction(load_class);
418 }
Guillaume Sanchez222862c2015-06-09 18:33:02 +0100419 } else {
420 // Don't do anything for exceptional cases for now. Ideally we should remove
421 // all instructions and blocks this instruction dominates.
422 }
Calin Juravle10e244f2015-01-26 18:54:32 +0000423 }
424}
425
Guillaume "Vermeille" Sanchezaf888352015-04-20 14:41:30 +0100426void InstructionSimplifierVisitor::VisitInstanceOf(HInstanceOf* instruction) {
Guillaume Sanchez222862c2015-06-09 18:33:02 +0100427 HInstruction* object = instruction->InputAt(0);
Calin Juravlee53fb552015-10-07 17:51:52 +0100428 HLoadClass* load_class = instruction->InputAt(1)->AsLoadClass();
429 if (load_class->NeedsAccessCheck()) {
430 // If we need to perform an access check we cannot remove the instruction.
431 return;
432 }
433
Guillaume Sanchez222862c2015-06-09 18:33:02 +0100434 bool can_be_null = true;
Nicolas Geoffray6e7455e2015-09-28 16:25:37 +0100435 if (CanEnsureNotNullAt(object, instruction)) {
Guillaume Sanchez222862c2015-06-09 18:33:02 +0100436 can_be_null = false;
Guillaume "Vermeille" Sanchezaf888352015-04-20 14:41:30 +0100437 instruction->ClearMustDoNullCheck();
438 }
Guillaume Sanchez222862c2015-06-09 18:33:02 +0100439
440 HGraph* graph = GetGraph();
441 if (object->IsNullConstant()) {
442 instruction->ReplaceWith(graph->GetIntConstant(0));
443 instruction->GetBlock()->RemoveInstruction(instruction);
444 RecordSimplification();
445 return;
446 }
447
448 bool outcome;
Nicolas Geoffrayefa84682015-08-12 18:28:14 -0700449 if (TypeCheckHasKnownOutcome(load_class, object, &outcome)) {
Guillaume Sanchez222862c2015-06-09 18:33:02 +0100450 if (outcome && can_be_null) {
451 // Type test will succeed, we just need a null test.
452 HNotEqual* test = new (graph->GetArena()) HNotEqual(graph->GetNullConstant(), object);
453 instruction->GetBlock()->InsertInstructionBefore(test, instruction);
454 instruction->ReplaceWith(test);
455 } else {
456 // We've statically determined the result of the instanceof.
457 instruction->ReplaceWith(graph->GetIntConstant(outcome));
458 }
459 RecordSimplification();
460 instruction->GetBlock()->RemoveInstruction(instruction);
Nicolas Geoffrayefa84682015-08-12 18:28:14 -0700461 if (outcome && !load_class->HasUses()) {
462 // We cannot rely on DCE to remove the class because the `HLoadClass` thinks it can throw.
463 // However, here we know that it cannot because the instanceof check was successfull, hence
464 // the class was already loaded.
465 load_class->GetBlock()->RemoveInstruction(load_class);
466 }
Guillaume Sanchez222862c2015-06-09 18:33:02 +0100467 }
Guillaume "Vermeille" Sanchezaf888352015-04-20 14:41:30 +0100468}
469
Nicolas Geoffray07276db2015-05-18 14:22:09 +0100470void InstructionSimplifierVisitor::VisitInstanceFieldSet(HInstanceFieldSet* instruction) {
471 if ((instruction->GetValue()->GetType() == Primitive::kPrimNot)
Nicolas Geoffray6e7455e2015-09-28 16:25:37 +0100472 && CanEnsureNotNullAt(instruction->GetValue(), instruction)) {
Nicolas Geoffray07276db2015-05-18 14:22:09 +0100473 instruction->ClearValueCanBeNull();
474 }
475}
476
477void InstructionSimplifierVisitor::VisitStaticFieldSet(HStaticFieldSet* instruction) {
478 if ((instruction->GetValue()->GetType() == Primitive::kPrimNot)
Nicolas Geoffray6e7455e2015-09-28 16:25:37 +0100479 && CanEnsureNotNullAt(instruction->GetValue(), instruction)) {
Nicolas Geoffray07276db2015-05-18 14:22:09 +0100480 instruction->ClearValueCanBeNull();
481 }
482}
483
Nicolas Geoffray5e6916c2014-11-18 16:53:35 +0000484void InstructionSimplifierVisitor::VisitSuspendCheck(HSuspendCheck* check) {
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100485 HBasicBlock* block = check->GetBlock();
486 // Currently always keep the suspend check at entry.
487 if (block->IsEntryBlock()) return;
488
489 // Currently always keep suspend checks at loop entry.
490 if (block->IsLoopHeader() && block->GetFirstInstruction() == check) {
491 DCHECK(block->GetLoopInformation()->GetSuspendCheck() == check);
492 return;
493 }
494
495 // Remove the suspend check that was added at build time for the baseline
496 // compiler.
497 block->RemoveInstruction(check);
498}
499
Nicolas Geoffray5e6916c2014-11-18 16:53:35 +0000500void InstructionSimplifierVisitor::VisitEqual(HEqual* equal) {
David Brazdil0d13fee2015-04-17 14:52:19 +0100501 HInstruction* input_const = equal->GetConstantRight();
502 if (input_const != nullptr) {
503 HInstruction* input_value = equal->GetLeastConstantLeft();
504 if (input_value->GetType() == Primitive::kPrimBoolean && input_const->IsIntConstant()) {
505 HBasicBlock* block = equal->GetBlock();
Nicolas Geoffray3c4ab802015-06-19 11:42:07 +0100506 // We are comparing the boolean to a constant which is of type int and can
507 // be any constant.
David Brazdil0d13fee2015-04-17 14:52:19 +0100508 if (input_const->AsIntConstant()->IsOne()) {
509 // Replace (bool_value == true) with bool_value
510 equal->ReplaceWith(input_value);
511 block->RemoveInstruction(equal);
512 RecordSimplification();
Nicolas Geoffray3c4ab802015-06-19 11:42:07 +0100513 } else if (input_const->AsIntConstant()->IsZero()) {
Mark Mendellf6529172015-11-17 11:16:56 -0500514 equal->ReplaceWith(GetGraph()->InsertOppositeCondition(input_value, equal));
515 block->RemoveInstruction(equal);
David Brazdil0d13fee2015-04-17 14:52:19 +0100516 RecordSimplification();
David Brazdil1e9ec052015-06-22 10:26:45 +0100517 } else {
518 // Replace (bool_value == integer_not_zero_nor_one_constant) with false
519 equal->ReplaceWith(GetGraph()->GetIntConstant(0));
520 block->RemoveInstruction(equal);
521 RecordSimplification();
David Brazdil0d13fee2015-04-17 14:52:19 +0100522 }
Mark Mendellc4701932015-04-10 13:18:51 -0400523 } else {
524 VisitCondition(equal);
Nicolas Geoffray01ef3452014-10-01 11:32:17 +0100525 }
Mark Mendellc4701932015-04-10 13:18:51 -0400526 } else {
527 VisitCondition(equal);
Nicolas Geoffray01ef3452014-10-01 11:32:17 +0100528 }
529}
530
David Brazdil0d13fee2015-04-17 14:52:19 +0100531void InstructionSimplifierVisitor::VisitNotEqual(HNotEqual* not_equal) {
532 HInstruction* input_const = not_equal->GetConstantRight();
533 if (input_const != nullptr) {
534 HInstruction* input_value = not_equal->GetLeastConstantLeft();
535 if (input_value->GetType() == Primitive::kPrimBoolean && input_const->IsIntConstant()) {
536 HBasicBlock* block = not_equal->GetBlock();
Nicolas Geoffray3c4ab802015-06-19 11:42:07 +0100537 // We are comparing the boolean to a constant which is of type int and can
538 // be any constant.
David Brazdil0d13fee2015-04-17 14:52:19 +0100539 if (input_const->AsIntConstant()->IsOne()) {
Mark Mendellf6529172015-11-17 11:16:56 -0500540 not_equal->ReplaceWith(GetGraph()->InsertOppositeCondition(input_value, not_equal));
541 block->RemoveInstruction(not_equal);
David Brazdil0d13fee2015-04-17 14:52:19 +0100542 RecordSimplification();
Nicolas Geoffray3c4ab802015-06-19 11:42:07 +0100543 } else if (input_const->AsIntConstant()->IsZero()) {
David Brazdil0d13fee2015-04-17 14:52:19 +0100544 // Replace (bool_value != false) with bool_value
David Brazdil0d13fee2015-04-17 14:52:19 +0100545 not_equal->ReplaceWith(input_value);
546 block->RemoveInstruction(not_equal);
547 RecordSimplification();
David Brazdil1e9ec052015-06-22 10:26:45 +0100548 } else {
549 // Replace (bool_value != integer_not_zero_nor_one_constant) with true
550 not_equal->ReplaceWith(GetGraph()->GetIntConstant(1));
551 block->RemoveInstruction(not_equal);
552 RecordSimplification();
David Brazdil0d13fee2015-04-17 14:52:19 +0100553 }
Mark Mendellc4701932015-04-10 13:18:51 -0400554 } else {
555 VisitCondition(not_equal);
David Brazdil0d13fee2015-04-17 14:52:19 +0100556 }
Mark Mendellc4701932015-04-10 13:18:51 -0400557 } else {
558 VisitCondition(not_equal);
David Brazdil0d13fee2015-04-17 14:52:19 +0100559 }
560}
561
562void InstructionSimplifierVisitor::VisitBooleanNot(HBooleanNot* bool_not) {
563 HInstruction* parent = bool_not->InputAt(0);
564 if (parent->IsBooleanNot()) {
565 HInstruction* value = parent->InputAt(0);
566 // Replace (!(!bool_value)) with bool_value
567 bool_not->ReplaceWith(value);
568 bool_not->GetBlock()->RemoveInstruction(bool_not);
569 // It is possible that `parent` is dead at this point but we leave
570 // its removal to DCE for simplicity.
571 RecordSimplification();
572 }
573}
574
Mingyao Yang0304e182015-01-30 16:41:29 -0800575void InstructionSimplifierVisitor::VisitArrayLength(HArrayLength* instruction) {
576 HInstruction* input = instruction->InputAt(0);
577 // If the array is a NewArray with constant size, replace the array length
578 // with the constant instruction. This helps the bounds check elimination phase.
579 if (input->IsNewArray()) {
580 input = input->InputAt(0);
581 if (input->IsIntConstant()) {
582 instruction->ReplaceWith(input);
583 }
584 }
585}
586
Nicolas Geoffray5e6916c2014-11-18 16:53:35 +0000587void InstructionSimplifierVisitor::VisitArraySet(HArraySet* instruction) {
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +0000588 HInstruction* value = instruction->GetValue();
589 if (value->GetType() != Primitive::kPrimNot) return;
590
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +0100591 if (CanEnsureNotNullAt(value, instruction)) {
592 instruction->ClearValueCanBeNull();
593 }
594
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +0000595 if (value->IsArrayGet()) {
596 if (value->AsArrayGet()->GetArray() == instruction->GetArray()) {
597 // If the code is just swapping elements in the array, no need for a type check.
598 instruction->ClearNeedsTypeCheck();
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +0100599 return;
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +0000600 }
601 }
Nicolas Geoffray07276db2015-05-18 14:22:09 +0100602
Nicolas Geoffray9fdb31e2015-07-01 12:56:46 +0100603 if (value->IsNullConstant()) {
604 instruction->ClearNeedsTypeCheck();
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +0100605 return;
Nicolas Geoffray9fdb31e2015-07-01 12:56:46 +0100606 }
607
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +0100608 ScopedObjectAccess soa(Thread::Current());
609 ReferenceTypeInfo array_rti = instruction->GetArray()->GetReferenceTypeInfo();
610 ReferenceTypeInfo value_rti = value->GetReferenceTypeInfo();
611 if (!array_rti.IsValid()) {
612 return;
613 }
614
615 if (value_rti.IsValid() && array_rti.CanArrayHold(value_rti)) {
616 instruction->ClearNeedsTypeCheck();
617 return;
618 }
619
620 if (array_rti.IsObjectArray()) {
621 if (array_rti.IsExact()) {
622 instruction->ClearNeedsTypeCheck();
623 return;
624 }
625 instruction->SetStaticTypeOfArrayIsObjectArray();
Nicolas Geoffray07276db2015-05-18 14:22:09 +0100626 }
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +0000627}
628
Nicolas Geoffray01fcc9e2014-12-01 14:16:20 +0000629void InstructionSimplifierVisitor::VisitTypeConversion(HTypeConversion* instruction) {
630 if (instruction->GetResultType() == instruction->GetInputType()) {
631 // Remove the instruction if it's converting to the same type.
632 instruction->ReplaceWith(instruction->GetInput());
633 instruction->GetBlock()->RemoveInstruction(instruction);
634 }
635}
636
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000637void InstructionSimplifierVisitor::VisitAdd(HAdd* instruction) {
638 HConstant* input_cst = instruction->GetConstantRight();
639 HInstruction* input_other = instruction->GetLeastConstantLeft();
640 if ((input_cst != nullptr) && input_cst->IsZero()) {
641 // Replace code looking like
642 // ADD dst, src, 0
643 // with
644 // src
Serguei Katkov115b53f2015-08-05 17:03:30 +0600645 // Note that we cannot optimize `x + 0.0` to `x` for floating-point. When
646 // `x` is `-0.0`, the former expression yields `0.0`, while the later
647 // yields `-0.0`.
648 if (Primitive::IsIntegralType(instruction->GetType())) {
649 instruction->ReplaceWith(input_other);
650 instruction->GetBlock()->RemoveInstruction(instruction);
651 return;
652 }
Alexandre Rames188d4312015-04-09 18:30:21 +0100653 }
654
655 HInstruction* left = instruction->GetLeft();
656 HInstruction* right = instruction->GetRight();
657 bool left_is_neg = left->IsNeg();
658 bool right_is_neg = right->IsNeg();
659
660 if (left_is_neg && right_is_neg) {
661 if (TryMoveNegOnInputsAfterBinop(instruction)) {
662 return;
663 }
664 }
665
666 HNeg* neg = left_is_neg ? left->AsNeg() : right->AsNeg();
667 if ((left_is_neg ^ right_is_neg) && neg->HasOnlyOneNonEnvironmentUse()) {
668 // Replace code looking like
669 // NEG tmp, b
670 // ADD dst, a, tmp
671 // with
672 // SUB dst, a, b
673 // We do not perform the optimization if the input negation has environment
674 // uses or multiple non-environment uses as it could lead to worse code. In
675 // particular, we do not want the live range of `b` to be extended if we are
676 // not sure the initial 'NEG' instruction can be removed.
677 HInstruction* other = left_is_neg ? right : left;
678 HSub* sub = new(GetGraph()->GetArena()) HSub(instruction->GetType(), other, neg->GetInput());
679 instruction->GetBlock()->ReplaceAndRemoveInstructionWith(instruction, sub);
680 RecordSimplification();
681 neg->GetBlock()->RemoveInstruction(neg);
Scott Wakeling40a04bf2015-12-11 09:50:36 +0000682 return;
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000683 }
Scott Wakeling40a04bf2015-12-11 09:50:36 +0000684
685 TryReplaceWithRotate(instruction);
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000686}
687
688void InstructionSimplifierVisitor::VisitAnd(HAnd* instruction) {
689 HConstant* input_cst = instruction->GetConstantRight();
690 HInstruction* input_other = instruction->GetLeastConstantLeft();
691
Vladimir Marko452c1b62015-09-25 14:44:17 +0100692 if (input_cst != nullptr) {
693 int64_t value = Int64FromConstant(input_cst);
694 if (value == -1) {
695 // Replace code looking like
696 // AND dst, src, 0xFFF...FF
697 // with
698 // src
699 instruction->ReplaceWith(input_other);
700 instruction->GetBlock()->RemoveInstruction(instruction);
701 RecordSimplification();
702 return;
703 }
704 // Eliminate And from UShr+And if the And-mask contains all the bits that
705 // can be non-zero after UShr. Transform Shr+And to UShr if the And-mask
706 // precisely clears the shifted-in sign bits.
707 if ((input_other->IsUShr() || input_other->IsShr()) && input_other->InputAt(1)->IsConstant()) {
708 size_t reg_bits = (instruction->GetResultType() == Primitive::kPrimLong) ? 64 : 32;
709 size_t shift = Int64FromConstant(input_other->InputAt(1)->AsConstant()) & (reg_bits - 1);
710 size_t num_tail_bits_set = CTZ(value + 1);
711 if ((num_tail_bits_set >= reg_bits - shift) && input_other->IsUShr()) {
712 // This AND clears only bits known to be clear, for example "(x >>> 24) & 0xff".
713 instruction->ReplaceWith(input_other);
714 instruction->GetBlock()->RemoveInstruction(instruction);
715 RecordSimplification();
716 return;
717 } else if ((num_tail_bits_set == reg_bits - shift) && IsPowerOfTwo(value + 1) &&
718 input_other->HasOnlyOneNonEnvironmentUse()) {
719 DCHECK(input_other->IsShr()); // For UShr, we would have taken the branch above.
720 // Replace SHR+AND with USHR, for example "(x >> 24) & 0xff" -> "x >>> 24".
721 HUShr* ushr = new (GetGraph()->GetArena()) HUShr(instruction->GetType(),
722 input_other->InputAt(0),
723 input_other->InputAt(1),
724 input_other->GetDexPc());
725 instruction->GetBlock()->ReplaceAndRemoveInstructionWith(instruction, ushr);
726 input_other->GetBlock()->RemoveInstruction(input_other);
727 RecordSimplification();
728 return;
729 }
730 }
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000731 }
732
733 // We assume that GVN has run before, so we only perform a pointer comparison.
734 // If for some reason the values are equal but the pointers are different, we
Alexandre Rames188d4312015-04-09 18:30:21 +0100735 // are still correct and only miss an optimization opportunity.
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000736 if (instruction->GetLeft() == instruction->GetRight()) {
737 // Replace code looking like
738 // AND dst, src, src
739 // with
740 // src
741 instruction->ReplaceWith(instruction->GetLeft());
742 instruction->GetBlock()->RemoveInstruction(instruction);
743 }
744}
745
Mark Mendellc4701932015-04-10 13:18:51 -0400746void InstructionSimplifierVisitor::VisitGreaterThan(HGreaterThan* condition) {
747 VisitCondition(condition);
748}
749
750void InstructionSimplifierVisitor::VisitGreaterThanOrEqual(HGreaterThanOrEqual* condition) {
751 VisitCondition(condition);
752}
753
754void InstructionSimplifierVisitor::VisitLessThan(HLessThan* condition) {
755 VisitCondition(condition);
756}
757
758void InstructionSimplifierVisitor::VisitLessThanOrEqual(HLessThanOrEqual* condition) {
759 VisitCondition(condition);
760}
761
Aart Bike9f37602015-10-09 11:15:55 -0700762// TODO: unsigned comparisons too?
763
Mark Mendellc4701932015-04-10 13:18:51 -0400764void InstructionSimplifierVisitor::VisitCondition(HCondition* condition) {
765 // Try to fold an HCompare into this HCondition.
766
Mark Mendellc4701932015-04-10 13:18:51 -0400767 HInstruction* left = condition->GetLeft();
768 HInstruction* right = condition->GetRight();
769 // We can only replace an HCondition which compares a Compare to 0.
770 // Both 'dx' and 'jack' generate a compare to 0 when compiling a
771 // condition with a long, float or double comparison as input.
772 if (!left->IsCompare() || !right->IsConstant() || right->AsIntConstant()->GetValue() != 0) {
773 // Conversion is not possible.
774 return;
775 }
776
777 // Is the Compare only used for this purpose?
778 if (!left->GetUses().HasOnlyOneUse()) {
779 // Someone else also wants the result of the compare.
780 return;
781 }
782
783 if (!left->GetEnvUses().IsEmpty()) {
784 // There is a reference to the compare result in an environment. Do we really need it?
785 if (GetGraph()->IsDebuggable()) {
786 return;
787 }
788
789 // We have to ensure that there are no deopt points in the sequence.
790 if (left->HasAnyEnvironmentUseBefore(condition)) {
791 return;
792 }
793 }
794
795 // Clean up any environment uses from the HCompare, if any.
796 left->RemoveEnvironmentUsers();
797
798 // We have decided to fold the HCompare into the HCondition. Transfer the information.
799 condition->SetBias(left->AsCompare()->GetBias());
800
801 // Replace the operands of the HCondition.
802 condition->ReplaceInput(left->InputAt(0), 0);
803 condition->ReplaceInput(left->InputAt(1), 1);
804
805 // Remove the HCompare.
806 left->GetBlock()->RemoveInstruction(left);
807
808 RecordSimplification();
809}
810
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000811void InstructionSimplifierVisitor::VisitDiv(HDiv* instruction) {
812 HConstant* input_cst = instruction->GetConstantRight();
813 HInstruction* input_other = instruction->GetLeastConstantLeft();
814 Primitive::Type type = instruction->GetType();
815
816 if ((input_cst != nullptr) && input_cst->IsOne()) {
817 // Replace code looking like
818 // DIV dst, src, 1
819 // with
820 // src
821 instruction->ReplaceWith(input_other);
822 instruction->GetBlock()->RemoveInstruction(instruction);
823 return;
824 }
825
Nicolas Geoffray0d221842015-04-27 08:53:46 +0000826 if ((input_cst != nullptr) && input_cst->IsMinusOne()) {
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000827 // Replace code looking like
828 // DIV dst, src, -1
829 // with
830 // NEG dst, src
831 instruction->GetBlock()->ReplaceAndRemoveInstructionWith(
Nicolas Geoffray0d221842015-04-27 08:53:46 +0000832 instruction, new (GetGraph()->GetArena()) HNeg(type, input_other));
Alexandre Rames188d4312015-04-09 18:30:21 +0100833 RecordSimplification();
Nicolas Geoffray0d221842015-04-27 08:53:46 +0000834 return;
835 }
836
837 if ((input_cst != nullptr) && Primitive::IsFloatingPointType(type)) {
838 // Try replacing code looking like
839 // DIV dst, src, constant
840 // with
841 // MUL dst, src, 1 / constant
842 HConstant* reciprocal = nullptr;
843 if (type == Primitive::Primitive::kPrimDouble) {
844 double value = input_cst->AsDoubleConstant()->GetValue();
845 if (CanDivideByReciprocalMultiplyDouble(bit_cast<int64_t, double>(value))) {
846 reciprocal = GetGraph()->GetDoubleConstant(1.0 / value);
847 }
848 } else {
849 DCHECK_EQ(type, Primitive::kPrimFloat);
850 float value = input_cst->AsFloatConstant()->GetValue();
851 if (CanDivideByReciprocalMultiplyFloat(bit_cast<int32_t, float>(value))) {
852 reciprocal = GetGraph()->GetFloatConstant(1.0f / value);
853 }
854 }
855
856 if (reciprocal != nullptr) {
857 instruction->GetBlock()->ReplaceAndRemoveInstructionWith(
858 instruction, new (GetGraph()->GetArena()) HMul(type, input_other, reciprocal));
859 RecordSimplification();
860 return;
861 }
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000862 }
863}
864
865void InstructionSimplifierVisitor::VisitMul(HMul* instruction) {
866 HConstant* input_cst = instruction->GetConstantRight();
867 HInstruction* input_other = instruction->GetLeastConstantLeft();
868 Primitive::Type type = instruction->GetType();
869 HBasicBlock* block = instruction->GetBlock();
870 ArenaAllocator* allocator = GetGraph()->GetArena();
871
872 if (input_cst == nullptr) {
873 return;
874 }
875
876 if (input_cst->IsOne()) {
877 // Replace code looking like
878 // MUL dst, src, 1
879 // with
880 // src
881 instruction->ReplaceWith(input_other);
882 instruction->GetBlock()->RemoveInstruction(instruction);
883 return;
884 }
885
886 if (input_cst->IsMinusOne() &&
887 (Primitive::IsFloatingPointType(type) || Primitive::IsIntOrLongType(type))) {
888 // Replace code looking like
889 // MUL dst, src, -1
890 // with
891 // NEG dst, src
892 HNeg* neg = new (allocator) HNeg(type, input_other);
893 block->ReplaceAndRemoveInstructionWith(instruction, neg);
Alexandre Rames188d4312015-04-09 18:30:21 +0100894 RecordSimplification();
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000895 return;
896 }
897
898 if (Primitive::IsFloatingPointType(type) &&
899 ((input_cst->IsFloatConstant() && input_cst->AsFloatConstant()->GetValue() == 2.0f) ||
900 (input_cst->IsDoubleConstant() && input_cst->AsDoubleConstant()->GetValue() == 2.0))) {
901 // Replace code looking like
902 // FP_MUL dst, src, 2.0
903 // with
904 // FP_ADD dst, src, src
905 // The 'int' and 'long' cases are handled below.
906 block->ReplaceAndRemoveInstructionWith(instruction,
907 new (allocator) HAdd(type, input_other, input_other));
Alexandre Rames188d4312015-04-09 18:30:21 +0100908 RecordSimplification();
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000909 return;
910 }
911
912 if (Primitive::IsIntOrLongType(type)) {
913 int64_t factor = Int64FromConstant(input_cst);
Serguei Katkov53849192015-04-20 14:22:27 +0600914 // Even though constant propagation also takes care of the zero case, other
915 // optimizations can lead to having a zero multiplication.
916 if (factor == 0) {
917 // Replace code looking like
918 // MUL dst, src, 0
919 // with
920 // 0
921 instruction->ReplaceWith(input_cst);
922 instruction->GetBlock()->RemoveInstruction(instruction);
923 } else if (IsPowerOfTwo(factor)) {
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000924 // Replace code looking like
925 // MUL dst, src, pow_of_2
926 // with
927 // SHL dst, src, log2(pow_of_2)
David Brazdil8d5b8b22015-03-24 10:51:52 +0000928 HIntConstant* shift = GetGraph()->GetIntConstant(WhichPowerOf2(factor));
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000929 HShl* shl = new(allocator) HShl(type, input_other, shift);
930 block->ReplaceAndRemoveInstructionWith(instruction, shl);
Alexandre Rames188d4312015-04-09 18:30:21 +0100931 RecordSimplification();
Alexandre Rames38db7852015-11-20 15:02:45 +0000932 } else if (IsPowerOfTwo(factor - 1)) {
933 // Transform code looking like
934 // MUL dst, src, (2^n + 1)
935 // into
936 // SHL tmp, src, n
937 // ADD dst, src, tmp
938 HShl* shl = new (allocator) HShl(type,
939 input_other,
940 GetGraph()->GetIntConstant(WhichPowerOf2(factor - 1)));
941 HAdd* add = new (allocator) HAdd(type, input_other, shl);
942
943 block->InsertInstructionBefore(shl, instruction);
944 block->ReplaceAndRemoveInstructionWith(instruction, add);
945 RecordSimplification();
946 } else if (IsPowerOfTwo(factor + 1)) {
947 // Transform code looking like
948 // MUL dst, src, (2^n - 1)
949 // into
950 // SHL tmp, src, n
951 // SUB dst, tmp, src
952 HShl* shl = new (allocator) HShl(type,
953 input_other,
954 GetGraph()->GetIntConstant(WhichPowerOf2(factor + 1)));
955 HSub* sub = new (allocator) HSub(type, shl, input_other);
956
957 block->InsertInstructionBefore(shl, instruction);
958 block->ReplaceAndRemoveInstructionWith(instruction, sub);
959 RecordSimplification();
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000960 }
961 }
962}
963
Alexandre Rames188d4312015-04-09 18:30:21 +0100964void InstructionSimplifierVisitor::VisitNeg(HNeg* instruction) {
965 HInstruction* input = instruction->GetInput();
966 if (input->IsNeg()) {
967 // Replace code looking like
968 // NEG tmp, src
969 // NEG dst, tmp
970 // with
971 // src
972 HNeg* previous_neg = input->AsNeg();
973 instruction->ReplaceWith(previous_neg->GetInput());
974 instruction->GetBlock()->RemoveInstruction(instruction);
975 // We perform the optimization even if the input negation has environment
976 // uses since it allows removing the current instruction. But we only delete
977 // the input negation only if it is does not have any uses left.
978 if (!previous_neg->HasUses()) {
979 previous_neg->GetBlock()->RemoveInstruction(previous_neg);
980 }
981 RecordSimplification();
982 return;
983 }
984
Serguei Katkov339dfc22015-04-20 12:29:32 +0600985 if (input->IsSub() && input->HasOnlyOneNonEnvironmentUse() &&
986 !Primitive::IsFloatingPointType(input->GetType())) {
Alexandre Rames188d4312015-04-09 18:30:21 +0100987 // Replace code looking like
988 // SUB tmp, a, b
989 // NEG dst, tmp
990 // with
991 // SUB dst, b, a
992 // We do not perform the optimization if the input subtraction has
993 // environment uses or multiple non-environment uses as it could lead to
994 // worse code. In particular, we do not want the live ranges of `a` and `b`
995 // to be extended if we are not sure the initial 'SUB' instruction can be
996 // removed.
Serguei Katkov339dfc22015-04-20 12:29:32 +0600997 // We do not perform optimization for fp because we could lose the sign of zero.
Alexandre Rames188d4312015-04-09 18:30:21 +0100998 HSub* sub = input->AsSub();
999 HSub* new_sub =
1000 new (GetGraph()->GetArena()) HSub(instruction->GetType(), sub->GetRight(), sub->GetLeft());
1001 instruction->GetBlock()->ReplaceAndRemoveInstructionWith(instruction, new_sub);
1002 if (!sub->HasUses()) {
1003 sub->GetBlock()->RemoveInstruction(sub);
1004 }
1005 RecordSimplification();
1006 }
1007}
1008
1009void InstructionSimplifierVisitor::VisitNot(HNot* instruction) {
1010 HInstruction* input = instruction->GetInput();
1011 if (input->IsNot()) {
1012 // Replace code looking like
1013 // NOT tmp, src
1014 // NOT dst, tmp
1015 // with
1016 // src
1017 // We perform the optimization even if the input negation has environment
1018 // uses since it allows removing the current instruction. But we only delete
1019 // the input negation only if it is does not have any uses left.
1020 HNot* previous_not = input->AsNot();
1021 instruction->ReplaceWith(previous_not->GetInput());
1022 instruction->GetBlock()->RemoveInstruction(instruction);
1023 if (!previous_not->HasUses()) {
1024 previous_not->GetBlock()->RemoveInstruction(previous_not);
1025 }
1026 RecordSimplification();
1027 }
1028}
1029
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +00001030void InstructionSimplifierVisitor::VisitOr(HOr* instruction) {
1031 HConstant* input_cst = instruction->GetConstantRight();
1032 HInstruction* input_other = instruction->GetLeastConstantLeft();
1033
1034 if ((input_cst != nullptr) && input_cst->IsZero()) {
1035 // Replace code looking like
1036 // OR dst, src, 0
1037 // with
1038 // src
1039 instruction->ReplaceWith(input_other);
1040 instruction->GetBlock()->RemoveInstruction(instruction);
1041 return;
1042 }
1043
1044 // We assume that GVN has run before, so we only perform a pointer comparison.
1045 // If for some reason the values are equal but the pointers are different, we
Alexandre Rames188d4312015-04-09 18:30:21 +01001046 // are still correct and only miss an optimization opportunity.
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +00001047 if (instruction->GetLeft() == instruction->GetRight()) {
1048 // Replace code looking like
1049 // OR dst, src, src
1050 // with
1051 // src
1052 instruction->ReplaceWith(instruction->GetLeft());
1053 instruction->GetBlock()->RemoveInstruction(instruction);
Scott Wakeling40a04bf2015-12-11 09:50:36 +00001054 return;
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +00001055 }
Scott Wakeling40a04bf2015-12-11 09:50:36 +00001056
1057 TryReplaceWithRotate(instruction);
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +00001058}
1059
1060void InstructionSimplifierVisitor::VisitShl(HShl* instruction) {
1061 VisitShift(instruction);
1062}
1063
1064void InstructionSimplifierVisitor::VisitShr(HShr* instruction) {
1065 VisitShift(instruction);
1066}
1067
1068void InstructionSimplifierVisitor::VisitSub(HSub* instruction) {
1069 HConstant* input_cst = instruction->GetConstantRight();
1070 HInstruction* input_other = instruction->GetLeastConstantLeft();
1071
Serguei Katkov115b53f2015-08-05 17:03:30 +06001072 Primitive::Type type = instruction->GetType();
1073 if (Primitive::IsFloatingPointType(type)) {
1074 return;
1075 }
1076
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +00001077 if ((input_cst != nullptr) && input_cst->IsZero()) {
1078 // Replace code looking like
1079 // SUB dst, src, 0
1080 // with
1081 // src
Serguei Katkov115b53f2015-08-05 17:03:30 +06001082 // Note that we cannot optimize `x - 0.0` to `x` for floating-point. When
1083 // `x` is `-0.0`, the former expression yields `0.0`, while the later
1084 // yields `-0.0`.
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +00001085 instruction->ReplaceWith(input_other);
1086 instruction->GetBlock()->RemoveInstruction(instruction);
1087 return;
1088 }
1089
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +00001090 HBasicBlock* block = instruction->GetBlock();
1091 ArenaAllocator* allocator = GetGraph()->GetArena();
1092
Alexandre Rames188d4312015-04-09 18:30:21 +01001093 HInstruction* left = instruction->GetLeft();
1094 HInstruction* right = instruction->GetRight();
1095 if (left->IsConstant()) {
1096 if (Int64FromConstant(left->AsConstant()) == 0) {
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +00001097 // Replace code looking like
1098 // SUB dst, 0, src
1099 // with
1100 // NEG dst, src
Alexandre Rames188d4312015-04-09 18:30:21 +01001101 // Note that we cannot optimize `0.0 - x` to `-x` for floating-point. When
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +00001102 // `x` is `0.0`, the former expression yields `0.0`, while the later
1103 // yields `-0.0`.
Alexandre Rames188d4312015-04-09 18:30:21 +01001104 HNeg* neg = new (allocator) HNeg(type, right);
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +00001105 block->ReplaceAndRemoveInstructionWith(instruction, neg);
Alexandre Rames188d4312015-04-09 18:30:21 +01001106 RecordSimplification();
1107 return;
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +00001108 }
1109 }
Alexandre Rames188d4312015-04-09 18:30:21 +01001110
1111 if (left->IsNeg() && right->IsNeg()) {
1112 if (TryMoveNegOnInputsAfterBinop(instruction)) {
1113 return;
1114 }
1115 }
1116
1117 if (right->IsNeg() && right->HasOnlyOneNonEnvironmentUse()) {
1118 // Replace code looking like
1119 // NEG tmp, b
1120 // SUB dst, a, tmp
1121 // with
1122 // ADD dst, a, b
1123 HAdd* add = new(GetGraph()->GetArena()) HAdd(type, left, right->AsNeg()->GetInput());
1124 instruction->GetBlock()->ReplaceAndRemoveInstructionWith(instruction, add);
1125 RecordSimplification();
1126 right->GetBlock()->RemoveInstruction(right);
1127 return;
1128 }
1129
1130 if (left->IsNeg() && left->HasOnlyOneNonEnvironmentUse()) {
1131 // Replace code looking like
1132 // NEG tmp, a
1133 // SUB dst, tmp, b
1134 // with
1135 // ADD tmp, a, b
1136 // NEG dst, tmp
1137 // The second version is not intrinsically better, but enables more
1138 // transformations.
1139 HAdd* add = new(GetGraph()->GetArena()) HAdd(type, left->AsNeg()->GetInput(), right);
1140 instruction->GetBlock()->InsertInstructionBefore(add, instruction);
1141 HNeg* neg = new (GetGraph()->GetArena()) HNeg(instruction->GetType(), add);
1142 instruction->GetBlock()->InsertInstructionBefore(neg, instruction);
1143 instruction->ReplaceWith(neg);
1144 instruction->GetBlock()->RemoveInstruction(instruction);
1145 RecordSimplification();
1146 left->GetBlock()->RemoveInstruction(left);
1147 }
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +00001148}
1149
1150void InstructionSimplifierVisitor::VisitUShr(HUShr* instruction) {
1151 VisitShift(instruction);
1152}
1153
1154void InstructionSimplifierVisitor::VisitXor(HXor* instruction) {
1155 HConstant* input_cst = instruction->GetConstantRight();
1156 HInstruction* input_other = instruction->GetLeastConstantLeft();
1157
1158 if ((input_cst != nullptr) && input_cst->IsZero()) {
1159 // Replace code looking like
1160 // XOR dst, src, 0
1161 // with
1162 // src
1163 instruction->ReplaceWith(input_other);
1164 instruction->GetBlock()->RemoveInstruction(instruction);
1165 return;
1166 }
1167
1168 if ((input_cst != nullptr) && AreAllBitsSet(input_cst)) {
1169 // Replace code looking like
1170 // XOR dst, src, 0xFFF...FF
1171 // with
1172 // NOT dst, src
1173 HNot* bitwise_not = new (GetGraph()->GetArena()) HNot(instruction->GetType(), input_other);
1174 instruction->GetBlock()->ReplaceAndRemoveInstructionWith(instruction, bitwise_not);
Alexandre Rames188d4312015-04-09 18:30:21 +01001175 RecordSimplification();
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +00001176 return;
1177 }
Scott Wakeling40a04bf2015-12-11 09:50:36 +00001178
1179 TryReplaceWithRotate(instruction);
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +00001180}
1181
Nicolas Geoffray2e7cd752015-07-10 11:38:52 +01001182void InstructionSimplifierVisitor::VisitFakeString(HFakeString* instruction) {
1183 HInstruction* actual_string = nullptr;
1184
1185 // Find the string we need to replace this instruction with. The actual string is
1186 // the return value of a StringFactory call.
1187 for (HUseIterator<HInstruction*> it(instruction->GetUses()); !it.Done(); it.Advance()) {
1188 HInstruction* use = it.Current()->GetUser();
1189 if (use->IsInvokeStaticOrDirect()
1190 && use->AsInvokeStaticOrDirect()->IsStringFactoryFor(instruction)) {
1191 use->AsInvokeStaticOrDirect()->RemoveFakeStringArgumentAsLastInput();
1192 actual_string = use;
1193 break;
1194 }
1195 }
1196
1197 // Check that there is no other instruction that thinks it is the factory for that string.
1198 if (kIsDebugBuild) {
1199 CHECK(actual_string != nullptr);
1200 for (HUseIterator<HInstruction*> it(instruction->GetUses()); !it.Done(); it.Advance()) {
1201 HInstruction* use = it.Current()->GetUser();
1202 if (use->IsInvokeStaticOrDirect()) {
1203 CHECK(!use->AsInvokeStaticOrDirect()->IsStringFactoryFor(instruction));
1204 }
1205 }
1206 }
1207
1208 // We need to remove any environment uses of the fake string that are not dominated by
1209 // `actual_string` to null.
1210 for (HUseIterator<HEnvironment*> it(instruction->GetEnvUses()); !it.Done(); it.Advance()) {
1211 HEnvironment* environment = it.Current()->GetUser();
1212 if (!actual_string->StrictlyDominates(environment->GetHolder())) {
1213 environment->RemoveAsUserOfInput(it.Current()->GetIndex());
1214 environment->SetRawEnvAt(it.Current()->GetIndex(), nullptr);
1215 }
1216 }
1217
1218 // Only uses dominated by `actual_string` must remain. We can safely replace and remove
1219 // `instruction`.
1220 instruction->ReplaceWith(actual_string);
1221 instruction->GetBlock()->RemoveInstruction(instruction);
1222}
1223
Nicolas Geoffrayee3cf072015-10-06 11:45:02 +01001224void InstructionSimplifierVisitor::SimplifyStringEquals(HInvoke* instruction) {
1225 HInstruction* argument = instruction->InputAt(1);
1226 HInstruction* receiver = instruction->InputAt(0);
1227 if (receiver == argument) {
1228 // Because String.equals is an instance call, the receiver is
1229 // a null check if we don't know it's null. The argument however, will
1230 // be the actual object. So we cannot end up in a situation where both
1231 // are equal but could be null.
1232 DCHECK(CanEnsureNotNullAt(argument, instruction));
1233 instruction->ReplaceWith(GetGraph()->GetIntConstant(1));
1234 instruction->GetBlock()->RemoveInstruction(instruction);
1235 } else {
1236 StringEqualsOptimizations optimizations(instruction);
1237 if (CanEnsureNotNullAt(argument, instruction)) {
1238 optimizations.SetArgumentNotNull();
1239 }
1240 ScopedObjectAccess soa(Thread::Current());
1241 ReferenceTypeInfo argument_rti = argument->GetReferenceTypeInfo();
1242 if (argument_rti.IsValid() && argument_rti.IsStringClass()) {
1243 optimizations.SetArgumentIsString();
1244 }
1245 }
1246}
1247
Scott Wakeling40a04bf2015-12-11 09:50:36 +00001248void InstructionSimplifierVisitor::SimplifyRotate(HInvoke* invoke, bool is_left) {
1249 DCHECK(invoke->IsInvokeStaticOrDirect());
1250 DCHECK_EQ(invoke->GetOriginalInvokeType(), InvokeType::kStatic);
Scott Wakeling40a04bf2015-12-11 09:50:36 +00001251 HInstruction* value = invoke->InputAt(0);
1252 HInstruction* distance = invoke->InputAt(1);
1253 // Replace the invoke with an HRor.
1254 if (is_left) {
1255 distance = new (GetGraph()->GetArena()) HNeg(distance->GetType(), distance);
1256 invoke->GetBlock()->InsertInstructionBefore(distance, invoke);
1257 }
1258 HRor* ror = new (GetGraph()->GetArena()) HRor(value->GetType(), value, distance);
1259 invoke->GetBlock()->ReplaceAndRemoveInstructionWith(invoke, ror);
1260 // Remove ClinitCheck and LoadClass, if possible.
1261 HInstruction* clinit = invoke->InputAt(invoke->InputCount() - 1);
1262 if (clinit->IsClinitCheck() && !clinit->HasUses()) {
1263 clinit->GetBlock()->RemoveInstruction(clinit);
1264 HInstruction* ldclass = clinit->InputAt(0);
1265 if (ldclass->IsLoadClass() && !ldclass->HasUses()) {
1266 ldclass->GetBlock()->RemoveInstruction(ldclass);
1267 }
1268 }
1269}
1270
Nicolas Geoffrayee3cf072015-10-06 11:45:02 +01001271static bool IsArrayLengthOf(HInstruction* potential_length, HInstruction* potential_array) {
1272 if (potential_length->IsArrayLength()) {
1273 return potential_length->InputAt(0) == potential_array;
1274 }
1275
1276 if (potential_array->IsNewArray()) {
1277 return potential_array->InputAt(0) == potential_length;
1278 }
1279
1280 return false;
1281}
1282
1283void InstructionSimplifierVisitor::SimplifySystemArrayCopy(HInvoke* instruction) {
1284 HInstruction* source = instruction->InputAt(0);
1285 HInstruction* destination = instruction->InputAt(2);
1286 HInstruction* count = instruction->InputAt(4);
1287 SystemArrayCopyOptimizations optimizations(instruction);
1288 if (CanEnsureNotNullAt(source, instruction)) {
1289 optimizations.SetSourceIsNotNull();
1290 }
1291 if (CanEnsureNotNullAt(destination, instruction)) {
1292 optimizations.SetDestinationIsNotNull();
1293 }
1294 if (destination == source) {
1295 optimizations.SetDestinationIsSource();
1296 }
1297
1298 if (IsArrayLengthOf(count, source)) {
1299 optimizations.SetCountIsSourceLength();
1300 }
1301
1302 if (IsArrayLengthOf(count, destination)) {
1303 optimizations.SetCountIsDestinationLength();
1304 }
1305
1306 {
1307 ScopedObjectAccess soa(Thread::Current());
1308 ReferenceTypeInfo destination_rti = destination->GetReferenceTypeInfo();
1309 if (destination_rti.IsValid()) {
1310 if (destination_rti.IsObjectArray()) {
1311 if (destination_rti.IsExact()) {
1312 optimizations.SetDoesNotNeedTypeCheck();
1313 }
1314 optimizations.SetDestinationIsTypedObjectArray();
Nicolas Geoffraya83a54d2015-10-02 17:30:26 +01001315 }
Nicolas Geoffrayee3cf072015-10-06 11:45:02 +01001316 if (destination_rti.IsPrimitiveArrayClass()) {
1317 optimizations.SetDestinationIsPrimitiveArray();
1318 } else if (destination_rti.IsNonPrimitiveArrayClass()) {
1319 optimizations.SetDestinationIsNonPrimitiveArray();
Nicolas Geoffraya83a54d2015-10-02 17:30:26 +01001320 }
1321 }
Nicolas Geoffrayee3cf072015-10-06 11:45:02 +01001322 ReferenceTypeInfo source_rti = source->GetReferenceTypeInfo();
1323 if (source_rti.IsValid()) {
1324 if (destination_rti.IsValid() && destination_rti.CanArrayHoldValuesOf(source_rti)) {
1325 optimizations.SetDoesNotNeedTypeCheck();
1326 }
1327 if (source_rti.IsPrimitiveArrayClass()) {
1328 optimizations.SetSourceIsPrimitiveArray();
1329 } else if (source_rti.IsNonPrimitiveArrayClass()) {
1330 optimizations.SetSourceIsNonPrimitiveArray();
1331 }
1332 }
1333 }
1334}
1335
1336void InstructionSimplifierVisitor::VisitInvoke(HInvoke* instruction) {
1337 if (instruction->GetIntrinsic() == Intrinsics::kStringEquals) {
1338 SimplifyStringEquals(instruction);
1339 } else if (instruction->GetIntrinsic() == Intrinsics::kSystemArrayCopy) {
1340 SimplifySystemArrayCopy(instruction);
Scott Wakeling40a04bf2015-12-11 09:50:36 +00001341 } else if (instruction->GetIntrinsic() == Intrinsics::kIntegerRotateRight ||
1342 instruction->GetIntrinsic() == Intrinsics::kLongRotateRight) {
1343 SimplifyRotate(instruction, false);
1344 } else if (instruction->GetIntrinsic() == Intrinsics::kIntegerRotateLeft ||
1345 instruction->GetIntrinsic() == Intrinsics::kLongRotateLeft) {
1346 SimplifyRotate(instruction, true);
Nicolas Geoffraya83a54d2015-10-02 17:30:26 +01001347 }
1348}
1349
Aart Bikbb245d12015-10-19 11:05:03 -07001350void InstructionSimplifierVisitor::VisitDeoptimize(HDeoptimize* deoptimize) {
1351 HInstruction* cond = deoptimize->InputAt(0);
1352 if (cond->IsConstant()) {
1353 if (cond->AsIntConstant()->IsZero()) {
1354 // Never deopt: instruction can be removed.
1355 deoptimize->GetBlock()->RemoveInstruction(deoptimize);
1356 } else {
1357 // Always deopt.
1358 }
1359 }
1360}
1361
Nicolas Geoffray3c049742014-09-24 18:10:46 +01001362} // namespace art