===================================================================
@@ -140,7 +140,9 @@ (define_operator_list inverted_tcc_compa
}
(if (!overflow_p)
(div @0 { wide_int_to_tree (type, mul); }))
- (if (overflow_p)
+ (if (overflow_p
+ && (TYPE_UNSIGNED (type)
+ || mul != wi::min_value (TYPE_PRECISION (type), SIGNED)))
{ build_zero_cst (type); }))))
/* Optimize A / A to 1.0 if we don't care about
===================================================================
@@ -0,0 +1,15 @@
+/* { dg-do run } */
+
+extern void abort (void);
+
+int foo (int x)
+{
+ return (x / 2) / ((-__INT_MAX__ - 1) / -2);
+}
+
+int main()
+{
+ if (foo (- __INT_MAX__ - 1) != -1)
+ abort ();
+ return 0;
+}