<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<meta name="Generator" content="Microsoft Word 14 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:Tahoma;
        panose-1:2 11 6 4 3 5 4 4 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman","serif";}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:#0069B4;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:#0069B4;
        text-decoration:underline;}
span.EmailStyle17
        {mso-style-type:personal-reply;
        font-family:"Calibri","sans-serif";
        color:#1F497D;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-size:10.0pt;}
@page WordSection1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="EN-US" link="#0069B4" vlink="#0069B4" style="word-wrap: break-word;-webkit-nbsp-mode: space;line-break:after-white-space">
<div class="WordSection1">
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">It's good that IR <-> BC produces consistent results.  I think it's not good that IR->Obj and BC->Obj produce different results.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">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.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">--paulr<o:p></o:p></span></p>
<p class="MsoNormal"><a name="_MailEndCompose"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"><o:p> </o:p></span></a></p>
<div style="border:none;border-left:solid blue 1.5pt;padding:0in 0in 0in 4.0pt">
<div>
<div style="border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0in 0in 0in">
<p class="MsoNormal"><b><span style="font-size:10.0pt;font-family:"Tahoma","sans-serif"">From:</span></b><span style="font-size:10.0pt;font-family:"Tahoma","sans-serif""> Dennis Frett [mailto:dennis.frett@guardsquare.com]
<br>
<b>Sent:</b> Sunday, January 20, 2019 10:18 AM<br>
<b>To:</b> Robinson, Paul<br>
<b>Cc:</b> llvm-dev@lists.llvm.org<br>
<b>Subject:</b> Re: [llvm-dev] Difference when compiling human readable IR vs bitcode with clang frontend<o:p></o:p></span></p>
</div>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Going from IR <-> BC does not seem to create a difference.<o:p></o:p></p>
<div>
<p class="MsoNormal">IR -> BC -> IR -> BC, either with clang frontent or by using llvm-as and llvm-dis yields identical bc files.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">I have only been able to reproduce this issue when emitting to an object file.<o:p></o:p></p>
</div>
<div>
<div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
</div>
<div>
<p class="MsoNormal"><br>
<br>
<o:p></o:p></p>
<div>
<p class="MsoNormal">On 18 Jan 2019, at 18:09, <<a href="mailto:paul.robinson@sony.com">paul.robinson@sony.com</a>> <<a href="mailto:paul.robinson@sony.com">paul.robinson@sony.com</a>> wrote:<o:p></o:p></p>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<div>
<p class="MsoNormal"><br>
<br>
<br>
<o:p></o:p></p>
<p class="MsoNormal">-----Original Message-----<br>
From: llvm-dev [<a href="mailto:llvm-dev-bounces@lists.llvm.org">mailto:llvm-dev-bounces@lists.llvm.org</a>] On Behalf Of<br>
Dennis Frett via llvm-dev<br>
Sent: Friday, January 18, 2019 4:15 AM<br>
To: <a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a><br>
Subject: [llvm-dev] Difference when compiling human readable IR vs bitcode<br>
with clang frontend<br>
<br>
We've noticed a difference in the embedded bitcode when compiling human<br>
readable IR to an object directly vs first compiling IR to BC and then an<br>
object through clang -cc1.<br>
If the original IR file contained an "llvm.compiler.used" gv, it will be<br>
preserved when compiling IR -> BC -> Obj.<br>
When compiling IR -> Obj directly, it will be removed.<br>
<br>
This difference does not exist for the "llvm.used" gv however, it is<br>
always preserved.<br>
This questions seems related to the following lit test in LLVM:<br>
<a href="https://github.com/llvm-">https://github.com/llvm-</a><br>
mirror/llvm/blob/master/test/Transforms/GlobalOpt/compiler-used.ll.<br>
<br>
Is this somehow expected behaviour?<o:p></o:p></p>
<p class="MsoNormal"><br>
I am curious what happens if you do IR -> BC -> IR -> BC; I'd expect<br>
the IR to more-or-less match (the differences all being due to one<br>
is hand-written and one is a disassembly) and the two BC files should<br>
be identical.<br>
<br>
If not (and I'm am guessing they aren't, which is why you see some<br>
differences in the compiled object file) that's a bug.<br>
--paulr<br>
<br>
<br>
<o:p></o:p></p>
<p class="MsoNormal"><br>
Reproduce:<br>
Source taken from the lit test.<br>
<br>
define void @foo() {<br>
 ret void<br>
}<br>
<br>
@llvm.used = appending global [1 x i8*] [i8* bitcast (void ()* @foo to<br>
i8*)], section "llvm.metadata"<br>
@llvm.compiler.used = appending global [1 x i8*] [i8* bitcast (void ()*<br>
@foo to i8*)], section "llvm.metadata"<br>
<br>
<br>
# Compile IR -> Obj directly.<br>
clang -cc1 -triple x86_64-apple-macosx10.13.0 -emit-obj -fembed-<br>
bitcode=all -x ir test.ll -o test_ll.o<br>
<br>
# Compile IR -> BC -> Obj.<br>
clang -cc1 -triple x86_64-apple-macosx10.13.0 -emit-llvm-bc -fblocks -<br>
fencode-extended-block-signature -x ir test.ll  -o test.bc<br>
clang -cc1 -triple x86_64-apple-macosx10.13.0 -emit-obj -fembed-<br>
bitcode=all -x ir test.bc -o test_bc.o<br>
<br>
# Extract and disassemble embedded bitcode from both scenarios.<br>
segedit test_bc.o -extract __LLVM __bitcode bc_bc.bc<br>
segedit test_ll.o -extract __LLVM __bitcode ll_bc.bc<br>
llvm-dis bc_bc.bc<br>
llvm-dis ll_bc.bc<br>
<br>
# Diff both IR files to show that only bc_bc.ll contains<br>
"llvm.compiler.used"<br>
diff bc_bc.ll ll_bc.ll<br>
<br>
- Dennis Frett<o:p></o:p></p>
</div>
</div>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
</div>
</div>
</body>
</html>