digitalmars.D.ldc - Switch -g disables optimizations.
- Marco Leise (24/24) Oct 08 2015 I found the root for the horrible codegen with ldc2 I was
- Joakim (4/26) Oct 08 2015 Optimization is turned off in debug mode, with a comment claiming
- David Nadlinger via digitalmars-d-ldc (9/18) Oct 09 2015 We should actually look into re-enabling that. I don't know the story
- Marco Leise (16/38) Oct 09 2015 Am Fri, 09 Oct 2015 09:24:05 +0200
- Kai Nacke (6/19) Oct 10 2015 There were once problems with debug info and code optimization.
I found the root for the horrible codegen with ldc2 I was experiencing. As soon as I added -g to get some line numbers in disassemblies, one or more optimizations steps got disabled. int main(string[]) { return 0; } compiles with -O to: xor eax,eax ret and with -O -g to: push rbp mov rbp,rsp xor eax,eax pop rbp ret ldc2 -version: LDC - the LLVM D compiler (0.16.0): based on DMD v2.067.1 and LLVM 3.6.2 Is that expected to improve the debugging experience and make local variables always available or a bug? clang's codegen is not influenced in this way by the -g flag. -- Marco
Oct 08 2015
On Friday, 9 October 2015 at 04:22:51 UTC, Marco Leise wrote:I found the root for the horrible codegen with ldc2 I was experiencing. As soon as I added -g to get some line numbers in disassemblies, one or more optimizations steps got disabled. int main(string[]) { return 0; } compiles with -O to: xor eax,eax ret and with -O -g to: push rbp mov rbp,rsp xor eax,eax pop rbp ret ldc2 -version: LDC - the LLVM D compiler (0.16.0): based on DMD v2.067.1 and LLVM 3.6.2 Is that expected to improve the debugging experience and make local variables always available or a bug? clang's codegen is not influenced in this way by the -g flag.Optimization is turned off in debug mode, with a comment claiming debug info doesn't work with optimization: https://github.com/ldc-developers/ldc/blob/9d3dd1f609e08f001aeec2cacb1c55707f37884b/gen/optimizer.cpp#L179
Oct 08 2015
On 9 Oct 2015, at 7:46, Joakim via digitalmars-d-ldc wrote:On Friday, 9 October 2015 at 04:22:51 UTC, Marco Leise wrote:We should actually look into re-enabling that. I don't know the story behind that comment, and I'm not sure who does. In this particular case, though, the reason for the "ugly" codegen is that LDC enables -disable-fp-elim (the equivalent of GCC's -fno-omit-frame-pointer) by default when -g is passed. I suppose the reason for this was that all the druntime backtracing code (inherited from DMD) relies on a full call frame being set up for each function. — Davidpush rbp mov rbp,rsp xor eax,eax pop rbp retOptimization is turned off in debug mode, with a comment claiming debug info doesn't work with optimization: https://github.com/ldc-developers/ldc/blob/9d3dd1f609e08f001aeec2cacb1c55707f37884b/gen/optimizer.cpp#L179
Oct 09 2015
Am Fri, 09 Oct 2015 09:24:05 +0200 schrieb David Nadlinger via digitalmars-d-ldc <digitalmars-d-ldc puremagic.com>:On 9 Oct 2015, at 7:46, Joakim via digitalmars-d-ldc wrote:55707f37884b/gen/optimizer.cpp#L179On Friday, 9 October 2015 at 04:22:51 UTC, Marco Leise wrote:push rbp mov rbp,rsp xor eax,eax pop rbp retOptimization is turned off in debug mode, with a comment claiming=20 debug info doesn't work with optimization: https://github.com/ldc-developers/ldc/blob/9d3dd1f609e08f001aeec2cacb1c==20 We should actually look into re-enabling that. I don't know the story=20 behind that comment, and I'm not sure who does. =20 In this particular case, though, the reason for the "ugly" codegen is=20 that LDC enables -disable-fp-elim (the equivalent of GCC's=20 -fno-omit-frame-pointer) by default when -g is passed. I suppose the=20 reason for this was that all the druntime backtracing code (inherited=20 from DMD) relies on a full call frame being set up for each function. =20 =E2=80=94 David=20 Then this was all intentional. It's just that neither Clang nor GDC do this and I generalized "-g" to be adding debug info to an otherwise unchanged compile. Maybe the other compilers also change to some saner defaults when -g is used. The stack unwinding code in druntime used to blow up anyways as soon as you call through GCC compiled functions, with -fomit-frame-pointer as default (on amd64). It's rather surprising when the default system ABI causes unexpected runtime crashes. --=20 Marco
Oct 09 2015
On Friday, 9 October 2015 at 07:24:17 UTC, David Nadlinger wrote:On 9 Oct 2015, at 7:46, Joakim via digitalmars-d-ldc wrote:There were once problems with debug info and code optimization. We should re-check this when we drop support for older LLVM versions. Regards, KaiOn Friday, 9 October 2015 at 04:22:51 UTC, Marco Leise wrote:We should actually look into re-enabling that. I don't know the story behind that comment, and I'm not sure who does.push rbp mov rbp,rsp xor eax,eax pop rbp retOptimization is turned off in debug mode, with a comment claiming debug info doesn't work with optimization: https://github.com/ldc-developers/ldc/blob/9d3dd1f609e08f001aeec2cacb1c55707f37884b/gen/optimizer.cpp#L179
Oct 10 2015