Stream: compiler development

Topic: llvm IR tail call


view this post on Zulip Anton (Mar 02 2024 at 19:17):

I compared the llvm IR for a simple program between Roc, Rust and Zig. We were using tail call frequently, whereas the Zig and Rust versions never used it (all were compiled unoptimized). I'm investigating a possible llvm bug and I would like to try emitting regular llvm IR calls. Anybody know how I can do that?

I've tried changing call.set_tail_call(true); to false in refcounting.rs but that did not reduce the number of tail calls for my program.

view this post on Zulip Brendan Hansknecht (Mar 02 2024 at 19:34):

I think it would be in the actual ir emission.

view this post on Zulip Brendan Hansknecht (Mar 02 2024 at 19:34):

I think we set it too much.

view this post on Zulip Folkert de Vries (Mar 02 2024 at 22:57):

no LLVM just infers those tail annotations. they almost never turn into actual tail calls

view this post on Zulip Brendan Hansknecht (Mar 02 2024 at 23:32):

Oh. Inferred, not explicit. Ok.

view this post on Zulip Anton (Mar 05 2024 at 16:13):

Replacing tail calls with calls fixed the issue :)

From my understanding the call to @"#UserApp_diffSelf... should not be marked as a tail call right?

define internal fastcc { %str.RocStr, {} } @"#UserApp_main_f03bf86f79d121cbfd774dec4a65912e99f5f17c33852bbc45e81916e62b53b"() !dbg !52 {
entry:
  %const_str_store3 = alloca %str.RocStr, align 8, !dbg !53
  %const_str_store = alloca %str.RocStr, align 8, !dbg !53
  %call = tail call fastcc i128 @"#UserApp_diffSelf_beb22fad19423347b2aa99b33212e862ded3f83df5d6238acb1a6a9ade3e"(i128 1), !dbg !53
  %call1 = tail call fastcc i1 @Bool_structuralEq_c610e85212d0697cb161d4ba431ba63f273feee7dcb7927c9ff5d74ae6cbfa3(i128 %call, i128 0), !dbg !53
  br i1 %call1, label %then_block, label %else_block, !dbg !53

view this post on Zulip Folkert de Vries (Mar 05 2024 at 18:44):

it should be harmless? but yeah it's not even in tail position so there is nothing the tail attribute can do

view this post on Zulip Anton (Mar 06 2024 at 09:23):

it should be harmless?

Uhu, yeah it should be, but it was not due to this llvm bug https://github.com/llvm/llvm-project/issues/70207

view this post on Zulip Folkert de Vries (Mar 06 2024 at 09:24):

ah, cool!


Last updated: Jul 06 2025 at 12:14 UTC