This is to address the bug:
https://bugs.llvm.org/show_bug.cgi?id=47591
Currently, when selection dag tries to check whether two frame index
accesses alias to each other, it assumes it cannot alias if for two
different frame indices at least one is not fixed. This does not take into
account later frames can be reused if they are disjoint.
This issue is exposed to BPF as it uses ILP scheduler and x86 does
not have issue as it uses Source. Even x86 uses ILP, it does not
expose the issue as its target code is different from BPF.
I have a BPF backend patch to also use Source scheduler
https://reviews.llvm.org/D88525
and it fixed the issue. But I feel this is not the right fix and
it appears to me that the optimized dag does not sound right.
The patch fixed the issue by assuming two frames may alias due to
possible future stack reuse. The fix caused some failures
for X86 target due to different code sequence. Will fix tests
once we got consensus about what is the right fix for this problem.
TODO: fix tests
tested with llvm/tests and found the following failures on x86:
Failed Tests (25): LLVM :: CodeGen/X86/2008-05-12-tailmerge-5.ll LLVM :: CodeGen/X86/alias-static-alloca.ll LLVM :: CodeGen/X86/arg-copy-elide-win64.ll LLVM :: CodeGen/X86/atomic-fp.ll LLVM :: CodeGen/X86/atomic-mi.ll ...
Removing this would be a bit of a shame as it has some nice improvements in other backends. (Also, is it only showing up in BPF or can you replicate this on X86/ARM?
I don't have the best knowledge on FrameInfo structures, so we should probably loop in someone who gets that better, but we should see if we can extract disjointed information out of the frame info.
At the very least, we should be able to retain that they can't alias if exactly one is fixed. However, the vast majority of improvements from this was catching disjointness of two separate allocations to see if we can keep this.