Created attachment 48025 [details] reduced reprocase g++ -c -O2 builtins-string.ii during GIMPLE pass: pre builtins-string.ii: In function ‘void as()’: builtins-string.ii:100:6: internal compiler error: in set_ptr_info_alignment, at tree-ssanames.c:671 100 | void as() { al j(&h); } | ^~ 0xbd95d1 set_ptr_info_alignment(ptr_info_def*, unsigned int, unsigned int) /usr/src/debug/sys-devel/gcc-9.2.0-r4/gcc-9.2.0/gcc/tree-ssanames.c:671 0xba3b58 create_expression_by_pieces /usr/src/debug/sys-devel/gcc-9.2.0-r4/gcc-9.2.0/gcc/tree-ssa-pre.c:2814 0x15f8b50 do_hoist_insertion /usr/src/debug/sys-devel/gcc-9.2.0-r4/gcc-9.2.0/gcc/tree-ssa-pre.c:3577 0x15f8b50 insert_aux /usr/src/debug/sys-devel/gcc-9.2.0-r4/gcc-9.2.0/gcc/tree-ssa-pre.c:3652 0x15f826f insert_aux /usr/src/debug/sys-devel/gcc-9.2.0-r4/gcc-9.2.0/gcc/tree-ssa-pre.c:3659 0x191d160 insert /usr/src/debug/sys-devel/gcc-9.2.0-r4/gcc-9.2.0/gcc/tree-ssa-pre.c:3682 0x191d160 execute /usr/src/debug/sys-devel/gcc-9.2.0-r4/gcc-9.2.0/gcc/tree-ssa-pre.c:4220 Reproduced on 8.3.0, 8.4.0, 9.2.0 Can't reproduce on 7.3.0, 7.4.0, 10.0 -O1 is okay; -O2 causes crash. Source is reduced from chromium-81/v8/src/builtins/builtins-string.cc
I wonder if this is a latent bug in GCC 10.
Likely - mine.
From /* There's no CCP pass after PRE which would re-compute alignment information so make sure we re-materialize this here. */ if (gimple_call_builtin_p (call, BUILT_IN_ASSUME_ALIGNED) && args.length () - 2 <= 1 && tree_fits_uhwi_p (args[1]) && (args.length () != 3 || tree_fits_uhwi_p (args[2]))) { unsigned HOST_WIDE_INT halign = tree_to_uhwi (args[1]); unsigned HOST_WIDE_INT hmisalign = args.length () == 3 ? tree_to_uhwi (args[2]) : 0; if ((halign & (halign - 1)) == 0 && (hmisalign & ~(halign - 1)) == 0) set_ptr_info_alignment (get_ptr_info (forcedname), halign, hmisalign); } where set_ptr_info_alignment ICEs for align == 0. set_ptr_info_alignment takes unsigned int args but the above computes HWI quantities that get truncated here.
So, either we can set the alignment to (unsigned) INT_MAX + 1 in that case, or throw the info away. Doesn't seem to be useful to enlarge ptr_info_def because of this. Perhaps the set_ptr_info_alignment could take unsigned HOST_WIDE_INT argument and do this saturation inside of it.
E.g. in tree-ssa-ccp.c, we drop very large alignments on the floor. /* Trailing mask bits specify the alignment, trailing value bits the misalignment. */ tem = val->mask.to_uhwi (); align = least_bit_hwi (tem); int * foo (int *p) { p = (int *) ((__UINTPTR_TYPE__) p & 0xfffffff000000000ULL); (*p)++; return p; } because tem is unsigned int and so will be 0, align 0 too and so align > 1 will not be true.
The patch in testing does the same as CCP. I agree that we possibly want saturation behavior but that can be done separately for GCC 11.
Fixed everywhere.
commit r8-10122-g8c55e44368d639849b28484f2c7842f4265b33c8 Author: Richard Biener <rguenther@suse.de> Date: Fri Mar 13 13:56:26 2020 +0100 tree-optimization/94163 constrain alignment set by PRE This avoids HWI -> unsigned truncation to end up with zero alignment which set_ptr_info_alignment ICEs on. 2020-03-13 Richard Biener <rguenther@suse.de> PR tree-optimization/94163 * tree-ssa-pre.c (create_expression_by_pieces): Check whether alignment would be zero.
commit r9-8373-gdb3584552871c8caccdc22e97ea1573da9458253 Author: Richard Biener <rguenther@suse.de> Date: Fri Mar 13 13:56:26 2020 +0100 tree-optimization/94163 constrain alignment set by PRE This avoids HWI -> unsigned truncation to end up with zero alignment which set_ptr_info_alignment ICEs on. 2020-03-13 Richard Biener <rguenther@suse.de> PR tree-optimization/94163 * tree-ssa-pre.c (create_expression_by_pieces): Check whether alignment would be zero.
commit r10-7158-g3604480a6fe493c51d6ebd53d9b1abeebbbb828f Author: Richard Biener <rguenther@suse.de> Date: Fri Mar 13 13:56:26 2020 +0100 tree-optimization/94163 constrain alignment set by PRE This avoids HWI -> unsigned truncation to end up with zero alignment which set_ptr_info_alignment ICEs on. 2020-03-13 Richard Biener <rguenther@suse.de> PR tree-optimization/94163 * tree-ssa-pre.c (create_expression_by_pieces): Check whether alignment would be zero.