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 ?

+   (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)

--
Marc Glisse

Reply via email to