Skip to content

Commit 7ea501d

Browse files
MATCH: Make zero_one_valued_p non-recursive fully
So it turns out VN can't handle any kind of recursion for match. In this case we have `b = a & -1` and we try to match a as being zero_one_valued_p and VN returns b as being the value and we just go into an infinite loop at this point. OK? Bootstrapped and tested on x86_64-linux-gnu with no regressions. Note genmatch should warn (or error out) if this gets detected so I filed PR 111446 which I will be looking into next week or the week after so we don't run into this issue again. PR tree-optimization/111442 gcc/ChangeLog: * match.pd (zero_one_valued_p): Have the bit_and match not be recursive. gcc/testsuite/ChangeLog: * gcc.c-torture/compile/pr111442-1.c: New test.
1 parent 951d3c1 commit 7ea501d

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

gcc/match.pd

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2183,8 +2183,11 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
21832183

21842184
/* (a&1) is always [0,1] too. This is useful again when
21852185
the range is not known. */
2186+
/* Note this can't be recursive due to VN handling of equivalents,
2187+
VN and would cause an infinite recursion. */
21862188
(match zero_one_valued_p
2187-
(bit_and:c@0 @1 zero_one_valued_p))
2189+
(bit_and:c@0 @1 integer_onep)
2190+
(if (INTEGRAL_TYPE_P (type))))
21882191

21892192
/* A conversion from an zero_one_valued_p is still a [0,1].
21902193
This is useful when the range of a variable is not known */
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
2+
int *a, b;
3+
int main() {
4+
int d = 1, e;
5+
if (d)
6+
e = a ? 0 % 0 : 0;
7+
if (d)
8+
a = &d;
9+
d = -1;
10+
b = d & e;
11+
b = 2 * e ^ 1;
12+
return 0;
13+
}

0 commit comments

Comments
 (0)