On Mon, Sep 7, 2015 at 4:55 AM, Kugan <kugan.vivekanandara...@linaro.org> wrote: > > This patch adds support for new tree code SEXT_EXPR.
diff --git a/gcc/cfgexpand.c b/gcc/cfgexpand.c index d567a87..bbc3c10 100644 --- a/gcc/cfgexpand.c +++ b/gcc/cfgexpand.c @@ -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; that looks wrong. Generate (sext:... ) here? + 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; + } Humm - is that really how we expand sign extensions right now? No helper that would generate (sext ...) directly? I wouldn't try using 'target' btw but simply return (sext:mode op0 op1) or so. But I am no way an RTL expert. Note that if we don't disallow arbitrary precision SEXT_EXPRs we have to fall back to using shifts (and smallest_mode_for_size is simply wrong). + case SEXT_EXPR: + { + if (!INTEGRAL_TYPE_P (lhs_type) + || !INTEGRAL_TYPE_P (rhs1_type) + || TREE_CODE (rhs2) != INTEGER_CST) please constrain this some more, with || !useless_type_conversion_p (lhs_type, rhs1_type) + { + error ("invalid operands in sext expr"); + return true; + } + return false; + } @@ -3414,6 +3422,9 @@ op_symbol_code (enum tree_code code) case MIN_EXPR: return "min"; + case SEXT_EXPR: + return "sext from bit"; + just "sext" please. +/* 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) "from the INTEGER_CST sign bit specified" Also add "The type of the result is that of the first operand." Otherwise looks good to me - of course the two RTL expansion related parts need auditing by somebody speaking more RTL than me. Richard. > gcc/ChangeLog: > > 2015-09-07 Kugan Vivekanandarajah <kug...@linaro.org> > > * cfgexpand.c (expand_debug_expr): Handle SEXT_EXPR. > * expr.c (expand_expr_real_2): Likewise. > * fold-const.c (int_const_binop_1): Likewise. > * tree-cfg.c (verify_gimple_assign_binary): Likewise. > * tree-inline.c (estimate_operator_cost): Likewise. > * tree-pretty-print.c (dump_generic_node): Likewise. > (op_symbol_code): Likewise. > * tree.def: Define new tree code SEXT_EXPR.