diff options
author | 2015-04-27 13:54:09 +0100 | |
---|---|---|
committer | 2015-04-27 17:00:58 +0100 | |
commit | 769c9e539da8ca80aa914cd12276aa5bd79148ee (patch) | |
tree | 9aadf98a3fcbf7909f76c53fa2ee036ebda00304 /compiler/optimizing/boolean_simplifier.h | |
parent | 0fbfe6f92a2481daf914043262b5854e65d8c3cc (diff) |
ART: Simplify Ifs with BooleanNot condition
If statements with negated condition can be simplified by removing the
negation and swapping the true and false branches.
Change-Id: I197afbc79fb7344d73b7b85d3611e7ca2519717f
Diffstat (limited to 'compiler/optimizing/boolean_simplifier.h')
-rw-r--r-- | compiler/optimizing/boolean_simplifier.h | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/compiler/optimizing/boolean_simplifier.h b/compiler/optimizing/boolean_simplifier.h index a88733e1af..733ebaac2c 100644 --- a/compiler/optimizing/boolean_simplifier.h +++ b/compiler/optimizing/boolean_simplifier.h @@ -14,11 +14,15 @@ * limitations under the License. */ -// This optimization recognizes a common pattern where a boolean value is -// either cast to an integer or negated by selecting from zero/one integer -// constants with an If statement. Because boolean values are internally -// represented as zero/one, we can safely replace the pattern with a suitable -// condition instruction. +// This optimization recognizes two common patterns: +// (a) Boolean selection: Casting a boolean to an integer or negating it is +// carried out with an If statement selecting from zero/one integer +// constants. Because Boolean values are represented as zero/one, the +// pattern can be replaced with the condition instruction itself or its +// negation, depending on the layout. +// (b) Negated condition: Instruction simplifier may replace an If's condition +// with a boolean value. If this value is the result of a Boolean negation, +// the true/false branches can be swapped and negation removed. // Example: Negating a boolean value // B1: @@ -66,6 +70,9 @@ class HBooleanSimplifier : public HOptimization { static constexpr const char* kBooleanSimplifierPassName = "boolean_simplifier"; private: + void TryRemovingNegatedCondition(HBasicBlock* block); + void TryRemovingBooleanSelection(HBasicBlock* block); + DISALLOW_COPY_AND_ASSIGN(HBooleanSimplifier); }; |