summaryrefslogtreecommitdiff
path: root/compiler/optimizing/constant_folding.cc
diff options
context:
space:
mode:
author Santiago Aboy Solanes <solanes@google.com> 2023-04-18 15:16:06 +0100
committer Santiago Aboy Solanes <solanes@google.com> 2023-04-19 15:31:53 +0000
commit5eb1fd0dae3832ceee2102613bb08c291daca6f3 (patch)
treeda074eb8ea773b594a455fa9cd7ddde21d8f885b /compiler/optimizing/constant_folding.cc
parent2ff7fcccdeb2100cb5a3cc5314411fd23dd5f7c9 (diff)
Restrict the use of ConstantFolding's VisitIf
It was taking a lot of time for the improvement it got. We can get 99.99% of the improvement, with only one VisitIf call. This is roughly 20% of the compile time it used to take. Bug: 278626992 Fixes: 278626992 Test: art/test/testrunner/testrunner.py --host --64 --optimizing -b Change-Id: Icc00c9ad6a9eb4f4fd18677bcb65655cbbe9d027
Diffstat (limited to 'compiler/optimizing/constant_folding.cc')
-rw-r--r--compiler/optimizing/constant_folding.cc20
1 files changed, 17 insertions, 3 deletions
diff --git a/compiler/optimizing/constant_folding.cc b/compiler/optimizing/constant_folding.cc
index b8ffe9efdd..06d19e3f29 100644
--- a/compiler/optimizing/constant_folding.cc
+++ b/compiler/optimizing/constant_folding.cc
@@ -28,8 +28,8 @@ namespace art HIDDEN {
// as constants.
class HConstantFoldingVisitor final : public HGraphDelegateVisitor {
public:
- explicit HConstantFoldingVisitor(HGraph* graph, OptimizingCompilerStats* stats)
- : HGraphDelegateVisitor(graph, stats) {}
+ HConstantFoldingVisitor(HGraph* graph, OptimizingCompilerStats* stats, bool use_all_optimizations)
+ : HGraphDelegateVisitor(graph, stats), use_all_optimizations_(use_all_optimizations) {}
private:
void VisitBasicBlock(HBasicBlock* block) override;
@@ -44,6 +44,9 @@ class HConstantFoldingVisitor final : public HGraphDelegateVisitor {
void PropagateValue(HBasicBlock* starting_block, HInstruction* variable, HConstant* constant);
+ // Use all optimizations without restrictions.
+ bool use_all_optimizations_;
+
DISALLOW_COPY_AND_ASSIGN(HConstantFoldingVisitor);
};
@@ -84,7 +87,7 @@ class InstructionWithAbsorbingInputSimplifier : public HGraphVisitor {
bool HConstantFolding::Run() {
- HConstantFoldingVisitor visitor(graph_, stats_);
+ HConstantFoldingVisitor visitor(graph_, stats_, use_all_optimizations_);
// Process basic blocks in reverse post-order in the dominator tree,
// so that an instruction turned into a constant, used as input of
// another instruction, may possibly be used to turn that second
@@ -145,6 +148,11 @@ void HConstantFoldingVisitor::PropagateValue(HBasicBlock* starting_block,
uses_before = variable->GetUses().SizeSlow();
}
+ if (variable->GetUses().HasExactlyOneElement()) {
+ // Nothing to do, since we only have the `if (variable)` use or the `condition` use.
+ return;
+ }
+
variable->ReplaceUsesDominatedBy(
starting_block->GetFirstInstruction(), constant, /* strictly_dominated= */ false);
@@ -157,6 +165,12 @@ void HConstantFoldingVisitor::PropagateValue(HBasicBlock* starting_block,
}
void HConstantFoldingVisitor::VisitIf(HIf* inst) {
+ // This optimization can take a lot of compile time since we have a lot of If instructions in
+ // graphs.
+ if (!use_all_optimizations_) {
+ return;
+ }
+
// Consistency check: the true and false successors do not dominate each other.
DCHECK(!inst->IfTrueSuccessor()->Dominates(inst->IfFalseSuccessor()) &&
!inst->IfFalseSuccessor()->Dominates(inst->IfTrueSuccessor()));