https://gcc.gnu.org/bugzilla/show_bug.cgi?id=123114
--- Comment #3 from Jakub Jelinek <jakub at gcc dot gnu.org> --- Full untested patch: 2025-12-13 Jakub Jelinek <[email protected]> PR rtl-optimization/123114 * simplify-rtx.cc (simplify_context::simplify_relational_operation): Verify XEXP (XEXP (op0, 0), 0) mode and use CONST0_RTX (cmp_mode) instead of CONST0_RTX (mode). * gcc.dg/pr123114.c: New test. --- gcc/simplify-rtx.cc.jj 2025-12-09 10:18:55.437229339 +0100 +++ gcc/simplify-rtx.cc 2025-12-13 23:04:14.672186706 +0100 @@ -6509,8 +6509,9 @@ simplify_context::simplify_relational_op /* only enters if op1 is 0 */ /* Verify IOR operand is NE */ && GET_CODE (XEXP (op0, 0)) == NE + && GET_MODE (XEXP (XEXP (op0, 0), 0)) == cmp_mode /* Verify second NE operand is 0 */ - && XEXP (XEXP (op0, 0), 1) == CONST0_RTX (mode)) + && XEXP (XEXP (op0, 0), 1) == CONST0_RTX (cmp_mode)) { rtx t = gen_rtx_IOR (cmp_mode, XEXP (XEXP (op0, 0), 0), XEXP (op0, 1)); t = gen_rtx_fmt_ee (code, mode, t, CONST0_RTX (mode)); --- gcc/testsuite/gcc.dg/pr123114.c.jj 2025-12-13 23:13:53.528178273 +0100 +++ gcc/testsuite/gcc.dg/pr123114.c 2025-12-13 23:13:25.964657498 +0100 @@ -0,0 +1,21 @@ +/* PR rtl-optimization/123114 */ +/* { dg-do compile } */ +/* { dg-options "-O3 -fno-tree-vrp" } */ + +volatile int a, b, g; +unsigned short e; +int f; + +int +main () +{ + int c, d; + while (a) + { + c = e = b << 2; + d = f; + g = (c <= 0 && d) || c ? 0 : d; + a = g; + } + return 0; +} Going to test on x86_64-linux/i686-linux momentarily.
