Bug 107997 - [10/11/12/13 Regression] r13-4389-gfd8dd6c0384969 probably uncovered an issue building the Linux kernel
Summary: [10/11/12/13 Regression] r13-4389-gfd8dd6c0384969 probably uncovered an issue...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: tree-optimization (show other bugs)
Version: 13.0
: P3 normal
Target Milestone: 10.5
Assignee: Jakub Jelinek
URL:
Keywords: ice-checking, ice-on-valid-code
Depends on:
Blocks:
 
Reported: 2022-12-06 22:24 UTC by Jan-Benedict Glaw
Modified: 2023-05-04 07:22 UTC (History)
4 users (show)

See Also:
Host:
Target: x86_64-linux-gnu powerpc64-linux
Build:
Known to work: 9.1.0
Known to fail: 10.1.0, 11.1.0, 12.2.0
Last reconfirmed: 2022-12-08 00:00:00


Attachments
Original preprocessed source (156.27 KB, application/gzip)
2022-12-08 18:47 UTC, Jan-Benedict Glaw
Details
Reduced testcase (cvise) (223 bytes, text/plain)
2022-12-08 18:47 UTC, Jan-Benedict Glaw
Details
gcc13-pr107997.patch (878 bytes, patch)
2022-12-09 13:49 UTC, Jakub Jelinek
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Jan-Benedict Glaw 2022-12-06 22:24:13 UTC
Hi!

Starting with commit fd8dd6c0384969170e594be34da278a072d5eb76, I see
Linux kernel build errors for the skiroot_defconfig:

[mk all 2022-12-05 19:50:10]   powerpc64-linux-gcc -Wp,-MMD,drivers/dma-buf/.dma-fence-array.o.d -nostdinc -I./arch/powerpc/include -I./arch/powerpc/include/generated  -I./include -I./arch/po
werpc/include/uapi -I./arch/powerpc/include/generated/uapi -I./include/uapi -I./include/generated/uapi -include ./include/linux/compiler-version.h -include ./include/linux/kconfig.h -include 
./include/linux/compiler_types.h -D__KERNEL__ -I ./arch/powerpc -DHAVE_AS_ATHIGH=1 -fmacro-prefix-map=./= -Wall -Wundef -Werror=strict-prototypes -Wno-trigraphs -fno-strict-aliasing -fno-comm
on -fshort-wchar -fno-PIE -Werror=implicit-function-declaration -Werror=implicit-int -Werror=return-type -Wno-format-security -std=gnu11 -mlittle-endian -m64 -msoft-float -pipe -mtraceback=no
 -mabi=elfv2 -mcmodel=medium -mno-pointers-to-nested-functions -mcpu=power8 -mtune=power10 -mno-prefixed -mno-pcrel -mno-altivec -mno-vsx -mno-mma -fno-asynchronous-unwind-tables -mno-string 
