<div dir="ltr">There is a design issue with making CFI_INSTRUCTION duplicable. Darwin compact unwind info emission can't handle multiple prologue setups. I will revert this and put the reduced test case in the commit message.</div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Nov 8, 2017 at 10:43 AM, Reid Kleckner <span dir="ltr"><<a href="mailto:rnk@google.com" target="_blank">rnk@google.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">I confirmed this caused a regression for AArch64 and I am reducing a test case.<div><div class="h5"><br><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Nov 8, 2017 at 9:34 AM, Reid Kleckner <span dir="ltr"><<a href="mailto:rnk@google.com" target="_blank">rnk@google.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">I suspect this change introduced a bug in compact unwind info on AArch64:<div><a href="https://logs.chromium.org/v/?s=chromium%2Fbb%2Fchromium.clang%2FToTiOS%2F250%2F%2B%2Frecipes%2Fsteps%2Fcompile%2F0%2Fstdout" target="_blank">https://logs.chromium.org/v/?s<wbr>=chromium%2Fbb%2Fchromium.clan<wbr>g%2FToTiOS%2F250%2F%2B%2Frecip<wbr>es%2Fsteps%2Fcompile%2F0%2Fstd<wbr>out</a><br></div><div><br></div><div><div>FAILED: ios_clang_arm64/obj/third_part<wbr>y/opus/opus/pitch.o </div><div>...</div><div>Assertion failed: (StackSize == 0 && "We already have the CFA offset!"), function generateCompactUnwindEncoding, file /b/c/b/ToTiOS/src/third_party/<wbr>llvm/lib/Target/AArch64/MCTarg<wbr>etDesc/AArch64AsmBackend.cpp, line 487.</div><div>0  clang                    0x00000001035d7fb8 llvm::sys::PrintStackTrace(llv<wbr>m::raw_ostream&) + 40</div><div>1  clang                    0x00000001035d86b6 llvm::sys::PrintStackTraceOnEr<wbr>rorSignal(llvm::StringRef, bool) + 838</div><div>2  libsystem_platform.dylib 0x00007fffeb995bba _sigtramp + 26</div><div>3  clang                    0x0000000103294e79 llvm::MCCVLineEntry::Make(llvm<wbr>::MCObjectStreamer*) + 25</div><div>4  libsystem_c.dylib        0x00007fffeb81c420 abort + 129</div><div>5  libsystem_c.dylib        0x00007fffeb7e3893 basename_r + 0</div><div>6  clang                    0x0000000101e22067 llvm::createAArch64beAsmBacken<wbr>d(llvm::Target const&, llvm::MCRegisterInfo const&, llvm::Triple const&, llvm::StringRef, llvm::MCTargetOptions const&) + 8631</div><div>7  clang                    0x00000001032bf4ef llvm::MCStreamer::generateComp<wbr>actUnwindEncodings(llvm::MCAsm<wbr>Backend*) + 79</div><div>8  clang                    0x00000001032a1196 llvm::MCDwarfFrameEmitter::Emi<wbr>t(llvm::MCObjectStreamer&, llvm::MCAsmBackend*, bool) + 38</div><div>9  clang                    0x00000001032b806e llvm::MCObjectStreamer::EmitFr<wbr>ames(llvm::MCAsmBackend*) + 62</div><div>10 clang                    0x00000001032b12f5 llvm::createMachOStreamer(llvm<wbr>::MCContext&, std::__1::unique_ptr<llvm::MCA<wbr>smBackend, std::__1::default_delete<llvm:<wbr>:MCAsmBackend> >&&, llvm::raw_pwrite_stream&, std::__1::unique_ptr<llvm::MCC<wbr>odeEmitter, std::__1::default_delete<llvm:<wbr>:MCCodeEmitter> >&&, bool, bool, bool) + 5749</div><div>11 clang                    0x00000001032c37f2 llvm::MCStreamer::Finish() + 306</div><div>12 clang                    0x0000000103d6e271 llvm::AsmPrinter::doFinalizati<wbr>on(llvm::Module&) + 3489</div><div>13 clang                    0x0000000102ffa740 llvm::FPPassManager::doFinaliz<wbr>ation(llvm::Module&) + 80</div><div>14 clang                    0x0000000102ffac8d llvm::legacy::PassManagerImpl:<wbr>:run(llvm::Module&) + 1277</div><div>15 clang                    0x000000010380cd33 clang::EmitBackendOutput(clang<wbr>::DiagnosticsEngine&, clang::HeaderSearchOptions const&, clang::CodeGenOptions const&, clang::TargetOptions const&, clang::LangOptions const&, llvm::DataLayout const&, llvm::Module*, clang::BackendAction, std::__1::unique_ptr<llvm::raw<wbr>_pwrite_stream, std::__1::default_delete<llvm:<wbr>:raw_pwrite_stream> >) + 15571</div><div>16 clang                    0x0000000103a44ed5 clang::EmitObjAction::EmitObjA<wbr>ction(llvm::LLVMContext*) + 2341</div><div>17 clang                    0x0000000103d10ccc clang::MultiplexConsumer::Hand<wbr>leTranslationUnit(clang::ASTCo<wbr>ntext&) + 44</div><div>18 clang                    0x00000001044cdfb5 clang::ParseAST(clang::Sema&, bool, bool) + 469</div><div>19 clang                    0x0000000103ccdfdc clang::FrontendAction::Execute<wbr>() + 76</div><div>20 clang                    0x0000000103c86e41 clang::CompilerInstance::Execu<wbr>teAction(clang::FrontendAction<wbr>&) + 1217</div><div>21 clang                    0x0000000103d340fa clang::ExecuteCompilerInvocati<wbr>on(clang::CompilerInstance*) + 4970</div><div>22 clang                    0x0000000101c86a57 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) + 1399</div><div>23 clang                    0x0000000101c850df main + 11951</div><div>24 libdyld.dylib            0x00007fffeb788255 start + 1</div><div><br></div></div><div>I'll try to get a reproducer.</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Nov 7, 2017 at 6:40 AM, Petar Jovanovic via llvm-commits <span dir="ltr"><<a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: petarj<br>
Date: Tue Nov  7 06:40:27 2017<br>
New Revision: 317579<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=317579&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-pr<wbr>oject?rev=317579&view=rev</a><br>
Log:<br>
Reland "Correct dwarf unwind information in function epilogue for X86"<br>
<br>
Reland r317100 with minor fix regarding ComputeCommonTailLength function in<br>
BranchFolding.cpp. Skipping top CFI instructions block needs to executed on<br>
several more return points in ComputeCommonTailLength().<br>
<br>
Original r317100 message:<br>
<br>
"Correct dwarf unwind information in function epilogue for X86"<br>
<br>
This patch aims to provide correct dwarf unwind information in function<br>
epilogue for X86.<br>
<br>
It consists of two parts. The first part inserts CFI instructions that set<br>
appropriate cfa offset and cfa register in emitEpilogue() in<br>
X86FrameLowering. This part is X86 specific.<br>
<br>
The second part is platform independent and ensures that:<br>
<br>
- CFI instructions do not affect code generation<br>
- Unwind information remains correct when a function is modified by<br>
  different passes. This is done in a late pass by analyzing information<br>
  about cfa offset and cfa register in BBs and inserting additional CFI<br>
  directives where necessary.<br>
<br>
Changed CFI instructions so that they:<br>
<br>
- are duplicable<br>
- are not counted as instructions when tail duplicating or tail merging<br>
- can be compared as equal<br>
<br>
Added CFIInstrInserter pass:<br>
<br>
- analyzes each basic block to determine cfa offset and register valid at<br>
  its entry and exit<br>
- verifies that outgoing cfa offset and register of predecessor blocks match<br>
  incoming values of their successors<br>
- inserts additional CFI directives at basic block beginning to correct the<br>
  rule for calculating CFA<br>
<br>
Having CFI instructions in function epilogue can cause incorrect CFA<br>
calculation rule for some basic blocks. This can happen if, due to basic<br>
block reordering, or the existence of multiple epilogue blocks, some of the<br>
blocks have wrong cfa offset and register values set by the epilogue block<br>
above them.<br>
<br>
CFIInstrInserter is currently run only on X86, but can be used by any target<br>
that implements support for adding CFI instructions in epilogue.<br><br></blockquote></div></div></blockquote></div></div></div></div></div>
</blockquote></div><br></div>