Fix a bug in optimizing when the null constant has been DCE.
If it has been DCE, we should create a new one, instead of
using the old one.
Also move the first DCE to a place where it could actually
be useful.
bug:21870788
Change-Id: I28fc52ae481ef92cba45fc1b5abcf07c995f524c
diff --git a/compiler/optimizing/nodes.cc b/compiler/optimizing/nodes.cc
index 4baa05c..830d84b 100644
--- a/compiler/optimizing/nodes.cc
+++ b/compiler/optimizing/nodes.cc
@@ -288,7 +288,10 @@
}
HNullConstant* HGraph::GetNullConstant() {
- if (cached_null_constant_ == nullptr) {
+ // For simplicity, don't bother reviving the cached null constant if it is
+ // not null and not in a block. Otherwise, we need to clear the instruction
+ // id and/or any invariants the graph is assuming when adding new instructions.
+ if ((cached_null_constant_ == nullptr) || (cached_null_constant_->GetBlock() == nullptr)) {
cached_null_constant_ = new (arena_) HNullConstant();
InsertConstant(cached_null_constant_);
}
diff --git a/compiler/optimizing/optimizing_compiler.cc b/compiler/optimizing/optimizing_compiler.cc
index 303a7cb..c695abe 100644
--- a/compiler/optimizing/optimizing_compiler.cc
+++ b/compiler/optimizing/optimizing_compiler.cc
@@ -348,10 +348,10 @@
HOptimization* optimizations[] = {
intrinsics,
- dce1,
fold1,
simplify1,
type_propagation,
+ dce1,
simplify2,
inliner,
// Run another type propagation phase: inlining will open up more opprotunities