From 9e23df5c21bed53ead79e3131b67105abc8871e4 Mon Sep 17 00:00:00 2001 From: Vladimir Marko Date: Tue, 10 Nov 2015 17:14:35 +0000 Subject: Optimizing: Improve constant folding + DCE for inlining. Run constant folding before DCE in inliner to eliminate more code that can prevent inlining. Improve the constant folding to evaluate Equals and NotEquals for null inputs. Change-Id: I876ffb903ef39484370b6c8793f0f8467a977362 --- compiler/optimizing/inliner.cc | 2 +- compiler/optimizing/nodes.cc | 2 ++ compiler/optimizing/nodes.h | 13 +++++++++++++ 3 files changed, 16 insertions(+), 1 deletion(-) (limited to 'compiler/optimizing') diff --git a/compiler/optimizing/inliner.cc b/compiler/optimizing/inliner.cc index 353881e47a..c9319f5d07 100644 --- a/compiler/optimizing/inliner.cc +++ b/compiler/optimizing/inliner.cc @@ -406,8 +406,8 @@ bool HInliner::TryBuildAndInline(ArtMethod* resolved_method, &type_propagation, &sharpening, &simplify, - &dce, &fold, + &dce, }; for (size_t i = 0; i < arraysize(optimizations); ++i) { diff --git a/compiler/optimizing/nodes.cc b/compiler/optimizing/nodes.cc index f006df1852..1a4685309d 100644 --- a/compiler/optimizing/nodes.cc +++ b/compiler/optimizing/nodes.cc @@ -1090,6 +1090,8 @@ HConstant* HBinaryOperation::TryStaticEvaluation() const { } else if (GetRight()->IsLongConstant()) { return Evaluate(GetLeft()->AsLongConstant(), GetRight()->AsLongConstant()); } + } else if (GetLeft()->IsNullConstant() && GetRight()->IsNullConstant()) { + return Evaluate(GetLeft()->AsNullConstant(), GetRight()->AsNullConstant()); } return nullptr; } diff --git a/compiler/optimizing/nodes.h b/compiler/optimizing/nodes.h index 4421419f10..ba140afc6b 100644 --- a/compiler/optimizing/nodes.h +++ b/compiler/optimizing/nodes.h @@ -2612,6 +2612,11 @@ class HBinaryOperation : public HExpression<2> { VLOG(compiler) << DebugName() << " is not defined for the (long, int) case."; return nullptr; } + virtual HConstant* Evaluate(HNullConstant* x ATTRIBUTE_UNUSED, + HNullConstant* y ATTRIBUTE_UNUSED) const { + VLOG(compiler) << DebugName() << " is not defined for the (null, null) case."; + return nullptr; + } // Returns an input that can legally be used as the right input and is // constant, or null. @@ -2702,6 +2707,10 @@ class HEqual : public HCondition { return GetBlock()->GetGraph()->GetIntConstant( Compute(x->GetValue(), y->GetValue()), GetDexPc()); } + HConstant* Evaluate(HNullConstant* x ATTRIBUTE_UNUSED, + HNullConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { + return GetBlock()->GetGraph()->GetConstant(GetType(), 1); + } DECLARE_INSTRUCTION(Equal); @@ -2734,6 +2743,10 @@ class HNotEqual : public HCondition { return GetBlock()->GetGraph()->GetIntConstant( Compute(x->GetValue(), y->GetValue()), GetDexPc()); } + HConstant* Evaluate(HNullConstant* x ATTRIBUTE_UNUSED, + HNullConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { + return GetBlock()->GetGraph()->GetConstant(GetType(), 0); + } DECLARE_INSTRUCTION(NotEqual); -- cgit v1.2.3-59-g8ed1b