On Sat, 1 Oct 2016, Marc Glisse wrote:
> On Wed, 28 Sep 2016, Richard Biener wrote:
>
> > --- gcc/match.pd (revision 240565)
> > +++ gcc/match.pd (working copy)
> > @@ -147,12 +147,25 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
> > (op @0 integer_onep)
> > (non_lvalue @0)))
> >
> > -/* X / -1 is -X. */
> > (for div (trunc_div ceil_div floor_div round_div exact_div)
> > + /* X / -1 is -X. */
> > (simplify
> > (div @0 integer_minus_onep@1)
> > (if (!TYPE_UNSIGNED (type))
> > - (negate @0))))
> > + (negate @0)))
> > + /* X / abs (X) is X < 0 ? -1 : 1. */
> > + (simplify
> > + (div @0 (abs @0))
>
> Should this be div:C ?
Yes.
> > + (if ((INTEGRAL_TYPE_P (type) || VECTOR_INTEGER_TYPE_P (type))
> > + && TYPE_OVERFLOW_UNDEFINED (type))
> > + (cond (lt @0 { build_zero_cst (type); })
> > + { build_minus_one_cst (type); } { build_one_cst (type); })))
>
> How does that work for vectors? It ICEs for me at revision 240696
>
> typedef int vec __attribute__((vector_size(16)));
> vec f(vec x){
> vec y=(x<0)?-x:x;
> return x/y;
> }
>
> (I wasn't sure if you had added a feature to turn cond into vec_cond
> automatically in some cases)
Whoops, indeed.
Testing the following.
Richard.
2016-10-04 Richard Biener <[email protected]>
PR middle-end/77407
* match.pd (X / abs (X) -> X < 0 ? -1 : 1): Drop vector
type support, mark with :C.
(X / -X -> -1): Mark with :C.
Index: gcc/match.pd
===================================================================
--- gcc/match.pd (revision 240738)
+++ gcc/match.pd (working copy)
@@ -155,14 +155,14 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
(negate @0)))
/* X / abs (X) is X < 0 ? -1 : 1. */
(simplify
- (div @0 (abs @0))
- (if ((INTEGRAL_TYPE_P (type) || VECTOR_INTEGER_TYPE_P (type))
+ (div:C @0 (abs @0))
+ (if (INTEGRAL_TYPE_P (type)
&& TYPE_OVERFLOW_UNDEFINED (type))
(cond (lt @0 { build_zero_cst (type); })
{ build_minus_one_cst (type); } { build_one_cst (type); })))
/* X / -X is -1. */
(simplify
- (div @0 (negate @0))
+ (div:C @0 (negate @0))
(if ((INTEGRAL_TYPE_P (type) || VECTOR_INTEGER_TYPE_P (type))
&& TYPE_OVERFLOW_UNDEFINED (type))
{ build_minus_one_cst (type); })))