From 556c3d193134f6461f3e1fe17c032b087c5931a0 Mon Sep 17 00:00:00 2001 From: Roland Levillain Date: Thu, 18 Sep 2014 15:25:07 +0100 Subject: 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 --- compiler/optimizing/nodes.cc | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'compiler/optimizing/nodes.cc') 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()) { -- cgit v1.2.3-59-g8ed1b