https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103314
--- Comment #5 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Simplified testcase:
int main() {
unsigned c = 0, d = c ? 1 ^ c ^ 1 >> (-1) : 0;
return c;
}
The problem is we get:
#3 0x0000000000b5aa2d in fold_binary_loc(unsigned int, tree_code, tree_node*,
tree_node*, tree_node*) () at
/home/apinski/src/upstream-gcc/gcc/gcc/fold-const.c:10822
10822 tem = generic_simplify (loc, code, type, op0, op1);
$1 = void
(gdb) p debug_generic_expr(op0)
(unsigned int) (1 >> -1)
$2 = void
(gdb) p debug_generic_expr(op1)
1
$3 = void
(gdb) op code
Undefined command: "op". Try "help".
(gdb) p code
$4 = BIT_XOR_EXPR
Which we produce:
(unsigned int) ((1 >> -1) ^ 1)
But the code in fold_binary_loc comes a long and decides we should
reassociative this and it just goes back and forth or deciding which is
correct.
So doing this instead:
TYPE_PRECISION (TREE_TYPE (@0)) < TYPE_PRECISION (type)
|| (GIMPLE && TYPE_PRECISION (TREE_TYPE (@0)) == TYPE_PRECISION
(type))
Fixes the problem and we should not run into the back and forth issue.