From 16e528957869c7debb1f6758c9a364819e15ee1a Mon Sep 17 00:00:00 2001 From: Mads Ager Date: Fri, 14 Jul 2017 13:11:37 +0200 Subject: RFC: Generate select instruction for conditional returns. The select generator currently only inserts select instructions if there is a diamond shape with a phi. This change extends the select generator to also deal with the pattern: if (condition) { movable instruction 0 return value0 } else { movable instruction 1 return value1 } which it turns into: moveable instruction 0 moveable instruction 1 return select (value0, value1, condition) Test: 592-checker-regression-bool-input Change-Id: Iac50fb181dc2c9b7619f28977298662bc09fc0e1 --- compiler/optimizing/select_generator.h | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) (limited to 'compiler/optimizing/select_generator.h') diff --git a/compiler/optimizing/select_generator.h b/compiler/optimizing/select_generator.h index c6dca581cc..c060146478 100644 --- a/compiler/optimizing/select_generator.h +++ b/compiler/optimizing/select_generator.h @@ -18,7 +18,7 @@ * This optimization recognizes the common diamond selection pattern and * replaces it with an instance of the HSelect instruction. * - * Recognized pattern: + * Recognized patterns: * * If [ Condition ] * / \ @@ -26,14 +26,30 @@ * \ / * Phi [FalseValue, TrueValue] * + * and + * + * If [ Condition ] + * / \ + * false branch true branch + * return FalseValue return TrueValue + * * The pattern will be simplified if `true_branch` and `false_branch` each * contain at most one instruction without any side effects. * - * Blocks are merged into one and Select replaces the If and the Phi: + * Blocks are merged into one and Select replaces the If and the Phi. + * + * For the first pattern it simplifies to: + * * true branch * false branch * Select [FalseValue, TrueValue, Condition] * + * For the second pattern it simplifies to: + * + * true branch + * false branch + * return Select [FalseValue, TrueValue, Condition] + * * Note: In order to recognize no side-effect blocks, this optimization must be * run after the instruction simplifier has removed redundant suspend checks. */ @@ -42,19 +58,22 @@ #define ART_COMPILER_OPTIMIZING_SELECT_GENERATOR_H_ #include "optimization.h" +#include "reference_type_propagation.h" namespace art { class HSelectGenerator : public HOptimization { public: - HSelectGenerator(HGraph* graph, OptimizingCompilerStats* stats) - : HOptimization(graph, kSelectGeneratorPassName, stats) {} + HSelectGenerator(HGraph* graph, + VariableSizedHandleScope* handles, + OptimizingCompilerStats* stats); void Run() OVERRIDE; static constexpr const char* kSelectGeneratorPassName = "select_generator"; private: + VariableSizedHandleScope* handle_scope_; DISALLOW_COPY_AND_ASSIGN(HSelectGenerator); }; -- cgit v1.2.3-59-g8ed1b