===================================================================
@@ -150,6 +150,8 @@
gcc_assert (res != ip.end () &&
"Could not map isl_id to tree expression");
isl_ast_expr_free (expr_id);
+ if (POINTER_TYPE_P (TREE_TYPE (res->second)))
+ return res->second;
return fold_convert (type, res->second);
}
@@ -178,18 +180,46 @@
type TYPE. */
static tree
-binary_op_to_tree (tree type, __isl_take isl_ast_expr *expr, ivs_params &ip)
+binary_op_to_tree (tree recommended_type, __isl_take isl_ast_expr *expr,
+ ivs_params &ip)
{
isl_ast_expr *arg_expr = isl_ast_expr_get_op_arg (expr, 0);
- tree tree_lhs_expr = gcc_expression_from_isl_expression (type, arg_expr, ip);
+ tree tree_lhs_expr =
+ gcc_expression_from_isl_expression (recommended_type, arg_expr, ip);
arg_expr = isl_ast_expr_get_op_arg (expr, 1);
- tree tree_rhs_expr = gcc_expression_from_isl_expression (type, arg_expr, ip);
+ tree tree_rhs_expr =
+ gcc_expression_from_isl_expression (recommended_type, arg_expr, ip);
+ tree type = POINTER_TYPE_P (TREE_TYPE (tree_lhs_expr)) ?
+ TREE_TYPE (tree_lhs_expr) : recommended_type;
+ type = POINTER_TYPE_P (TREE_TYPE (tree_rhs_expr)) ?
+ TREE_TYPE (tree_rhs_expr) : type;
+ if (POINTER_TYPE_P (type))
+ {
+ if (isl_ast_expr_get_op_type (expr) == isl_ast_op_add ||
+ isl_ast_expr_get_op_type (expr) == isl_ast_op_mul ||
+ isl_ast_expr_get_op_type (expr) == isl_ast_op_div)
+ {
+ if (!POINTER_TYPE_P (TREE_TYPE (tree_lhs_expr)))
+ tree_lhs_expr = fold_convert (sizetype, tree_lhs_expr);
+ if (!POINTER_TYPE_P (TREE_TYPE (tree_rhs_expr)))
+ tree_rhs_expr = fold_convert (sizetype, tree_rhs_expr);
+ }
+ else
+ {
+ tree_lhs_expr = fold_convert (type, tree_lhs_expr);
+ tree_rhs_expr = fold_convert (type, tree_rhs_expr);
+ }
+ }
enum isl_ast_op_type expr_type = isl_ast_expr_get_op_type (expr);
isl_ast_expr_free (expr);
switch (expr_type)
{
case isl_ast_op_add:
- return fold_build2 (PLUS_EXPR, type, tree_lhs_expr, tree_rhs_expr);
+ if (POINTER_TYPE_P (type))
+ return fold_build2 (POINTER_PLUS_EXPR, type, tree_lhs_expr,
+ tree_rhs_expr);
+ else
+ return fold_build2 (PLUS_EXPR, type, tree_lhs_expr, tree_rhs_expr);
case isl_ast_op_sub:
return fold_build2 (MINUS_EXPR, type, tree_lhs_expr, tree_rhs_expr);
@@ -210,26 +240,32 @@
return fold_build2 (FLOOR_DIV_EXPR, type, tree_lhs_expr, tree_rhs_expr);
case isl_ast_op_and:
- return fold_build2 (TRUTH_ANDIF_EXPR, type,
+ return fold_build2 (TRUTH_ANDIF_EXPR, boolean_type_node,
tree_lhs_expr, tree_rhs_expr);
case isl_ast_op_or:
- return fold_build2 (TRUTH_ORIF_EXPR, type, tree_lhs_expr, tree_rhs_expr);
+ return fold_build2 (TRUTH_ORIF_EXPR, boolean_type_node, tree_lhs_expr,
+ tree_rhs_expr);
case isl_ast_op_eq:
- return fold_build2 (EQ_EXPR, type, tree_lhs_expr, tree_rhs_expr);
+ return fold_build2 (EQ_EXPR, boolean_type_node, tree_lhs_expr,
+ tree_rhs_expr);
case isl_ast_op_le:
- return fold_build2 (LE_EXPR, type, tree_lhs_expr, tree_rhs_expr);
+ return fold_build2 (LE_EXPR, boolean_type_node, tree_lhs_expr,
+ tree_rhs_expr);
case isl_ast_op_lt:
- return fold_build2 (LT_EXPR, type, tree_lhs_expr, tree_rhs_expr);
+ return fold_build2 (LT_EXPR, boolean_type_node, tree_lhs_expr,
+ tree_rhs_expr);
case isl_ast_op_ge:
- return fold_build2 (GE_EXPR, type, tree_lhs_expr, tree_rhs_expr);
+ return fold_build2 (GE_EXPR, boolean_type_node, tree_lhs_expr,
+ tree_rhs_expr);
case isl_ast_op_gt:
- return fold_build2 (GT_EXPR, type, tree_lhs_expr, tree_rhs_expr);
+ return fold_build2 (GT_EXPR, boolean_type_node, tree_lhs_expr,
+ tree_rhs_expr);
default:
gcc_unreachable ();
@@ -261,12 +297,16 @@
type TYPE. */
static tree
-unary_op_to_tree (tree type, __isl_take isl_ast_expr *expr, ivs_params &ip)
+unary_op_to_tree (tree recommended_type, __isl_take isl_ast_expr *expr,
+ ivs_params &ip)
{
gcc_assert (isl_ast_expr_get_op_type (expr) == isl_ast_op_minus);
isl_ast_expr *arg_expr = isl_ast_expr_get_op_arg (expr, 0);
- tree tree_expr = gcc_expression_from_isl_expression (type, arg_expr, ip);
+ tree tree_expr =
+ gcc_expression_from_isl_expression (recommended_type, arg_expr, ip);
isl_ast_expr_free (expr);
+ tree type = POINTER_TYPE_P (TREE_TYPE (tree_expr)) ?
+ TREE_TYPE (tree_expr) : recommended_type;
return fold_build1 (NEGATE_EXPR, type, tree_expr);
}