This is an archive of the discontinued LLVM Phabricator instance.

[RISCV] Align odd address in assemble code
Needs RevisionPublic

Authored by StephenFan on Nov 30 2021, 8:07 AM.

Details

Summary

In the past, llvm riscv assember can't align odd address. It can only align address which is multiple of 2 or 4.

In this patch, first insert zeros to make the address is 2 or 4 align, then utilize the nop instruction to align the address to the given align value.

Diff Detail

Event Timeline

StephenFan created this revision.Nov 30 2021, 8:07 AM
StephenFan requested review of this revision.Nov 30 2021, 8:07 AM
Herald added a project: Restricted Project. · View Herald TranscriptNov 30 2021, 8:07 AM
jrtc27 added inline comments.Nov 30 2021, 8:23 AM
llvm/test/MC/RISCV/align-odd.s
2

+relax? +c? (and maybe riscv32?)

3

Pipe to llvm-objdump, don't needlessly create temporary files

5

Weird formatting in this whole block, and I don't see why we need this particular CHECK line

13

.text is the default

Don't indent assembly when there are no labels involved

15

This only ever tests odd->even, it doesn't test 1mod4->multiple of 4 for !RVC

jrtc27 added inline comments.Nov 30 2021, 8:28 AM
llvm/lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.cpp
360–363

IALIGN is the architecturally-defined term for the minimum instruction alignment, and is precisely this

363

You don't need the if any more, write_zeros can happily take in 0 as the length (see AArch64 that does this, for example). Probably worth copying the comment from there too; it's also present for AMDGPU.

StephenFan updated this revision to Diff 390979.Dec 1 2021, 4:31 AM

Address jrtc27's comments. Thank you, @jrtc27!

jrtc27 added inline comments.Dec 1 2021, 5:28 AM
llvm/test/MC/RISCV/align-odd.s
19

Pad after the colon not before the CHECK prefix

20

Why a two space gap?

46

These are still broken, and we should probably be checking where the R_RISCV_RELAX is pointing

69

Double blank line

78

Double blank line

MaskRay added inline comments.Dec 1 2021, 10:58 PM
llvm/test/MC/RISCV/align-odd.s
20

It will make sense when the address takes 2 digits, which can happen if the test gets more instructions. So I won't disallow two spaces here

MaskRay requested changes to this revision.Jul 1 2022, 10:41 AM
This revision now requires changes to proceed.Jul 1 2022, 10:41 AM