Bug 94163 - [8/9 Regression] ICE in set_ptr_info_alignment with -O2 and __builtin_assume_aligned
Summary: [8/9 Regression] ICE in set_ptr_info_alignment with -O2 and __builtin_assume_...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: tree-optimization (show other bugs)
Version: 9.2.0
: P2 normal
Target Milestone: 8.5
Assignee: Richard Biener
URL:
Keywords: ice-on-valid-code
Depends on:
Blocks:
 
Reported: 2020-03-13 06:40 UTC by Slava Barinov
Modified: 2020-03-13 14:07 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work: 10.0, 7.3.0, 7.4.0
Known to fail: 8.3.0, 8.4.0, 9.2.0
Last reconfirmed: 2020-03-13 00:00:00


Attachments
reduced reprocase (703 bytes, text/x-modelica)
2020-03-13 06:40 UTC, Slava Barinov
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Slava Barinov 2020-03-13 06:40:27 UTC
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
Comment 1 Andrew Pinski 2020-03-13 07:09:58 UTC
I wonder if this is a latent bug in GCC 10.
Comment 2 Richard Biener 2020-03-13 07:28:04 UTC
Likely - mine.
Comment 3 Richard Biener 2020-03-13 07:30:09 UTC
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.
Comment 4 Jakub Jelinek 2020-03-13 08:43:48 UTC
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.
Comment 5 Jakub Jelinek 2020-03-13 08:51:41 UTC
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.
Comment 6 Richard Biener 2020-03-13 09:13:34 UTC
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.
Comment 7 Richard Biener 2020-03-13 13:00:52 UTC
Fixed everywhere.
Comment 8 Martin Liška 2020-03-13 14:07:18 UTC
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.
Comment 9 Martin Liška 2020-03-13 14:07:28 UTC
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.
Comment 10 Martin Liška 2020-03-13 14:07:36 UTC
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.