[Bug tree-optimization/110176] wrong code at -Os and above on x86_64-linux-gnu
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110176 Andrew Pinski changed: What|Removed |Added Status|UNCONFIRMED |NEW Ever confirmed|0 |1 Last reconfirmed||2023-06-08 --- Comment #2 from Andrew Pinski --- Here is a testcase which will abort rather than do an infinite loop: ``` int f(_Bool t) { int tt = t; unsigned x = -1; int xx = x; return xx <= tt; } int a, b; void c() {} [[gnu::noipa]] void h() {__builtin_abort();} int d() { unsigned f[1]; int i; if (a) goto h; f[0] = -1; while (1) { c(); for (; a < 1; a++) { if (0) { j: continue; } i = f[0]; if (a) break; b = i >= (b == 0); } if (!b) { if (0) { h: goto j; } return 0; } h(); } } int main() { d(); return 0; } ```
[Bug tree-optimization/110176] wrong code at -Os and above on x86_64-linux-gnu
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110176 --- Comment #1 from Andrew Pinski --- Fre turns: b.2_4 = b; _5 = b.2_4 == 0; _6 = (int) _5; _7 = _6 <= i_19; _8 = (int) _7; b = _8; Into: b.2_4 = b; _5 = b.2_4 == 0; _6 = (int) _5; b = 1; Which is wrong as _6 <= -1 is always 0. (simplify (cmp (convert@0 @00) (convert?@1 @10)) ... tree min = lower_bound_in_type (TREE_TYPE (@10), TREE_TYPE (@00)); tree max = upper_bound_in_type (TREE_TYPE (@10), TREE_TYPE (@00)); bool above = integer_nonzerop (const_binop (LT_EXPR, type, max, @10)); bool below = integer_nonzerop (const_binop (LT_EXPR, type, @10, min)); ... (if (above || below) ... { constant_boolean_node (above ? true : false, type); }