summaryrefslogtreecommitdiff
path: root/compiler/optimizing/constant_folding.cc
diff options
context:
space:
mode:
author Roland Levillain <rpl@google.com> 2014-10-20 16:47:04 +0100
committer Roland Levillain <rpl@google.com> 2014-10-21 13:48:41 +0100
commit9240d6a2baa9ed1e18ee08744b461fe49a1ee269 (patch)
tree0adc27979a1c30defa16de4142b1d54fac6f93dc /compiler/optimizing/constant_folding.cc
parent88cb1755e1d6acaed0f66ce65d7a2a4465053342 (diff)
Constant folding on unary operations in the optimizing compiler.
Change-Id: I4b77afa2a89f5ad2eedd4d6c0c6c382585419349
Diffstat (limited to 'compiler/optimizing/constant_folding.cc')
-rw-r--r--compiler/optimizing/constant_folding.cc14
1 files changed, 11 insertions, 3 deletions
diff --git a/compiler/optimizing/constant_folding.cc b/compiler/optimizing/constant_folding.cc
index 0b3ad9809f..10a7e46299 100644
--- a/compiler/optimizing/constant_folding.cc
+++ b/compiler/optimizing/constant_folding.cc
@@ -31,11 +31,19 @@ void HConstantFolding::Run() {
for (HInstructionIterator it(block->GetInstructions());
!it.Done(); it.Advance()) {
HInstruction* inst = it.Current();
- // Constant folding: replace `c <- a op b' with a compile-time
- // evaluation of `a op b' if `a' and `b' are constant.
if (inst->IsBinaryOperation()) {
+ // Constant folding: replace `op(a, b)' with a constant at
+ // compile time if `a' and `b' are both constants.
HConstant* constant =
- inst->AsBinaryOperation()->TryStaticEvaluation(graph_->GetArena());
+ inst->AsBinaryOperation()->TryStaticEvaluation();
+ if (constant != nullptr) {
+ inst->GetBlock()->ReplaceAndRemoveInstructionWith(inst, constant);
+ }
+ } else if (inst->IsUnaryOperation()) {
+ // Constant folding: replace `op(a)' with a constant at compile
+ // time if `a' is a constant.
+ HConstant* constant =
+ inst->AsUnaryOperation()->TryStaticEvaluation();
if (constant != nullptr) {
inst->GetBlock()->ReplaceAndRemoveInstructionWith(inst, constant);
}