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.
This commit is contained in:
Andrew MacLeod 2020-10-26 14:55:00 -04:00
parent b784bbbe45
commit 48722d158c
2 changed files with 36 additions and 2 deletions

View file

@ -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
{

View file

@ -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; }