diff options
author | 2023-03-10 15:58:17 +0000 | |
---|---|---|
committer | 2023-10-10 12:51:37 +0000 | |
commit | d003e7530ed0b00df5504cf57f0dd6479629c67a (patch) | |
tree | 205938c02bfb914f007fc4e7e30f78b9b50b63e4 /compiler/optimizing/nodes.h | |
parent | 472f6bced8e088fe8f97213587933e0c4420238f (diff) |
Add optimization to simplify Select+Binary/Unary ops
We can simplify a Select + Binary/Unary Op if:
* Both inputs to the Select instruction are constant, and
* The Select instruction is not used in another instruction
to avoid duplicating Selects.
* In the case of Binary ops, both inputs can't be Select.
Test: art/test/testrunner/testrunner.py --host --64 --optimizing -b
Change-Id: Ic716155e9a8515126c2867bb1d54593fa63011ae
Diffstat (limited to 'compiler/optimizing/nodes.h')
-rw-r--r-- | compiler/optimizing/nodes.h | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/compiler/optimizing/nodes.h b/compiler/optimizing/nodes.h index 3f60ec5241..9cf52183b8 100644 --- a/compiler/optimizing/nodes.h +++ b/compiler/optimizing/nodes.h @@ -3858,6 +3858,9 @@ class HUnaryOperation : public HExpression<1> { // be evaluated as a constant, return null. HConstant* TryStaticEvaluation() const; + // Same but for `input` instead of GetInput(). + HConstant* TryStaticEvaluation(HInstruction* input) const; + // Apply this operation to `x`. virtual HConstant* Evaluate(HIntConstant* x) const = 0; virtual HConstant* Evaluate(HLongConstant* x) const = 0; @@ -3934,6 +3937,9 @@ class HBinaryOperation : public HExpression<2> { // be evaluated as a constant, return null. HConstant* TryStaticEvaluation() const; + // Same but for `left` and `right` instead of GetLeft() and GetRight(). + HConstant* TryStaticEvaluation(HInstruction* left, HInstruction* right) const; + // Apply this operation to `x` and `y`. virtual HConstant* Evaluate([[maybe_unused]] HNullConstant* x, [[maybe_unused]] HNullConstant* y) const { @@ -6188,6 +6194,9 @@ class HTypeConversion final : public HExpression<1> { // containing the result. If the input cannot be converted, return nullptr. HConstant* TryStaticEvaluation() const; + // Same but for `input` instead of GetInput(). + HConstant* TryStaticEvaluation(HInstruction* input) const; + DECLARE_INSTRUCTION(TypeConversion); protected: @@ -8377,6 +8386,12 @@ class HSelect final : public HExpression<3> { return GetTrueValue()->CanBeNull() || GetFalseValue()->CanBeNull(); } + void UpdateType() { + DCHECK_EQ(HPhi::ToPhiType(GetTrueValue()->GetType()), + HPhi::ToPhiType(GetFalseValue()->GetType())); + SetPackedField<TypeField>(HPhi::ToPhiType(GetTrueValue()->GetType())); + } + DECLARE_INSTRUCTION(Select); protected: |