isl_ast_expr_mod: perform missing multiplication
authorSven Verdoolaege <skimo@kotnet.org>
Fri, 21 Sep 2012 16:11:07 +0000 (18:11 +0200)
committerSven Verdoolaege <skimo@kotnet.org>
Sat, 22 Sep 2012 17:16:43 +0000 (19:16 +0200)
The function was documented as multiplying the constructed modulo expression
by the first argument, but failed to do so.
The problem went unnoticed because the first argument is usually equal to 1.

Signed-off-by: Sven Verdoolaege <skimo@kotnet.org>
isl_ast_build_expr.c
test_inputs/codegen/mod.c [new file with mode: 0644]
test_inputs/codegen/mod.in [new file with mode: 0644]

index adab2a2..4f945f8 100644 (file)
@@ -204,7 +204,14 @@ static __isl_give isl_ast_expr *isl_ast_expr_mod(isl_int v,
        expr = isl_ast_expr_from_aff(isl_aff_copy(aff), build);
 
        c = isl_ast_expr_alloc_int(ctx, d);
-       return isl_ast_expr_alloc_binary(isl_ast_op_pdiv_r, expr, c);
+       expr = isl_ast_expr_alloc_binary(isl_ast_op_pdiv_r, expr, c);
+
+       if (!isl_int_is_one(v)) {
+               c = isl_ast_expr_alloc_int(ctx, v);
+               expr = isl_ast_expr_mul(c, expr);
+       }
+
+       return expr;
 }
 
 /* Create an isl_ast_expr evaluating "v" times the specified dimension of "ls".
diff --git a/test_inputs/codegen/mod.c b/test_inputs/codegen/mod.c
new file mode 100644 (file)
index 0000000..dcd8319
--- /dev/null
@@ -0,0 +1,2 @@
+if (2 * (n % 100) == 3 * (m % 200))
+  A();
diff --git a/test_inputs/codegen/mod.in b/test_inputs/codegen/mod.in
new file mode 100644 (file)
index 0000000..7a04c5a
--- /dev/null
@@ -0,0 +1,4 @@
+# check that modulo constraint is generated correctly
+[n, m] -> { A[] -> [] : 2 * (n % 100) = 3 * (m % 200) }
+[n, m] -> { : m, n >= 0 }
+{}