From b2fd7bca70b580921eebf7c45769c39d2dfd8a5a Mon Sep 17 00:00:00 2001 From: Alexandre Rames Date: Wed, 11 Mar 2015 16:48:16 +0000 Subject: Opt compiler: Basic simplification for arithmetic operations. The optimisations in this patch do not look further than the inputs of each operation. Change-Id: Iddd0ab6b360b9e7bb042db22086d51a31be85530 --- compiler/optimizing/nodes.cc | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'compiler/optimizing/nodes.cc') diff --git a/compiler/optimizing/nodes.cc b/compiler/optimizing/nodes.cc index e51bbc330a..adcadf5a51 100644 --- a/compiler/optimizing/nodes.cc +++ b/compiler/optimizing/nodes.cc @@ -673,10 +673,43 @@ HConstant* HBinaryOperation::TryStaticEvaluation() const { return nullptr; } +HConstant* HBinaryOperation::GetConstantRight() const { + if (GetRight()->IsConstant()) { + return GetRight()->AsConstant(); + } else if (IsCommutative() && GetLeft()->IsConstant()) { + return GetLeft()->AsConstant(); + } else { + return nullptr; + } +} + +// If `GetConstantRight()` returns one of the input, this returns the other +// one. Otherwise it returns nullptr. +HInstruction* HBinaryOperation::GetLeastConstantLeft() const { + HInstruction* most_constant_right = GetConstantRight(); + if (most_constant_right == nullptr) { + return nullptr; + } else if (most_constant_right == GetLeft()) { + return GetRight(); + } else { + return GetLeft(); + } +} + bool HCondition::IsBeforeWhenDisregardMoves(HIf* if_) const { return this == if_->GetPreviousDisregardingMoves(); } +HConstant* HConstant::NewConstant(ArenaAllocator* allocator, Primitive::Type type, int64_t val) { + if (type == Primitive::kPrimInt) { + DCHECK(IsInt<32>(val)); + return new (allocator) HIntConstant(val); + } else { + DCHECK_EQ(type, Primitive::kPrimLong); + return new (allocator) HLongConstant(val); + } +} + bool HInstruction::Equals(HInstruction* other) const { if (!InstructionTypeEquals(other)) return false; DCHECK_EQ(GetKind(), other->GetKind()); -- cgit v1.2.3