This is an archive of the discontinued LLVM Phabricator instance.

[RISCV] Fix isStoreToStackSlot
ClosedPublic

Authored by rogfer01 on Jun 14 2020, 7:06 AM.

Details

Summary

Because of the layout of stores (that don't have a destination operand) this check is exactly the same as the one in RISCVInstrInfo::isLoadFromStackSlot.

I discovered this while doing some experiments that needed identifying loads/stores from/to the stack. Stores always return false.

Diff Detail

Event Timeline

rogfer01 created this revision.Jun 14 2020, 7:06 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 14 2020, 7:06 AM

I have been unable to come up with a test that shows any change (I may check LNT to see if something changes), so ideas are welcome here.

However I'd expect this function return true (at least for now in RISC-V) for every instruction created in RISCVInstrInfo::storeRegToStackSlot. Conceptually (not part of the current patch) like this.

diff --git a/llvm/lib/Target/RISCV/RISCVInstrInfo.cpp b/llvm/lib/Target/RISCV/RISCVInstrInfo.cpp
index dc212d9cde2..8a28a21a29e 100644
--- a/llvm/lib/Target/RISCV/RISCVInstrInfo.cpp
+++ b/llvm/lib/Target/RISCV/RISCVInstrInfo.cpp
@@ -131,10 +131,14 @@ void RISCVInstrInfo::storeRegToStackSlot(MachineBasicBlock &MBB,
   else
     llvm_unreachable("Can't store this register to stack slot");
 
-  BuildMI(MBB, I, DL, get(Opcode))
+  MachineInstr *MI = BuildMI(MBB, I, DL, get(Opcode))
       .addReg(SrcReg, getKillRegState(IsKill))
       .addFrameIndex(FI)
       .addImm(0);
+
+  int Dummy;
+  (void)Dummy;
+  assert(this->isStoreToStackSlot(*MI, Dummy) && "This is exactly a store to a stack slot");
 }
rogfer01 set the repository for this revision to rG LLVM Github Monorepo.Jun 14 2020, 7:07 AM
luismarques accepted this revision.Jul 6 2020, 1:14 PM

LGTM. Good catch Roger!
(I have verified that the code change makes sense based both on tablegen definitions and the sanity test that Roger indicated on the comment).

This revision is now accepted and ready to land.Jul 6 2020, 1:14 PM
asb accepted this revision.Jul 8 2020, 11:45 PM

This looks good to me, good catch. I do see a codegen change on regstack-1.c from the GCC Torture Suite, so it might be worth having a quick look to see if it's easy to make a test case based on that.

rogfer01 updated this revision to Diff 277689.Jul 14 2020, 12:35 AM

ChangeLog:

rogfer01 updated this revision to Diff 277764.Jul 14 2020, 3:36 AM

ChangeLog:

  • Rebase
This revision was automatically updated to reflect the committed changes.