1*795d594fSAndroid Build Coastguard Worker /*
2*795d594fSAndroid Build Coastguard Worker * Copyright (C) 2015 The Android Open Source Project
3*795d594fSAndroid Build Coastguard Worker *
4*795d594fSAndroid Build Coastguard Worker * Licensed under the Apache License, Version 2.0 (the "License");
5*795d594fSAndroid Build Coastguard Worker * you may not use this file except in compliance with the License.
6*795d594fSAndroid Build Coastguard Worker * You may obtain a copy of the License at
7*795d594fSAndroid Build Coastguard Worker *
8*795d594fSAndroid Build Coastguard Worker * http://www.apache.org/licenses/LICENSE-2.0
9*795d594fSAndroid Build Coastguard Worker *
10*795d594fSAndroid Build Coastguard Worker * Unless required by applicable law or agreed to in writing, software
11*795d594fSAndroid Build Coastguard Worker * distributed under the License is distributed on an "AS IS" BASIS,
12*795d594fSAndroid Build Coastguard Worker * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13*795d594fSAndroid Build Coastguard Worker * See the License for the specific language governing permissions and
14*795d594fSAndroid Build Coastguard Worker * limitations under the License.
15*795d594fSAndroid Build Coastguard Worker */
16*795d594fSAndroid Build Coastguard Worker
17*795d594fSAndroid Build Coastguard Worker #ifndef ART_COMPILER_OPTIMIZING_INSTRUCTION_SIMPLIFIER_SHARED_H_
18*795d594fSAndroid Build Coastguard Worker #define ART_COMPILER_OPTIMIZING_INSTRUCTION_SIMPLIFIER_SHARED_H_
19*795d594fSAndroid Build Coastguard Worker
20*795d594fSAndroid Build Coastguard Worker #include "base/macros.h"
21*795d594fSAndroid Build Coastguard Worker #include "nodes.h"
22*795d594fSAndroid Build Coastguard Worker
23*795d594fSAndroid Build Coastguard Worker namespace art HIDDEN {
24*795d594fSAndroid Build Coastguard Worker
25*795d594fSAndroid Build Coastguard Worker class CodeGenerator;
26*795d594fSAndroid Build Coastguard Worker
27*795d594fSAndroid Build Coastguard Worker namespace helpers {
28*795d594fSAndroid Build Coastguard Worker
CanFitInShifterOperand(HInstruction * instruction)29*795d594fSAndroid Build Coastguard Worker inline bool CanFitInShifterOperand(HInstruction* instruction) {
30*795d594fSAndroid Build Coastguard Worker if (instruction->IsTypeConversion()) {
31*795d594fSAndroid Build Coastguard Worker HTypeConversion* conversion = instruction->AsTypeConversion();
32*795d594fSAndroid Build Coastguard Worker DataType::Type result_type = conversion->GetResultType();
33*795d594fSAndroid Build Coastguard Worker DataType::Type input_type = conversion->GetInputType();
34*795d594fSAndroid Build Coastguard Worker // We don't expect to see the same type as input and result.
35*795d594fSAndroid Build Coastguard Worker return DataType::IsIntegralType(result_type) && DataType::IsIntegralType(input_type) &&
36*795d594fSAndroid Build Coastguard Worker (result_type != input_type);
37*795d594fSAndroid Build Coastguard Worker } else {
38*795d594fSAndroid Build Coastguard Worker return (instruction->IsShl() && instruction->AsShl()->InputAt(1)->IsIntConstant()) ||
39*795d594fSAndroid Build Coastguard Worker (instruction->IsShr() && instruction->AsShr()->InputAt(1)->IsIntConstant()) ||
40*795d594fSAndroid Build Coastguard Worker (instruction->IsUShr() && instruction->AsUShr()->InputAt(1)->IsIntConstant());
41*795d594fSAndroid Build Coastguard Worker }
42*795d594fSAndroid Build Coastguard Worker }
43*795d594fSAndroid Build Coastguard Worker
HasShifterOperand(HInstruction * instr,InstructionSet isa)44*795d594fSAndroid Build Coastguard Worker inline bool HasShifterOperand(HInstruction* instr, InstructionSet isa) {
45*795d594fSAndroid Build Coastguard Worker // On ARM64 `neg` instructions are an alias of `sub` using the zero register
46*795d594fSAndroid Build Coastguard Worker // as the first register input.
47*795d594fSAndroid Build Coastguard Worker bool res = instr->IsAdd() || instr->IsAnd() ||
48*795d594fSAndroid Build Coastguard Worker (isa == InstructionSet::kArm64 && instr->IsNeg()) ||
49*795d594fSAndroid Build Coastguard Worker instr->IsOr() || instr->IsSub() || instr->IsXor();
50*795d594fSAndroid Build Coastguard Worker return res;
51*795d594fSAndroid Build Coastguard Worker }
52*795d594fSAndroid Build Coastguard Worker
53*795d594fSAndroid Build Coastguard Worker // Check the specified sub is the last operation of the sequence:
54*795d594fSAndroid Build Coastguard Worker // t1 = Shl
55*795d594fSAndroid Build Coastguard Worker // t2 = Sub(t1, *)
56*795d594fSAndroid Build Coastguard Worker // t3 = Sub(*, t2)
IsSubRightSubLeftShl(HSub * sub)57*795d594fSAndroid Build Coastguard Worker inline bool IsSubRightSubLeftShl(HSub *sub) {
58*795d594fSAndroid Build Coastguard Worker HInstruction* right = sub->GetRight();
59*795d594fSAndroid Build Coastguard Worker return right->IsSub() && right->AsSub()->GetLeft()->IsShl();
60*795d594fSAndroid Build Coastguard Worker }
61*795d594fSAndroid Build Coastguard Worker
62*795d594fSAndroid Build Coastguard Worker } // namespace helpers
63*795d594fSAndroid Build Coastguard Worker
64*795d594fSAndroid Build Coastguard Worker bool TryCombineMultiplyAccumulate(HMul* mul, InstructionSet isa);
65*795d594fSAndroid Build Coastguard Worker
66*795d594fSAndroid Build Coastguard Worker bool TryExtractArrayAccessAddress(CodeGenerator* codegen,
67*795d594fSAndroid Build Coastguard Worker HInstruction* access,
68*795d594fSAndroid Build Coastguard Worker HInstruction* array,
69*795d594fSAndroid Build Coastguard Worker HInstruction* index,
70*795d594fSAndroid Build Coastguard Worker size_t data_offset);
71*795d594fSAndroid Build Coastguard Worker
72*795d594fSAndroid Build Coastguard Worker bool TryExtractVecArrayAccessAddress(HVecMemoryOperation* access, HInstruction* index);
73*795d594fSAndroid Build Coastguard Worker
74*795d594fSAndroid Build Coastguard Worker // Try to replace
75*795d594fSAndroid Build Coastguard Worker // Sub(c, Sub(a, b))
76*795d594fSAndroid Build Coastguard Worker // with
77*795d594fSAndroid Build Coastguard Worker // Add(c, Sub(b, a))
78*795d594fSAndroid Build Coastguard Worker bool TryReplaceSubSubWithSubAdd(HSub* last_sub);
79*795d594fSAndroid Build Coastguard Worker
80*795d594fSAndroid Build Coastguard Worker // ARM does not contain instruction ROL so replace
81*795d594fSAndroid Build Coastguard Worker // ROL dest, a, distance
82*795d594fSAndroid Build Coastguard Worker // with
83*795d594fSAndroid Build Coastguard Worker // NEG neg, distance
84*795d594fSAndroid Build Coastguard Worker // ROR dest, a, neg
85*795d594fSAndroid Build Coastguard Worker // before GVN to give it a chance to deduplicate the instructions, if it's able.
86*795d594fSAndroid Build Coastguard Worker void UnfoldRotateLeft(HRol* rol);
87*795d594fSAndroid Build Coastguard Worker
88*795d594fSAndroid Build Coastguard Worker } // namespace art
89*795d594fSAndroid Build Coastguard Worker
90*795d594fSAndroid Build Coastguard Worker #endif // ART_COMPILER_OPTIMIZING_INSTRUCTION_SIMPLIFIER_SHARED_H_
91