This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [3/7] Optimize ZEXT_EXPR with tree-vrp
- From: Richard Biener <richard dot guenther at gmail dot com>
- To: Kugan <kugan dot vivekanandarajah at linaro dot org>
- Cc: "gcc-patches at gcc dot gnu dot org" <gcc-patches at gcc dot gnu dot org>
- Date: Tue, 15 Sep 2015 15:08:26 +0200
- Subject: Re: [3/7] Optimize ZEXT_EXPR with tree-vrp
- Authentication-results: sourceware.org; auth=none
- References: <55ECFC2A dot 7050908 at linaro dot org> <55ECFD57 dot 5060507 at linaro dot org>
On Mon, Sep 7, 2015 at 4:58 AM, Kugan <kugan.vivekanandarajah@linaro.org> wrote:
> This patch tree-vrp handling and optimization for ZEXT_EXPR.
+ else if (code == SEXT_EXPR)
+ {
+ gcc_assert (range_int_cst_p (&vr1));
+ unsigned int prec = tree_to_uhwi (vr1.min);
+ type = vr0.type;
+ wide_int tmin, tmax;
+ wide_int type_min, type_max;
+ wide_int may_be_nonzero, must_be_nonzero;
+
+ gcc_assert (!TYPE_UNSIGNED (expr_type));
hmm, I don't think we should restrict SEXT_EXPR this way. SEXT_EXPR
should operate on both signed and unsigned types and the result type
should be the same as the type of operand 0.
+ type_min = wi::shwi (1 << (prec - 1),
+ TYPE_PRECISION (TREE_TYPE (vr0.min)));
+ type_max = wi::shwi (((1 << (prec - 1)) - 1),
+ TYPE_PRECISION (TREE_TYPE (vr0.max)));
there is wi::min_value and max_value for this.
+ HOST_WIDE_INT int_may_be_nonzero = may_be_nonzero.to_uhwi ();
+ HOST_WIDE_INT int_must_be_nonzero = must_be_nonzero.to_uhwi ();
this doesn't need to fit a HOST_WIDE_INT, please use wi::bit_and (can't
find a test_bit with a quick search).
+ tmin = wi::sext (tmin, prec - 1);
+ tmax = wi::sext (tmax, prec - 1);
+ min = wide_int_to_tree (expr_type, tmin);
+ max = wide_int_to_tree (expr_type, tmax);
not sure why you need the extra sign-extensions here.
+ case SEXT_EXPR:
+ {
+ gcc_assert (is_gimple_min_invariant (op1));
+ unsigned int prec = tree_to_uhwi (op1);
no need to assert, tree_to_uhwi will do that for you.
+ HOST_WIDE_INT may_be_nonzero = may_be_nonzero0.to_uhwi ();
+ HOST_WIDE_INT must_be_nonzero = must_be_nonzero0.to_uhwi ();
likewise with HOST_WIDE__INT issue.
Otherwise looks ok to me. Btw, this and adding of SEXT_EXPR could be
accompanied with a match.pd pattern detecting sign-extension patterns,
that would give some extra test coverage.
Thanks,
Richard.
>
>
> gcc/ChangeLog:
>
> 2015-09-07 Kugan Vivekanandarajah <kuganv@linaro.org>
>
> * tree-vrp.c (extract_range_from_binary_expr_1): Handle SEXT_EXPR.
> (simplify_bit_ops_using_ranges): Likewise.
> (simplify_stmt_using_ranges): Likewise.