Missed optimization?
David Nadlinger via digitalmars-d-ldc
digitalmars-d-ldc at puremagic.com
Fri Oct 21 15:19:26 PDT 2016
On 21 Oct 2016, at 22:14, safety0ff via digitalmars-d-ldc wrote:
> I was experimenting with pure functions, exceptions and inlining and I
> noticed that LDC seems to generate inferior code to GDC in the cases I
> was considering.
> […]
> https://godbolt.org/g/WI12Bk
That's indeed a bit surprising. The generated IR looks like this:
---
define i64 @_D4test3fooFyAlZl({ i64, i64* } %a_arg) local_unnamed_addr
#0 comdat {
%.getAddressOf_dump.i2 = alloca { i64, i8* }, align 8 ; [#uses = 4,
size/byte = 16]
%.getAddressOf_dump.i = alloca { i64, i8* }, align 8 ; [#uses = 4,
size/byte = 16]
%a_arg.fca.1.extract = extractvalue { i64, i64* } %a_arg, 1 ; [#uses
= 2]
%1 = load i64, i64* %a_arg.fca.1.extract, align 8 ; [#uses = 2]
%2 = bitcast { i64, i8* }* %.getAddressOf_dump.i to i8* ; [#uses = 2]
call void @llvm.lifetime.start(i64 16, i8* %2)
%3 = icmp eq i64 %1, 9223372036854775807 ; [#uses = 1]
br i1 %3, label %if.i, label %_D4test4add1FNalZl.exit
[…]
_D4test4add1FNalZl.exit: ; preds = %0
call void @llvm.lifetime.end(i64 16, i8* %2)
%9 = load i64, i64* %a_arg.fca.1.extract, align 8 ; [#uses = 2]
%10 = bitcast { i64, i8* }* %.getAddressOf_dump.i2 to i8* ; [#uses =
2]
call void @llvm.lifetime.start(i64 16, i8* %10)
%11 = icmp eq i64 %9, 9223372036854775807 ; [#uses = 1]
br i1 %11, label %if.i8, label %_D4test4add1FNalZl.exit9
---
There doesn't seem to be any stores which would potentially make %9 not
foldable with %1. Tracking this down might be an interesting trip down
the LLVM pass pipeline.
— David
More information about the digitalmars-d-ldc
mailing list