This is an archive of the discontinued LLVM Phabricator instance.

[RISCV] Support LUI+ADDIW in doPeepholeLoadStoreADDI.
ClosedPublic

Authored by craig.topper on Jun 3 2022, 11:45 AM.

Details

Summary

This fixes an inconsistency between RV32 and RV64. Still considering
trying to do this peephole during isel, but wanted to fix the
inconsistency first.

Diff Detail

Event Timeline

craig.topper created this revision.Jun 3 2022, 11:45 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 3 2022, 11:45 AM
craig.topper requested review of this revision.Jun 3 2022, 11:45 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 3 2022, 11:45 AM

Upload whole patch.

reames added inline comments.Jun 3 2022, 12:42 PM
llvm/lib/Target/RISCV/RISCVISelDAGToDAG.cpp
2248

Correct me if I'm wrong here, but isn't this the same as proving we could replace the ADDIW with an ADDI? If so, should that be done somewhere else generically?

llvm/test/CodeGen/RISCV/fold-addi-loadstore.ll
321

Can you precommit these please? I need to see the current code to wrap my head around the change,

craig.topper added inline comments.Jun 3 2022, 1:16 PM
llvm/lib/Target/RISCV/RISCVISelDAGToDAG.cpp
2248

Yes. So we definitely teach constant materialization to emit LUI+ADDI instead of LUI+ADDIW for more cases. And update a bunch of tests.

But I think we would then need to teach the RISCVSExtWRemoval pass that LUI+ADDI produces a sign extended result most of the time. It already knows ADDIW always produces a sign extended result. So as long as we always emit LUI+ADDIW we didn't need a special case.

So we'd just be moving the problem around.

Since I also wrote something similar to this patch for RISCVMergeBaseOffset D126729. Maybe that's another vote in favor of changing so we only have to deal with it in RISCVSExtWRemoval?

reames added inline comments.Jun 3 2022, 1:23 PM
llvm/lib/Target/RISCV/RISCVISelDAGToDAG.cpp
2248

Let me ask this differently, why isn't RISCVSExtWRemoval using ComputeNumSignBits? Do we not have an equivalent of that for MI?

Quick digging shows that no we don't appear to have that. Unless, maybe I'm missing it?

Yeah, so I'm leaning towards canonicalizing towards ADDI, and making this RISCVSExtWRemoval.cpp's problem.

To be clear, I'm fine landing this patch as is (now that I actually am clear on what it's doing), and *then* working in that direction. Not urgent, not even required immediate followup.

Could you put a comment in this code which makes it very clear this is matching the case where ADDIW is the same as ADDI?

craig.topper added inline comments.Jun 3 2022, 1:29 PM
llvm/lib/Target/RISCV/RISCVISelDAGToDAG.cpp
2248

Let me ask this differently, why isn't RISCVSExtWRemoval using ComputeNumSignBits? Do we not have an equivalent of that for MI?

Quick digging shows that no we don't appear to have that. Unless, maybe I'm missing it?

We don't have that. And if we did we'd still have to add LUI+ADDI as a special case in it.

Yeah, so I'm leaning towards canonicalizing towards ADDI, and making this RISCVSExtWRemoval.cpp's problem.

To be clear, I'm fine landing this patch as is (now that I actually am clear on what it's doing), and *then* working in that direction. Not urgent, not even required immediate followup.

Could you put a comment in this code which makes it very clear this is matching the case where ADDIW is the same as ADDI?

Sure.

Improve comment. Rebase on pre-committed tests

Improve comment on the negative test.

reames accepted this revision.Jun 3 2022, 2:23 PM

LGTM

This revision is now accepted and ready to land.Jun 3 2022, 2:23 PM
This revision was landed with ongoing or failed builds.Jun 3 2022, 6:07 PM
This revision was automatically updated to reflect the committed changes.