This is an archive of the discontinued LLVM Phabricator instance.

[RISCV][NFC] Simplify immediate materialisation
AbandonedPublic

Authored by benshi001 on Nov 16 2021, 10:54 PM.

Details

Summary
  1. Make alias: (slli.uw x, 0) -> (zexti32 x).
  2. Use (zexti32 x) instead of (zext.w x) to simplify building the instruction sequence of immediate materialisation.

Diff Detail

Event Timeline

benshi001 created this revision.Nov 16 2021, 10:54 PM
benshi001 requested review of this revision.Nov 16 2021, 10:54 PM
Herald added a project: Restricted Project. · View Herald TranscriptNov 16 2021, 10:54 PM
benshi001 added a comment.EditedNov 16 2021, 10:57 PM

According to the spec of the B extension, (slli.uw x, 0) can fully replace the (zext.w x).

Using slli.uw can simpify the logic, which reduce an extra else branch in several places of the RISCV backend.

Is the compiler simplicity worth making the assembly harder to read since it won't print zext.w anymore?

benshi001 added a comment.EditedNov 16 2021, 11:35 PM

Is the compiler simplicity worth making the assembly harder to read since it won't print zext.w anymore?

The immediate materialisation already become more tricky with SHxADD/BCLRI/BSETI/SLLIUW, most assembly sequances are not obvious, so is it necessary to keep immediate materialisation assembly readable ?

Is the compiler simplicity worth making the assembly harder to read since it won't print zext.w anymore?

The immediate materialisation already become more tricky with SHxADD/BCLRI/BSETI/SLLIUW, most assembly sequances are not obvious, so is it necessary to keep immediate materialisation assembly readable ?

I'm not arguing the readability of the whole immediate materialization itself. That you have to be able to read like any other instructions. My concern is that this is the only time the compiler will emit a slli.uw with a zero shift amount and there's no alias for it. It might be surprising the first time someone sees it.

Is the compiler simplicity worth making the assembly harder to read since it won't print zext.w anymore?

The immediate materialisation already become more tricky with SHxADD/BCLRI/BSETI/SLLIUW, most assembly sequances are not obvious, so is it necessary to keep immediate materialisation assembly readable ?

I'm not arguing the readability of the whole immediate materialization itself. That you have to be able to read like any other instructions. My concern is that this is the only time the compiler will emit a slli.uw with a zero shift amount and there's no alias for it. It might be surprising the first time someone sees it.

According to the spec of the B extension, "zext.w" has already been aliased to "add.uw x, zero", so how about making a new alias like "zext32 x" to "slli.uw t, 0" ?

benshi001 updated this revision to Diff 387888.Nov 17 2021, 3:03 AM
benshi001 edited the summary of this revision. (Show Details)

Is the compiler simplicity worth making the assembly harder to read since it won't print zext.w anymore?

The immediate materialisation already become more tricky with SHxADD/BCLRI/BSETI/SLLIUW, most assembly sequances are not obvious, so is it necessary to keep immediate materialisation assembly readable ?

I'm not arguing the readability of the whole immediate materialization itself. That you have to be able to read like any other instructions. My concern is that this is the only time the compiler will emit a slli.uw with a zero shift amount and there's no alias for it. It might be surprising the first time someone sees it.

According to the spec of the B extension, "zext.w" has already been aliased to "add.uw x, zero", so how about making a new alias like "zext32 x" to "slli.uw t, 0" ?

I have added alias (slli.uw x, 0) -> (zexti32 x), not sure the name is proper. But I think (slli.uw x, 0) should have an alias.

jrtc27 requested changes to this revision.Nov 17 2021, 5:14 AM

Don’t make up your own non-standard aliases; I get annoyed when binutils does the same and we have to copy them

This revision now requires changes to proceed.Nov 17 2021, 5:14 AM

Is the compiler simplicity worth making the assembly harder to read since it won't print zext.w anymore?

The immediate materialisation already become more tricky with SHxADD/BCLRI/BSETI/SLLIUW, most assembly sequances are not obvious, so is it necessary to keep immediate materialisation assembly readable ?

I'm not arguing the readability of the whole immediate materialization itself. That you have to be able to read like any other instructions. My concern is that this is the only time the compiler will emit a slli.uw with a zero shift amount and there's no alias for it. It might be surprising the first time someone sees it.

Is there a way to append a comment after the machine instruction when calling BuildMI ? Could it be better to be slli.uw a0, a0, 0 ; zero extend i32 to i64 ?

benshi001 abandoned this revision.Nov 18 2021, 6:08 PM