This is an archive of the discontinued LLVM Phabricator instance.

[RISCV] Remove unnecessary move of undefined with subregister liveness enabled
AbandonedPublic

Authored by BeMg on Jul 11 2023, 10:02 PM.

Details

Summary

In D129735, we introduce a new pass to fix the undef may break the early-clobber constraints problem. For sub-register liveness situation, this pass uses the INSERT_SUBREG to init undef part of full register. This will cause the unnecessary COPY because INSERT_SUBREG will be transformed into COPY during TwoAddrInstruction pass.

To fix the problem, this patch introduces the new pseudo RVVInitSubUndef and the new pass init-sub-undef. RVVInitSubUndef acts like INSERT_SUBREG but in a RISC-V specific version, and the init-sub-undef pass turns RVVInitSubUndef into RVVInitUndef.

%3:vrm2 = RVVInitSubUndef %3, %subreg.sub_vrm1_1
=>
%3.sub_vrm1_1:vrm2 = RVVInitUndef

It could maintain the sub-register liveness for undef part and without unnecessary move.

Diff Detail

Event Timeline

BeMg created this revision.Jul 11 2023, 10:02 PM
Herald added a project: Restricted Project. · View Herald TranscriptJul 11 2023, 10:02 PM
BeMg requested review of this revision.Jul 11 2023, 10:02 PM
Herald added a project: Restricted Project. · View Herald TranscriptJul 11 2023, 10:02 PM
BeMg edited the summary of this revision. (Show Details)Jul 11 2023, 10:15 PM

Can you take a step back and describe what the motivating code here is? The description on the change seems to start from a level of detail, which makes it hard to reverse back to your motivation. I think you must be seeing overly constrained register allocation on some example, but which example?

Also, you may find https://reviews.llvm.org/D156709 partially addresses the same issue. Not sure as without the original example, or something reasonable illustrative, it's hard to tell what you're trying to do here.

A random thought on optimization here.

In the common case where only one sub-register is defined, inserting the defined element into an undefined pseudo - i.e. doing the inverse of the current code - might be better. We could maybe generalize this when multiple sub-regs are defined, but that starts looking like somekind of subreg_select like construct, and I don't know of any support for that.

BeMg planned changes to this revision.Jul 31 2023, 10:47 PM

Yes.

Can you take a step back and describe what the motivating code here is? The description on the change seems to start from a level of detail, which makes it hard to reverse back to your motivation. I think you must be seeing overly constrained register allocation on some example, but which example?

Also, you may find https://reviews.llvm.org/D156709 partially addresses the same issue. Not sure as without the original example, or something reasonable illustrative, it's hard to tell what you're trying to do here.

Originally, I observed some insert_subreg that generate from init-undef pass will be transform into COPY and it can't be eliminated by the following optimization pass. I thought if we could have a RISC-V own insert_subreg node, then we could manual eliminated it from MIR precisely. It make sure there are not extra instruction from init-undef pass.

Now D156709 shows that redundant COPY come from unnecessary undef register fix-up, so those insert_subreg I observed is unnecessary too.


I will investigate whether there are any reasonable testcase can be resolved by this patch.

BeMg abandoned this revision.Aug 14 2023, 4:18 AM