This is an archive of the discontinued LLVM Phabricator instance.

[RISCV] Handle addimm chains in SelectAddrRegImm
AbandonedPublic

Authored by dtcxzyw on May 16 2023, 6:03 AM.

Details

Reviewers
craig.topper
luke
Summary

Fixes https://github.com/llvm/llvm-project/issues/62734.

This patch handles addimm chains in SelectAddrRegImm to better reuse materialized constant when the offset is larger than the maximum immediate.

Diff Detail

Event Timeline

dtcxzyw created this revision.May 16 2023, 6:03 AM
Herald added a project: Restricted Project. · View Herald TranscriptMay 16 2023, 6:03 AM
dtcxzyw requested review of this revision.May 16 2023, 6:03 AM

Can this create additional LUIs if the lower 12-bits wrap around? That defeats the point of the common base optimization.

Does this prevent using C.LW/C.SW/C.LD/C.SD because we've increased the size of the offsets?

dtcxzyw updated this revision to Diff 523038.May 17 2023, 7:09 AM
  • Rebase
  • Find the best (base, offset) pair to emit compressed load/store instructions with C/Zca/Zcf/Zcd.
  • Add additional tests with large offsets

I feel like this should be handled where the chain was formed or in DAG combine. The whole reason the chain exists is to provide a common base. If the common base isn't right we should fix that.

llvm/lib/Target/RISCV/RISCVISelDAGToDAG.cpp
2318

Zcf and Zcd imply Zca so I don't think you need to check them. You can also hasStdExtCOrZca.

dtcxzyw updated this revision to Diff 523265.May 17 2023, 10:11 PM

Rebase and address comments.

dtcxzyw marked an inline comment as done.May 17 2023, 10:30 PM

I feel like this should be handled where the chain was formed or in DAG combine. The whole reason the chain exists is to provide a common base. If the common base isn't right we should fix that.

I cannot find code about forming chains in RISCVISelLowering.cpp and RISCVISelDAGToDAG.cpp. Should I implement some virtual member functions of class TargetLowering?

I feel like this should be handled where the chain was formed or in DAG combine. The whole reason the chain exists is to provide a common base. If the common base isn't right we should fix that.

I cannot find code about forming chains in RISCVISelLowering.cpp and RISCVISelDAGToDAG.cpp. Should I implement some virtual member functions of class TargetLowering?

I think the splitting is done by CodeGenPrepare::splitLargeGEPOffsets()

I feel like this should be handled where the chain was formed or in DAG combine. The whole reason the chain exists is to provide a common base. If the common base isn't right we should fix that.

I cannot find code about forming chains in RISCVISelLowering.cpp and RISCVISelDAGToDAG.cpp. Should I implement some virtual member functions of class TargetLowering?

I think the splitting is done by CodeGenPrepare::splitLargeGEPOffsets()

I think we can select a better offset by calling a new virtual function like TLI->selectBaseOffset() instead of just using GEP with the smallest offset.

dtcxzyw abandoned this revision.Jul 15 2023, 4:18 AM