From a7c461a767fd6cc3babc41179e0e945e6044ffd1 Mon Sep 17 00:00:00 2001 From: Santiago Aboy Solanes Date: Tue, 30 Jan 2024 14:46:54 +0000 Subject: Speed up HConstantFoldingVisitor::PropagateValue We can speed it up in two ways: 1) Don't call it if it has exactly one element, as we will never be able to replace its use in the if clause 2) Lazily compute the dominated blocks when needed Compiling locally GMS, HConstantFoldingVisitor::VisitIf goes down from 1.8% of the compile time to 0.7%. Most of this improvement (90%+) is coming from the `1)` optimization. This is because there are many cases where we have only one use (the if), which is in the same block so we compute the domination to always end up not doing the optimization. Bug: 278626992 Test: Locally compile gms Test: art/test/testrunner/testrunner.py --host --64 --optimizing -b Change-Id: Ic17b4b44840c7efa0224504031bf635584850ced --- compiler/optimizing/constant_folding.cc | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'compiler/optimizing/constant_folding.cc') diff --git a/compiler/optimizing/constant_folding.cc b/compiler/optimizing/constant_folding.cc index 64ef17898a..b0a65ca64d 100644 --- a/compiler/optimizing/constant_folding.cc +++ b/compiler/optimizing/constant_folding.cc @@ -229,8 +229,10 @@ void HConstantFoldingVisitor::PropagateValue(HBasicBlock* starting_block, uses_before = variable->GetUses().SizeSlow(); } - variable->ReplaceUsesDominatedBy( - starting_block->GetFirstInstruction(), constant, /* strictly_dominated= */ false); + if (!variable->GetUses().HasExactlyOneElement()) { + variable->ReplaceUsesDominatedBy( + starting_block->GetFirstInstruction(), constant, /* strictly_dominated= */ false); + } if (recording_stats) { uses_after = variable->GetUses().SizeSlow(); -- cgit v1.2.3-59-g8ed1b