Bug 110422 - asm goto vs SRA
Summary: asm goto vs SRA
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: tree-optimization (show other bugs)
Version: 14.0
: P3 normal
Target Milestone: 11.5
Assignee: Martin Jambor
URL:
Keywords: ice-on-valid-code, inline-asm
: 112503 (view as bug list)
Depends on:
Blocks:
 
Reported: 2023-06-27 00:02 UTC by Andrew Pinski
Modified: 2024-02-10 08:15 UTC (History)
4 users (show)

See Also:
Host:
Target:
Build:
Known to work: 11.4.1, 12.3.1, 13.2.1, 14.0
Known to fail:
Last reconfirmed: 2023-11-13 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Andrew Pinski 2023-06-27 00:02:59 UTC
Testcase from originally from PR 103979:

```
struct S { char a[64]; };

int
foo (void)
{
  struct S s, t;
  asm goto ("" : "=g" (s) : : : l);
  t = s;
  asm goto ("" : "=g" (s) : : : l);
  return s.a[0] + t.a[63];
l:
  return -1;
}
```

This is not related to asm goto not being volatile but rather SRA (just like complex lowering, PR 105165) does not know how to handle `asm goto` with outputs.
Comment 1 Andrew Pinski 2023-11-13 03:24:22 UTC
*** Bug 112503 has been marked as a duplicate of this bug. ***
Comment 2 Andrew Pinski 2023-11-13 03:24:58 UTC
Better testcase from the dup:
```
struct T { int x; };
int foo(void) {
  struct T v;
  asm goto("" : "+r"(v.x) : : : lab);
  return 0;
lab:
  return -5;
}
```

Confirmed.
Comment 3 Martin Jambor 2024-01-17 16:17:44 UTC
Mine.
Comment 4 GCC Commits 2024-01-18 13:26:10 UTC
The master branch has been updated by Martin Jambor <jamborm@gcc.gnu.org>:

https://gcc.gnu.org/g:6764043e88a4208f7c69bf0ccd19ddc7a6016fb1

commit r14-8230-g6764043e88a4208f7c69bf0ccd19ddc7a6016fb1
Author: Martin Jambor <mjambor@suse.cz>
Date:   Thu Jan 18 14:24:15 2024 +0100

    sra: Disqualify bases of operands of asm gotos
    
    PR 110422 shows that SRA can ICE assuming there is a single edge
    outgoing from a block terminated with an asm goto.  We need that for
    BB-terminating statements so that any adjustments they make to the
    aggregates can be copied over to their replacements.  Because we can't
    have that after ASM gotos, we need to punt.
    
    gcc/ChangeLog:
    
    2024-01-17  Martin Jambor  <mjambor@suse.cz>
    
            PR tree-optimization/110422
            * tree-sra.cc (scan_function): Disqualify bases of operands of asm
            gotos.
    
    gcc/testsuite/ChangeLog:
    
    2024-01-17  Martin Jambor  <mjambor@suse.cz>
    
            PR tree-optimization/110422
            * gcc.dg/torture/pr110422.c: New test.
Comment 5 Martin Jambor 2024-01-19 09:37:13 UTC
Fixed on trunk, I plan to backport to open release branches in the upcoming weeks.
Comment 6 GCC Commits 2024-01-24 19:37:52 UTC
The releases/gcc-13 branch has been updated by Martin Jambor <jamborm@gcc.gnu.org>:

https://gcc.gnu.org/g:2b7204c52392c1c0da9c91a5feae0c44018a6f37

commit r13-8246-g2b7204c52392c1c0da9c91a5feae0c44018a6f37
Author: Martin Jambor <mjambor@suse.cz>
Date:   Wed Jan 24 20:35:00 2024 +0100

    sra: Disqualify bases of operands of asm gotos
    
    PR 110422 shows that SRA can ICE assuming there is a single edge
    outgoing from a block terminated with an asm goto.  We need that for
    BB-terminating statements so that any adjustments they make to the
    aggregates can be copied over to their replacements.  Because we can't
    have that after ASM gotos, we need to punt.
    
    gcc/ChangeLog:
    
    2024-01-17  Martin Jambor  <mjambor@suse.cz>
    
            PR tree-optimization/110422
            * tree-sra.cc (scan_function): Disqualify bases of operands of asm
            gotos.
    
    gcc/testsuite/ChangeLog:
    
    2024-01-17  Martin Jambor  <mjambor@suse.cz>
    
            PR tree-optimization/110422
            * gcc.dg/torture/pr110422.c: New test.
    
    (cherry picked from commit 6764043e88a4208f7c69bf0ccd19ddc7a6016fb1)
Comment 7 GCC Commits 2024-02-02 12:30:11 UTC
The releases/gcc-12 branch has been updated by Martin Jambor <jamborm@gcc.gnu.org>:

https://gcc.gnu.org/g:fda015646b9450a2147bd9f01e49e3836b724da4

commit r12-10128-gfda015646b9450a2147bd9f01e49e3836b724da4
Author: Martin Jambor <mjambor@suse.cz>
Date:   Fri Feb 2 13:27:50 2024 +0100

    sra: Disqualify bases of operands of asm gotos
    
    PR 110422 shows that SRA can ICE assuming there is a single edge
    outgoing from a block terminated with an asm goto.  We need that for
    BB-terminating statements so that any adjustments they make to the
    aggregates can be copied over to their replacements.  Because we can't
    have that after ASM gotos, we need to punt.
    
    gcc/ChangeLog:
    
    2024-01-17  Martin Jambor  <mjambor@suse.cz>
    
            PR tree-optimization/110422
            * tree-sra.cc (scan_function): Disqualify bases of operands of asm
            gotos.
    
    gcc/testsuite/ChangeLog:
    
    2024-01-17  Martin Jambor  <mjambor@suse.cz>
    
            PR tree-optimization/110422
            * gcc.dg/torture/pr110422.c: New test.
    
    (cherry picked from commit 2b7204c52392c1c0da9c91a5feae0c44018a6f37)
Comment 8 GCC Commits 2024-02-09 18:00:11 UTC
The releases/gcc-11 branch has been updated by Martin Jambor <jamborm@gcc.gnu.org>:

https://gcc.gnu.org/g:010e4a04c4daaf1b0dacf6aa30fcbdaa73eda33c

commit r11-11230-g010e4a04c4daaf1b0dacf6aa30fcbdaa73eda33c
Author: Martin Jambor <mjambor@suse.cz>
Date:   Fri Feb 9 18:58:43 2024 +0100

    sra: Disqualify bases of operands of asm gotos
    
    PR 110422 shows that SRA can ICE assuming there is a single edge
    outgoing from a block terminated with an asm goto.  We need that for
    BB-terminating statements so that any adjustments they make to the
    aggregates can be copied over to their replacements.  Because we can't
    have that after ASM gotos, we need to punt.
    
    gcc/ChangeLog:
    
    2024-01-17  Martin Jambor  <mjambor@suse.cz>
    
            PR tree-optimization/110422
            * tree-sra.c (scan_function): Disqualify bases of operands of asm
            gotos.
    
    gcc/testsuite/ChangeLog:
    
    2024-01-17  Martin Jambor  <mjambor@suse.cz>
    
            PR tree-optimization/110422
            * gcc.dg/torture/pr110422.c: New test.
    
    (cherry picked from commit 2b7204c52392c1c0da9c91a5feae0c44018a6f37)
Comment 9 Martin Jambor 2024-02-09 18:01:11 UTC
Fixed on all opened release branches too.