From 2a2f42c25d068a5233bd1239222ad7d2948963ee Mon Sep 17 00:00:00 2001 From: Dmitry Stogov Date: Thu, 25 Jun 2015 18:56:14 +0300 Subject: [PATCH] Optimize out usless conditions used by specializer --- Zend/zend_execute.h | 8 ++++---- Zend/zend_portability.h | 8 ++++++++ 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/Zend/zend_execute.h b/Zend/zend_execute.h index 9719eda42b..f595edca9b 100644 --- a/Zend/zend_execute.h +++ b/Zend/zend_execute.h @@ -58,7 +58,7 @@ static zend_always_inline zval* zend_assign_to_variable(zval *variable_ptr, zval { zend_refcounted *ref = NULL; - if ((value_type & (IS_VAR|IS_CV)) && Z_ISREF_P(value)) { + if (ZEND_CONST_COND(value_type & (IS_VAR|IS_CV), 1) && Z_ISREF_P(value)) { ref = Z_COUNTED_P(value); value = Z_REFVAL_P(value); } @@ -78,7 +78,7 @@ static zend_always_inline zval* zend_assign_to_variable(zval *variable_ptr, zval Z_OBJ_HANDLER_P(variable_ptr, set)(variable_ptr, value); return variable_ptr; } - if ((value_type & (IS_VAR|IS_CV)) && variable_ptr == value) { + if (ZEND_CONST_COND(value_type & (IS_VAR|IS_CV), 1) && variable_ptr == value) { return variable_ptr; } garbage = Z_COUNTED_P(variable_ptr); @@ -93,7 +93,7 @@ static zend_always_inline zval* zend_assign_to_variable(zval *variable_ptr, zval if (UNEXPECTED(Z_OPT_REFCOUNTED_P(variable_ptr))) { Z_ADDREF_P(variable_ptr); } - } else if (/* value_type == IS_VAR && */ UNEXPECTED(ref)) { + } else if (ZEND_CONST_COND(value_type == IS_VAR, 1) && UNEXPECTED(ref)) { if (UNEXPECTED(--GC_REFCOUNT(ref) == 0)) { efree_size(ref, sizeof(zend_reference)); } else if (Z_OPT_REFCOUNTED_P(variable_ptr)) { @@ -122,7 +122,7 @@ static zend_always_inline zval* zend_assign_to_variable(zval *variable_ptr, zval if (UNEXPECTED(Z_OPT_REFCOUNTED_P(variable_ptr))) { Z_ADDREF_P(variable_ptr); } - } else if (/* value_type == IS_VAR && */ UNEXPECTED(ref)) { + } else if (ZEND_CONST_COND(value_type == IS_VAR, 1) && UNEXPECTED(ref)) { if (UNEXPECTED(--GC_REFCOUNT(ref) == 0)) { efree_size(ref, sizeof(zend_reference)); } else if (Z_OPT_REFCOUNTED_P(variable_ptr)) { diff --git a/Zend/zend_portability.h b/Zend/zend_portability.h index 8c6989d030..214ece53e6 100644 --- a/Zend/zend_portability.h +++ b/Zend/zend_portability.h @@ -250,6 +250,14 @@ char *alloca(); # define HAVE_BUILTIN_CONSTANT_P #endif +#ifdef HAVE_BUILTIN_CONSTANT_P +# define ZEND_CONST_COND(_condition, _default) \ + (__builtin_constant_p(_condition) ? (_condition) : (_default)) +#else +# define ZEND_CONST_COND(_condition, _default) \ + (_default) +#endif + #if ZEND_DEBUG # define zend_always_inline inline # define zend_never_inline -- 2.40.0