-
Notifications
You must be signed in to change notification settings - Fork 15.1k
[AArch64] Use 0-cycle reg2reg MOVs for FPR32, FPR16, FPR8 #144152
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
tomershafir
merged 2 commits into
llvm:main
from
tomershafir:aarch64-utilize-zcm-for-fp-reg-classes
Jun 26, 2025
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5302,30 +5302,78 @@ void AArch64InstrInfo::copyPhysReg(MachineBasicBlock &MBB, | |
|
|
||
| if (AArch64::FPR32RegClass.contains(DestReg) && | ||
| AArch64::FPR32RegClass.contains(SrcReg)) { | ||
| BuildMI(MBB, I, DL, get(AArch64::FMOVSr), DestReg) | ||
| .addReg(SrcReg, getKillRegState(KillSrc)); | ||
| if (Subtarget.hasZeroCycleRegMoveFPR64() && | ||
| !Subtarget.hasZeroCycleRegMoveFPR32()) { | ||
| const TargetRegisterInfo *TRI = &getRegisterInfo(); | ||
| MCRegister DestRegD = TRI->getMatchingSuperReg(DestReg, AArch64::ssub, | ||
| &AArch64::FPR64RegClass); | ||
| MCRegister SrcRegD = TRI->getMatchingSuperReg(SrcReg, AArch64::ssub, | ||
| &AArch64::FPR64RegClass); | ||
| // This instruction is reading and writing D registers. This may upset | ||
| // the register scavenger and machine verifier, so we need to indicate | ||
| // that we are reading an undefined value from SrcRegD, but a proper | ||
| // value from SrcReg. | ||
| BuildMI(MBB, I, DL, get(AArch64::FMOVDr), DestRegD) | ||
| .addReg(SrcRegD, RegState::Undef) | ||
| .addReg(SrcReg, RegState::Implicit | getKillRegState(KillSrc)); | ||
| } else { | ||
| BuildMI(MBB, I, DL, get(AArch64::FMOVSr), DestReg) | ||
| .addReg(SrcReg, getKillRegState(KillSrc)); | ||
| } | ||
| return; | ||
| } | ||
|
|
||
| if (AArch64::FPR16RegClass.contains(DestReg) && | ||
| AArch64::FPR16RegClass.contains(SrcReg)) { | ||
| DestReg = | ||
| RI.getMatchingSuperReg(DestReg, AArch64::hsub, &AArch64::FPR32RegClass); | ||
| SrcReg = | ||
| RI.getMatchingSuperReg(SrcReg, AArch64::hsub, &AArch64::FPR32RegClass); | ||
| BuildMI(MBB, I, DL, get(AArch64::FMOVSr), DestReg) | ||
| .addReg(SrcReg, getKillRegState(KillSrc)); | ||
| if (Subtarget.hasZeroCycleRegMoveFPR64() && | ||
| !Subtarget.hasZeroCycleRegMoveFPR32()) { | ||
| const TargetRegisterInfo *TRI = &getRegisterInfo(); | ||
| MCRegister DestRegD = TRI->getMatchingSuperReg(DestReg, AArch64::hsub, | ||
| &AArch64::FPR64RegClass); | ||
| MCRegister SrcRegD = TRI->getMatchingSuperReg(SrcReg, AArch64::hsub, | ||
| &AArch64::FPR64RegClass); | ||
| // This instruction is reading and writing D registers. This may upset | ||
| // the register scavenger and machine verifier, so we need to indicate | ||
| // that we are reading an undefined value from SrcRegD, but a proper | ||
| // value from SrcReg. | ||
| BuildMI(MBB, I, DL, get(AArch64::FMOVDr), DestRegD) | ||
| .addReg(SrcRegD, RegState::Undef) | ||
| .addReg(SrcReg, RegState::Implicit | getKillRegState(KillSrc)); | ||
| } else { | ||
| DestReg = RI.getMatchingSuperReg(DestReg, AArch64::hsub, | ||
| &AArch64::FPR32RegClass); | ||
| SrcReg = RI.getMatchingSuperReg(SrcReg, AArch64::hsub, | ||
| &AArch64::FPR32RegClass); | ||
| BuildMI(MBB, I, DL, get(AArch64::FMOVSr), DestReg) | ||
| .addReg(SrcReg, getKillRegState(KillSrc)); | ||
| } | ||
| return; | ||
| } | ||
|
|
||
|
||
| if (AArch64::FPR8RegClass.contains(DestReg) && | ||
| AArch64::FPR8RegClass.contains(SrcReg)) { | ||
| DestReg = | ||
| RI.getMatchingSuperReg(DestReg, AArch64::bsub, &AArch64::FPR32RegClass); | ||
| SrcReg = | ||
| RI.getMatchingSuperReg(SrcReg, AArch64::bsub, &AArch64::FPR32RegClass); | ||
| BuildMI(MBB, I, DL, get(AArch64::FMOVSr), DestReg) | ||
| .addReg(SrcReg, getKillRegState(KillSrc)); | ||
| if (Subtarget.hasZeroCycleRegMoveFPR64() && | ||
| !Subtarget.hasZeroCycleRegMoveFPR32()) { | ||
| const TargetRegisterInfo *TRI = &getRegisterInfo(); | ||
| MCRegister DestRegD = TRI->getMatchingSuperReg(DestReg, AArch64::bsub, | ||
| &AArch64::FPR64RegClass); | ||
| MCRegister SrcRegD = TRI->getMatchingSuperReg(SrcReg, AArch64::bsub, | ||
| &AArch64::FPR64RegClass); | ||
| // This instruction is reading and writing D registers. This may upset | ||
| // the register scavenger and machine verifier, so we need to indicate | ||
| // that we are reading an undefined value from SrcRegD, but a proper | ||
| // value from SrcReg. | ||
| BuildMI(MBB, I, DL, get(AArch64::FMOVDr), DestRegD) | ||
| .addReg(SrcRegD, RegState::Undef) | ||
| .addReg(SrcReg, RegState::Implicit | getKillRegState(KillSrc)); | ||
| } else { | ||
| DestReg = RI.getMatchingSuperReg(DestReg, AArch64::bsub, | ||
| &AArch64::FPR32RegClass); | ||
| SrcReg = RI.getMatchingSuperReg(SrcReg, AArch64::bsub, | ||
| &AArch64::FPR32RegClass); | ||
| BuildMI(MBB, I, DL, get(AArch64::FMOVSr), DestReg) | ||
| .addReg(SrcReg, getKillRegState(KillSrc)); | ||
| } | ||
| return; | ||
| } | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
103 changes: 103 additions & 0 deletions
103
llvm/test/CodeGen/AArch64/arm64-zero-cycle-regmov-fpr.ll
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,103 @@ | ||
| ; RUN: llc < %s -mtriple=arm64-linux-gnu | FileCheck %s -check-prefixes=NOTCPU-LINUX --match-full-lines | ||
| ; RUN: llc < %s -mtriple=arm64-apple-macosx -mcpu=generic | FileCheck %s -check-prefixes=NOTCPU-APPLE --match-full-lines | ||
| ; RUN: llc < %s -mtriple=arm64-apple-macosx -mcpu=apple-m1 | FileCheck %s -check-prefixes=CPU --match-full-lines | ||
| ; RUN: llc < %s -mtriple=arm64-apple-macosx -mcpu=apple-m1 -mattr=-zcm-fpr64 | FileCheck %s -check-prefixes=NOTATTR --match-full-lines | ||
| ; RUN: llc < %s -mtriple=arm64-apple-macosx -mattr=+zcm-fpr64 | FileCheck %s -check-prefixes=ATTR --match-full-lines | ||
|
|
||
| define void @zero_cycle_regmov_FPR32(float %a, float %b, float %c, float %d) { | ||
| entry: | ||
| ; CHECK-LABEL: t: | ||
| ; NOTCPU-LINUX: fmov s0, s2 | ||
| ; NOTCPU-LINUX: fmov s1, s3 | ||
| ; NOTCPU-LINUX: fmov [[REG2:s[0-9]+]], s3 | ||
| ; NOTCPU-LINUX: fmov [[REG1:s[0-9]+]], s2 | ||
| ; NOTCPU-LINUX-NEXT: bl {{_?foo_float}} | ||
| ; NOTCPU-LINUX: fmov s0, [[REG1]] | ||
| ; NOTCPU-LINUX: fmov s1, [[REG2]] | ||
|
|
||
| ; NOTCPU-APPLE: fmov s0, s2 | ||
| ; NOTCPU-APPLE: fmov s1, s3 | ||
| ; NOTCPU-APPLE: fmov [[REG2:s[0-9]+]], s3 | ||
| ; NOTCPU-APPLE: fmov [[REG1:s[0-9]+]], s2 | ||
| ; NOTCPU-APPLE-NEXT: bl {{_?foo_float}} | ||
| ; NOTCPU-APPLE: fmov s0, [[REG1]] | ||
| ; NOTCPU-APPLE: fmov s1, [[REG2]] | ||
|
|
||
| ; CPU: fmov [[REG2:d[0-9]+]], d3 | ||
| ; CPU: fmov [[REG1:d[0-9]+]], d2 | ||
| ; CPU: fmov d0, d2 | ||
| ; CPU: fmov d1, d3 | ||
| ; CPU-NEXT: bl {{_?foo_float}} | ||
| ; CPU: fmov d0, [[REG1]] | ||
| ; CPU: fmov d1, [[REG2]] | ||
|
|
||
| ; NOTATTR: fmov [[REG2:s[0-9]+]], s3 | ||
| ; NOTATTR: fmov [[REG1:s[0-9]+]], s2 | ||
| ; NOTATTR: fmov s0, s2 | ||
| ; NOTATTR: fmov s1, s3 | ||
| ; NOTATTR-NEXT: bl {{_?foo_float}} | ||
| ; NOTATTR: fmov s0, [[REG1]] | ||
| ; NOTATTR: fmov s1, [[REG2]] | ||
|
|
||
| ; ATTR: fmov d0, d2 | ||
| ; ATTR: fmov d1, d3 | ||
| ; ATTR: fmov [[REG2:d[0-9]+]], d3 | ||
| ; ATTR: fmov [[REG1:d[0-9]+]], d2 | ||
| ; ATTR-NEXT: bl {{_?foo_float}} | ||
| ; ATTR: fmov d0, [[REG1]] | ||
| ; ATTR: fmov d1, [[REG2]] | ||
| %call = call float @foo_float(float %c, float %d) | ||
| %call1 = call float @foo_float(float %c, float %d) | ||
| unreachable | ||
| } | ||
|
|
||
| declare float @foo_float(float, float) | ||
|
|
||
| define void @zero_cycle_regmov_FPR16(half %a, half %b, half %c, half %d) { | ||
| entry: | ||
| ; CHECK-LABEL: t: | ||
| ; NOTCPU-LINUX: fmov s0, s2 | ||
| ; NOTCPU-LINUX: fmov s1, s3 | ||
| ; NOTCPU-LINUX: fmov [[REG2:s[0-9]+]], s3 | ||
| ; NOTCPU-LINUX: fmov [[REG1:s[0-9]+]], s2 | ||
| ; NOTCPU-LINUX-NEXT: bl {{_?foo_half}} | ||
| ; NOTCPU-LINUX: fmov s0, [[REG1]] | ||
| ; NOTCPU-LINUX: fmov s1, [[REG2]] | ||
|
|
||
| ; NOTCPU-APPLE: fmov s0, s2 | ||
| ; NOTCPU-APPLE: fmov s1, s3 | ||
| ; NOTCPU-APPLE: fmov [[REG2:s[0-9]+]], s3 | ||
| ; NOTCPU-APPLE: fmov [[REG1:s[0-9]+]], s2 | ||
| ; NOTCPU-APPLE-NEXT: bl {{_?foo_half}} | ||
| ; NOTCPU-APPLE: fmov s0, [[REG1]] | ||
| ; NOTCPU-APPLE: fmov s1, [[REG2]] | ||
|
|
||
| ; CPU: fmov [[REG2:d[0-9]+]], d3 | ||
| ; CPU: fmov [[REG1:d[0-9]+]], d2 | ||
| ; CPU: fmov d0, d2 | ||
| ; CPU: fmov d1, d3 | ||
| ; CPU-NEXT: bl {{_?foo_half}} | ||
| ; CPU: fmov d0, [[REG1]] | ||
| ; CPU: fmov d1, [[REG2]] | ||
|
|
||
| ; NOTATTR: fmov [[REG2:s[0-9]+]], s3 | ||
| ; NOTATTR: fmov [[REG1:s[0-9]+]], s2 | ||
| ; NOTATTR: fmov s0, s2 | ||
| ; NOTATTR: fmov s1, s3 | ||
| ; NOTATTR-NEXT: bl {{_?foo_half}} | ||
| ; NOTATTR: fmov s0, [[REG1]] | ||
| ; NOTATTR: fmov s1, [[REG2]] | ||
|
|
||
| ; ATTR: fmov d0, d2 | ||
| ; ATTR: fmov d1, d3 | ||
| ; ATTR: fmov [[REG2:d[0-9]+]], d3 | ||
| ; ATTR: fmov [[REG1:d[0-9]+]], d2 | ||
| ; ATTR-NEXT: bl {{_?foo_half}} | ||
| ; ATTR: fmov d0, [[REG1]] | ||
| ; ATTR: fmov d1, [[REG2]] | ||
| %call = call half @foo_half(half %c, half %d) | ||
| %call1 = call half @foo_half(half %c, half %d) | ||
| unreachable | ||
| } | ||
|
|
||
| declare half @foo_half(half, half) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's keep these blank lines after the
return; }'s. They help draw your eye to their early-return-ness.