Bug 110332 - [14 regression] ICE in dominated_by_p when building LLVM with -O3
Summary: [14 regression] ICE in dominated_by_p when building LLVM with -O3
Alias: None
Product: gcc
Classification: Unclassified
Component: tree-optimization (show other bugs)
Version: 14.0
: P3 normal
Target Milestone: 14.0
Assignee: Richard Biener
Keywords: ice-on-valid-code
Depends on:
Reported: 2023-06-21 04:57 UTC by Sam James
Modified: 2023-06-22 09:55 UTC (History)
3 users (show)

See Also:
Known to work:
Known to fail:
Last reconfirmed: 2023-06-21 00:00:00

SplitKit.ii.xz (518.24 KB, application/x-xz)
2023-06-21 04:57 UTC, Sam James
reduced.ii (581 bytes, text/plain)
2023-06-21 16:57 UTC, Sam James

Note You need to log in before you can comment on or make changes to this bug.
Description Sam James 2023-06-21 04:57:50 UTC
Created attachment 55377 [details]

# /usr/bin/aarch64-unknown-linux-gnu-g++ -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -I/var/tmp/portage/sys-devel/llvm-16.0.6/work/llvm_build-.arm64/lib/CodeGen -I/var/tmp/portage/sys-devel/llvm-16.0.6/work/llvm/lib/CodeGen -I/var/tmp/portage/sys-devel/llvm-16.0.6/work/llvm_build-.arm64/include -I/var/tmp/portage/sys-devel/llvm-16.0.6/work/llvm/include  -DNDEBUG -O3 -pipe -mcpu=native -fdiagnostics-color=always -fPIC -fno-semantic-interposition -fvisibility-inlines-hidden -Werror=date-time -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wno-missing-field-initializers -pedantic -Wno-long-long -Wimplicit-fallthrough -Wno-maybe-uninitialized -Wno-class-memaccess -Wno-redundant-move -Wno-pessimizing-move -Wno-noexcept-type -Wdelete-non-virtual-dtor -Wsuggest-override -Wno-comment -Wno-misleading-indentation -Wctad-maybe-unsupported -fdiagnostics-color -ffunction-sections -fdata-sections -std=c++17 -fdiagnostics-color=always -c /var/tmp/portage/sys-devel/llvm-16.0.6/work/llvm/lib/CodeGen/SplitKit.cpp -save-temps
aarch64-unknown-linux-gnu-g++: warning: ‘-pipe’ ignored because ‘-save-temps’ specified
during GIMPLE pass: phiprop
/var/tmp/portage/sys-devel/llvm-16.0.6/work/llvm/lib/CodeGen/SplitKit.cpp: In member function ‘bool llvm::SplitEditor::transferValues()’:
/var/tmp/portage/sys-devel/llvm-16.0.6/work/llvm/lib/CodeGen/SplitKit.cpp:1888:1: internal compiler error: Segmentation fault
 1888 | }
      | ^
0xaaaab5e4625f crash_signal
0xaaaab58a4ec8 dominated_by_p(cdi_direction, basic_block_def const*, basic_block_def const*)
0xaaaab603cd8f propagate_with_phi
0xaaaab603cd8f execute
Please submit a full bug report, with preprocessed source (by using -freport-bug).
Please include the complete backtrace with any bug report.
See <https://bugs.gentoo.org/> for instructions.

gcc (Gentoo 14.0.0 p, commit 6cb33e2f39e289ec4f25f845d8153053147c5c49) 14.0.0 20230620 (experimental) f5d0cec170d6d5496edf4038499d288c07d79b18
Copyright (C) 2023 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
Comment 1 Sam James 2023-06-21 04:59:38 UTC
g++ -O3 -c ... is enough to repro
Comment 2 Andrew Pinski 2023-06-21 05:07:28 UTC
Either r14-1981 or r14-1951
Comment 3 Andrew Pinski 2023-06-21 05:19:53 UTC
Reducing ...
Comment 4 Richard Biener 2023-06-21 08:36:30 UTC
possibly edge insertions with virtual operands confuse the machinery
Comment 5 Sam James 2023-06-21 16:57:06 UTC
Created attachment 55379 [details]
Comment 6 Sergei Trofimovich 2023-06-21 17:05:29 UTC
I think I see the same ICE on llvm-12 and r14-2009-g864c6471bdc6cd:

