<html><head><meta http-equiv="Content-Type" content="text/html; charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><div class="">Hi Jonas,</div><div class=""><br class=""></div><div class="">The reason why you are not seeing a difference is because you are not directly calling the clang frontend.</div><div class="">When running the clang driver like this with -v, you will notice it does 2 clang frontent invocations: IR -> BC, BC -> Obj.</div><div class="">So commands in your case will always go to BC before being compiled to an object.</div><div class=""><br class=""></div><div class="">Hi Paul,</div><div class=""><br class=""></div><div class="">llc outputs the same in both cases. This is what I would expect since the object files in both cases will be equivalent, except for the bitcode embedded inside.</div><div class=""><br class=""></div><div class="">- Dennis Frett</div><div class=""><br class=""></div><div><br class=""><blockquote type="cite" class=""><div class="">On 23 Jan 2019, at 02:08, Jonas Devlieghere <<a href="mailto:jonas@devlieghere.com" class="">jonas@devlieghere.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class=""><div dir="ltr" class=""><div dir="ltr" class=""><div dir="ltr" class=""><div dir="ltr" class=""><div dir="ltr" class=""><div dir="ltr" class=""><div dir="ltr" class=""><div dir="ltr" class=""><div dir="ltr" class="">Hey Dennis,<div class=""><br class=""></div><div class="">Maybe I'm doing something wrong, but I cannot reproduce your issue. Starting with your example as input.ll:</div><div class=""><br class=""></div><div class="">$ llvm-as input.ll -o input.bc<br class=""></div><div class="">$ clang -fembed-bitcode=all -x ir input.ll -c -o ll.o<br class=""></div><div class="">$ clang -fembed-bitcode=all -x ir input.bc -c -o bc.o</div><div class="">$ md5 ll.o</div><div class="">MD5 (ll.o) = 7e9bd15c4dd786a4bb4aec762d4e842e</div><div class=""><div class="">$ md5 bc.o</div><div class="">MD5 (bc.o) = 7e9bd15c4dd786a4bb4aec762d4e842e</div></div><div class=""><br class=""></div><div class="">I verified with otool that there's actually an embedded bitcode section. </div><div class=""><br class=""></div><div class="">However, looking at the cc1 invocation, I noticed the `-emit-llvm-uselists`, that sounds like it might have something to do with the behavior you're seeing?</div><div class=""><br class=""></div><div class="">Cheers,</div><div class="">Jonas</div></div></div></div></div></div></div></div></div></div></div><br class=""><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Jan 22, 2019 at 8:21 AM via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" class="">llvm-dev@lists.llvm.org</a>> wrote:<br class=""></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex">





<div lang="EN-US" style="word-wrap:break-word;line-break:after-white-space" class="">
<div class="gmail-m_-1612369761717600358WordSection1"><p class="MsoNormal"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)" class="">It's good that IR <-> BC produces consistent results.  I think it's not good that IR->Obj and BC->Obj produce different results.<u class=""></u><u class=""></u></span></p><p class="MsoNormal"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)" class="">The next step would be to look at the dumps from llc to see what is different when starting with IR versus BC. That should help track down where something gets
 lost.<u class=""></u><u class=""></u></span></p><p class="MsoNormal"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)" class="">--paulr<u class=""></u><u class=""></u></span></p><p class="MsoNormal"><a name="m_-1612369761717600358__MailEndCompose" class=""><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)" class=""><u class=""></u> <u class=""></u></span></a></p>
