public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug d/105360] New: Inlined lazy parameters / delegate literals, still emitted
@ 2022-04-23 15:25 witold.baryluk+gcc at gmail dot com
  2022-04-23 15:54 ` [Bug d/105360] " witold.baryluk+gcc at gmail dot com
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: witold.baryluk+gcc at gmail dot com @ 2022-04-23 15:25 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105360

            Bug ID: 105360
           Summary: Inlined lazy parameters / delegate literals, still
                    emitted
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: d
          Assignee: ibuclaw at gdcproject dot org
          Reporter: witold.baryluk+gcc at gmail dot com
  Target Milestone: ---

```
extern bool g();
extern void f(int n);

void log(lazy int num) {
    if (g()) {
        const n = num();
        f(n);
    }
}

void p(int n) {
    log(n * 137);
}
```


This should emit the same (or close to the same) as code with no `lazy` (and
num reference changed accordingly) on `log` function. (Because compiler knows
that `num ` is called once, has no side effects, is moderately expensive, etc).

And the code for p is exactly the same - log and `n * 137` fully inlined.

However, the anonymous dgliteral code is still emitted, despite not being
referenced anywhere:

```
pure nothrow @nogc @safe int example.p(int).__dgliteral2():  #   < This should
not be in object file
        imul    eax, DWORD PTR [rdi], 137
        ret
```


Rest of the object file is correct and optimal:

```
void example.log(lazy int):
        push    rbp
        push    rbx
        mov     rbp, rdi
        mov     rbx, rsi
        sub     rsp, 8
        call    bool example.g()
        test    al, al
        je      .L3
        mov     rdi, rbp
        call    rbx
        add     rsp, 8
        pop     rbx
        pop     rbp
        mov     edi, eax
        jmp     void example.f(int)
.L3:
        add     rsp, 8
        pop     rbx
        pop     rbp
        ret
void example.p(int):
        push    rbx
        mov     ebx, edi
        call    bool example.g()
        test    al, al
        je      .L6
        imul    edi, ebx, 137
        pop     rbx
        jmp     void example.f(int)
.L6:
        pop     rbx
        ret
```


gdc
(Compiler-Explorer-Build-gcc-748d46cd049c89a799f99f14547267ebae915af6-binutils-2.36.1)
12.0.1 20220421 (experimental)  via godbolt.org


For a code passing reasonably big literals, this can lead to object file code
duplication.

ldc2 shows no such problem.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug d/105360] Inlined lazy parameters / delegate literals, still emitted
  2022-04-23 15:25 [Bug d/105360] New: Inlined lazy parameters / delegate literals, still emitted witold.baryluk+gcc at gmail dot com
@ 2022-04-23 15:54 ` witold.baryluk+gcc at gmail dot com
  2022-08-09 15:58 ` ibuclaw at gdcproject dot org
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: witold.baryluk+gcc at gmail dot com @ 2022-04-23 15:54 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105360

--- Comment #1 from Witold Baryluk <witold.baryluk+gcc at gmail dot com> ---
https://godbolt.org/z/c8oT6E4cf

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug d/105360] Inlined lazy parameters / delegate literals, still emitted
  2022-04-23 15:25 [Bug d/105360] New: Inlined lazy parameters / delegate literals, still emitted witold.baryluk+gcc at gmail dot com
  2022-04-23 15:54 ` [Bug d/105360] " witold.baryluk+gcc at gmail dot com
@ 2022-08-09 15:58 ` ibuclaw at gdcproject dot org
  2022-08-09 16:21 ` ibuclaw at gdcproject dot org
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: ibuclaw at gdcproject dot org @ 2022-08-09 15:58 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105360

--- Comment #2 from Iain Buclaw <ibuclaw at gdcproject dot org> ---
Looks like it's a middle-end missed-optimization, not a D front-end one.

https://godbolt.org/z/5WWYEG4jW

Perhaps we need an extra DCE pass?

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug d/105360] Inlined lazy parameters / delegate literals, still emitted
  2022-04-23 15:25 [Bug d/105360] New: Inlined lazy parameters / delegate literals, still emitted witold.baryluk+gcc at gmail dot com
  2022-04-23 15:54 ` [Bug d/105360] " witold.baryluk+gcc at gmail dot com
  2022-08-09 15:58 ` ibuclaw at gdcproject dot org
@ 2022-08-09 16:21 ` ibuclaw at gdcproject dot org
  2022-08-09 16:24 ` [Bug ipa/105360] " pinskia at gcc dot gnu.org
  2022-08-09 16:25 ` pinskia at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: ibuclaw at gdcproject dot org @ 2022-08-09 16:21 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105360

Iain Buclaw <ibuclaw at gdcproject dot org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           See Also|                            |https://gcc.gnu.org/bugzill
                   |                            |a/show_bug.cgi?id=80680,
                   |                            |https://gcc.gnu.org/bugzill
                   |                            |a/show_bug.cgi?id=99373

--- Comment #3 from Iain Buclaw <ibuclaw at gdcproject dot org> ---
Possibly a duplicate of pr80680 or pr99373.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug ipa/105360] Inlined lazy parameters / delegate literals, still emitted
  2022-04-23 15:25 [Bug d/105360] New: Inlined lazy parameters / delegate literals, still emitted witold.baryluk+gcc at gmail dot com
                   ` (2 preceding siblings ...)
  2022-08-09 16:21 ` ibuclaw at gdcproject dot org
@ 2022-08-09 16:24 ` pinskia at gcc dot gnu.org
  2022-08-09 16:25 ` pinskia at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-08-09 16:24 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105360

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Assignee|ibuclaw at gdcproject dot org      |unassigned at gcc dot gnu.org
                 CC|                            |marxin at gcc dot gnu.org
           See Also|                            |https://gcc.gnu.org/bugzill
                   |                            |a/show_bug.cgi?id=94818
           Severity|normal                      |enhancement
          Component|d                           |ipa

--- Comment #4 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Or PR 94818.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug ipa/105360] Inlined lazy parameters / delegate literals, still emitted
  2022-04-23 15:25 [Bug d/105360] New: Inlined lazy parameters / delegate literals, still emitted witold.baryluk+gcc at gmail dot com
                   ` (3 preceding siblings ...)
  2022-08-09 16:24 ` [Bug ipa/105360] " pinskia at gcc dot gnu.org
@ 2022-08-09 16:25 ` pinskia at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-08-09 16:25 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105360

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |DUPLICATE
             Status|UNCONFIRMED                 |RESOLVED

--- Comment #5 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Dup of bug 89139.

*** This bug has been marked as a duplicate of bug 89139 ***

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2022-08-09 16:25 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-23 15:25 [Bug d/105360] New: Inlined lazy parameters / delegate literals, still emitted witold.baryluk+gcc at gmail dot com
2022-04-23 15:54 ` [Bug d/105360] " witold.baryluk+gcc at gmail dot com
2022-08-09 15:58 ` ibuclaw at gdcproject dot org
2022-08-09 16:21 ` ibuclaw at gdcproject dot org
2022-08-09 16:24 ` [Bug ipa/105360] " pinskia at gcc dot gnu.org
2022-08-09 16:25 ` pinskia at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).