cvise produced this thing:

// $ cat a.cpp.cpp
struct SlotIndex { int lie; };
SlotIndex si7, si8;

unsigned u9, u6;
bool b3, b4;
unsigned &value() {
  return b4 ? u6 : u9;
void transferValues() {
  unsigned RegIdx;
  SlotIndex End;
  RegIdx = value();
  End = b3 ? si7 : si8;

$ g++ -O3  -c a.cpp.cpp -o a.o
during GIMPLE pass: phiprop
a.cpp.cpp: In function 'void transferValues()':
a.cpp.cpp:14:1: internal compiler error: Segmentation fault
   14 | }
      | ^
0x1d74824 diagnostic_impl(rich_location*, diagnostic_metadata const*, int, char const*, __va_list_tag (*) [1], diagnostic_t)
0x1d74d97 internal_error(char const*, ...)
0xe9bfdf crash_signal(int)
0xa851da dominated_by_p(cdi_direction, basic_block_def const*, basic_block_def const*)
0x102096b (anonymous namespace)::pass_phiprop::execute(function*)

$ g++  -v
Using built-in specs.
Target: x86_64-unknown-linux-gnu
Configured with: 
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 14.0.0 99999999 (experimental) (GCC)
Comment 7 Andrew Pinski 2023-06-21 17:11:51 UTC
Reduced C testcase:
struct s { int lie; };
struct s si7, si8;
unsigned u9, u6;
_Bool b3, b4;
unsigned transferValues(struct s *End) {
  unsigned RegIdx;
  unsigned *t = b4 ? &u6 : &u9;
  RegIdx = *t;
  *End = *(b3 ? &si7 : &si8);
  return RegIdx;
Comment 8 Andrew Pinski 2023-06-21 20:55:01 UTC
(In reply to Andrew Pinski from comment #7)
Another one reduced C testcase, very similar to the previous one but slightly more reduced:
_Bool a;
struct s { int t; } c, d;
unsigned e, f;
unsigned transferValues(struct s *End) {
  unsigned RegIdx = *(a ? &e : &f);
  *End = *(a ? &c : &d);
  return RegIdx;
Comment 9 Sergei Trofimovich 2023-06-22 06:08:35 UTC
(In reply to Andrew Pinski from comment #2)
> Either r14-1981 or r14-1951

Reverting r14-1981-g85107abeb71bbf restores llvm-12 build for me.
Comment 10 Richard Biener 2023-06-22 06:40:24 UTC
Comment 11 GCC Commits 2023-06-22 08:14:21 UTC
The master branch has been updated by Richard Biener <rguenth@gcc.gnu.org>:


commit r14-2031-g2ac41866270e9fbab504bbda7a942a97abaa203a
Author: Richard Biener <rguenther@suse.de>
Date:   Thu Jun 22 09:04:01 2023 +0200

    tree-optimization/110332 - fix ICE with phiprop
    The following fixes an ICE that occurs when we visit an edge
    inserted load from the code validating correctness for inserting
    an aggregate copy there.  We can simply skip those loads here.
            PR tree-optimization/110332
            * tree-ssa-phiprop.cc (propagate_with_phi): Always
            check aliasing with edge inserted loads.
            * g++.dg/torture/pr110332.C: New testcase.
            * gcc.dg/torture/pr110332-1.c: Likewise.
            * gcc.dg/torture/pr110332-2.c: Likewise.
Comment 12 Richard Biener 2023-06-22 08:14:42 UTC
Comment 13 Sergei Trofimovich 2023-06-22 09:55:32 UTC
The fix fixes llvm-12 build for me. Thank you!