This is an archive of the discontinued LLVM Phabricator instance.

[RISCV] Teach RISCVMergeBaseOffset to handle read-modify-write of a global.
ClosedPublic

Authored by craig.topper on Jun 26 2022, 12:21 AM.

Details

Summary

The pass was previously limited to LUI+ADDI being used by a single
instruction.

This patch allows the pass to optimize multiple memory operations
that use the same offset. Each of them will receive a separate %lo
relocation. My main motivation is to handle a read-modify-write
where we have a load and store to the same address, but I didn't
restrict it to that case.

Diff Detail

Unit TestsFailed

Event Timeline

craig.topper created this revision.Jun 26 2022, 12:21 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 26 2022, 12:21 AM
craig.topper requested review of this revision.Jun 26 2022, 12:21 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 26 2022, 12:21 AM
asb added a comment.Jun 27 2022, 12:22 PM

I've not had a chance to delve in any further, but I'm getting a compilation failure with builtin-prefetch-2.c from the GCC torture suite when applying this patch:

clang-15: /home/asb/llvm-project/llvm/lib/CodeGen/LiveVariables.cpp:129: void llvm::LiveVariables::HandleVirtRegUse(llvm::Register, llvm::MachineBasicBlock *, llvm::MachineInstr &): Assertion `MRI->getVRegDef(Reg) && "Register use before def!"' failed.

I've not had a chance to delve in any further, but I'm getting a compilation failure with builtin-prefetch-2.c from the GCC torture suite when applying this patch:

clang-15: /home/asb/llvm-project/llvm/lib/CodeGen/LiveVariables.cpp:129: void llvm::LiveVariables::HandleVirtRegUse(llvm::Register, llvm::MachineBasicBlock *, llvm::MachineInstr &): Assertion `MRI->getVRegDef(Reg) && "Register use before def!"' failed.

The test contains an instruction that stores a pointer value to the location it points to

SD %3:gpr, %3:gpr, 16 :: (store (s64) into `ptr getelementptr inbounds (%struct.S, ptr @str, i64 0, i32 4)`, !tbaa !10)

In the old code the DestReg != BaseAddrReg check combine with single use prevented this. Without the one use check DestReg != BaseAddrReg isn't strong enough by itself to catch this case.

Fix the crash @asb reported.

Add test for the crash that @asb found

asb accepted this revision.Jun 28 2022, 11:33 AM

LGTM, thanks!

This revision is now accepted and ready to land.Jun 28 2022, 11:33 AM
This revision was landed with ongoing or failed builds.Jun 28 2022, 11:47 AM
This revision was automatically updated to reflect the committed changes.