@@ -1953,7 +1953,9 @@ operator_div::fold_range (irange &r, tree type,
return true;
tree t;
- if (rh.singleton_p (&t))
+ if (code == TRUNC_DIV_EXPR
+ && rh.singleton_p (&t)
+ && !wi::neg_p (lh.lower_bound ()))
{
wide_int wi = wi::to_wide (t);
int shift = wi::exact_log2 (wi);
new file mode 100644
@@ -0,0 +1,16 @@
+// { dg-do run }
+// { dg-options "-O1" }
+
+unsigned char a = 1;
+char b, e;
+long c;
+short d;
+int main() {
+ a = ~(1 && a);
+ c = ~((~a / 8 | -2) & 11007578330939886389LLU);
+ e = -c;
+ d = ~c / e;
+ if (d < 2000)
+ __builtin_abort();
+ return 0;
+}