public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug d/94496] New: [D] Use aggressive optimizations in release mode
@ 2020-04-06  8:59 ibuclaw at gdcproject dot org
  2020-05-14  0:03 ` [Bug d/94496] " witold.baryluk+gcc at gmail dot com
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: ibuclaw at gdcproject dot org @ 2020-04-06  8:59 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 94496
           Summary: [D] Use aggressive optimizations in release mode
           Product: gcc
           Version: 10.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: d
          Assignee: ibuclaw at gdcproject dot org
          Reporter: ibuclaw at gdcproject dot org
  Target Milestone: ---

There are a number of attributes in D that on the surface may seem like a good
fit for producing better optimisations, but there's always an escape latch, or
a latent issue that means none of these actually work in practice, for example:

- 'nothrow' code allows throwing Errors.
- 'pure' code allows modifying context state, what's called weakly pure.
- 'in' parameters are documented as const and no escape, but only the const
part was ever enforced.

So to avoid breaking code in ways that are not always immediately obvious,
nothing is really enforced.

When compiling release code however (-frelease), all considerations done to not
break runtime could be thrown out the window.  To take the first example, in
the event of throwing in a 'nothrow' function in release mode, crashing the
run-time at the point of throw is a perfectly valid thing to do, as Errors are
not meant to be caught.

Some of these optimizations could include (repeating some in the list above):

- 'nothrow' attribute sets TREE_NOTHROW
- 'pure' (strongly pure) attribute sets DECL_PURE_P or...
- ...function calls determined to be free of side effects set ECF_PURE if
DECL_PURE_P turns out to be problematic.
- 'const scope' parameters sets (EAF_NOCLOBBER | EAF_NOESCAPE)
- 'asm pure' unsets ASM_VOLATILE_P
- Enable strict aliasing for dynamic arrays.
- 'return' parameters set ERF_RETURNS_ARG.

More may come to mind later.

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

* [Bug d/94496] [D] Use aggressive optimizations in release mode
  2020-04-06  8:59 [Bug d/94496] New: [D] Use aggressive optimizations in release mode ibuclaw at gdcproject dot org
@ 2020-05-14  0:03 ` witold.baryluk+gcc at gmail dot com
  2020-05-14  5:51 ` ibuclaw at gdcproject dot org
  2020-05-15 12:22 ` witold.baryluk+gcc at gmail dot com
  2 siblings, 0 replies; 4+ messages in thread
From: witold.baryluk+gcc at gmail dot com @ 2020-05-14  0:03 UTC (permalink / raw)
  To: gcc-bugs

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

Witold Baryluk <witold.baryluk+gcc at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |witold.baryluk+gcc at gmail dot co
                   |                            |m

--- Comment #1 from Witold Baryluk <witold.baryluk+gcc at gmail dot com> ---
We are close to making 'in' mean 'scope const', it is already available as a
preview in dmd 2.092: https://dlang.org/changelog/2.092.0.html#preview-in

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

* [Bug d/94496] [D] Use aggressive optimizations in release mode
  2020-04-06  8:59 [Bug d/94496] New: [D] Use aggressive optimizations in release mode ibuclaw at gdcproject dot org
  2020-05-14  0:03 ` [Bug d/94496] " witold.baryluk+gcc at gmail dot com
@ 2020-05-14  5:51 ` ibuclaw at gdcproject dot org
  2020-05-15 12:22 ` witold.baryluk+gcc at gmail dot com
  2 siblings, 0 replies; 4+ messages in thread
From: ibuclaw at gdcproject dot org @ 2020-05-14  5:51 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Iain Buclaw <ibuclaw at gdcproject dot org> ---
(In reply to Witold Baryluk from comment #1)
> We are close to making 'in' mean 'scope const', it is already available as a
> preview in dmd 2.092: https://dlang.org/changelog/2.092.0.html#preview-in

Indeed, the new @live attribute should also allow strict aliasing rules to be
turned on for them as well.

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

* [Bug d/94496] [D] Use aggressive optimizations in release mode
  2020-04-06  8:59 [Bug d/94496] New: [D] Use aggressive optimizations in release mode ibuclaw at gdcproject dot org
  2020-05-14  0:03 ` [Bug d/94496] " witold.baryluk+gcc at gmail dot com
  2020-05-14  5:51 ` ibuclaw at gdcproject dot org
@ 2020-05-15 12:22 ` witold.baryluk+gcc at gmail dot com
  2 siblings, 0 replies; 4+ messages in thread
From: witold.baryluk+gcc at gmail dot com @ 2020-05-15 12:22 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Witold Baryluk <witold.baryluk+gcc at gmail dot com> ---
Also about 'nothrow' and Errors.

I would really welcome a flag to compiler that simply terminates all threads
immidetly any Error is thrown at throw location. They aren't really
recoverable. The only option is either catch them really high in the stack or
terminate the program (in D this will I think unwind all the stack and destroy
scoped structs, also call full GC collection, optionally call all class
destrustors, and module destructors). But in many cases terminating the program
at the spot (_exit(2) or _Exit(2), from glibc (not kernel) to terminate all
threads via exit_group).

As of the 'nothrow' itself. I belive it doesn't mean there is 'no thrown
exceptions in the call tree'. I think it means there is no 'uncought exceptions
possibly throw by call to this function'.

```d
extern int g(int x);  // not nothrow

int f(int x) nothrow {
  try {
     return g(x);
     throw new MyException("ble");
  } catch (Exception e) {
    return 1;
  }
  return 0;
}
```

https://gcc.godbolt.org/z/Y3vNQr


As of the asm pure, considering there is asm volatile, wouldn't it make sense
to not allow 'asm pure volatilve' in the first place in the source?

strict aliasing should be enabled for dynamic arrays, static arrays and normal
pointer to other types.   I.e.

```d
void f(int* x, float[] y);  // x, y, y.ptr should not alias.
```



```d
void f(int* x, int[] y);  // x, y and y.ptr can alias.
```

Also how about using `restrict` automatically for transitively const types?
I.e. 

```d
void f(const scope int[] a, int *b);  // can't alias. if b aliases a, then it
is UB.
```

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

end of thread, other threads:[~2020-05-15 12:22 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-06  8:59 [Bug d/94496] New: [D] Use aggressive optimizations in release mode ibuclaw at gdcproject dot org
2020-05-14  0:03 ` [Bug d/94496] " witold.baryluk+gcc at gmail dot com
2020-05-14  5:51 ` ibuclaw at gdcproject dot org
2020-05-15 12:22 ` witold.baryluk+gcc at gmail dot com

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).