diff options
author | Reid Kleckner <rnk@google.com> | 2017-11-08 21:31:14 +0000 |
---|---|---|
committer | Reid Kleckner <rnk@google.com> | 2017-11-08 21:31:14 +0000 |
commit | 7adb2fdbbadd0c588a2137c7362a9099574d79ae (patch) | |
tree | 51b8a7eec92f22bbf2869969130a0fce1886de6b /llvm/lib/CodeGen/BranchFolding.cpp | |
parent | a702fa17f31abd5efce302ef3d4cf2fbaf167368 (diff) | |
download | llvm-7adb2fdbbadd0c588a2137c7362a9099574d79ae.zip llvm-7adb2fdbbadd0c588a2137c7362a9099574d79ae.tar.gz llvm-7adb2fdbbadd0c588a2137c7362a9099574d79ae.tar.bz2 |
Revert "Correct dwarf unwind information in function epilogue for X86"
This reverts r317579, originally committed as r317100.
There is a design issue with marking CFI instructions duplicatable. Not
all targets support the CFIInstrInserter pass, and targets like Darwin
can't cope with duplicated prologue setup CFI instructions. The compact
unwind info emission fails.
When the following code is compiled for arm64 on Mac at -O3, the CFI
instructions end up getting tail duplicated, which causes compact unwind
info emission to fail:
int a, c, d, e, f, g, h, i, j, k, l, m;
void n(int o, int *b) {
if (g)
f = 0;
for (; f < o; f++) {
m = a;
if (l > j * k > i)
j = i = k = d;
h = b[c] - e;
}
}
We get assembly that looks like this:
; BB#1: ; %if.then
Lloh3:
adrp x9, _f@GOTPAGE
Lloh4:
ldr x9, [x9, _f@GOTPAGEOFF]
mov w8, wzr
Lloh5:
str wzr, [x9]
stp x20, x19, [sp, #-16]! ; 8-byte Folded Spill
.cfi_def_cfa_offset 16
.cfi_offset w19, -8
.cfi_offset w20, -16
cmp w8, w0
b.lt LBB0_3
b LBB0_7
LBB0_2: ; %entry.if.end_crit_edge
Lloh6:
adrp x8, _f@GOTPAGE
Lloh7:
ldr x8, [x8, _f@GOTPAGEOFF]
Lloh8:
ldr w8, [x8]
stp x20, x19, [sp, #-16]! ; 8-byte Folded Spill
.cfi_def_cfa_offset 16
.cfi_offset w19, -8
.cfi_offset w20, -16
cmp w8, w0
b.ge LBB0_7
LBB0_3: ; %for.body.lr.ph
Note the multiple .cfi_def* directives. Compact unwind info emission
can't handle that.
llvm-svn: 317726
Diffstat (limited to 'llvm/lib/CodeGen/BranchFolding.cpp')
-rw-r--r-- | llvm/lib/CodeGen/BranchFolding.cpp | 61 |
1 files changed, 12 insertions, 49 deletions
diff --git a/llvm/lib/CodeGen/BranchFolding.cpp b/llvm/lib/CodeGen/BranchFolding.cpp index cd6056b..8de3dd2 100644 --- a/llvm/lib/CodeGen/BranchFolding.cpp +++ b/llvm/lib/CodeGen/BranchFolding.cpp @@ -296,11 +296,6 @@ static unsigned HashEndOfMBB(const MachineBasicBlock &MBB) { return HashMachineInstr(*I); } -/// Whether MI should be counted as an instruction when calculating common tail. -static bool countsAsInstruction(const MachineInstr &MI) { - return !(MI.isDebugValue() || MI.isCFIInstruction()); -} - /// ComputeCommonTailLength - Given two machine basic blocks, compute the number /// of instructions they actually have in common together at their end. Return /// iterators for the first shared instruction in each block. @@ -315,27 +310,26 @@ static unsigned ComputeCommonTailLength(MachineBasicBlock *MBB1, while (I1 != MBB1->begin() && I2 != MBB2->begin()) { --I1; --I2; // Skip debugging pseudos; necessary to avoid changing the code. - while (!countsAsInstruction(*I1)) { + while (I1->isDebugValue()) { if (I1==MBB1->begin()) { - while (!countsAsInstruction(*I2)) { - if (I2==MBB2->begin()) { + while (I2->isDebugValue()) { + if (I2==MBB2->begin()) // I1==DBG at begin; I2==DBG at begin - goto SkipTopCFIAndReturn; - } + return TailLen; --I2; } ++I2; // I1==DBG at begin; I2==non-DBG, or first of DBGs not at begin - goto SkipTopCFIAndReturn; + return TailLen; } --I1; } // I1==first (untested) non-DBG preceding known match - while (!countsAsInstruction(*I2)) { + while (I2->isDebugValue()) { if (I2==MBB2->begin()) { ++I1; // I1==non-DBG, or first of DBGs not at begin; I2==DBG at begin - goto SkipTopCFIAndReturn; + return TailLen; } --I2; } @@ -374,37 +368,6 @@ static unsigned ComputeCommonTailLength(MachineBasicBlock *MBB1, } ++I1; } - -SkipTopCFIAndReturn: - // Ensure that I1 and I2 do not point to a CFI_INSTRUCTION. This can happen if - // I1 and I2 are non-identical when compared and then one or both of them ends - // up pointing to a CFI instruction after being incremented. For example: - /* - BB1: - ... - INSTRUCTION_A - ADD32ri8 <- last common instruction - ... - BB2: - ... - INSTRUCTION_B - CFI_INSTRUCTION - ADD32ri8 <- last common instruction - ... - */ - // When INSTRUCTION_A and INSTRUCTION_B are compared as not equal, after - // incrementing the iterators, I1 will point to ADD, however I2 will point to - // the CFI instruction. Later on, this leads to BB2 being 'hacked off' at the - // wrong place (in ReplaceTailWithBranchTo()) which results in losing this CFI - // instruction. - while (I1 != MBB1->end() && I1->isCFIInstruction()) { - ++I1; - } - - while (I2 != MBB2->end() && I2->isCFIInstruction()) { - ++I2; - } - return TailLen; } @@ -491,7 +454,7 @@ static unsigned EstimateRuntime(MachineBasicBlock::iterator I, MachineBasicBlock::iterator E) { unsigned Time = 0; for (; I != E; ++I) { - if (!countsAsInstruction(*I)) + if (I->isDebugValue()) continue; if (I->isCall()) Time += 10; @@ -851,12 +814,12 @@ mergeOperations(MachineBasicBlock::iterator MBBIStartPos, assert(MBBI != MBBIE && "Reached BB end within common tail length!"); (void)MBBIE; - if (!countsAsInstruction(*MBBI)) { + if (MBBI->isDebugValue()) { ++MBBI; continue; } - while ((MBBICommon != MBBIECommon) && !countsAsInstruction(*MBBICommon)) + while ((MBBICommon != MBBIECommon) && MBBICommon->isDebugValue()) ++MBBICommon; assert(MBBICommon != MBBIECommon && @@ -896,7 +859,7 @@ void BranchFolder::mergeCommonTails(unsigned commonTailIndex) { } for (auto &MI : *MBB) { - if (!countsAsInstruction(MI)) + if (MI.isDebugValue()) continue; DebugLoc DL = MI.getDebugLoc(); for (unsigned int i = 0 ; i < NextCommonInsts.size() ; i++) { @@ -906,7 +869,7 @@ void BranchFolder::mergeCommonTails(unsigned commonTailIndex) { auto &Pos = NextCommonInsts[i]; assert(Pos != SameTails[i].getBlock()->end() && "Reached BB end within common tail"); - while (!countsAsInstruction(*Pos)) { + while (Pos->isDebugValue()) { ++Pos; assert(Pos != SameTails[i].getBlock()->end() && "Reached BB end within common tail"); |