This is an archive of the discontinued LLVM Phabricator instance.

[WebAssembly] Add ComplexPattern for loads
AbandonedPublic

Authored by luke on Dec 7 2022, 4:46 AM.

Details

Summary

This refactors out the offset and address operand pattern matching into a ComplexPattern which can do more advanced matching. It also now folds global addresses into the offset whenever the stack operand is not a constant.

More specifically, this should address https://github.com/llvm/llvm-project/issues/57771

Diff Detail

Event Timeline

luke created this revision.Dec 7 2022, 4:46 AM
Herald added a project: Restricted Project. · View Herald TranscriptDec 7 2022, 4:46 AM
luke requested review of this revision.Dec 7 2022, 4:46 AM
Herald added a project: Restricted Project. · View Herald TranscriptDec 7 2022, 4:46 AM
luke edited the summary of this revision. (Show Details)Dec 7 2022, 4:47 AM

Nice, but maybe the global folding should be done in a following patch so this can be an NFC?

luke added inline comments.Dec 7 2022, 10:33 AM
llvm/lib/Target/WebAssembly/WebAssemblyISelDAGToDAG.cpp
320–321

Is there a better way to iterate over the two operands of an add?

tlively added inline comments.Dec 7 2022, 10:46 AM
llvm/lib/Target/WebAssembly/WebAssemblyISelDAGToDAG.cpp
360–361

Do we have tests covering these cases?

llvm/lib/Target/WebAssembly/WebAssemblyRegisterInfo.cpp
79

What's the benefit of this extra logic?

Haven't read the code part yet, but I wonder, is there no way to cover the global-GEP folding tests with TableGen by adding some more patterns there? I think we are trying to keep patterns in TableGen if possible, especially if the patterns are not complex and used frequently, which I believe is the case for basic loads and stores.

asb added a comment.Dec 8 2022, 5:56 AM

Haven't read the code part yet, but I wonder, is there no way to cover the global-GEP folding tests with TableGen by adding some more patterns there? I think we are trying to keep patterns in TableGen if possible, especially if the patterns are not complex and used frequently, which I believe is the case for basic loads and stores.

I'd add a bit of context to this. I suggested that Luke take a look to see if the current patterns could be cleaned up using a ComplexPattern. For the RISC-V backend we similarly started out using a big list of patterns for loads/stores, but later made this same switch to a ComplexPattern and I think it was an improvement. It's right to prefer tablegen-based pattern matching where feasible, but I think in this case a relatively small amount of C++ code does make it easier to understand and maintain, with less room for errors by missing cases.

luke marked an inline comment as not done.Dec 8 2022, 6:01 AM
luke added inline comments.
llvm/lib/Target/WebAssembly/WebAssemblyISelDAGToDAG.cpp
360–361

I believe so in test/CodeGen/WebAssembly/offset.ll with the functions ending in with_folded_or_offset

llvm/lib/Target/WebAssembly/WebAssemblyRegisterInfo.cpp
79

Now that (add tga x) is now selected into something like i32.load offset=tga, x, the above assertion was being triggered because it assumed that any offset operand would always be an immediate, not a target global address. So this just wraps around it.
I'm not 100% sure as to why this is only triggered now with this patch as I'm fairly certain there were loads being selected like i32.load offset=tga, 0

luke abandoned this revision.Dec 8 2022, 9:33 AM
luke marked 2 inline comments as not done.

Split into D139631 & D139645