<div dir="ltr"><div><div><div>Looks like you are calling a function with no prototype or with the wrong prototype - which is why it's being bitcast. <br><br></div>32 (i8*, i64, i8*)* is <br>int (*)(void *, int64_t, char *)<br><br>[or void * instead of char * - impossible to tell apart in LLVM IR, but I'm guessing based on str in your inline function] in C. <br><br>And your function is declared as <br>i8* (i8*, i64, i8*)*<br>so <br>char* (*)(char *, int64_t, char *)<br><br></div>Do you actually want to return an i32 as a pointer?<br><br></div>Maybe you shoudl declare foo to return a pointer to char (or void).<br></div><div class="gmail_extra"><br><div class="gmail_quote">On 27 May 2015 at 15:22, Nat! <span dir="ltr"><<a href="mailto:nat@mulle-kybernetik.com" target="_blank">nat@mulle-kybernetik.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">OK, I found out that llc doesn't do the inlining either. I was scratching my head why llc -O2 <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__test.ir&d=AwMFaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=CnzuN65ENJ1H9py9XLiRvC_UQz6u3oG6GUNn7_wosSM&m=JEFki4y3b1nh_72Grp8wKpUa1bDEXe-mFTWWaOkZsiY&s=oG2zzJ-5hiRnd4OgltDoLJ_fXC-WBd4QausBEtvLxCg&e=" target="_blank">test.ir</a> refused to inline my code. As it turns out, the optimization is done by a different program called "opt".<br>
<br>
So for anyone else interested (and for myself looking this up in a year or so :))<br>
<br>
clang -S -emit-llvm -mllvm -disable-llvm-optzns -o <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__test.ir&d=AwMFaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=CnzuN65ENJ1H9py9XLiRvC_UQz6u3oG6GUNn7_wosSM&m=JEFki4y3b1nh_72Grp8wKpUa1bDEXe-mFTWWaOkZsiY&s=oG2zzJ-5hiRnd4OgltDoLJ_fXC-WBd4QausBEtvLxCg&e=" target="_blank">test.ir</a> test.c<br>
<br>
produces the unoptimized readable IR file<br>
<br>
opt -O2 -o test.opt.bc <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__test.ir&d=AwMFaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=CnzuN65ENJ1H9py9XLiRvC_UQz6u3oG6GUNn7_wosSM&m=JEFki4y3b1nh_72Grp8wKpUa1bDEXe-mFTWWaOkZsiY&s=oG2zzJ-5hiRnd4OgltDoLJ_fXC-WBd4QausBEtvLxCg&e=" target="_blank">test.ir</a><br>
<br>
then creates the optimized binary IR, which then can be assembled into an .s file with<br>
<br>
llc -o test.opt.s test.opt.cb<br>
<br>
or disassembled into a readable IR again<br>
<br>
llvm-dis -o <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__test.opt.ir&d=AwMFaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=CnzuN65ENJ1H9py9XLiRvC_UQz6u3oG6GUNn7_wosSM&m=JEFki4y3b1nh_72Grp8wKpUa1bDEXe-mFTWWaOkZsiY&s=o9ziK9Vf7Agq_w52D93u24xmW3szd25DKaLej1fEFFI&e=" target="_blank">test.opt.ir</a> test.opt.cb<br>
<br>
<br>
I am getting closer to the reason, why my code does not get inlined, but I am not there yet. I can put the following through opt -O2 and it does not inline (though "inline_call " is even marked as alwaysinline):<br>
<br>
---<br>
<br>
;LLVM (<a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_&d=AwMFaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=CnzuN65ENJ1H9py9XLiRvC_UQz6u3oG6GUNn7_wosSM&m=JEFki4y3b1nh_72Grp8wKpUa1bDEXe-mFTWWaOkZsiY&s=suko9h-M7qs1tXouzD-IbNva11x4gFy9HBF1NisKzsg&e=" target="_blank">http://llvm.org/</a>):<br>
; LLVM version 3.6.1<br>
; DEBUG build with assertions.<br>
; Built May 26 2015 (18:26:41).<br>
: Default target: x86_64-apple-darwin14.3.0<br>
; Host CPU: core-avx2<br>
; ModuleID = 'test.opt.bc'<br>
target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"<br>
target triple = "x86_64-apple-macosx10.10.0"<br>
<br>
@.str = private unnamed_addr constant [4 x i8] c"hit\00", align 1<br>
<br>
; Function Attrs: alwaysinline inlinehint nounwind readnone ssp uwtable<br>
define internal i8* @inline_call(i8* readnone %p, i64 %aux, i8* nocapture readnone %params) #0 {<br>
entry:<br>
%cmp = icmp eq i8* %p, inttoptr (i64 305419896 to i8*)<br>
%.p = select i1 %cmp, i8* getelementptr inbounds ([4 x i8]* @.str, i64 0, i64 0), i8* %p<br>
ret i8* %.p<br>
}<br>
<br>
; Function Attrs: nounwind ssp uwtable<br>
define i32 @foo(i8* %p, i64 %aux) #1 {<br>
entry:<br>
%call = tail call i32 bitcast (i8* (i8*, i64, i8*)* @inline_call to i32 (i8*, i64, i8*)*)(i8* %p, i64 -5999611798422882212, i8* %p) #2<br>
ret i32 %call<br>
}<br>
<br>
attributes #0 = { alwaysinline inlinehint nounwind readnone ssp uwtable "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }<br>
attributes #1 = { nounwind ssp uwtable "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }<br>
attributes #2 = { nounwind }<br>
---<br>
<br>
I suspect it has something to do with the "call bitcast". But to me it appears to be more like a limitation of llvm not to inline it, then a coding error of mine.<br>
<br>
Ciao<br>
<span class="HOEnZb"><font color="#888888"> Nat!<br>
------------------------------------------------------<br>
i hurt when i think too much i love roadtrips i hate<br>
my weight i fear being alone for the rest of my life.<br>
-- AOL #3696023<br>
</font></span><div class="HOEnZb"><div class="h5"><br>
<br>
<br>
_______________________________________________<br>
cfe-dev mailing list<br>
<a href="mailto:cfe-dev@cs.uiuc.edu">cfe-dev@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev</a><br>
</div></div></blockquote></div><br></div>