-Wa,-maltivec -Wa,-mpower4 -Wa,-many -mno-strict-align -mlittle-endian -mstack-protector-guard=tls -mstack-protector-guard-reg=r13 -fno-delete-null-pointer-checks -Wno-frame-address -Wno-form
at-truncation -Wno-format-overflow -Wno-address-of-packed-member -Os -fno-allow-store-data-races -Wframe-larger-than=2048 -fstack-protector-strong -Wno-main -Wno-unused-but-set-variable -Wno-
unused-const-variable -Wno-dangling-pointer -fomit-frame-pointer -ftrivial-auto-var-init=zero -fno-stack-clash-protection -Wdeclaration-after-statement -Wvla -Wno-pointer-sign -Wcast-function
-type -Wno-stringop-truncation -Wno-stringop-overflow -Wno-restrict -Wno-maybe-uninitialized -Wno-alloc-size-larger-than -Wimplicit-fallthrough=5 -fno-strict-overflow -fno-stack-check -fconse
rve-stack -Werror=date-time -Werror=incompatible-pointer-types -Werror=designated-init -Wno-packed-not-aligned -mstack-protector-guard-offset=2800    -DKBUILD_MODFILE='"drivers/dma-buf/dma-fe
nce-array"' -DKBUILD_BASENAME='"dma_fence_array"' -DKBUILD_MODNAME='"dma_fence_array"' -D__KBUILD_MODNAME=kmod_dma_fence_array -c -o drivers/dma-buf/dma-fence-array.o drivers/dma-buf/dma-fenc
e-array.c                                                                                                                                                                                      
[mk all 2022-12-05 19:50:10] drivers/dma-buf/dma-fence-array.c: In function 'dma_fence_array_create':                                                                                          
[mk all 2022-12-05 19:50:10] drivers/dma-buf/dma-fence-array.c:154:25: error: control flow in the middle of basic block 12                                                                     
[mk all 2022-12-05 19:50:10]   154 | struct dma_fence_array *dma_fence_array_create(int num_fences,                                                                                            
[mk all 2022-12-05 19:50:10]       |                         ^~~~~~~~~~~~~~~~~~~~~~                                                                                                            
[mk all 2022-12-05 19:50:10] during GIMPLE pass: ivopts                                                                                                                                        
[mk all 2022-12-05 19:50:10] drivers/dma-buf/dma-fence-array.c:154:25: internal compiler error: verify_flow_info failed                                                                        
[mk all 2022-12-05 19:50:10] 0x19ea876 internal_error(char const*, ...)                                                                                                                        
[mk all 2022-12-05 19:50:10]    ???:0                                                                                                                                                          
[mk all 2022-12-05 19:50:10] 0x94b00e verify_flow_info()                                                                                                                                       
[mk all 2022-12-05 19:50:10]    ???:0                                                                                                                                                          
[mk all 2022-12-05 19:50:10] Please submit a full bug report, with preprocessed source (by using -freport-bug).                                                                                
[mk all 2022-12-05 19:50:10] Please include the complete backtrace with any bug report.                                                                                                        
[mk all 2022-12-05 19:50:10] See <https://gcc.gnu.org/bugs/> for instructions.                                                                                                                 


(Cf. https://gcc.gnu.org/pipermail/gcc-patches/2022-December/607874.html)

I'll add the preprocessed sources.
Comment 1 Jakub Jelinek 2022-12-08 17:41:18 UTC
(In reply to Jan-Benedict Glaw from comment #0)
> I'll add the preprocessed sources.

Could you please?  Without it there isn't much that can be done.
Comment 2 Jan-Benedict Glaw 2022-12-08 18:07:56 UTC
(In reply to Jakub Jelinek from comment #1)
> (In reply to Jan-Benedict Glaw from comment #0)
> > I'll add the preprocessed sources.
> 
> Could you please?  Without it there isn't much that can be done.

At it right now, throwing it at cvise.
Comment 3 Jan-Benedict Glaw 2022-12-08 18:47:02 UTC
Created attachment 54048 [details]
Original preprocessed source
Comment 4 Jan-Benedict Glaw 2022-12-08 18:47:36 UTC
Created attachment 54049 [details]
Reduced testcase (cvise)
Comment 5 Jakub Jelinek 2022-12-08 18:55:26 UTC
Cleaned up, just -Os is needed:
int a, b;
void bar (int);
int baz (void);

void *
foo (int x, void *y)
{
  asm goto ("" : : "r" (x || !a) : : l);
l:
  if (y)
    return 0;
  bar (b ? b : x);
  while (x--)
    {
      if (!baz ())
	baz ();
      asm goto ("" : : : : l2);
    l2:
    }
  return y;
}
Comment 6 Jakub Jelinek 2022-12-08 19:18:13 UTC
create_new_iv is called with cand->pos being IP_END, where the last stmt of the body is asm goto.
  __asm__ __volatile__ goto("" :  :  :  : "l2" l2);
;;    succ:       13

;;   basic block 13, loop depth 1
;;    pred:       9
;;                12
  # x_4 = PHI <x_10(D)(9), x_14(12)>
l2:

As the label is in the same bb as fallthrough, the bb which ends with asm goto has just a single succ edge, but in order to insert something at the end of the latch bb,
we would need to create a new bb, move the label to it and insert the iv there.
I guess gsi_insert_on_edge_immediate should be able to handle that case, or
perhaps just detect when gsi_last_bb (ip_end_pos (data->current_loop))
is GIMPLE_ASM or better yet stmt_ends_bb_p and split_edge in that case?
Comment 7 Andrew Pinski 2022-12-08 19:22:29 UTC
With the reduced testcase in comment #5 (with a `;` add after `l2:` to allow compiling with older gcc), the ICE is there for GCC 10+ (with -fchecking).
GCC 9 didn't ICE nor did it place gimple after the `asm goto`.
Comment 8 Jakub Jelinek 2022-12-08 19:50:30 UTC
Indeed, and it started with r10-5288-g52dc9c32311e8ea4833b8865c0d3121cad03937d
but guess it has been latent before.
Comment 9 Jakub Jelinek 2022-12-09 13:49:21 UTC
Created attachment 54053 [details]
gcc13-pr107997.patch

Untested fix.
Comment 10 Jan-Benedict Glaw 2022-12-09 18:27:28 UTC
I gave that patch a try: GCC build is successful, as is the Linux build afterwards using that toolchain. (Cannot test the resulting kernel of course---I don't have the hardware.)
Comment 11 GCC Commits 2022-12-10 15:51:25 UTC
The master branch has been updated by Jakub Jelinek <jakub@gcc.gnu.org>:

https://gcc.gnu.org/g:7676235f690e624b7ed41a22b22ce8ccfac1492f

commit r13-4594-g7676235f690e624b7ed41a22b22ce8ccfac1492f
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Sat Dec 10 16:50:39 2022 +0100

    ivopts: Fix IP_END handling for asm goto [PR107997]
    
    The following testcase ICEs, because the latch bb ends with
    asm goto which has both fallthrough to the header and one or more labels
    in the header too.  In that case there is just a single edge out of the
    latch block, but still the asm goto is stmt_ends_bb_p statement, yet
    ivopts decides to emit an IV bump at the IP_END position and inserts
    it into the same bb as the asm goto after it, which then fails verification
    (control flow in the middle of bb).
    
    The following patch fixes it by splitting the latch -> header edge in that
    case and inserting into the newly created bb, where split_edge ->
    redirect_edge_and_branch is able to deal with this case correctly.
    
    2022-12-10  Jakub Jelinek  <jakub@redhat.com>
    
            PR tree-optimization/107997
            * tree-ssa-loop-ivopts.cc: Include cfganal.h.
            (create_new_iv) <case IP_END>: If ip_end_pos bb is non-empty and ends
            with a stmt which ends bb, instead of adding iv update after it split
            the latch edge and insert iterator into the new latch bb.
    
            * gcc.c-torture/compile/pr107997.c: New test.
Comment 12 Jan-Benedict Glaw 2022-12-14 10:33:50 UTC
Fixed with that commit. There is a similar unrelated (PR108095), but that's got its own ticket.
Comment 13 GCC Commits 2023-02-10 17:44:21 UTC
The releases/gcc-12 branch has been updated by Jakub Jelinek <jakub@gcc.gnu.org>:

https://gcc.gnu.org/g:89daf0dd6f1748077c03fbeb27ca5980a0b9abd5

commit r12-9125-g89daf0dd6f1748077c03fbeb27ca5980a0b9abd5
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Sat Dec 10 16:50:39 2022 +0100

    ivopts: Fix IP_END handling for asm goto [PR107997]
    
    The following testcase ICEs, because the latch bb ends with
    asm goto which has both fallthrough to the header and one or more labels
    in the header too.  In that case there is just a single edge out of the
    latch block, but still the asm goto is stmt_ends_bb_p statement, yet
    ivopts decides to emit an IV bump at the IP_END position and inserts
    it into the same bb as the asm goto after it, which then fails verification
    (control flow in the middle of bb).
    
    The following patch fixes it by splitting the latch -> header edge in that
    case and inserting into the newly created bb, where split_edge ->
    redirect_edge_and_branch is able to deal with this case correctly.
    
    2022-12-10  Jakub Jelinek  <jakub@redhat.com>
    
            PR tree-optimization/107997
            * tree-ssa-loop-ivopts.cc: Include cfganal.h.
            (create_new_iv) <case IP_END>: If ip_end_pos bb is non-empty and ends
            with a stmt which ends bb, instead of adding iv update after it split
            the latch edge and insert iterator into the new latch bb.
    
            * gcc.c-torture/compile/pr107997.c: New test.
    
    (cherry picked from commit 7676235f690e624b7ed41a22b22ce8ccfac1492f)
Comment 14 Jakub Jelinek 2023-02-10 17:58:18 UTC
Fixed for gcc 12.3 too.
Comment 15 GCC Commits 2023-05-02 20:12:35 UTC
The releases/gcc-11 branch has been updated by Jakub Jelinek <jakub@gcc.gnu.org>:

https://gcc.gnu.org/g:5a0fd69bb3aa1709f0bea5d6b91fb30ca226c1ed

commit r11-10687-g5a0fd69bb3aa1709f0bea5d6b91fb30ca226c1ed
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Sat Dec 10 16:50:39 2022 +0100

    ivopts: Fix IP_END handling for asm goto [PR107997]
    
    The following testcase ICEs, because the latch bb ends with
    asm goto which has both fallthrough to the header and one or more labels
    in the header too.  In that case there is just a single edge out of the
    latch block, but still the asm goto is stmt_ends_bb_p statement, yet
    ivopts decides to emit an IV bump at the IP_END position and inserts
    it into the same bb as the asm goto after it, which then fails verification
    (control flow in the middle of bb).
    
    The following patch fixes it by splitting the latch -> header edge in that
    case and inserting into the newly created bb, where split_edge ->
    redirect_edge_and_branch is able to deal with this case correctly.
    
    2022-12-10  Jakub Jelinek  <jakub@redhat.com>
    
            PR tree-optimization/107997
            * tree-ssa-loop-ivopts.c: Include cfganal.h.
            (create_new_iv) <case IP_END>: If ip_end_pos bb is non-empty and ends
            with a stmt which ends bb, instead of adding iv update after it split
            the latch edge and insert iterator into the new latch bb.
    
            * gcc.c-torture/compile/pr107997.c: New test.
    
    (cherry picked from commit 7676235f690e624b7ed41a22b22ce8ccfac1492f)
Comment 16 Jakub Jelinek 2023-05-03 09:33:26 UTC
Fixed for 11.4 as well.
Comment 17 GCC Commits 2023-05-03 15:19:50 UTC
The releases/gcc-10 branch has been updated by Jakub Jelinek <jakub@gcc.gnu.org>:

https://gcc.gnu.org/g:5589bb8d1fd3d4ecfb71e764d54bf931a743b85d

commit r10-11346-g5589bb8d1fd3d4ecfb71e764d54bf931a743b85d
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Sat Dec 10 16:50:39 2022 +0100

    ivopts: Fix IP_END handling for asm goto [PR107997]
    
    The following testcase ICEs, because the latch bb ends with
    asm goto which has both fallthrough to the header and one or more labels
    in the header too.  In that case there is just a single edge out of the
    latch block, but still the asm goto is stmt_ends_bb_p statement, yet
    ivopts decides to emit an IV bump at the IP_END position and inserts
    it into the same bb as the asm goto after it, which then fails verification
    (control flow in the middle of bb).
    
    The following patch fixes it by splitting the latch -> header edge in that
    case and inserting into the newly created bb, where split_edge ->
    redirect_edge_and_branch is able to deal with this case correctly.
    
    2022-12-10  Jakub Jelinek  <jakub@redhat.com>
    
            PR tree-optimization/107997
            * tree-ssa-loop-ivopts.c: Include cfganal.h.
            (create_new_iv) <case IP_END>: If ip_end_pos bb is non-empty and ends
            with a stmt which ends bb, instead of adding iv update after it split
            the latch edge and insert iterator into the new latch bb.
    
            * gcc.c-torture/compile/pr107997.c: New test.
    
    (cherry picked from commit 7676235f690e624b7ed41a22b22ce8ccfac1492f)
Comment 18 Jakub Jelinek 2023-05-04 07:22:16 UTC
Fixed for 10.5 too.