This is an archive of the discontinued LLVM Phabricator instance.

[RISCV] Fix wrong register rename for store value during make-compressible optimization
ClosedPublic

Authored by kito-cheng on Jun 29 2022, 10:18 PM.

Details

Summary

Current implementation will rename both register in store instructions if
we store base address into memory with same base register, it's OK if
the offset is 0, however that is wrong transform if offset isn't 0, give
a smalle example here:

sd a0, 808(a0)

We should not transform into:

addi a2, a0, 768
sd a2, 40(a2)

That should just rename base address like this:

addi a2, a0, 768
sd a0, 40(a2)

Diff Detail

Event Timeline

kito-cheng created this revision.Jun 29 2022, 10:18 PM
Herald added a project: Restricted Project. · View Herald TranscriptJun 29 2022, 10:18 PM
kito-cheng requested review of this revision.Jun 29 2022, 10:18 PM
craig.topper added inline comments.Jul 5 2022, 6:30 PM
llvm/lib/Target/RISCV/RISCVMakeCompressible.cpp
105

Methods name start with lower case.

Is this ever called?

kito-cheng updated this revision to Diff 442422.Jul 5 2022, 7:05 PM

Changes:

  • Rename Incompressible -> incompressible
  • Use incompressible function to check it's incompressible or not.
  • Use const ref if possible for CompressibleInfo
kito-cheng marked an inline comment as done.Jul 5 2022, 7:10 PM
kito-cheng added inline comments.
llvm/lib/Target/RISCV/RISCVMakeCompressible.cpp
105

Use CI.incompressible() instead of !RegImm.Reg && RegImm.Imm == 0 now

kito-cheng updated this revision to Diff 442430.Jul 5 2022, 7:47 PM
kito-cheng marked an inline comment as done.

Changes:

  • Less invasive way to fix this issue.
asb accepted this revision.Jul 7 2022, 1:25 AM

LGTM, though see suggestion about slightly more detailed comment.

llvm/lib/Target/RISCV/RISCVMakeCompressible.cpp
304

This is a bit subtle, but easy to understand when spelled out so I'd be tempted to write a slightly more in-depth comment. e.g.:

Perhaps "Skip the first (value) operand to a store instruction (except if the store offset is zero) in order to avoid an incorrect transformation. e.g. sd a0, 808(a0) to addi a2, a0, 768; sd a2, 40(a2)"

This revision is now accepted and ready to land.Jul 7 2022, 1:25 AM
This revision was landed with ongoing or failed builds.Jul 8 2022, 3:07 AM
This revision was automatically updated to reflect the committed changes.