diff options
author | 2019-09-10 09:41:29 -0500 | |
---|---|---|
committer | 2019-09-18 01:20:03 +0000 | |
commit | 4eb6eb40e88214fcc874d93e75660cb580cb4d58 (patch) | |
tree | 4d13edeab88bd6fd724388c48385b0c3cca4f3a8 /compiler/optimizing/constant_folding.cc | |
parent | c971eafeff43e4e26959a6e86b62ab0a8f1a6e1c (diff) |
[optimizing] Improve constant folding on logical and
Constant fold a & ~a = ~a & a = 0.
Test: added test to 442-checker-constant-folding
Test: test-art-host,test-art-target
Change-Id: Ib637c93e99ce22dd1ecd5684d05ce5ca4c9c823a
Diffstat (limited to 'compiler/optimizing/constant_folding.cc')
-rw-r--r-- | compiler/optimizing/constant_folding.cc | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/compiler/optimizing/constant_folding.cc b/compiler/optimizing/constant_folding.cc index 09e7cabfa4..2031707759 100644 --- a/compiler/optimizing/constant_folding.cc +++ b/compiler/optimizing/constant_folding.cc @@ -217,6 +217,7 @@ void InstructionWithAbsorbingInputSimplifier::VisitBelowOrEqual(HBelowOrEqual* i } void InstructionWithAbsorbingInputSimplifier::VisitAnd(HAnd* instruction) { + DataType::Type type = instruction->GetType(); HConstant* input_cst = instruction->GetConstantRight(); if ((input_cst != nullptr) && input_cst->IsZeroBitPattern()) { // Replace code looking like @@ -226,6 +227,25 @@ void InstructionWithAbsorbingInputSimplifier::VisitAnd(HAnd* instruction) { instruction->ReplaceWith(input_cst); instruction->GetBlock()->RemoveInstruction(instruction); } + + HInstruction* left = instruction->GetLeft(); + HInstruction* right = instruction->GetRight(); + + if (left->IsNot() ^ right->IsNot()) { + // Replace code looking like + // NOT notsrc, src + // AND dst, notsrc, src + // with + // CONSTANT 0 + HInstruction* hnot = (left->IsNot() ? left : right); + HInstruction* hother = (left->IsNot() ? right : left); + HInstruction* src = hnot->AsNot()->GetInput(); + + if (src == hother) { + instruction->ReplaceWith(GetGraph()->GetConstant(type, 0)); + instruction->GetBlock()->RemoveInstruction(instruction); + } + } } void InstructionWithAbsorbingInputSimplifier::VisitCompare(HCompare* instruction) { |