<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="">Going from IR <-> BC does not seem to create a difference.<div class="">IR -> BC -> IR -> BC, either with clang frontent or by using llvm-as and llvm-dis yields identical bc files.</div><div class=""><br class=""></div><div class="">I have only been able to reproduce this issue when emitting to an object file.</div><div class=""><div class="">
<div dir="auto" style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><br class="">


<style class="">
a {color: #0069b4;}
</style>



</div>
</div><div><br class=""><blockquote type="cite" class=""><div class="">On 18 Jan 2019, at 18:09, <<a href="mailto:paul.robinson@sony.com" class="">paul.robinson@sony.com</a>> <<a href="mailto:paul.robinson@sony.com" class="">paul.robinson@sony.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div class=""><br class=""><br class=""><blockquote type="cite" class="">-----Original Message-----<br class="">From: llvm-dev [<a href="mailto:llvm-dev-bounces@lists.llvm.org" 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" 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-" 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?<br class=""></blockquote><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=""><blockquote type="cite" class=""><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<br class=""></blockquote></div></div></blockquote></div><br class=""></div></body></html>