Open 31fbadee-9e60-4c99-b908-8380e6a40c85 opened 4 years ago
Interesting, this calls BranchFolder, so it might be the same fix for llvm/llvm-bugzilla-archive#46009
// No tail merging opportunities if the block number is less than four. if (MF.size() > 3 && EnableTailMerge) { unsigned TailMergeSize = TailDupSize + 1; BranchFolder BF(/EnableTailMerge=/true, /CommonHoist=/false, MBFI, MBPI, PSI, TailMergeSize);
auto *MMIWP = getAnalysisIfAvailable<MachineModuleInfoWrapperPass>();
if (BF.OptimizeFunction(MF, TII, MF.getSubtarget().getRegisterInfo(),
MMIWP ? &MMIWP->getMMI() : nullptr, MLI,
/*AfterPlacement=*/true)) {
// Redo the layout if tail merging creates/removes/moves blocks.
BlockToChain.clear();
ComputedEdges.clear();
// Must redo the post-dominator tree if blocks were changed.
if (MPDT)
MPDT->runOnMachineFunction(MF);
ChainAllocator.DestroyAll();
buildCFGChains();
}
}
So, I might be wrong, but my bisection points to:
BISECT: running pass (190) Stack Slot Coloring on function (e) BISECT: running pass (191) Machine Copy Propagation Pass on function (e) BISECT: running pass (192) Machine Loop Invariant Code Motion on function (e) BISECT: running pass (193) Fixup Statepoint Caller Saved on function (e) BISECT: running pass (194) PostRA Machine Sink on function (e) BISECT: running pass (195) Shrink Wrapping analysis on function (e) BISECT: running pass (196) Control Flow Optimizer on function (e) BISECT: running pass (197) Tail Duplication on function (e) BISECT: running pass (198) Machine Copy Propagation Pass on function (e) BISECT: running pass (199) Post RA top-down list latency scheduler on function (e) BISECT: running pass (200) Branch Probability Basic Block Placement on function (e)
^----
Process 3928 launched: '/Users/davide/work/build/bin/a.out' (x86_64) a.out was compiled with optimization - stepping may behave oddly; variables may not be available. Process 3928 stopped
Neat; looks like it's this [0] folding of return blocks together. SimplifyCFG replaces identical return blocks with one of them; it should also be merging the DebugLocs too.
Extended Description
Line 8 should not be hit during debugging.
$ cat a.c char a, b; int g_37[] = {1}; int c; char(d)() { return a; } void e() { if (g_37[0]) return; --b &&d() || c; } int main() { e(); }
$ clang -v clang version 11.0.0 (https://github.com/llvm/llvm-project.git 709c52b9553f4ba83ab901a873392f8a7f2c56a5) Target: x86_64-unknown-linux-gnu Thread model: posix InstalledDir: /usr/local/bin Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/7 Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/7.5.0 Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/8 Selected GCC installation: /usr/lib/gcc/x86_64-linux-gnu/7.5.0 Candidate multilib: .;@m64 Selected multilib: .;@m64
$ lldb -v lldb version 11.0.0 clang revision 709c52b9553f4ba83ab901a873392f8a7f2c56a5 llvm revision 709c52b9553f4ba83ab901a873392f8a7f2c56a5
$ gdb -v GNU gdb (Ubuntu 8.1-0ubuntu3.2) 8.1.0.20180409-git
$ clang -Og -g -o opt a.c
$ lldb opt (lldb) target create "opt" Current executable set to 'opt' (x86_64). (lldb) b main Breakpoint 1: where = opt`main + 1 at a.c:10:14, address = 0x00000000004004b1 (lldb) r Process 231 launched: '/home/stepping/output/opt' (x86_64) Process 231 stopped
e at a.c:8:13 5 void e() { 6 if (g_37[0]) 7 return; -> 8 --b &&d() || c; 9 } 10 int main() { e(); } (lldb) di opt
e: 0x400490 <+0>: cmpl $0x0, 0x200b91(%rip) ; __dso_handle + 7 0x400497 <+7>: je 0x40049a ; <+10> at a.c:8:3 -> 0x400499 <+9>: retq0x40049a <+10>: addb $-0x1, 0x200b90(%rip) ; opt.PT_LOAD[1]..bss + 4 0x4004a1 <+17>: retq
$ gdb opt (gdb) b main Breakpoint 1 at 0x4004b1: file a.c, line 10. (gdb) r Starting program: opt
Breakpoint 1, main () at a.c:10 10 int main() { e(); } (gdb) s e () at a.c:6 6 if (g_37[0]) (gdb) s e () at a.c:8 8 --b &&d() || c; (gdb) s 0x00007ffff7a05b97 in __libc_start_main () from /lib/x86_64-linux-gnu/libc.so.6 (gdb)