gcc-10.0.1-alpha20200301 snapshot (g:151bf47e78f5d919f6cc591d11cc1f6aff61078f) ICEs when compiling the following testcase w/ -O2 -ftrapv: void tt (int *ga, int *p6, int *s7, long int ut) { while (p6 + ut > s7) { ga[ut] = 0; --ut; } } % gcc-10.0.1 -O2 -ftrapv -c eipsxtfv.c during GIMPLE pass: ldist eipsxtfv.c: In function 'tt': eipsxtfv.c:6:14: internal compiler error: in gimplify_modify_expr, at gimplify.c:5936 6 | ga[ut] = 0; | ~~~~~~~^~~ 0x64695a gimplify_modify_expr /var/tmp/portage/sys-devel/gcc-10.0.1_alpha20200301/work/gcc-10-20200301/gcc/gimplify.c:5936 0xad681a gimplify_expr(tree_node**, gimple**, gimple**, bool (*)(tree_node*), int) /var/tmp/portage/sys-devel/gcc-10.0.1_alpha20200301/work/gcc-10-20200301/gcc/gimplify.c:13602 0xad9f96 gimplify_stmt(tree_node**, gimple**) /var/tmp/portage/sys-devel/gcc-10.0.1_alpha20200301/work/gcc-10-20200301/gcc/gimplify.c:6823 0xaec9ed gimplify_cond_expr /var/tmp/portage/sys-devel/gcc-10.0.1_alpha20200301/work/gcc-10-20200301/gcc/gimplify.c:4240 0xad6d22 gimplify_expr(tree_node**, gimple**, gimple**, bool (*)(tree_node*), int) /var/tmp/portage/sys-devel/gcc-10.0.1_alpha20200301/work/gcc-10-20200301/gcc/gimplify.c:13559 0xad9f96 gimplify_stmt(tree_node**, gimple**) /var/tmp/portage/sys-devel/gcc-10.0.1_alpha20200301/work/gcc-10-20200301/gcc/gimplify.c:6823 0xaec6d6 gimplify_cond_expr /var/tmp/portage/sys-devel/gcc-10.0.1_alpha20200301/work/gcc-10-20200301/gcc/gimplify.c:4137 0xad6d22 gimplify_expr(tree_node**, gimple**, gimple**, bool (*)(tree_node*), int) /var/tmp/portage/sys-devel/gcc-10.0.1_alpha20200301/work/gcc-10-20200301/gcc/gimplify.c:13559 0xad6648 gimplify_expr(tree_node**, gimple**, gimple**, bool (*)(tree_node*), int) /var/tmp/portage/sys-devel/gcc-10.0.1_alpha20200301/work/gcc-10-20200301/gcc/gimplify.c:14369 0xad6cce gimplify_expr(tree_node**, gimple**, gimple**, bool (*)(tree_node*), int) /var/tmp/portage/sys-devel/gcc-10.0.1_alpha20200301/work/gcc-10-20200301/gcc/gimplify.c:14309 0xaf09d0 force_gimple_operand_1(tree_node*, gimple**, bool (*)(tree_node*), tree_node*) /var/tmp/portage/sys-devel/gcc-10.0.1_alpha20200301/work/gcc-10-20200301/gcc/gimplify-me.c:78 0xaf0b1d force_gimple_operand_gsi_1(gimple_stmt_iterator*, tree_node*, bool (*)(tree_node*), tree_node*, bool, gsi_iterator_update) /var/tmp/portage/sys-devel/gcc-10.0.1_alpha20200301/work/gcc-10-20200301/gcc/gimplify-me.c:115 0xaf0b1d force_gimple_operand_gsi(gimple_stmt_iterator*, tree_node*, bool, tree_node*, bool, gsi_iterator_update) /var/tmp/portage/sys-devel/gcc-10.0.1_alpha20200301/work/gcc-10-20200301/gcc/gimplify-me.c:141 0xe2b216 generate_memset_builtin /var/tmp/portage/sys-devel/gcc-10.0.1_alpha20200301/work/gcc-10-20200301/gcc/tree-loop-distribution.c:1155 0xe2b216 generate_code_for_partition /var/tmp/portage/sys-devel/gcc-10.0.1_alpha20200301/work/gcc-10-20200301/gcc/tree-loop-distribution.c:1329 0xe2b216 loop_distribution::distribute_loop(loop*, vec<gimple*, va_heap, vl_ptr>, control_dependences*, int*, bool*, bool) /var/tmp/portage/sys-devel/gcc-10.0.1_alpha20200301/work/gcc-10-20200301/gcc/tree-loop-distribution.c:3105 0xe2cad3 loop_distribution::execute(function*) /var/tmp/portage/sys-devel/gcc-10.0.1_alpha20200301/work/gcc-10-20200301/gcc/tree-loop-distribution.c:3294 0xe2cffb execute /var/tmp/portage/sys-devel/gcc-10.0.1_alpha20200301/work/gcc-10-20200301/gcc/tree-loop-distribution.c:3382
Started with r10-619-g5879ab5fafedc8f6f9bfe95a4cf8501b0df90edd only because that enabled -ftree-loop-distribute-patterns at -O2. With -O2 -ftrapv -ftree-loop-distribute-patterns it started with r0-127193-gb83b550780a6ee31c6e8b9da922c2a087f7bd44c. Guess we need to add rewrite_to_non_trapping_overflow somewhere.
Created attachment 48004 [details] gcc10-pr94114.patch Untested fix.
commit r10-7120-g05ac4d9c7b336e30413dd80c3630981151499f9e Author: Jakub Jelinek <jakub@redhat.com> Date: Wed Mar 11 09:32:22 2020 +0100 ldist: Further fixes for -ftrapv [PR94114] As the testcase shows, arithmetics that for -ftrapv would need multiple basic blocks can show up not just in nb_bytes expressions where we are calling rewrite_to_non_trapping_overflow for a while already, but also in the pointer expression to the start of the region. While the testcase covers just the first hunk and I've failed to create a testcase for the latter, it is at least in theory possible too, so I've adjusted that hunk too. 2020-03-11 Jakub Jelinek <jakub@redhat.com> PR tree-optimization/94114 * tree-loop-distribution.c (generate_memset_builtin): Call rewrite_to_non_trapping_overflow even on mem. (generate_memcpy_builtin): Call rewrite_to_non_trapping_overflow even on dest and src. * gcc.dg/pr94114.c: New test.
The releases/gcc-9 branch has been updated by Jakub Jelinek <jakub@gcc.gnu.org>: https://gcc.gnu.org/g:2fd27691f213f2e808626c4cd492b00c801a00fa commit r9-8388-g2fd27691f213f2e808626c4cd492b00c801a00fa Author: Jakub Jelinek <jakub@redhat.com> Date: Wed Mar 11 09:32:22 2020 +0100 ldist: Further fixes for -ftrapv [PR94114] As the testcase shows, arithmetics that for -ftrapv would need multiple basic blocks can show up not just in nb_bytes expressions where we are calling rewrite_to_non_trapping_overflow for a while already, but also in the pointer expression to the start of the region. While the testcase covers just the first hunk and I've failed to create a testcase for the latter, it is at least in theory possible too, so I've adjusted that hunk too. 2020-03-11 Jakub Jelinek <jakub@redhat.com> PR tree-optimization/94114 * tree-loop-distribution.c (generate_memset_builtin): Call rewrite_to_non_trapping_overflow even on mem. (generate_memcpy_builtin): Call rewrite_to_non_trapping_overflow even on dest and src. * gcc.dg/pr94114.c: New test.
Fixed for 9.4+ too.
The releases/gcc-8 branch has been updated by Jakub Jelinek <jakub@gcc.gnu.org>: https://gcc.gnu.org/g:8d5332862e86edb92f27bd136ccd9fdba3524039 commit r8-10459-g8d5332862e86edb92f27bd136ccd9fdba3524039 Author: Jakub Jelinek <jakub@redhat.com> Date: Wed Mar 11 09:32:22 2020 +0100 ldist: Further fixes for -ftrapv [PR94114] As the testcase shows, arithmetics that for -ftrapv would need multiple basic blocks can show up not just in nb_bytes expressions where we are calling rewrite_to_non_trapping_overflow for a while already, but also in the pointer expression to the start of the region. While the testcase covers just the first hunk and I've failed to create a testcase for the latter, it is at least in theory possible too, so I've adjusted that hunk too. 2020-03-11 Jakub Jelinek <jakub@redhat.com> PR tree-optimization/94114 * tree-loop-distribution.c (generate_memset_builtin): Call rewrite_to_non_trapping_overflow even on mem. (generate_memcpy_builtin): Call rewrite_to_non_trapping_overflow even on dest and src. * gcc.dg/pr94114.c: New test. (cherry picked from commit 2fd27691f213f2e808626c4cd492b00c801a00fa)
Fixed for 8.5 too.