Closed nickdesaulniers closed 3 years ago
This bug has been marked as a duplicate of bug llvm/llvm-project#49469
Sorry, I think that should have been:
though we could have produced:
baz:
# %bb.0: # %entry
testb %sil, %sil
jne foo # TAILCALL <== JNE
# %bb.1: # %if.end
addq $5, %rdi
jmp bar # TAILCALL
Extended Description
The blog post https://blog.reverberate.org/2021/04/21/musttail-efficient-interpreters.html and comment thread https://news.ycombinator.com/item?id=26934616#26937585 point to a test case (reduced):
run through llc will instead produce:
though we could have produced:
Some code added in D29856 in llvm/lib/CodeGen/BranchFolding.cpp looks like it could do the folding. Quick experimentation with removing the guards:
enables this optimizations, but seems to regress quite a few tests: Failed Tests (29): LLVM :: CodeGen/X86/add.ll LLVM :: CodeGen/X86/atom-pad-short-functions.ll LLVM :: CodeGen/X86/avx512-i1test.ll LLVM :: CodeGen/X86/bmi.ll LLVM :: CodeGen/X86/brcond.ll LLVM :: CodeGen/X86/btq.ll LLVM :: CodeGen/X86/cmp.ll LLVM :: CodeGen/X86/conditional-tailcall-pgso.ll LLVM :: CodeGen/X86/conditional-tailcall.ll LLVM :: CodeGen/X86/copy-eflags.ll LLVM :: CodeGen/X86/extern_weak.ll LLVM :: CodeGen/X86/fold-rmw-ops.ll LLVM :: CodeGen/X86/fp-strict-scalar-cmp.ll LLVM :: CodeGen/X86/funnel-shift.ll LLVM :: CodeGen/X86/neg_cmp.ll LLVM :: CodeGen/X86/or-branch.ll LLVM :: CodeGen/X86/peep-test-4.ll LLVM :: CodeGen/X86/pr37063.ll LLVM :: CodeGen/X86/rd-mod-wr-eflags.ll LLVM :: CodeGen/X86/sibcall.ll LLVM :: CodeGen/X86/slow-incdec.ll LLVM :: CodeGen/X86/sqrt-partial.ll LLVM :: CodeGen/X86/switch-bt.ll LLVM :: CodeGen/X86/tail-call-conditional.mir LLVM :: CodeGen/X86/tail-opts.ll LLVM :: CodeGen/X86/tailcall-cgp-dup.ll LLVM :: CodeGen/X86/tailcall-extract.ll LLVM :: CodeGen/X86/xor-icmp.ll LLVM :: DebugInfo/COFF/pgo.ll
Some of these are straightforward fixes that I think make sense, but others like llvm/test/CodeGen/X86/conditional-tailcall.ll look quite wrong (branching the wrong way, IIUC)!