From 52b9a7a720c6230069d2975f9777fa7beb96aa53 Mon Sep 17 00:00:00 2001 From: Sven Verdoolaege Date: Wed, 31 May 2023 11:42:50 +0200 Subject: [PATCH] isl_ast_build_expr.c: check_parallel_or_opposite: extract replace_if_simpler This reduces the size of check_parallel_or_opposite and makes it easier to perform error handling on the result of the mod_constraint_is_simpler call in the next commit. Signed-off-by: Sven Verdoolaege --- isl_ast_build_expr.c | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/isl_ast_build_expr.c b/isl_ast_build_expr.c index b49eedca..c3c9c9a3 100644 --- a/isl_ast_build_expr.c +++ b/isl_ast_build_expr.c @@ -734,6 +734,23 @@ static int mod_constraint_is_simpler(struct isl_extract_mod_data *data, return simpler; } +/* If "c" is "simpler" than data->nonneg, + * then replace data->nonneg by the affine expression of "c" and + * set data->sign to "sign". + */ +static isl_stat replace_if_simpler(struct isl_extract_mod_data *data, + __isl_keep isl_constraint *c, int sign) +{ + if (!mod_constraint_is_simpler(data, c)) + return isl_stat_ok; + + isl_aff_free(data->nonneg); + data->nonneg = isl_constraint_get_aff(c); + data->sign = sign; + + return isl_stat_non_null(data->nonneg); +} + /* Check if the coefficients of "c" are either equal or opposite to those * of data->div modulo data->d. If so, and if "c" is "simpler" than * data->nonneg, then replace data->nonneg by the affine expression of "c" @@ -810,17 +827,7 @@ static isl_stat check_parallel_or_opposite(struct isl_extract_mod_data *data, } } - if (mod_constraint_is_simpler(data, c)) { - isl_aff_free(data->nonneg); - data->nonneg = isl_constraint_get_aff(c); - data->sign = parallel ? 1 : -1; - } - - - if (data->sign != 0 && data->nonneg == NULL) - return isl_stat_error; - - return isl_stat_ok; + return replace_if_simpler(data, c, parallel ? 1 : -1); } /* Wrapper around check_parallel_or_opposite for use -- 2.11.4.GIT