diff options
author | 2014-09-18 15:25:07 +0100 | |
---|---|---|
committer | 2014-09-18 15:25:07 +0100 | |
commit | 556c3d193134f6461f3e1fe17c032b087c5931a0 (patch) | |
tree | 436660c7155d0864c37f8aeabbc0f52e889a0cc2 /compiler/optimizing/nodes.cc | |
parent | 6aa606c9284ac31961f4c5b20c3645ac78acfaad (diff) |
Initiate a constant propagation pass in the optimizing compiler.
- Perform constant folding on int and long additions and subtractions in
the optimizing compiler.
- Apply constant folding to conditions and comparisons.
Change-Id: Ic88783a3c975fda777c74c531e257fa777be42eb
Diffstat (limited to 'compiler/optimizing/nodes.cc')
-rw-r--r-- | compiler/optimizing/nodes.cc | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/compiler/optimizing/nodes.cc b/compiler/optimizing/nodes.cc index 7b5a78eb39..82827952ba 100644 --- a/compiler/optimizing/nodes.cc +++ b/compiler/optimizing/nodes.cc @@ -505,6 +505,18 @@ void HGraphVisitor::VisitBasicBlock(HBasicBlock* block) { } } +HConstant* HBinaryOperation::TryStaticEvaluation(ArenaAllocator* allocator) const { + if (GetLeft()->IsIntConstant() && GetRight()->IsIntConstant()) { + int32_t value = Evaluate(GetLeft()->AsIntConstant()->GetValue(), + GetRight()->AsIntConstant()->GetValue()); + return new(allocator) HIntConstant(value); + } else if (GetLeft()->IsLongConstant() && GetRight()->IsLongConstant()) { + int64_t value = Evaluate(GetLeft()->AsLongConstant()->GetValue(), + GetRight()->AsLongConstant()->GetValue()); + return new(allocator) HLongConstant(value); + } + return nullptr; +} bool HCondition::NeedsMaterialization() const { if (!HasOnlyOneUse()) { |