summaryrefslogtreecommitdiff
path: root/compiler/optimizing/nodes.cc
diff options
context:
space:
mode:
author Vladimir Marko <vmarko@google.com> 2024-08-13 10:59:26 +0000
committer Vladimir Marko <vmarko@google.com> 2024-08-14 13:46:06 +0000
commit3b6024d5db60c891c5ef6dc18cc17f8ece56c796 (patch)
treef3ec7d0d8543e28db82f9d9f1e3c58421b68458b /compiler/optimizing/nodes.cc
parent4910586af2f208262dd1f8225f42fa6f6e95d355 (diff)
Clean up condition simplification.
Leave condition construction in the `HGraph` but move the rest of the condition simplification code to the simplifier where it belongs. Also clean up simplifier tests and a few other gtests. Note that `SuperblockClonerTest.IndividualInstrCloner` now clones an additional `HGoto` from the entry block. Test: m test-art-host-gtest Test: testrunner.py --host --optimizing Change-Id: I73ee8c227c1c100ac7eb9d4a3813c61ad928b6dd
Diffstat (limited to 'compiler/optimizing/nodes.cc')
-rw-r--r--compiler/optimizing/nodes.cc56
1 files changed, 18 insertions, 38 deletions
diff --git a/compiler/optimizing/nodes.cc b/compiler/optimizing/nodes.cc
index 38711c074b..4b401c8f75 100644
--- a/compiler/optimizing/nodes.cc
+++ b/compiler/optimizing/nodes.cc
@@ -3339,45 +3339,25 @@ HInstruction* ReplaceInstrOrPhiByClone(HInstruction* instr) {
return clone;
}
-// Returns an instruction with the opposite Boolean value from 'cond'.
-HInstruction* HGraph::InsertOppositeCondition(HInstruction* cond, HInstruction* cursor) {
+HCondition* HGraph::CreateCondition(IfCondition cond,
+ HInstruction* lhs,
+ HInstruction* rhs,
+ uint32_t dex_pc) {
ArenaAllocator* allocator = GetAllocator();
-
- if (cond->IsCondition() &&
- !DataType::IsFloatingPointType(cond->InputAt(0)->GetType())) {
- // Can't reverse floating point conditions. We have to use HBooleanNot in that case.
- HInstruction* lhs = cond->InputAt(0);
- HInstruction* rhs = cond->InputAt(1);
- HInstruction* replacement = nullptr;
- switch (cond->AsCondition()->GetOppositeCondition()) { // get *opposite*
- case kCondEQ: replacement = new (allocator) HEqual(lhs, rhs); break;
- case kCondNE: replacement = new (allocator) HNotEqual(lhs, rhs); break;
- case kCondLT: replacement = new (allocator) HLessThan(lhs, rhs); break;
- case kCondLE: replacement = new (allocator) HLessThanOrEqual(lhs, rhs); break;
- case kCondGT: replacement = new (allocator) HGreaterThan(lhs, rhs); break;
- case kCondGE: replacement = new (allocator) HGreaterThanOrEqual(lhs, rhs); break;
- case kCondB: replacement = new (allocator) HBelow(lhs, rhs); break;
- case kCondBE: replacement = new (allocator) HBelowOrEqual(lhs, rhs); break;
- case kCondA: replacement = new (allocator) HAbove(lhs, rhs); break;
- case kCondAE: replacement = new (allocator) HAboveOrEqual(lhs, rhs); break;
- default:
- LOG(FATAL) << "Unexpected condition";
- UNREACHABLE();
- }
- cursor->GetBlock()->InsertInstructionBefore(replacement, cursor);
- return replacement;
- } else if (cond->IsIntConstant()) {
- HIntConstant* int_const = cond->AsIntConstant();
- if (int_const->IsFalse()) {
- return GetIntConstant(1);
- } else {
- DCHECK(int_const->IsTrue()) << int_const->GetValue();
- return GetIntConstant(0);
- }
- } else {
- HInstruction* replacement = new (allocator) HBooleanNot(cond);
- cursor->GetBlock()->InsertInstructionBefore(replacement, cursor);
- return replacement;
+ switch (cond) {
+ case kCondEQ: return new (allocator) HEqual(lhs, rhs, dex_pc);
+ case kCondNE: return new (allocator) HNotEqual(lhs, rhs, dex_pc);
+ case kCondLT: return new (allocator) HLessThan(lhs, rhs, dex_pc);
+ case kCondLE: return new (allocator) HLessThanOrEqual(lhs, rhs, dex_pc);
+ case kCondGT: return new (allocator) HGreaterThan(lhs, rhs, dex_pc);
+ case kCondGE: return new (allocator) HGreaterThanOrEqual(lhs, rhs, dex_pc);
+ case kCondB: return new (allocator) HBelow(lhs, rhs, dex_pc);
+ case kCondBE: return new (allocator) HBelowOrEqual(lhs, rhs, dex_pc);
+ case kCondA: return new (allocator) HAbove(lhs, rhs, dex_pc);
+ case kCondAE: return new (allocator) HAboveOrEqual(lhs, rhs, dex_pc);
+ default:
+ LOG(FATAL) << "Unexpected condition " << cond;
+ UNREACHABLE();
}
}