This is an archive of the discontinued LLVM Phabricator instance.

[PowerPC] Put the CR field in low bits of GRC during copying CRRC to GRC.
ClosedPublic

Authored by Esme on Sep 24 2020, 7:54 PM.

Details

Summary
********** EXPANDING POST-RA PSEUDO INSTRS **********
real copy:  renamable $r3 = COPY killed renamable $cr0
replaced by: $r3 = MFOCRF $cr0

As shown above, how we copying the CRRC to GRC is using a single MFOCRF to copy the contents of CR field n (CR bits 4×n+32:4×n+35) into bits 4×n+32:4×n+35 of register GRC. That's not correct because we expect the value of destination register equals to source so we have to put the the contents of CR field in the lowest 4 bits.

This patch adds a RLWINM after MFOCRF to achieve that.

In fact, the problem came up when adding builtins for xvtdivdp, xvtdivsp, xvtsqrtdp, xvtsqrtsp, as posted in D88278.
We need to move the outputs (in CR register) to GRC. However outputs of these instructions may not in a fixed CR# register, so we can't directly add a rotation instruction in the .td patterns, but need to wait until the CR register is determined. Then we confirmed this should be a bug in POST-RA PSEUDO PASS.

Diff Detail

Event Timeline

Esme created this revision.Sep 24 2020, 7:54 PM
Herald added a project: Restricted Project. · View Herald TranscriptSep 24 2020, 7:54 PM
Esme requested review of this revision.Sep 24 2020, 7:54 PM
Esme edited the summary of this revision. (Show Details)
shchenz added inline comments.Sep 26 2020, 5:48 PM
llvm/test/CodeGen/PowerPC/reg_copy.mir
83 ↗(On Diff #294218)

Maybe we can save the rlwinm when cr field is cr7. Rotate left 32 equals to no rotate?

Esme updated this revision to Diff 294887.Sep 28 2020, 11:12 PM

Skip rotation if CR7.

nemanjai accepted this revision.Sep 29 2020, 5:17 AM

LGTM. The code here is correct, but I do have a couple of questions:

  1. Do these copies come up in real code? And if so, under which circumstances. We don't have copies in the other direction implemented, so that makes me wonder when these ever come up.
  2. Does this solve a problem seen in real code? If so, is there a bugzilla report? At the very least, the conditions under which this causes a problem should be added to the description.
  3. Is there any follow up required/planned for this?
This revision is now accepted and ready to land.Sep 29 2020, 5:17 AM
Esme added a comment.Sep 29 2020, 7:25 PM

LGTM. The code here is correct, but I do have a couple of questions:

  1. Do these copies come up in real code? And if so, under which circumstances. We don't have copies in the other direction implemented, so that makes me wonder when these ever come up.
  2. Does this solve a problem seen in real code? If so, is there a bugzilla report? At the very least, the conditions under which this causes a problem should be added to the description.
  3. Is there any follow up required/planned for this?

Thanks for your comments!
Sorry that I forgot to mention the real scenarios where the problem occurred.
The problem came up when adding builtins for xvtdivdp, xvtdivsp, xvtsqrtdp, xvtsqrtsp, as posted in D88278.
Outputs of these instructions will not be placed into a fixed CR# register, so I can't directly add a rotation instruction in the .td patterns, but need to wait until the CR register is determined.
So D88278 has to depend on this patch.

shchenz accepted this revision.Sep 30 2020, 7:04 PM

LGTM too. Thanks for sharing the background. Before committing this, it's better to update the description for later reference like @nemanjai pointed out?

Esme edited the summary of this revision. (Show Details)Oct 1 2020, 8:56 AM
Esme edited the summary of this revision. (Show Details)Oct 1 2020, 9:07 AM
Esme added a comment.Oct 1 2020, 9:10 AM

LGTM too. Thanks for sharing the background. Before committing this, it's better to update the description for later reference like @nemanjai pointed out?

Yes, thanks for your help! I'll commit soon.