Affects versions down to at least r5 : $ cat z1.c #define vector __attribute__((vector_size(16))) int f () { vector int a = {0, 0, 0, 0}; vector int b = {1, 0, 0, 0}; return (a & (1 << b)) != 0; } $ gcc-11-20210221 -c z1.c z1.c: In function 'f': z1.c:6:3: internal compiler error: in wide_int_to_tree_1, at tree.c:1644 6 | return (a & (1 << b)) != 0; | ^~~~~~ 0xde3e1e wide_int_to_tree_1 ../../gcc/tree.c:1644 0xde433b wide_int_to_tree(tree_node*, poly_int<1u, generic_wide_int<wide_int_ref_storage<false, true> > > const&) ../../gcc/tree.c:1756 0xde433b build_int_cst(tree_node*, poly_int<1u, long>) ../../gcc/tree.c:1396 0x8945ea fold_binary_loc(unsigned int, tree_code, tree_node*, tree_node*, tree_node*) ../../gcc/fold-const.c:12048 0x894caa fold_build2_loc(unsigned int, tree_code, tree_node*, tree_node*, tree_node*) ../../gcc/fold-const.c:13715 0x69e80b c_fully_fold_internal ../../gcc/c/c-fold.c:371 0x69e00d c_fully_fold_internal ../../gcc/c/c-fold.c:623 0x69f0a9 c_fully_fold(tree_node*, bool, bool*, bool) ../../gcc/c/c-fold.c:125 0x65c2cd c_finish_return(unsigned int, tree_node*, tree_node*) ../../gcc/c/c-typeck.c:10742 0x6918b6 c_parser_statement_after_labels ../../gcc/c/c-parser.c:6162 0x69339a c_parser_compound_statement_nostart ../../gcc/c/c-parser.c:5788 0x693c13 c_parser_compound_statement ../../gcc/c/c-parser.c:5597 0x6954c8 c_parser_declaration_or_fndef ../../gcc/c/c-parser.c:2539 0x69c337 c_parser_external_declaration ../../gcc/c/c-parser.c:1777 0x69ce59 c_parser_translation_unit ../../gcc/c/c-parser.c:1650 0x69ce59 c_parse_file() ../../gcc/c/c-parser.c:21984 0x6eccc2 c_common_parse_file() ../../gcc/c-family/c-opts.c:1218
ICEs since r0-119394-ga212e43fca22f730987ad4d15a0bd58efae9677e , before that it has been rejected.
Created attachment 50244 [details] gcc11-pr99225.patch Untested fix.
The master branch has been updated by Jakub Jelinek <jakub@gcc.gnu.org>: https://gcc.gnu.org/g:6e646abbe02f2c79cc3ba1f3de705ee62ff9dcd1 commit r11-7356-g6e646abbe02f2c79cc3ba1f3de705ee62ff9dcd1 Author: Jakub Jelinek <jakub@redhat.com> Date: Wed Feb 24 12:10:25 2021 +0100 fold-const: Fix up ((1 << x) & y) != 0 folding for vectors [PR99225] This optimization was written purely with scalar integers in mind, can work fine even with vectors, but we can't use build_int_cst but need to use build_one_cst instead. 2021-02-24 Jakub Jelinek <jakub@redhat.com> PR tree-optimization/99225 * fold-const.c (fold_binary_loc) <case NE_EXPR>: In (x & (1 << y)) != 0 to ((x >> y) & 1) != 0 simplifications use build_one_cst instead of build_int_cst (..., 1). Formatting fixes. * gcc.c-torture/compile/pr99225.c: New test.
Fixed on the trunk so far.
The releases/gcc-10 branch has been updated by Jakub Jelinek <jakub@gcc.gnu.org>: https://gcc.gnu.org/g:4de402ab60c54fff48cb7371644b024d10d7e5bb commit r10-9476-g4de402ab60c54fff48cb7371644b024d10d7e5bb Author: Jakub Jelinek <jakub@redhat.com> Date: Wed Feb 24 12:10:25 2021 +0100 fold-const: Fix up ((1 << x) & y) != 0 folding for vectors [PR99225] This optimization was written purely with scalar integers in mind, can work fine even with vectors, but we can't use build_int_cst but need to use build_one_cst instead. 2021-02-24 Jakub Jelinek <jakub@redhat.com> PR tree-optimization/99225 * fold-const.c (fold_binary_loc) <case NE_EXPR>: In (x & (1 << y)) != 0 to ((x >> y) & 1) != 0 simplifications use build_one_cst instead of build_int_cst (..., 1). Formatting fixes. * gcc.c-torture/compile/pr99225.c: New test. (cherry picked from commit 6e646abbe02f2c79cc3ba1f3de705ee62ff9dcd1)
Fixed for 10.3 too.
The releases/gcc-9 branch has been updated by Jakub Jelinek <jakub@gcc.gnu.org>: https://gcc.gnu.org/g:7c9f7293c995b662457b4e7aba97a6faa4d86dc5 commit r9-9426-g7c9f7293c995b662457b4e7aba97a6faa4d86dc5 Author: Jakub Jelinek <jakub@redhat.com> Date: Wed Feb 24 12:10:25 2021 +0100 fold-const: Fix up ((1 << x) & y) != 0 folding for vectors [PR99225] This optimization was written purely with scalar integers in mind, can work fine even with vectors, but we can't use build_int_cst but need to use build_one_cst instead. 2021-02-24 Jakub Jelinek <jakub@redhat.com> PR tree-optimization/99225 * fold-const.c (fold_binary_loc) <case NE_EXPR>: In (x & (1 << y)) != 0 to ((x >> y) & 1) != 0 simplifications use build_one_cst instead of build_int_cst (..., 1). Formatting fixes. * gcc.c-torture/compile/pr99225.c: New test. (cherry picked from commit 4de402ab60c54fff48cb7371644b024d10d7e5bb)
The releases/gcc-8 branch has been updated by Jakub Jelinek <jakub@gcc.gnu.org>: https://gcc.gnu.org/g:cf570d10449a35fe4f5e45db087a527eefd0dcf3 commit r8-10891-gcf570d10449a35fe4f5e45db087a527eefd0dcf3 Author: Jakub Jelinek <jakub@redhat.com> Date: Wed Feb 24 12:10:25 2021 +0100 fold-const: Fix up ((1 << x) & y) != 0 folding for vectors [PR99225] This optimization was written purely with scalar integers in mind, can work fine even with vectors, but we can't use build_int_cst but need to use build_one_cst instead. 2021-02-24 Jakub Jelinek <jakub@redhat.com> PR tree-optimization/99225 * fold-const.c (fold_binary_loc) <case NE_EXPR>: In (x & (1 << y)) != 0 to ((x >> y) & 1) != 0 simplifications use build_one_cst instead of build_int_cst (..., 1). Formatting fixes. * gcc.c-torture/compile/pr99225.c: New test. (cherry picked from commit 4de402ab60c54fff48cb7371644b024d10d7e5bb)
Fixed.