isl_ast_build_expr.c: isl_ast_expr_add_term: allow stealing from constant term
commit7413f5ec16b471288e476d8d67dfbc9f3980b058
authorSven Verdoolaege <skimo@kotnet.org>
Sun, 21 Dec 2014 22:28:39 +0000 (21 23:28 +0100)
committerSven Verdoolaege <skimo@kotnet.org>
Thu, 25 Dec 2014 09:52:36 +0000 (25 10:52 +0100)
treed17bbecd6c4d1971c2f0627ffffa38997e0b7c4b
parenta5d1080b76f34a6758e0469379de5720caf36852
isl_ast_build_expr.c: isl_ast_expr_add_term: allow stealing from constant term

In particular, if the argument of a floor may be negative itself, but
can be made non-negative by moving part of the constant term of
the expression in which the floor appears inside the floor argument,
then do so by the minimial required amount.

For example, in a context where c0 >= 0, the argument of the floord
expression in

2 * floord(c0 - 1, 3) + 2

may be negative, but by moving the constant (in this case completely)
into this argument, we can write

2 * ((c0 + 2) / 3)

instead.

The reason for only using part of the constant term of the containing
expression rather than any positive offset is to reduce the risk of
introducing overflows.  For example, if we have an expression
floord(n,2) in a context where n >= -2147483648, then we do not
want to shift the argument to make it positive.

Signed-off-by: Sven Verdoolaege <skimo@kotnet.org>
isl_ast_build_expr.c
test_inputs/codegen/cloog/faber.c
test_inputs/codegen/cloog/nul_complex1.c
test_inputs/codegen/omega/lefur00-0.c
test_inputs/codegen/omega/lefur01-0.c
test_inputs/codegen/omega/lefur01-1.c
test_inputs/codegen/omega/substitution-1.c