<div style="border-style:none none none solid;border-left-width:1.5pt;border-left-color:blue;padding:0in 0in 0in 4pt" class="">
<div class="">
<div style="border-style:solid none none;border-top-width:1pt;border-top-color:rgb(181,196,223);padding:3pt 0in 0in" class=""><p class="MsoNormal"><b class=""><span style="font-size:10pt;font-family:Tahoma,sans-serif" class="">From:</span></b><span style="font-size:10pt;font-family:Tahoma,sans-serif" class=""> Dennis Frett [mailto:<a href="mailto:dennis.frett@guardsquare.com" target="_blank" class="">dennis.frett@guardsquare.com</a>]
<br class="">
<b class="">Sent:</b> Sunday, January 20, 2019 10:18 AM<br class="">
<b class="">To:</b> Robinson, Paul<br class="">
<b class="">Cc:</b> <a href="mailto:llvm-dev@lists.llvm.org" target="_blank" class="">llvm-dev@lists.llvm.org</a><br class="">
<b class="">Subject:</b> Re: [llvm-dev] Difference when compiling human readable IR vs bitcode with clang frontend<u class=""></u><u class=""></u></span></p>
</div>
</div><p class="MsoNormal"><u class=""></u> <u class=""></u></p><p class="MsoNormal">Going from IR <-> BC does not seem to create a difference.<u class=""></u><u class=""></u></p>
<div class=""><p class="MsoNormal">IR -> BC -> IR -> BC, either with clang frontent or by using llvm-as and llvm-dis yields identical bc files.<u class=""></u><u class=""></u></p>
</div>
<div class=""><p class="MsoNormal"><u class=""></u> <u class=""></u></p>
</div>
<div class=""><p class="MsoNormal">I have only been able to reproduce this issue when emitting to an object file.<u class=""></u><u class=""></u></p>
</div>
<div class="">
<div class="">
<div class=""><p class="MsoNormal"><u class=""></u> <u class=""></u></p>
</div>
</div>
<div class=""><p class="MsoNormal"><br class="">
<br class="">
<u class=""></u><u class=""></u></p>
<div class=""><p class="MsoNormal">On 18 Jan 2019, at 18:09, <<a href="mailto:paul.robinson@sony.com" target="_blank" class="">paul.robinson@sony.com</a>> <<a href="mailto:paul.robinson@sony.com" target="_blank" class="">paul.robinson@sony.com</a>> wrote:<u class=""></u><u class=""></u></p>
</div><p class="MsoNormal"><u class=""></u> <u class=""></u></p>
<div class="">
<div class=""><p class="MsoNormal"><br class="">
<br class="">
<br class="">
<u class=""></u><u class=""></u></p><p class="MsoNormal">-----Original Message-----<br class="">
From: llvm-dev [<a href="mailto:llvm-dev-bounces@lists.llvm.org" target="_blank" class="">mailto:llvm-dev-bounces@lists.llvm.org</a>] On Behalf Of<br class="">
Dennis Frett via llvm-dev<br class="">
Sent: Friday, January 18, 2019 4:15 AM<br class="">
To: <a href="mailto:llvm-dev@lists.llvm.org" target="_blank" class="">llvm-dev@lists.llvm.org</a><br class="">
Subject: [llvm-dev] Difference when compiling human readable IR vs bitcode<br class="">
with clang frontend<br class="">
<br class="">
We've noticed a difference in the embedded bitcode when compiling human<br class="">
readable IR to an object directly vs first compiling IR to BC and then an<br class="">
object through clang -cc1.<br class="">
If the original IR file contained an "llvm.compiler.used" gv, it will be<br class="">
preserved when compiling IR -> BC -> Obj.<br class="">
When compiling IR -> Obj directly, it will be removed.<br class="">
<br class="">
This difference does not exist for the "llvm.used" gv however, it is<br class="">
always preserved.<br class="">
This questions seems related to the following lit test in LLVM:<br class="">
<a href="https://github.com/llvm-" target="_blank" class="">https://github.com/llvm-</a><br class="">
mirror/llvm/blob/master/test/Transforms/GlobalOpt/compiler-used.ll.<br class="">
<br class="">
Is this somehow expected behaviour?<u class=""></u><u class=""></u></p><p class="MsoNormal"><br class="">
I am curious what happens if you do IR -> BC -> IR -> BC; I'd expect<br class="">
the IR to more-or-less match (the differences all being due to one<br class="">
is hand-written and one is a disassembly) and the two BC files should<br class="">
be identical.<br class="">
<br class="">
If not (and I'm am guessing they aren't, which is why you see some<br class="">
differences in the compiled object file) that's a bug.<br class="">
--paulr<br class="">
<br class="">
<br class="">
<u class=""></u><u class=""></u></p><p class="MsoNormal"><br class="">
Reproduce:<br class="">
Source taken from the lit test.<br class="">
<br class="">
define void @foo() {<br class="">
 ret void<br class="">
}<br class="">
<br class="">
@llvm.used = appending global [1 x i8*] [i8* bitcast (void ()* @foo to<br class="">
i8*)], section "llvm.metadata"<br class="">
@llvm.compiler.used = appending global [1 x i8*] [i8* bitcast (void ()*<br class="">
@foo to i8*)], section "llvm.metadata"<br class="">
<br class="">
<br class="">
# Compile IR -> Obj directly.<br class="">
clang -cc1 -triple x86_64-apple-macosx10.13.0 -emit-obj -fembed-<br class="">
bitcode=all -x ir test.ll -o test_ll.o<br class="">
<br class="">
# Compile IR -> BC -> Obj.<br class="">
clang -cc1 -triple x86_64-apple-macosx10.13.0 -emit-llvm-bc -fblocks -<br class="">
fencode-extended-block-signature -x ir test.ll  -o test.bc<br class="">
clang -cc1 -triple x86_64-apple-macosx10.13.0 -emit-obj -fembed-<br class="">
bitcode=all -x ir test.bc -o test_bc.o<br class="">
<br class="">
# Extract and disassemble embedded bitcode from both scenarios.<br class="">
segedit test_bc.o -extract __LLVM __bitcode bc_bc.bc<br class="">
segedit test_ll.o -extract __LLVM __bitcode ll_bc.bc<br class="">
llvm-dis bc_bc.bc<br class="">
llvm-dis ll_bc.bc<br class="">
<br class="">
# Diff both IR files to show that only bc_bc.ll contains<br class="">
"llvm.compiler.used"<br class="">
diff bc_bc.ll ll_bc.ll<br class="">
<br class="">
- Dennis Frett<u class=""></u><u class=""></u></p>
</div>
</div>
</div><p class="MsoNormal"><u class=""></u> <u class=""></u></p>
</div>
</div>
</div>
</div>

_______________________________________________<br class="">
LLVM Developers mailing list<br class="">
<a href="mailto:llvm-dev@lists.llvm.org" target="_blank" class="">llvm-dev@lists.llvm.org</a><br class="">
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank" class="">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br class="">
</blockquote></div>
</div></blockquote></div><br class=""></body></html>