blob: 931a1c3cb7f03a113e820d4fd057d517f2a5f282 [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
Calin Juravleacf735c2015-02-12 15:25:22 +000019#include "mirror/class-inl.h"
20#include "scoped_thread_state_change.h"
21
Nicolas Geoffray3c049742014-09-24 18:10:46 +010022namespace art {
23
Nicolas Geoffray5e6916c2014-11-18 16:53:35 +000024class InstructionSimplifierVisitor : public HGraphVisitor {
25 public:
Calin Juravleacf735c2015-02-12 15:25:22 +000026 InstructionSimplifierVisitor(HGraph* graph, OptimizingCompilerStats* stats)
Alexandre Rames188d4312015-04-09 18:30:21 +010027 : HGraphVisitor(graph),
28 stats_(stats) {}
29
30 void Run();
Nicolas Geoffray5e6916c2014-11-18 16:53:35 +000031
32 private:
Alexandre Rames188d4312015-04-09 18:30:21 +010033 void RecordSimplification() {
34 simplification_occurred_ = true;
35 simplifications_at_current_position_++;
36 if (stats_) {
37 stats_->RecordStat(kInstructionSimplifications);
38 }
39 }
40
41 bool TryMoveNegOnInputsAfterBinop(HBinaryOperation* binop);
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +000042 void VisitShift(HBinaryOperation* shift);
43
Nicolas Geoffray5e6916c2014-11-18 16:53:35 +000044 void VisitSuspendCheck(HSuspendCheck* check) OVERRIDE;
45 void VisitEqual(HEqual* equal) OVERRIDE;
David Brazdil0d13fee2015-04-17 14:52:19 +010046 void VisitNotEqual(HNotEqual* equal) OVERRIDE;
47 void VisitBooleanNot(HBooleanNot* bool_not) OVERRIDE;
Nicolas Geoffray07276db2015-05-18 14:22:09 +010048 void VisitInstanceFieldSet(HInstanceFieldSet* equal) OVERRIDE;
49 void VisitStaticFieldSet(HStaticFieldSet* equal) OVERRIDE;
Nicolas Geoffray5e6916c2014-11-18 16:53:35 +000050 void VisitArraySet(HArraySet* equal) OVERRIDE;
Nicolas Geoffray01fcc9e2014-12-01 14:16:20 +000051 void VisitTypeConversion(HTypeConversion* instruction) OVERRIDE;
Calin Juravle10e244f2015-01-26 18:54:32 +000052 void VisitNullCheck(HNullCheck* instruction) OVERRIDE;
Mingyao Yang0304e182015-01-30 16:41:29 -080053 void VisitArrayLength(HArrayLength* instruction) OVERRIDE;
Calin Juravleacf735c2015-02-12 15:25:22 +000054 void VisitCheckCast(HCheckCast* instruction) OVERRIDE;
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +000055 void VisitAdd(HAdd* instruction) OVERRIDE;
56 void VisitAnd(HAnd* instruction) OVERRIDE;
Mark Mendellc4701932015-04-10 13:18:51 -040057 void VisitCondition(HCondition* instruction) OVERRIDE;
58 void VisitGreaterThan(HGreaterThan* condition) OVERRIDE;
59 void VisitGreaterThanOrEqual(HGreaterThanOrEqual* condition) OVERRIDE;
60 void VisitLessThan(HLessThan* condition) OVERRIDE;
61 void VisitLessThanOrEqual(HLessThanOrEqual* condition) OVERRIDE;
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +000062 void VisitDiv(HDiv* instruction) OVERRIDE;
63 void VisitMul(HMul* instruction) OVERRIDE;
Alexandre Rames188d4312015-04-09 18:30:21 +010064 void VisitNeg(HNeg* instruction) OVERRIDE;
65 void VisitNot(HNot* instruction) OVERRIDE;
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +000066 void VisitOr(HOr* instruction) OVERRIDE;
67 void VisitShl(HShl* instruction) OVERRIDE;
68 void VisitShr(HShr* instruction) OVERRIDE;
69 void VisitSub(HSub* instruction) OVERRIDE;
70 void VisitUShr(HUShr* instruction) OVERRIDE;
71 void VisitXor(HXor* instruction) OVERRIDE;
Guillaume "Vermeille" Sanchezaf888352015-04-20 14:41:30 +010072 void VisitInstanceOf(HInstanceOf* instruction) OVERRIDE;
Nicolas Geoffray2e7cd752015-07-10 11:38:52 +010073 void VisitFakeString(HFakeString* fake_string) OVERRIDE;
Guillaume "Vermeille" Sanchez8909baf2015-04-23 21:35:11 +010074 bool IsDominatedByInputNullCheck(HInstruction* instr);
Calin Juravleacf735c2015-02-12 15:25:22 +000075
76 OptimizingCompilerStats* stats_;
Alexandre Rames188d4312015-04-09 18:30:21 +010077 bool simplification_occurred_ = false;
78 int simplifications_at_current_position_ = 0;
79 // We ensure we do not loop infinitely. The value is a finger in the air guess
80 // that should allow enough simplification.
81 static constexpr int kMaxSamePositionSimplifications = 10;
Nicolas Geoffray5e6916c2014-11-18 16:53:35 +000082};
83
Nicolas Geoffray3c049742014-09-24 18:10:46 +010084void InstructionSimplifier::Run() {
Calin Juravleacf735c2015-02-12 15:25:22 +000085 InstructionSimplifierVisitor visitor(graph_, stats_);
Alexandre Rames188d4312015-04-09 18:30:21 +010086 visitor.Run();
87}
88
89void InstructionSimplifierVisitor::Run() {
Nicolas Geoffray07276db2015-05-18 14:22:09 +010090 // Iterate in reverse post order to open up more simplifications to users
91 // of instructions that got simplified.
Alexandre Rames188d4312015-04-09 18:30:21 +010092 for (HReversePostOrderIterator it(*GetGraph()); !it.Done();) {
93 // The simplification of an instruction to another instruction may yield
94 // possibilities for other simplifications. So although we perform a reverse
95 // post order visit, we sometimes need to revisit an instruction index.
96 simplification_occurred_ = false;
97 VisitBasicBlock(it.Current());
98 if (simplification_occurred_ &&
99 (simplifications_at_current_position_ < kMaxSamePositionSimplifications)) {
100 // New simplifications may be applicable to the instruction at the
101 // current index, so don't advance the iterator.
102 continue;
103 }
Alexandre Rames188d4312015-04-09 18:30:21 +0100104 simplifications_at_current_position_ = 0;
105 it.Advance();
106 }
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100107}
108
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000109namespace {
110
111bool AreAllBitsSet(HConstant* constant) {
112 return Int64FromConstant(constant) == -1;
113}
114
115} // namespace
116
Alexandre Rames188d4312015-04-09 18:30:21 +0100117// Returns true if the code was simplified to use only one negation operation
118// after the binary operation instead of one on each of the inputs.
119bool InstructionSimplifierVisitor::TryMoveNegOnInputsAfterBinop(HBinaryOperation* binop) {
120 DCHECK(binop->IsAdd() || binop->IsSub());
121 DCHECK(binop->GetLeft()->IsNeg() && binop->GetRight()->IsNeg());
122 HNeg* left_neg = binop->GetLeft()->AsNeg();
123 HNeg* right_neg = binop->GetRight()->AsNeg();
124 if (!left_neg->HasOnlyOneNonEnvironmentUse() ||
125 !right_neg->HasOnlyOneNonEnvironmentUse()) {
126 return false;
127 }
128 // Replace code looking like
129 // NEG tmp1, a
130 // NEG tmp2, b
131 // ADD dst, tmp1, tmp2
132 // with
133 // ADD tmp, a, b
134 // NEG dst, tmp
135 binop->ReplaceInput(left_neg->GetInput(), 0);
136 binop->ReplaceInput(right_neg->GetInput(), 1);
137 left_neg->GetBlock()->RemoveInstruction(left_neg);
138 right_neg->GetBlock()->RemoveInstruction(right_neg);
139 HNeg* neg = new (GetGraph()->GetArena()) HNeg(binop->GetType(), binop);
140 binop->GetBlock()->InsertInstructionBefore(neg, binop->GetNext());
141 binop->ReplaceWithExceptInReplacementAtIndex(neg, 0);
142 RecordSimplification();
143 return true;
144}
145
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000146void InstructionSimplifierVisitor::VisitShift(HBinaryOperation* instruction) {
147 DCHECK(instruction->IsShl() || instruction->IsShr() || instruction->IsUShr());
148 HConstant* input_cst = instruction->GetConstantRight();
149 HInstruction* input_other = instruction->GetLeastConstantLeft();
150
Mark Mendellba56d062015-05-05 21:34:03 -0400151 if (input_cst != nullptr) {
152 if (input_cst->IsZero()) {
153 // Replace code looking like
154 // SHL dst, src, 0
155 // with
156 // src
157 instruction->ReplaceWith(input_other);
158 instruction->GetBlock()->RemoveInstruction(instruction);
159 } else if (instruction->IsShl() && input_cst->IsOne()) {
160 // Replace Shl looking like
161 // SHL dst, src, 1
162 // with
163 // ADD dst, src, src
164 HAdd *add = new(GetGraph()->GetArena()) HAdd(instruction->GetType(),
165 input_other,
166 input_other);
167 instruction->GetBlock()->ReplaceAndRemoveInstructionWith(instruction, add);
168 RecordSimplification();
169 }
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000170 }
171}
172
Calin Juravle10e244f2015-01-26 18:54:32 +0000173void InstructionSimplifierVisitor::VisitNullCheck(HNullCheck* null_check) {
174 HInstruction* obj = null_check->InputAt(0);
175 if (!obj->CanBeNull()) {
176 null_check->ReplaceWith(obj);
177 null_check->GetBlock()->RemoveInstruction(null_check);
Calin Juravleacf735c2015-02-12 15:25:22 +0000178 if (stats_ != nullptr) {
179 stats_->RecordStat(MethodCompilationStat::kRemovedNullCheck);
180 }
181 }
182}
183
Guillaume "Vermeille" Sanchez8909baf2015-04-23 21:35:11 +0100184bool InstructionSimplifierVisitor::IsDominatedByInputNullCheck(HInstruction* instr) {
185 HInstruction* input = instr->InputAt(0);
186 for (HUseIterator<HInstruction*> it(input->GetUses()); !it.Done(); it.Advance()) {
187 HInstruction* use = it.Current()->GetUser();
188 if (use->IsNullCheck() && use->StrictlyDominates(instr)) {
189 return true;
190 }
191 }
192 return false;
193}
194
Guillaume Sanchez222862c2015-06-09 18:33:02 +0100195// Returns whether doing a type test between the class of `object` against `klass` has
196// a statically known outcome. The result of the test is stored in `outcome`.
197static bool TypeCheckHasKnownOutcome(HLoadClass* klass, HInstruction* object, bool* outcome) {
Calin Juravle2e768302015-07-28 14:41:11 +0000198 DCHECK(!object->IsNullConstant()) << "Null constants should be special cased";
199 ReferenceTypeInfo obj_rti = object->GetReferenceTypeInfo();
200 ScopedObjectAccess soa(Thread::Current());
201 if (!obj_rti.IsValid()) {
202 // We run the simplifier before the reference type propagation so type info might not be
203 // available.
Guillaume Sanchez222862c2015-06-09 18:33:02 +0100204 return false;
Calin Juravleacf735c2015-02-12 15:25:22 +0000205 }
Guillaume Sanchez222862c2015-06-09 18:33:02 +0100206
Guillaume Sanchez222862c2015-06-09 18:33:02 +0100207 ReferenceTypeInfo class_rti = klass->GetLoadedClassRTI();
Calin Juravle2e768302015-07-28 14:41:11 +0000208 DCHECK(class_rti.IsValid() && class_rti.IsExact());
Calin Juravleacf735c2015-02-12 15:25:22 +0000209 if (class_rti.IsSupertypeOf(obj_rti)) {
Guillaume Sanchez222862c2015-06-09 18:33:02 +0100210 *outcome = true;
211 return true;
212 } else if (obj_rti.IsExact()) {
213 // The test failed at compile time so will also fail at runtime.
214 *outcome = false;
215 return true;
Nicolas Geoffray7cb499b2015-06-17 11:35:11 +0100216 } else if (!class_rti.IsInterface()
217 && !obj_rti.IsInterface()
218 && !obj_rti.IsSupertypeOf(class_rti)) {
Guillaume Sanchez222862c2015-06-09 18:33:02 +0100219 // Different type hierarchy. The test will fail.
220 *outcome = false;
221 return true;
222 }
223 return false;
224}
225
226void InstructionSimplifierVisitor::VisitCheckCast(HCheckCast* check_cast) {
227 HInstruction* object = check_cast->InputAt(0);
228 if (!object->CanBeNull() || IsDominatedByInputNullCheck(check_cast)) {
229 check_cast->ClearMustDoNullCheck();
230 }
231
232 if (object->IsNullConstant()) {
Calin Juravleacf735c2015-02-12 15:25:22 +0000233 check_cast->GetBlock()->RemoveInstruction(check_cast);
234 if (stats_ != nullptr) {
235 stats_->RecordStat(MethodCompilationStat::kRemovedCheckedCast);
236 }
Guillaume Sanchez222862c2015-06-09 18:33:02 +0100237 return;
238 }
239
240 bool outcome;
241 if (TypeCheckHasKnownOutcome(check_cast->InputAt(1)->AsLoadClass(), object, &outcome)) {
242 if (outcome) {
243 check_cast->GetBlock()->RemoveInstruction(check_cast);
244 if (stats_ != nullptr) {
245 stats_->RecordStat(MethodCompilationStat::kRemovedCheckedCast);
246 }
247 } else {
248 // Don't do anything for exceptional cases for now. Ideally we should remove
249 // all instructions and blocks this instruction dominates.
250 }
Calin Juravle10e244f2015-01-26 18:54:32 +0000251 }
252}
253
Guillaume "Vermeille" Sanchezaf888352015-04-20 14:41:30 +0100254void InstructionSimplifierVisitor::VisitInstanceOf(HInstanceOf* instruction) {
Guillaume Sanchez222862c2015-06-09 18:33:02 +0100255 HInstruction* object = instruction->InputAt(0);
256 bool can_be_null = true;
257 if (!object->CanBeNull() || IsDominatedByInputNullCheck(instruction)) {
258 can_be_null = false;
Guillaume "Vermeille" Sanchezaf888352015-04-20 14:41:30 +0100259 instruction->ClearMustDoNullCheck();
260 }
Guillaume Sanchez222862c2015-06-09 18:33:02 +0100261
262 HGraph* graph = GetGraph();
263 if (object->IsNullConstant()) {
264 instruction->ReplaceWith(graph->GetIntConstant(0));
265 instruction->GetBlock()->RemoveInstruction(instruction);
266 RecordSimplification();
267 return;
268 }
269
270 bool outcome;
271 if (TypeCheckHasKnownOutcome(instruction->InputAt(1)->AsLoadClass(), object, &outcome)) {
272 if (outcome && can_be_null) {
273 // Type test will succeed, we just need a null test.
274 HNotEqual* test = new (graph->GetArena()) HNotEqual(graph->GetNullConstant(), object);
275 instruction->GetBlock()->InsertInstructionBefore(test, instruction);
276 instruction->ReplaceWith(test);
277 } else {
278 // We've statically determined the result of the instanceof.
279 instruction->ReplaceWith(graph->GetIntConstant(outcome));
280 }
281 RecordSimplification();
282 instruction->GetBlock()->RemoveInstruction(instruction);
283 }
Guillaume "Vermeille" Sanchezaf888352015-04-20 14:41:30 +0100284}
285
Nicolas Geoffray07276db2015-05-18 14:22:09 +0100286void InstructionSimplifierVisitor::VisitInstanceFieldSet(HInstanceFieldSet* instruction) {
287 if ((instruction->GetValue()->GetType() == Primitive::kPrimNot)
288 && !instruction->GetValue()->CanBeNull()) {
289 instruction->ClearValueCanBeNull();
290 }
291}
292
293void InstructionSimplifierVisitor::VisitStaticFieldSet(HStaticFieldSet* instruction) {
294 if ((instruction->GetValue()->GetType() == Primitive::kPrimNot)
295 && !instruction->GetValue()->CanBeNull()) {
296 instruction->ClearValueCanBeNull();
297 }
298}
299
Nicolas Geoffray5e6916c2014-11-18 16:53:35 +0000300void InstructionSimplifierVisitor::VisitSuspendCheck(HSuspendCheck* check) {
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100301 HBasicBlock* block = check->GetBlock();
302 // Currently always keep the suspend check at entry.
303 if (block->IsEntryBlock()) return;
304
305 // Currently always keep suspend checks at loop entry.
306 if (block->IsLoopHeader() && block->GetFirstInstruction() == check) {
307 DCHECK(block->GetLoopInformation()->GetSuspendCheck() == check);
308 return;
309 }
310
311 // Remove the suspend check that was added at build time for the baseline
312 // compiler.
313 block->RemoveInstruction(check);
314}
315
Nicolas Geoffray5e6916c2014-11-18 16:53:35 +0000316void InstructionSimplifierVisitor::VisitEqual(HEqual* equal) {
David Brazdil0d13fee2015-04-17 14:52:19 +0100317 HInstruction* input_const = equal->GetConstantRight();
318 if (input_const != nullptr) {
319 HInstruction* input_value = equal->GetLeastConstantLeft();
320 if (input_value->GetType() == Primitive::kPrimBoolean && input_const->IsIntConstant()) {
321 HBasicBlock* block = equal->GetBlock();
Nicolas Geoffray3c4ab802015-06-19 11:42:07 +0100322 // We are comparing the boolean to a constant which is of type int and can
323 // be any constant.
David Brazdil0d13fee2015-04-17 14:52:19 +0100324 if (input_const->AsIntConstant()->IsOne()) {
325 // Replace (bool_value == true) with bool_value
326 equal->ReplaceWith(input_value);
327 block->RemoveInstruction(equal);
328 RecordSimplification();
Nicolas Geoffray3c4ab802015-06-19 11:42:07 +0100329 } else if (input_const->AsIntConstant()->IsZero()) {
David Brazdil0d13fee2015-04-17 14:52:19 +0100330 // Replace (bool_value == false) with !bool_value
David Brazdil0d13fee2015-04-17 14:52:19 +0100331 block->ReplaceAndRemoveInstructionWith(
332 equal, new (block->GetGraph()->GetArena()) HBooleanNot(input_value));
333 RecordSimplification();
David Brazdil1e9ec052015-06-22 10:26:45 +0100334 } else {
335 // Replace (bool_value == integer_not_zero_nor_one_constant) with false
336 equal->ReplaceWith(GetGraph()->GetIntConstant(0));
337 block->RemoveInstruction(equal);
338 RecordSimplification();
David Brazdil0d13fee2015-04-17 14:52:19 +0100339 }
Mark Mendellc4701932015-04-10 13:18:51 -0400340 } else {
341 VisitCondition(equal);
Nicolas Geoffray01ef3452014-10-01 11:32:17 +0100342 }
Mark Mendellc4701932015-04-10 13:18:51 -0400343 } else {
344 VisitCondition(equal);
Nicolas Geoffray01ef3452014-10-01 11:32:17 +0100345 }
346}
347
David Brazdil0d13fee2015-04-17 14:52:19 +0100348void InstructionSimplifierVisitor::VisitNotEqual(HNotEqual* not_equal) {
349 HInstruction* input_const = not_equal->GetConstantRight();
350 if (input_const != nullptr) {
351 HInstruction* input_value = not_equal->GetLeastConstantLeft();
352 if (input_value->GetType() == Primitive::kPrimBoolean && input_const->IsIntConstant()) {
353 HBasicBlock* block = not_equal->GetBlock();
Nicolas Geoffray3c4ab802015-06-19 11:42:07 +0100354 // We are comparing the boolean to a constant which is of type int and can
355 // be any constant.
David Brazdil0d13fee2015-04-17 14:52:19 +0100356 if (input_const->AsIntConstant()->IsOne()) {
357 // Replace (bool_value != true) with !bool_value
358 block->ReplaceAndRemoveInstructionWith(
359 not_equal, new (block->GetGraph()->GetArena()) HBooleanNot(input_value));
360 RecordSimplification();
Nicolas Geoffray3c4ab802015-06-19 11:42:07 +0100361 } else if (input_const->AsIntConstant()->IsZero()) {
David Brazdil0d13fee2015-04-17 14:52:19 +0100362 // Replace (bool_value != false) with bool_value
David Brazdil0d13fee2015-04-17 14:52:19 +0100363 not_equal->ReplaceWith(input_value);
364 block->RemoveInstruction(not_equal);
365 RecordSimplification();
David Brazdil1e9ec052015-06-22 10:26:45 +0100366 } else {
367 // Replace (bool_value != integer_not_zero_nor_one_constant) with true
368 not_equal->ReplaceWith(GetGraph()->GetIntConstant(1));
369 block->RemoveInstruction(not_equal);
370 RecordSimplification();
David Brazdil0d13fee2015-04-17 14:52:19 +0100371 }
Mark Mendellc4701932015-04-10 13:18:51 -0400372 } else {
373 VisitCondition(not_equal);
David Brazdil0d13fee2015-04-17 14:52:19 +0100374 }
Mark Mendellc4701932015-04-10 13:18:51 -0400375 } else {
376 VisitCondition(not_equal);
David Brazdil0d13fee2015-04-17 14:52:19 +0100377 }
378}
379
380void InstructionSimplifierVisitor::VisitBooleanNot(HBooleanNot* bool_not) {
381 HInstruction* parent = bool_not->InputAt(0);
382 if (parent->IsBooleanNot()) {
383 HInstruction* value = parent->InputAt(0);
384 // Replace (!(!bool_value)) with bool_value
385 bool_not->ReplaceWith(value);
386 bool_not->GetBlock()->RemoveInstruction(bool_not);
387 // It is possible that `parent` is dead at this point but we leave
388 // its removal to DCE for simplicity.
389 RecordSimplification();
390 }
391}
392
Mingyao Yang0304e182015-01-30 16:41:29 -0800393void InstructionSimplifierVisitor::VisitArrayLength(HArrayLength* instruction) {
394 HInstruction* input = instruction->InputAt(0);
395 // If the array is a NewArray with constant size, replace the array length
396 // with the constant instruction. This helps the bounds check elimination phase.
397 if (input->IsNewArray()) {
398 input = input->InputAt(0);
399 if (input->IsIntConstant()) {
400 instruction->ReplaceWith(input);
401 }
402 }
403}
404
Nicolas Geoffray5e6916c2014-11-18 16:53:35 +0000405void InstructionSimplifierVisitor::VisitArraySet(HArraySet* instruction) {
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +0000406 HInstruction* value = instruction->GetValue();
407 if (value->GetType() != Primitive::kPrimNot) return;
408
409 if (value->IsArrayGet()) {
410 if (value->AsArrayGet()->GetArray() == instruction->GetArray()) {
411 // If the code is just swapping elements in the array, no need for a type check.
412 instruction->ClearNeedsTypeCheck();
413 }
414 }
Nicolas Geoffray07276db2015-05-18 14:22:09 +0100415
Nicolas Geoffray9fdb31e2015-07-01 12:56:46 +0100416 if (value->IsNullConstant()) {
417 instruction->ClearNeedsTypeCheck();
418 }
419
Nicolas Geoffray07276db2015-05-18 14:22:09 +0100420 if (!value->CanBeNull()) {
421 instruction->ClearValueCanBeNull();
422 }
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +0000423}
424
Nicolas Geoffray01fcc9e2014-12-01 14:16:20 +0000425void InstructionSimplifierVisitor::VisitTypeConversion(HTypeConversion* instruction) {
426 if (instruction->GetResultType() == instruction->GetInputType()) {
427 // Remove the instruction if it's converting to the same type.
428 instruction->ReplaceWith(instruction->GetInput());
429 instruction->GetBlock()->RemoveInstruction(instruction);
430 }
431}
432
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000433void InstructionSimplifierVisitor::VisitAdd(HAdd* instruction) {
434 HConstant* input_cst = instruction->GetConstantRight();
435 HInstruction* input_other = instruction->GetLeastConstantLeft();
436 if ((input_cst != nullptr) && input_cst->IsZero()) {
437 // Replace code looking like
438 // ADD dst, src, 0
439 // with
440 // src
Serguei Katkov115b53f2015-08-05 17:03:30 +0600441 // Note that we cannot optimize `x + 0.0` to `x` for floating-point. When
442 // `x` is `-0.0`, the former expression yields `0.0`, while the later
443 // yields `-0.0`.
444 if (Primitive::IsIntegralType(instruction->GetType())) {
445 instruction->ReplaceWith(input_other);
446 instruction->GetBlock()->RemoveInstruction(instruction);
447 return;
448 }
Alexandre Rames188d4312015-04-09 18:30:21 +0100449 }
450
451 HInstruction* left = instruction->GetLeft();
452 HInstruction* right = instruction->GetRight();
453 bool left_is_neg = left->IsNeg();
454 bool right_is_neg = right->IsNeg();
455
456 if (left_is_neg && right_is_neg) {
457 if (TryMoveNegOnInputsAfterBinop(instruction)) {
458 return;
459 }
460 }
461
462 HNeg* neg = left_is_neg ? left->AsNeg() : right->AsNeg();
463 if ((left_is_neg ^ right_is_neg) && neg->HasOnlyOneNonEnvironmentUse()) {
464 // Replace code looking like
465 // NEG tmp, b
466 // ADD dst, a, tmp
467 // with
468 // SUB dst, a, b
469 // We do not perform the optimization if the input negation has environment
470 // uses or multiple non-environment uses as it could lead to worse code. In
471 // particular, we do not want the live range of `b` to be extended if we are
472 // not sure the initial 'NEG' instruction can be removed.
473 HInstruction* other = left_is_neg ? right : left;
474 HSub* sub = new(GetGraph()->GetArena()) HSub(instruction->GetType(), other, neg->GetInput());
475 instruction->GetBlock()->ReplaceAndRemoveInstructionWith(instruction, sub);
476 RecordSimplification();
477 neg->GetBlock()->RemoveInstruction(neg);
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000478 }
479}
480
481void InstructionSimplifierVisitor::VisitAnd(HAnd* instruction) {
482 HConstant* input_cst = instruction->GetConstantRight();
483 HInstruction* input_other = instruction->GetLeastConstantLeft();
484
485 if ((input_cst != nullptr) && AreAllBitsSet(input_cst)) {
486 // Replace code looking like
487 // AND dst, src, 0xFFF...FF
488 // with
489 // src
490 instruction->ReplaceWith(input_other);
491 instruction->GetBlock()->RemoveInstruction(instruction);
492 return;
493 }
494
495 // We assume that GVN has run before, so we only perform a pointer comparison.
496 // If for some reason the values are equal but the pointers are different, we
Alexandre Rames188d4312015-04-09 18:30:21 +0100497 // are still correct and only miss an optimization opportunity.
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000498 if (instruction->GetLeft() == instruction->GetRight()) {
499 // Replace code looking like
500 // AND dst, src, src
501 // with
502 // src
503 instruction->ReplaceWith(instruction->GetLeft());
504 instruction->GetBlock()->RemoveInstruction(instruction);
505 }
506}
507
Mark Mendellc4701932015-04-10 13:18:51 -0400508void InstructionSimplifierVisitor::VisitGreaterThan(HGreaterThan* condition) {
509 VisitCondition(condition);
510}
511
512void InstructionSimplifierVisitor::VisitGreaterThanOrEqual(HGreaterThanOrEqual* condition) {
513 VisitCondition(condition);
514}
515
516void InstructionSimplifierVisitor::VisitLessThan(HLessThan* condition) {
517 VisitCondition(condition);
518}
519
520void InstructionSimplifierVisitor::VisitLessThanOrEqual(HLessThanOrEqual* condition) {
521 VisitCondition(condition);
522}
523
524void InstructionSimplifierVisitor::VisitCondition(HCondition* condition) {
525 // Try to fold an HCompare into this HCondition.
526
Roland Levillain7f63c522015-07-13 15:54:55 +0000527 // This simplification is currently supported on x86, x86_64, ARM and ARM64.
528 // TODO: Implement it for MIPS64.
Mark Mendellc4701932015-04-10 13:18:51 -0400529 InstructionSet instruction_set = GetGraph()->GetInstructionSet();
Roland Levillain7f63c522015-07-13 15:54:55 +0000530 if (instruction_set == kMips64) {
Mark Mendellc4701932015-04-10 13:18:51 -0400531 return;
532 }
533
534 HInstruction* left = condition->GetLeft();
535 HInstruction* right = condition->GetRight();
536 // We can only replace an HCondition which compares a Compare to 0.
537 // Both 'dx' and 'jack' generate a compare to 0 when compiling a
538 // condition with a long, float or double comparison as input.
539 if (!left->IsCompare() || !right->IsConstant() || right->AsIntConstant()->GetValue() != 0) {
540 // Conversion is not possible.
541 return;
542 }
543
544 // Is the Compare only used for this purpose?
545 if (!left->GetUses().HasOnlyOneUse()) {
546 // Someone else also wants the result of the compare.
547 return;
548 }
549
550 if (!left->GetEnvUses().IsEmpty()) {
551 // There is a reference to the compare result in an environment. Do we really need it?
552 if (GetGraph()->IsDebuggable()) {
553 return;
554 }
555
556 // We have to ensure that there are no deopt points in the sequence.
557 if (left->HasAnyEnvironmentUseBefore(condition)) {
558 return;
559 }
560 }
561
562 // Clean up any environment uses from the HCompare, if any.
563 left->RemoveEnvironmentUsers();
564
565 // We have decided to fold the HCompare into the HCondition. Transfer the information.
566 condition->SetBias(left->AsCompare()->GetBias());
567
568 // Replace the operands of the HCondition.
569 condition->ReplaceInput(left->InputAt(0), 0);
570 condition->ReplaceInput(left->InputAt(1), 1);
571
572 // Remove the HCompare.
573 left->GetBlock()->RemoveInstruction(left);
574
575 RecordSimplification();
576}
577
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000578void InstructionSimplifierVisitor::VisitDiv(HDiv* instruction) {
579 HConstant* input_cst = instruction->GetConstantRight();
580 HInstruction* input_other = instruction->GetLeastConstantLeft();
581 Primitive::Type type = instruction->GetType();
582
583 if ((input_cst != nullptr) && input_cst->IsOne()) {
584 // Replace code looking like
585 // DIV dst, src, 1
586 // with
587 // src
588 instruction->ReplaceWith(input_other);
589 instruction->GetBlock()->RemoveInstruction(instruction);
590 return;
591 }
592
Nicolas Geoffray0d221842015-04-27 08:53:46 +0000593 if ((input_cst != nullptr) && input_cst->IsMinusOne()) {
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000594 // Replace code looking like
595 // DIV dst, src, -1
596 // with
597 // NEG dst, src
598 instruction->GetBlock()->ReplaceAndRemoveInstructionWith(
Nicolas Geoffray0d221842015-04-27 08:53:46 +0000599 instruction, new (GetGraph()->GetArena()) HNeg(type, input_other));
Alexandre Rames188d4312015-04-09 18:30:21 +0100600 RecordSimplification();
Nicolas Geoffray0d221842015-04-27 08:53:46 +0000601 return;
602 }
603
604 if ((input_cst != nullptr) && Primitive::IsFloatingPointType(type)) {
605 // Try replacing code looking like
606 // DIV dst, src, constant
607 // with
608 // MUL dst, src, 1 / constant
609 HConstant* reciprocal = nullptr;
610 if (type == Primitive::Primitive::kPrimDouble) {
611 double value = input_cst->AsDoubleConstant()->GetValue();
612 if (CanDivideByReciprocalMultiplyDouble(bit_cast<int64_t, double>(value))) {
613 reciprocal = GetGraph()->GetDoubleConstant(1.0 / value);
614 }
615 } else {
616 DCHECK_EQ(type, Primitive::kPrimFloat);
617 float value = input_cst->AsFloatConstant()->GetValue();
618 if (CanDivideByReciprocalMultiplyFloat(bit_cast<int32_t, float>(value))) {
619 reciprocal = GetGraph()->GetFloatConstant(1.0f / value);
620 }
621 }
622
623 if (reciprocal != nullptr) {
624 instruction->GetBlock()->ReplaceAndRemoveInstructionWith(
625 instruction, new (GetGraph()->GetArena()) HMul(type, input_other, reciprocal));
626 RecordSimplification();
627 return;
628 }
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000629 }
630}
631
632void InstructionSimplifierVisitor::VisitMul(HMul* instruction) {
633 HConstant* input_cst = instruction->GetConstantRight();
634 HInstruction* input_other = instruction->GetLeastConstantLeft();
635 Primitive::Type type = instruction->GetType();
636 HBasicBlock* block = instruction->GetBlock();
637 ArenaAllocator* allocator = GetGraph()->GetArena();
638
639 if (input_cst == nullptr) {
640 return;
641 }
642
643 if (input_cst->IsOne()) {
644 // Replace code looking like
645 // MUL dst, src, 1
646 // with
647 // src
648 instruction->ReplaceWith(input_other);
649 instruction->GetBlock()->RemoveInstruction(instruction);
650 return;
651 }
652
653 if (input_cst->IsMinusOne() &&
654 (Primitive::IsFloatingPointType(type) || Primitive::IsIntOrLongType(type))) {
655 // Replace code looking like
656 // MUL dst, src, -1
657 // with
658 // NEG dst, src
659 HNeg* neg = new (allocator) HNeg(type, input_other);
660 block->ReplaceAndRemoveInstructionWith(instruction, neg);
Alexandre Rames188d4312015-04-09 18:30:21 +0100661 RecordSimplification();
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000662 return;
663 }
664
665 if (Primitive::IsFloatingPointType(type) &&
666 ((input_cst->IsFloatConstant() && input_cst->AsFloatConstant()->GetValue() == 2.0f) ||
667 (input_cst->IsDoubleConstant() && input_cst->AsDoubleConstant()->GetValue() == 2.0))) {
668 // Replace code looking like
669 // FP_MUL dst, src, 2.0
670 // with
671 // FP_ADD dst, src, src
672 // The 'int' and 'long' cases are handled below.
673 block->ReplaceAndRemoveInstructionWith(instruction,
674 new (allocator) HAdd(type, input_other, input_other));
Alexandre Rames188d4312015-04-09 18:30:21 +0100675 RecordSimplification();
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000676 return;
677 }
678
679 if (Primitive::IsIntOrLongType(type)) {
680 int64_t factor = Int64FromConstant(input_cst);
Serguei Katkov53849192015-04-20 14:22:27 +0600681 // Even though constant propagation also takes care of the zero case, other
682 // optimizations can lead to having a zero multiplication.
683 if (factor == 0) {
684 // Replace code looking like
685 // MUL dst, src, 0
686 // with
687 // 0
688 instruction->ReplaceWith(input_cst);
689 instruction->GetBlock()->RemoveInstruction(instruction);
690 } else if (IsPowerOfTwo(factor)) {
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000691 // Replace code looking like
692 // MUL dst, src, pow_of_2
693 // with
694 // SHL dst, src, log2(pow_of_2)
David Brazdil8d5b8b22015-03-24 10:51:52 +0000695 HIntConstant* shift = GetGraph()->GetIntConstant(WhichPowerOf2(factor));
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000696 HShl* shl = new(allocator) HShl(type, input_other, shift);
697 block->ReplaceAndRemoveInstructionWith(instruction, shl);
Alexandre Rames188d4312015-04-09 18:30:21 +0100698 RecordSimplification();
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000699 }
700 }
701}
702
Alexandre Rames188d4312015-04-09 18:30:21 +0100703void InstructionSimplifierVisitor::VisitNeg(HNeg* instruction) {
704 HInstruction* input = instruction->GetInput();
705 if (input->IsNeg()) {
706 // Replace code looking like
707 // NEG tmp, src
708 // NEG dst, tmp
709 // with
710 // src
711 HNeg* previous_neg = input->AsNeg();
712 instruction->ReplaceWith(previous_neg->GetInput());
713 instruction->GetBlock()->RemoveInstruction(instruction);
714 // We perform the optimization even if the input negation has environment
715 // uses since it allows removing the current instruction. But we only delete
716 // the input negation only if it is does not have any uses left.
717 if (!previous_neg->HasUses()) {
718 previous_neg->GetBlock()->RemoveInstruction(previous_neg);
719 }
720 RecordSimplification();
721 return;
722 }
723
Serguei Katkov339dfc22015-04-20 12:29:32 +0600724 if (input->IsSub() && input->HasOnlyOneNonEnvironmentUse() &&
725 !Primitive::IsFloatingPointType(input->GetType())) {
Alexandre Rames188d4312015-04-09 18:30:21 +0100726 // Replace code looking like
727 // SUB tmp, a, b
728 // NEG dst, tmp
729 // with
730 // SUB dst, b, a
731 // We do not perform the optimization if the input subtraction has
732 // environment uses or multiple non-environment uses as it could lead to
733 // worse code. In particular, we do not want the live ranges of `a` and `b`
734 // to be extended if we are not sure the initial 'SUB' instruction can be
735 // removed.
Serguei Katkov339dfc22015-04-20 12:29:32 +0600736 // We do not perform optimization for fp because we could lose the sign of zero.
Alexandre Rames188d4312015-04-09 18:30:21 +0100737 HSub* sub = input->AsSub();
738 HSub* new_sub =
739 new (GetGraph()->GetArena()) HSub(instruction->GetType(), sub->GetRight(), sub->GetLeft());
740 instruction->GetBlock()->ReplaceAndRemoveInstructionWith(instruction, new_sub);
741 if (!sub->HasUses()) {
742 sub->GetBlock()->RemoveInstruction(sub);
743 }
744 RecordSimplification();
745 }
746}
747
748void InstructionSimplifierVisitor::VisitNot(HNot* instruction) {
749 HInstruction* input = instruction->GetInput();
750 if (input->IsNot()) {
751 // Replace code looking like
752 // NOT tmp, src
753 // NOT dst, tmp
754 // with
755 // src
756 // We perform the optimization even if the input negation has environment
757 // uses since it allows removing the current instruction. But we only delete
758 // the input negation only if it is does not have any uses left.
759 HNot* previous_not = input->AsNot();
760 instruction->ReplaceWith(previous_not->GetInput());
761 instruction->GetBlock()->RemoveInstruction(instruction);
762 if (!previous_not->HasUses()) {
763 previous_not->GetBlock()->RemoveInstruction(previous_not);
764 }
765 RecordSimplification();
766 }
767}
768
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000769void InstructionSimplifierVisitor::VisitOr(HOr* instruction) {
770 HConstant* input_cst = instruction->GetConstantRight();
771 HInstruction* input_other = instruction->GetLeastConstantLeft();
772
773 if ((input_cst != nullptr) && input_cst->IsZero()) {
774 // Replace code looking like
775 // OR dst, src, 0
776 // with
777 // src
778 instruction->ReplaceWith(input_other);
779 instruction->GetBlock()->RemoveInstruction(instruction);
780 return;
781 }
782
783 // We assume that GVN has run before, so we only perform a pointer comparison.
784 // If for some reason the values are equal but the pointers are different, we
Alexandre Rames188d4312015-04-09 18:30:21 +0100785 // are still correct and only miss an optimization opportunity.
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000786 if (instruction->GetLeft() == instruction->GetRight()) {
787 // Replace code looking like
788 // OR dst, src, src
789 // with
790 // src
791 instruction->ReplaceWith(instruction->GetLeft());
792 instruction->GetBlock()->RemoveInstruction(instruction);
793 }
794}
795
796void InstructionSimplifierVisitor::VisitShl(HShl* instruction) {
797 VisitShift(instruction);
798}
799
800void InstructionSimplifierVisitor::VisitShr(HShr* instruction) {
801 VisitShift(instruction);
802}
803
804void InstructionSimplifierVisitor::VisitSub(HSub* instruction) {
805 HConstant* input_cst = instruction->GetConstantRight();
806 HInstruction* input_other = instruction->GetLeastConstantLeft();
807
Serguei Katkov115b53f2015-08-05 17:03:30 +0600808 Primitive::Type type = instruction->GetType();
809 if (Primitive::IsFloatingPointType(type)) {
810 return;
811 }
812
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000813 if ((input_cst != nullptr) && input_cst->IsZero()) {
814 // Replace code looking like
815 // SUB dst, src, 0
816 // with
817 // src
Serguei Katkov115b53f2015-08-05 17:03:30 +0600818 // Note that we cannot optimize `x - 0.0` to `x` for floating-point. When
819 // `x` is `-0.0`, the former expression yields `0.0`, while the later
820 // yields `-0.0`.
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000821 instruction->ReplaceWith(input_other);
822 instruction->GetBlock()->RemoveInstruction(instruction);
823 return;
824 }
825
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000826 HBasicBlock* block = instruction->GetBlock();
827 ArenaAllocator* allocator = GetGraph()->GetArena();
828
Alexandre Rames188d4312015-04-09 18:30:21 +0100829 HInstruction* left = instruction->GetLeft();
830 HInstruction* right = instruction->GetRight();
831 if (left->IsConstant()) {
832 if (Int64FromConstant(left->AsConstant()) == 0) {
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000833 // Replace code looking like
834 // SUB dst, 0, src
835 // with
836 // NEG dst, src
Alexandre Rames188d4312015-04-09 18:30:21 +0100837 // Note that we cannot optimize `0.0 - x` to `-x` for floating-point. When
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000838 // `x` is `0.0`, the former expression yields `0.0`, while the later
839 // yields `-0.0`.
Alexandre Rames188d4312015-04-09 18:30:21 +0100840 HNeg* neg = new (allocator) HNeg(type, right);
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000841 block->ReplaceAndRemoveInstructionWith(instruction, neg);
Alexandre Rames188d4312015-04-09 18:30:21 +0100842 RecordSimplification();
843 return;
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000844 }
845 }
Alexandre Rames188d4312015-04-09 18:30:21 +0100846
847 if (left->IsNeg() && right->IsNeg()) {
848 if (TryMoveNegOnInputsAfterBinop(instruction)) {
849 return;
850 }
851 }
852
853 if (right->IsNeg() && right->HasOnlyOneNonEnvironmentUse()) {
854 // Replace code looking like
855 // NEG tmp, b
856 // SUB dst, a, tmp
857 // with
858 // ADD dst, a, b
859 HAdd* add = new(GetGraph()->GetArena()) HAdd(type, left, right->AsNeg()->GetInput());
860 instruction->GetBlock()->ReplaceAndRemoveInstructionWith(instruction, add);
861 RecordSimplification();
862 right->GetBlock()->RemoveInstruction(right);
863 return;
864 }
865
866 if (left->IsNeg() && left->HasOnlyOneNonEnvironmentUse()) {
867 // Replace code looking like
868 // NEG tmp, a
869 // SUB dst, tmp, b
870 // with
871 // ADD tmp, a, b
872 // NEG dst, tmp
873 // The second version is not intrinsically better, but enables more
874 // transformations.
875 HAdd* add = new(GetGraph()->GetArena()) HAdd(type, left->AsNeg()->GetInput(), right);
876 instruction->GetBlock()->InsertInstructionBefore(add, instruction);
877 HNeg* neg = new (GetGraph()->GetArena()) HNeg(instruction->GetType(), add);
878 instruction->GetBlock()->InsertInstructionBefore(neg, instruction);
879 instruction->ReplaceWith(neg);
880 instruction->GetBlock()->RemoveInstruction(instruction);
881 RecordSimplification();
882 left->GetBlock()->RemoveInstruction(left);
883 }
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000884}
885
886void InstructionSimplifierVisitor::VisitUShr(HUShr* instruction) {
887 VisitShift(instruction);
888}
889
890void InstructionSimplifierVisitor::VisitXor(HXor* instruction) {
891 HConstant* input_cst = instruction->GetConstantRight();
892 HInstruction* input_other = instruction->GetLeastConstantLeft();
893
894 if ((input_cst != nullptr) && input_cst->IsZero()) {
895 // Replace code looking like
896 // XOR dst, src, 0
897 // with
898 // src
899 instruction->ReplaceWith(input_other);
900 instruction->GetBlock()->RemoveInstruction(instruction);
901 return;
902 }
903
904 if ((input_cst != nullptr) && AreAllBitsSet(input_cst)) {
905 // Replace code looking like
906 // XOR dst, src, 0xFFF...FF
907 // with
908 // NOT dst, src
909 HNot* bitwise_not = new (GetGraph()->GetArena()) HNot(instruction->GetType(), input_other);
910 instruction->GetBlock()->ReplaceAndRemoveInstructionWith(instruction, bitwise_not);
Alexandre Rames188d4312015-04-09 18:30:21 +0100911 RecordSimplification();
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000912 return;
913 }
914}
915
Nicolas Geoffray2e7cd752015-07-10 11:38:52 +0100916void InstructionSimplifierVisitor::VisitFakeString(HFakeString* instruction) {
917 HInstruction* actual_string = nullptr;
918
919 // Find the string we need to replace this instruction with. The actual string is
920 // the return value of a StringFactory call.
921 for (HUseIterator<HInstruction*> it(instruction->GetUses()); !it.Done(); it.Advance()) {
922 HInstruction* use = it.Current()->GetUser();
923 if (use->IsInvokeStaticOrDirect()
924 && use->AsInvokeStaticOrDirect()->IsStringFactoryFor(instruction)) {
925 use->AsInvokeStaticOrDirect()->RemoveFakeStringArgumentAsLastInput();
926 actual_string = use;
927 break;
928 }
929 }
930
931 // Check that there is no other instruction that thinks it is the factory for that string.
932 if (kIsDebugBuild) {
933 CHECK(actual_string != nullptr);
934 for (HUseIterator<HInstruction*> it(instruction->GetUses()); !it.Done(); it.Advance()) {
935 HInstruction* use = it.Current()->GetUser();
936 if (use->IsInvokeStaticOrDirect()) {
937 CHECK(!use->AsInvokeStaticOrDirect()->IsStringFactoryFor(instruction));
938 }
939 }
940 }
941
942 // We need to remove any environment uses of the fake string that are not dominated by
943 // `actual_string` to null.
944 for (HUseIterator<HEnvironment*> it(instruction->GetEnvUses()); !it.Done(); it.Advance()) {
945 HEnvironment* environment = it.Current()->GetUser();
946 if (!actual_string->StrictlyDominates(environment->GetHolder())) {
947 environment->RemoveAsUserOfInput(it.Current()->GetIndex());
948 environment->SetRawEnvAt(it.Current()->GetIndex(), nullptr);
949 }
950 }
951
952 // Only uses dominated by `actual_string` must remain. We can safely replace and remove
953 // `instruction`.
954 instruction->ReplaceWith(actual_string);
955 instruction->GetBlock()->RemoveInstruction(instruction);
956}
957
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100958} // namespace art