From 9e9fd271b84580ae40ce21eb39f9be8072e6dd12 Mon Sep 17 00:00:00 2001
From: Kugan Vivekanandarajah <kugan.vivekanandarajah@linaro.org>
Date: Mon, 17 Aug 2015 13:37:15 +1000
Subject: [PATCH 1/8] Add new SEXT_EXPR tree code
---
gcc/cfgexpand.c | 4 ++++
gcc/expr.c | 16 ++++++++++++++++
gcc/fold-const.c | 4 ++++
gcc/tree-cfg.c | 12 ++++++++++++
gcc/tree-inline.c | 1 +
gcc/tree-pretty-print.c | 11 +++++++++++
gcc/tree.def | 4 ++++
7 files changed, 52 insertions(+)
@@ -5071,6 +5071,10 @@ expand_debug_expr (tree exp)
case FMA_EXPR:
return simplify_gen_ternary (FMA, mode, inner_mode, op0, op1, op2);
+ case SEXT_EXPR:
+ return op0;
+
+
default:
flag_unsupported:
#ifdef ENABLE_CHECKING
@@ -9273,6 +9273,22 @@ expand_expr_real_2 (sepops ops, rtx target, machine_mode tmode,
target = expand_vec_cond_expr (type, treeop0, treeop1, treeop2, target);
return target;
+ case SEXT_EXPR:
+ {
+ rtx op0 = expand_normal (treeop0);
+ rtx temp;
+ if (!target)
+ target = gen_reg_rtx (TYPE_MODE (TREE_TYPE (treeop0)));
+
+ machine_mode inner_mode
+ = smallest_mode_for_size (tree_to_shwi (treeop1),
+ MODE_INT);
+ temp = convert_modes (inner_mode,
+ TYPE_MODE (TREE_TYPE (treeop0)), op0, 0);
+ convert_move (target, temp, 0);
+ return target;
+ }
+
default:
gcc_unreachable ();
}
@@ -984,6 +984,10 @@ int_const_binop_1 (enum tree_code code, const_tree arg1, const_tree parg2,
res = wi::bit_and (arg1, arg2);
break;
+ case SEXT_EXPR:
+ res = wi::sext (arg1, arg2.to_uhwi ());
+ break;
+
case RSHIFT_EXPR:
case LSHIFT_EXPR:
if (wi::neg_p (arg2))
@@ -3756,6 +3756,18 @@ verify_gimple_assign_binary (gassign *stmt)
return false;
}
+ case SEXT_EXPR:
+ {
+ if (!INTEGRAL_TYPE_P (lhs_type)
+ || !INTEGRAL_TYPE_P (rhs1_type)
+ || TREE_CODE (rhs2) != INTEGER_CST)
+ {
+ error ("invalid operands in sext expr");
+ return true;
+ }
+ return false;
+ }
+
case VEC_WIDEN_LSHIFT_HI_EXPR:
case VEC_WIDEN_LSHIFT_LO_EXPR:
{
@@ -3884,6 +3884,7 @@ estimate_operator_cost (enum tree_code code, eni_weights *weights,
case BIT_XOR_EXPR:
case BIT_AND_EXPR:
case BIT_NOT_EXPR:
+ case SEXT_EXPR:
case TRUTH_ANDIF_EXPR:
case TRUTH_ORIF_EXPR:
@@ -1794,6 +1794,14 @@ dump_generic_node (pretty_printer *pp, tree node, int spc, int flags,
}
break;
+ case SEXT_EXPR:
+ pp_string (pp, "SEXT_EXPR <");
+ dump_generic_node (pp, TREE_OPERAND (node, 0), spc, flags, false);
+ pp_string (pp, ", ");
+ dump_generic_node (pp, TREE_OPERAND (node, 1), spc, flags, false);
+ pp_greater (pp);
+ break;
+
case MODIFY_EXPR:
case INIT_EXPR:
dump_generic_node (pp, TREE_OPERAND (node, 0), spc, flags,
@@ -3414,6 +3422,9 @@ op_symbol_code (enum tree_code code)
case MIN_EXPR:
return "min";
+ case SEXT_EXPR:
+ return "sext from bit";
+
default:
return "<<< ??? >>>";
}
@@ -752,6 +752,10 @@ DEFTREECODE (BIT_XOR_EXPR, "bit_xor_expr", tcc_binary, 2)
DEFTREECODE (BIT_AND_EXPR, "bit_and_expr", tcc_binary, 2)
DEFTREECODE (BIT_NOT_EXPR, "bit_not_expr", tcc_unary, 1)
+/* Sign-extend operation. It will sign extend first operand from
+ the sign bit specified by the second operand. */
+DEFTREECODE (SEXT_EXPR, "sext_expr", tcc_binary, 2)
+
/* ANDIF and ORIF allow the second operand not to be computed if the
value of the expression is determined from the first operand. AND,
OR, and XOR always compute the second operand whether its value is
--
1.9.1