From 1a65388f1d86bb232c2e44fecb44cebe13105d2e Mon Sep 17 00:00:00 2001 From: Roland Levillain Date: Fri, 18 Mar 2016 18:05:57 +0000 Subject: Clean up art::HConstant predicates. - Make the difference between arithmetic zero and zero-bit pattern non ambiguous. - Introduce Boolean predicates in art::HIntConstant for when they are used as Booleans. - Introduce aritmetic positive and negative zero predicates for floating-point constants. Bug: 27639313 Change-Id: Ia04ecc6f6aa7450136028c5362ed429760c883bd --- compiler/optimizing/nodes.h | 43 ++++++++++++++++++++++++++++++++++++++----- 1 file changed, 38 insertions(+), 5 deletions(-) (limited to 'compiler/optimizing/nodes.h') diff --git a/compiler/optimizing/nodes.h b/compiler/optimizing/nodes.h index 3733850745..88d39d16e5 100644 --- a/compiler/optimizing/nodes.h +++ b/compiler/optimizing/nodes.h @@ -2427,8 +2427,13 @@ class HConstant : public HExpression<0> { bool CanBeMoved() const OVERRIDE { return true; } + // Is this constant -1 in the arithmetic sense? virtual bool IsMinusOne() const { return false; } - virtual bool IsZero() const { return false; } + // Is this constant 0 in the arithmetic sense? + virtual bool IsArithmeticZero() const { return false; } + // Is this constant a 0-bit pattern? + virtual bool IsZeroBitPattern() const { return false; } + // Is this constant 1 in the arithmetic sense? virtual bool IsOne() const { return false; } virtual uint64_t GetValueAsUint64() const = 0; @@ -2449,6 +2454,9 @@ class HNullConstant : public HConstant { size_t ComputeHashCode() const OVERRIDE { return 0; } + // The null constant representation is a 0-bit pattern. + virtual bool IsZeroBitPattern() const { return true; } + DECLARE_INSTRUCTION(NullConstant); private: @@ -2476,9 +2484,15 @@ class HIntConstant : public HConstant { size_t ComputeHashCode() const OVERRIDE { return GetValue(); } bool IsMinusOne() const OVERRIDE { return GetValue() == -1; } - bool IsZero() const OVERRIDE { return GetValue() == 0; } + bool IsArithmeticZero() const OVERRIDE { return GetValue() == 0; } + bool IsZeroBitPattern() const OVERRIDE { return GetValue() == 0; } bool IsOne() const OVERRIDE { return GetValue() == 1; } + // Integer constants are used to encode Boolean values as well, + // where 1 means true and 0 means false. + bool IsTrue() const { return GetValue() == 1; } + bool IsFalse() const { return GetValue() == 0; } + DECLARE_INSTRUCTION(IntConstant); private: @@ -2509,7 +2523,8 @@ class HLongConstant : public HConstant { size_t ComputeHashCode() const OVERRIDE { return static_cast(GetValue()); } bool IsMinusOne() const OVERRIDE { return GetValue() == -1; } - bool IsZero() const OVERRIDE { return GetValue() == 0; } + bool IsArithmeticZero() const OVERRIDE { return GetValue() == 0; } + bool IsZeroBitPattern() const OVERRIDE { return GetValue() == 0; } bool IsOne() const OVERRIDE { return GetValue() == 1; } DECLARE_INSTRUCTION(LongConstant); @@ -2542,7 +2557,16 @@ class HFloatConstant : public HConstant { bool IsMinusOne() const OVERRIDE { return bit_cast(value_) == bit_cast((-1.0f)); } - bool IsZero() const OVERRIDE { + bool IsArithmeticZero() const OVERRIDE { + return std::fpclassify(value_) == FP_ZERO; + } + bool IsArithmeticPositiveZero() const { + return IsArithmeticZero() && !std::signbit(value_); + } + bool IsArithmeticNegativeZero() const { + return IsArithmeticZero() && std::signbit(value_); + } + bool IsZeroBitPattern() const OVERRIDE { return bit_cast(value_) == bit_cast(0.0f); } bool IsOne() const OVERRIDE { @@ -2584,7 +2608,16 @@ class HDoubleConstant : public HConstant { bool IsMinusOne() const OVERRIDE { return bit_cast(value_) == bit_cast((-1.0)); } - bool IsZero() const OVERRIDE { + bool IsArithmeticZero() const OVERRIDE { + return std::fpclassify(value_) == FP_ZERO; + } + bool IsArithmeticPositiveZero() const { + return IsArithmeticZero() && !std::signbit(value_); + } + bool IsArithmeticNegativeZero() const { + return IsArithmeticZero() && std::signbit(value_); + } + bool IsZeroBitPattern() const OVERRIDE { return bit_cast(value_) == bit_cast((0.0)); } bool IsOne() const OVERRIDE { -- cgit v1.2.3-59-g8ed1b