diff options
author | 2025-02-12 13:59:45 +0000 | |
---|---|---|
committer | 2025-02-14 06:11:40 -0800 | |
commit | 115169004430011a3328345769e0b014508208fe (patch) | |
tree | 3405d95e77121a3b34a201b95ac0eb6f1c622502 | |
parent | 1a3ce3502dd8b72ab51bddfee0ac894a2d987f4e (diff) |
Optimize HConstantFoldingVisitor::PropagateValue
We can avoid creating constants which were created with
GetGraph()->GetIntConstant. In theory, we could still be creating
a constant that ReplaceUsesDominatedBy doesn't use. In practice,
we can eliminate most (95%+) of constants being created without
impacting or refactoring ReplaceUsesDominatedBy.
Bug: 240543764
Bug: 393108375
Test: art/test/testrunner/testrunner.py --host --64 -b --optimizing
Change-Id: I91f93c373b9097d5598398cc92767ecde5d4aec7
-rw-r--r-- | compiler/optimizing/constant_folding.cc | 25 |
1 files changed, 13 insertions, 12 deletions
diff --git a/compiler/optimizing/constant_folding.cc b/compiler/optimizing/constant_folding.cc index 0ec60b5ead..66fb04e11a 100644 --- a/compiler/optimizing/constant_folding.cc +++ b/compiler/optimizing/constant_folding.cc @@ -54,7 +54,9 @@ class HConstantFoldingVisitor final : public HGraphDelegateVisitor { void VisitInvoke(HInvoke* inst) override; void VisitTypeConversion(HTypeConversion* inst) override; - void PropagateValue(HBasicBlock* starting_block, HInstruction* variable, HConstant* constant); + void PropagateValue(HBasicBlock* starting_block, + HInstruction* variable, + std::variant<HConstant*, bool> constant); // Intrinsics foldings void FoldReverseIntrinsic(HInvoke* invoke); @@ -218,7 +220,7 @@ void HConstantFoldingVisitor::VisitDivZeroCheck(HDivZeroCheck* inst) { void HConstantFoldingVisitor::PropagateValue(HBasicBlock* starting_block, HInstruction* variable, - HConstant* constant) { + std::variant<HConstant*, bool> constant) { const bool recording_stats = stats_ != nullptr; size_t uses_before = 0; size_t uses_after = 0; @@ -227,8 +229,12 @@ void HConstantFoldingVisitor::PropagateValue(HBasicBlock* starting_block, } if (!variable->GetUses().HasExactlyOneElement()) { - variable->ReplaceUsesDominatedBy( - starting_block->GetFirstInstruction(), constant, /* strictly_dominated= */ false); + HConstant* c = std::holds_alternative<HConstant*>(constant) + ? std::get<HConstant*>(constant) + : GetGraph()->GetIntConstant(std::get<bool>(constant) ? 1 : 0); + variable->ReplaceUsesDominatedBy(starting_block->GetFirstInstruction(), + c, + /* strictly_dominated= */ false); } if (recording_stats) { @@ -256,8 +262,8 @@ void HConstantFoldingVisitor::VisitIf(HIf* inst) { // } else { // and here false // } - PropagateValue(inst->IfTrueSuccessor(), if_input, GetGraph()->GetIntConstant(1)); - PropagateValue(inst->IfFalseSuccessor(), if_input, GetGraph()->GetIntConstant(0)); + PropagateValue(inst->IfTrueSuccessor(), if_input, true); + PropagateValue(inst->IfFalseSuccessor(), if_input, false); // If the input is a condition, we can propagate the information of the condition itself. if (!if_input->IsCondition()) { @@ -341,12 +347,7 @@ void HConstantFoldingVisitor::VisitIf(HIf* inst) { HBasicBlock* other_starting_block = condition->IsEqual() ? inst->IfFalseSuccessor() : inst->IfTrueSuccessor(); DCHECK_NE(other_starting_block, starting_block); - - HConstant* other_constant = constant->AsIntConstant()->IsTrue() ? - GetGraph()->GetIntConstant(0) : - GetGraph()->GetIntConstant(1); - DCHECK_NE(other_constant, constant); - PropagateValue(other_starting_block, variable, other_constant); + PropagateValue(other_starting_block, variable, !constant->AsIntConstant()->IsTrue()); } } |