On Tue, May 22, 2018 at 12:51 AM Kugan Vivekanandarajah <
kugan.vivekanandara...@linaro.org> wrote:

> Hi,

> I am looking to introduce ABSU_EXPR and that would create:

> unsigned short res = ABSU_EXPR (short);

> Note that the argument is signed and result is unsigned. As per the
> review, I have a match.pd entry to generate this as:
> (simplify (abs (convert @0))
>   (if (ANY_INTEGRAL_TYPE_P (TREE_TYPE (@0)))
>    (convert (absu @0))))

This would convert abs ((int) unsigned_int_var) to (int) absu
(unsigned_int_var)
which is bogus given it results in -1 for abs (-1).  You want to restrict
this to
sign-extensions, thus !TYPE_UNSIGNED (TREE_TYPE (@0)) && !TYPE_UNSIGNED
(type)
&& element_precision (type) < element_precision (TREE_TYPE (@0))

> Now when gimplifying the converted tree, how do we tell that ABSU_EXPR
> will take a signed arg and return unsigned. I will have other match.pd
> entries so this will be generated while in gimple.passes too. Should I
> add new functions in gimple.[h|c] for this.

As Marc says you can use sth like

  (with { tree utype = unsigned_type_for (TREE_TYPE (@0)); }
  (convert (absu:utype @0))

or you can hack genmatch to recognize ABSU_EXPR.

> Is there any examples I can refer to. Conversion expressions seems to
> be the only place where sign can change in gimple assignment but they
> are very specific.

> Thanks,
> Kugan

Reply via email to