diff options
| author | 2015-08-05 17:03:30 +0600 | |
|---|---|---|
| committer | 2015-08-06 18:22:02 +0100 | |
| commit | 115b53f609e74672fa93eea1845bb17340d5112a (patch) | |
| tree | a791ed8bcd97c5a97c329e4dc708604e1defed4b /compiler/optimizing/instruction_simplifier.cc | |
| parent | 1339409345cc8b46d64570430ca3197408fda159 (diff) | |
ART: Fix the simplifier for add/sub
Instruction simplifier for add/sub should not proceed with floats
because that might cause the incorrect behavior with signed zero.
Change-Id: If0c9bf3931bcbf96b0814f8605a86997aea37145
Signed-off-by: Serguei Katkov <serguei.i.katkov@intel.com>
Diffstat (limited to 'compiler/optimizing/instruction_simplifier.cc')
| -rw-r--r-- | compiler/optimizing/instruction_simplifier.cc | 24 |
1 files changed, 16 insertions, 8 deletions
diff --git a/compiler/optimizing/instruction_simplifier.cc b/compiler/optimizing/instruction_simplifier.cc index d3911456fb..931a1c3cb7 100644 --- a/compiler/optimizing/instruction_simplifier.cc +++ b/compiler/optimizing/instruction_simplifier.cc @@ -438,9 +438,14 @@ void InstructionSimplifierVisitor::VisitAdd(HAdd* instruction) { // ADD dst, src, 0 // with // src - instruction->ReplaceWith(input_other); - instruction->GetBlock()->RemoveInstruction(instruction); - return; + // Note that we cannot optimize `x + 0.0` to `x` for floating-point. When + // `x` is `-0.0`, the former expression yields `0.0`, while the later + // yields `-0.0`. + if (Primitive::IsIntegralType(instruction->GetType())) { + instruction->ReplaceWith(input_other); + instruction->GetBlock()->RemoveInstruction(instruction); + return; + } } HInstruction* left = instruction->GetLeft(); @@ -800,21 +805,24 @@ void InstructionSimplifierVisitor::VisitSub(HSub* instruction) { HConstant* input_cst = instruction->GetConstantRight(); HInstruction* input_other = instruction->GetLeastConstantLeft(); + Primitive::Type type = instruction->GetType(); + if (Primitive::IsFloatingPointType(type)) { + return; + } + if ((input_cst != nullptr) && input_cst->IsZero()) { // Replace code looking like // SUB dst, src, 0 // with // src + // Note that we cannot optimize `x - 0.0` to `x` for floating-point. When + // `x` is `-0.0`, the former expression yields `0.0`, while the later + // yields `-0.0`. instruction->ReplaceWith(input_other); instruction->GetBlock()->RemoveInstruction(instruction); return; } - Primitive::Type type = instruction->GetType(); - if (!Primitive::IsIntegralType(type)) { - return; - } - HBasicBlock* block = instruction->GetBlock(); ArenaAllocator* allocator = GetGraph()->GetArena(); |