diff options
author | 2015-02-25 11:28:05 -0800 | |
---|---|---|
committer | 2015-03-03 13:24:03 -0800 | |
commit | dc5ac731f6369b53b42f1cee3404f3b3384cec34 (patch) | |
tree | 72a90f1da01185014551628078b98a79e5d5230e /compiler/optimizing/gvn.cc | |
parent | 0e5e728a4a4f042f157e1897cc8bbc2b0bb110b1 (diff) |
Opt compiler: enhance gvn for commutative ops.
Change-Id: I415b50d58b30cab4ec38077be22373eb9598ec40
Diffstat (limited to 'compiler/optimizing/gvn.cc')
-rw-r--r-- | compiler/optimizing/gvn.cc | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/compiler/optimizing/gvn.cc b/compiler/optimizing/gvn.cc index cb448c883f..ea65dc0780 100644 --- a/compiler/optimizing/gvn.cc +++ b/compiler/optimizing/gvn.cc @@ -299,8 +299,17 @@ void GlobalValueNumberer::VisitBasicBlock(HBasicBlock* block) { // Save the next instruction in case `current` is removed from the graph. HInstruction* next = current->GetNext(); if (current->CanBeMoved()) { + if (current->IsBinaryOperation() && current->AsBinaryOperation()->IsCommutative()) { + // For commutative ops, (x op y) will be treated the same as (y op x) + // after fixed ordering. + current->AsBinaryOperation()->OrderInputs(); + } HInstruction* existing = set->Lookup(current); if (existing != nullptr) { + // This replacement doesn't make more OrderInputs() necessary since + // current is either used by an instruction that it dominates, + // which hasn't been visited yet due to the order we visit instructions. + // Or current is used by a phi, and we don't do OrderInputs() on a phi anyway. current->ReplaceWith(existing); current->GetBlock()->RemoveInstruction(current); } else { |