From: Andrew MacLeod Date: Mon, 26 Oct 2020 18:55:00 +0000 (-0400) Subject: Combine logical OR ranges properly. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=48722d158cbf692c24025e345ecbbbb570f66aa5;p=gcc.git Combine logical OR ranges properly. When combining logical OR operands with a FALSE result, union the false ranges for operand1 and operand2... not intersection. gcc/ PR tree-optimization/97567 * gimple-range-gori.cc (gori_compute::logical_combine): Union the ranges of operand1 and operand2, not intersect. gcc/testsuite/ * gcc.dg/pr97567.c: New. --- diff --git a/gcc/gimple-range-gori.cc b/gcc/gimple-range-gori.cc index 5d50b111d2a..de0f653860d 100644 --- a/gcc/gimple-range-gori.cc +++ b/gcc/gimple-range-gori.cc @@ -730,10 +730,10 @@ gori_compute::logical_combine (irange &r, enum tree_code code, if (lhs.zero_p ()) { // An OR operation will only take the FALSE path if both - // operands are false, so [20, 255] intersect [0, 5] is the + // operands are false, so either [20, 255] or [0, 5] is the // union: [0,5][20,255]. r = op1.false_range; - r.intersect (op2.false_range); + r.union_ (op2.false_range); } else { diff --git a/gcc/testsuite/gcc.dg/pr97567.c b/gcc/testsuite/gcc.dg/pr97567.c new file mode 100644 index 00000000000..b2b72a4d2a7 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr97567.c @@ -0,0 +1,34 @@ +/* { dg-do run } */ +/* { dg-options "-O2" } */ + +int a, b, c, d; +void k() { + unsigned f = 1; + long g = 4073709551615; + for (; a; a++) + for (;;) { + d = 0; + L1: + break; + } + if (f) + for (; a; a++) + ; + g || f; + int i = 0 - f || g; + long j = g - f; + if (j || f) { + if (g < 4073709551615) + for (;;) + ; + int e = ~f, h = b / ~e; + if (c) + goto L2; + g = f = h; + } + g || d; +L2: + if (c) + goto L1; +} +int main() { k(); return 0; }