diff options
author | 2020-06-17 15:37:02 +0100 | |
---|---|---|
committer | 2020-06-19 11:32:38 +0000 | |
commit | 3d190c0f01071c5c402a96ac77ef07d20291405a (patch) | |
tree | c99b356725b7474448ae2c14d7bbe0e491c0cd15 /compiler/optimizing/instruction_simplifier_shared.h | |
parent | 86c8752f64629325026945cd4eabd1dcea224acb (diff) |
ART: Transform Sub+Sub into Sub+Add to merge Shl
In the instruction sequence like the following:
t1 = Shl(a, n)
t2 = Sub(t1, *)
r = Sub(*, t2)
Shl cannot be merged with Sub. However it can be done when the first Sub
operands are reordered and the second Sub is replaced with Add:
t1 = Shl(a, n)
t2 = Sub(*, t1)
r = Add(*, t2)
This CL implements this transformation in the ARM/ARM64 instruction simplifiers.
Test: 411-checker-instruct-simplifier-hrem
Test: test.py --host --optimizing --jit --gtest --interpreter
Test: test.py --target --optimizing --jit --interpreter
Test: run-gtests.sh
Change-Id: I24fde29d307f3ad53a8df8bbafe945b4f733ce6c
Diffstat (limited to 'compiler/optimizing/instruction_simplifier_shared.h')
-rw-r--r-- | compiler/optimizing/instruction_simplifier_shared.h | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/compiler/optimizing/instruction_simplifier_shared.h b/compiler/optimizing/instruction_simplifier_shared.h index 758fc7663d..876ed21a22 100644 --- a/compiler/optimizing/instruction_simplifier_shared.h +++ b/compiler/optimizing/instruction_simplifier_shared.h @@ -47,6 +47,15 @@ inline bool HasShifterOperand(HInstruction* instr, InstructionSet isa) { return res; } +// Check the specified sub is the last operation of the sequence: +// t1 = Shl +// t2 = Sub(t1, *) +// t3 = Sub(*, t2) +inline bool IsSubRightSubLeftShl(HSub *sub) { + HInstruction* right = sub->GetRight(); + return right->IsSub() && right->AsSub()->GetLeft()->IsShl();; +} + } // namespace helpers bool TryCombineMultiplyAccumulate(HMul* mul, InstructionSet isa); @@ -61,6 +70,12 @@ bool TryExtractArrayAccessAddress(HInstruction* access, bool TryExtractVecArrayAccessAddress(HVecMemoryOperation* access, HInstruction* index); +// Try to replace +// Sub(c, Sub(a, b)) +// with +// Add(c, Sub(b, a)) +bool TryReplaceSubSubWithSubAdd(HSub* last_sub); + } // namespace art #endif // ART_COMPILER_OPTIMIZING_INSTRUCTION_SIMPLIFIER_SHARED_H_ |