Skip to content

[Thumb1] LivePhysRegs to LiveRegUnits #84474

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
merged 1 commit into from
Mar 27, 2024
Merged

Conversation

AZero13
Copy link
Contributor

@AZero13 AZero13 commented Mar 8, 2024

This removes the r7 exception because otherwise, LiveRegUnits will try to use that register.

@llvmbot
Copy link
Member

llvmbot commented Mar 8, 2024

@llvm/pr-subscribers-backend-arm

Author: AtariDreams (AtariDreams)

Changes

This fixes a register allocation bug, because while r7 was marked as allowed to be used, LivePhysRegs always reported it as unavailable because it is reserved, despite this being an exception to the rule.


Full diff: https://github.com/llvm/llvm-project/pull/84474.diff

2 Files Affected:

  • (modified) llvm/lib/Target/ARM/Thumb1FrameLowering.cpp (+3-3)
  • (modified) llvm/test/CodeGen/Thumb/PR35481.ll (+6-8)
diff --git a/llvm/lib/Target/ARM/Thumb1FrameLowering.cpp b/llvm/lib/Target/ARM/Thumb1FrameLowering.cpp
index 0f4ece64bff532..a8cf036f363cdd 100644
--- a/llvm/lib/Target/ARM/Thumb1FrameLowering.cpp
+++ b/llvm/lib/Target/ARM/Thumb1FrameLowering.cpp
@@ -612,11 +612,11 @@ bool Thumb1FrameLowering::needPopSpecialFixUp(const MachineFunction &MF) const {
 
 static void findTemporariesForLR(const BitVector &GPRsNoLRSP,
                                  const BitVector &PopFriendly,
-                                 const LivePhysRegs &UsedRegs, unsigned &PopReg,
+                                 const LiveRegUnits &UsedRegs, unsigned &PopReg,
                                  unsigned &TmpReg, MachineRegisterInfo &MRI) {
   PopReg = TmpReg = 0;
   for (auto Reg : GPRsNoLRSP.set_bits()) {
-    if (UsedRegs.available(MRI, Reg)) {
+    if (UsedRegs.available(Reg)) {
       // Remember the first pop-friendly register and exit.
       if (PopFriendly.test(Reg)) {
         PopReg = Reg;
@@ -684,7 +684,7 @@ bool Thumb1FrameLowering::emitPopSpecialFixUp(MachineBasicBlock &MBB,
   // Look for a temporary register to use.
   // First, compute the liveness information.
   const TargetRegisterInfo &TRI = *STI.getRegisterInfo();
-  LivePhysRegs UsedRegs(TRI);
+  LiveRegUnits UsedRegs(TRI);
   UsedRegs.addLiveOuts(MBB);
   // The semantic of pristines changed recently and now,
   // the callee-saved registers that are touched in the function
diff --git a/llvm/test/CodeGen/Thumb/PR35481.ll b/llvm/test/CodeGen/Thumb/PR35481.ll
index ad3215ecb94952..e48d1547782caf 100644
--- a/llvm/test/CodeGen/Thumb/PR35481.ll
+++ b/llvm/test/CodeGen/Thumb/PR35481.ll
@@ -18,11 +18,10 @@ define <4 x i32> @f() local_unnamed_addr #0 {
 ; CHECK-V4T-NEXT:    movs r2, #3
 ; CHECK-V4T-NEXT:    movs r3, #4
 ; CHECK-V4T-NEXT:    bl g
+; CHECK-V4T-NEXT:    ldr r7, [sp, #4]
+; CHECK-V4T-NEXT:    mov lr, r7
 ; CHECK-V4T-NEXT:    pop {r7}
-; CHECK-V4T-NEXT:    mov r12, r0
-; CHECK-V4T-NEXT:    pop {r0}
-; CHECK-V4T-NEXT:    mov lr, r0
-; CHECK-V4T-NEXT:    mov r0, r12
+; CHECK-V4T-NEXT:    add sp, #4
 ; CHECK-V4T-NEXT:    bx lr
 ;
 ; CHECK-V8M-LABEL: f:
@@ -36,11 +35,10 @@ define <4 x i32> @f() local_unnamed_addr #0 {
 ; CHECK-V8M-NEXT:    movs r1, #2
 ; CHECK-V8M-NEXT:    movs r2, #3
 ; CHECK-V8M-NEXT:    movs r3, #4
+; CHECK-V8M-NEXT:    ldr r7, [sp, #4]
+; CHECK-V8M-NEXT:    mov lr, r7
 ; CHECK-V8M-NEXT:    pop {r7}
-; CHECK-V8M-NEXT:    mov r12, r0
-; CHECK-V8M-NEXT:    pop {r0}
-; CHECK-V8M-NEXT:    mov lr, r0
-; CHECK-V8M-NEXT:    mov r0, r12
+; CHECK-V8M-NEXT:    add sp, #4
 ; CHECK-V8M-NEXT:    b g
 entry:
   %call = tail call i32 @h(i32 1)

@AZero13 AZero13 changed the title [ARM] Switch to LiveRegUnits [ARM] Switch to LiveRegUnits to fix r7 register allocation bug Mar 8, 2024
@AZero13 AZero13 force-pushed the thumb-1 branch 4 times, most recently from 8759051 to 91058cd Compare March 11, 2024 20:30
Copy link

github-actions bot commented Mar 13, 2024

✅ With the latest revision this PR passed the C/C++ code formatter.

@AZero13 AZero13 force-pushed the thumb-1 branch 2 times, most recently from d21da8c to 9054d3e Compare March 14, 2024 01:26
@AZero13 AZero13 changed the title [ARM] Switch to LiveRegUnits to fix r7 register allocation bug [Thumb1] LivePhysRegs to LiveRegUnits Mar 14, 2024
@efriedma-quic
Copy link
Collaborator

Please fix the commit message (which is taken from the first comment in the thread when I hit "squash and merge").

Also, your email address is currently hidden (see https://discourse.llvm.org/t/hidden-emails-on-github-should-we-do-something-about-it/74223/)

@AZero13
Copy link
Contributor Author

AZero13 commented Mar 18, 2024

Please fix the commit message (which is taken from the first comment in the thread when I hit "squash and merge").

Also, your email address is currently hidden (see https://discourse.llvm.org/t/hidden-emails-on-github-should-we-do-something-about-it/74223/)

Done!

@efriedma-quic
Copy link
Collaborator

Email address is still hidden. Quoting the automated message that's supposed to trigger (not sure why it didn't trigger here):

⚠️ We detected that you are using a GitHub private e-mail address to contribute to the repo. Please turn off Keep my email addresses private setting in your account. See LLVM Discourse for more information.

@AZero13
Copy link
Contributor Author

AZero13 commented Mar 20, 2024

@efriedma-quic Fixed

@efriedma-quic
Copy link
Collaborator

Still hidden.

@AZero13
Copy link
Contributor Author

AZero13 commented Mar 26, 2024

Still hidden.

Nope. See the commit itself.

@efriedma-quic
Copy link
Collaborator

The "squash and merge" button in the GitHub UI only depends on your GitHub account settings, not the "author" line in the commit. (I don't really want to cherry-pick the patch manually.)

@AZero13
Copy link
Contributor Author

AZero13 commented Mar 26, 2024

The "squash and merge" button in the GitHub UI only depends on your GitHub account settings, not the "author" line in the commit. (I don't really want to cherry-pick the patch manually.)

My github account setting changed to my public email so I don't understand

@AZero13
Copy link
Contributor Author

AZero13 commented Mar 26, 2024

The "squash and merge" button in the GitHub UI only depends on your GitHub account settings, not the "author" line in the commit. (I don't really want to cherry-pick the patch manually.)

There's only one commit so you just have to merge it.

@efriedma-quic
Copy link
Collaborator

The "squash and merge" button in the GitHub UI only depends on your GitHub account settings, not the "author" line in the commit. (I don't really want to cherry-pick the patch manually.)

My github account setting changed to my public email so I don't understand

There's a checkbox "Keep my email addresses private" at https://github.com/settings/emails . If you have it checked, operations through the GitHub UI set the the author email address to "[email protected]", instead of whatever you have set.

There's only one commit so you just have to merge it.

If it was just the one time, I'd just do it, but this is going to be a repeating problem for anyone merging commits on your behalf.

@AZero13
Copy link
Contributor Author

AZero13 commented Mar 27, 2024

The "squash and merge" button in the GitHub UI only depends on your GitHub account settings, not the "author" line in the commit. (I don't really want to cherry-pick the patch manually.)

My github account setting changed to my public email so I don't understand

There's a checkbox "Keep my email addresses private" at https://github.com/settings/emails . If you have it checked, operations through the GitHub UI set the the author email address to "[email protected]", instead of whatever you have set.

There's only one commit so you just have to merge it.

If it was just the one time, I'd just do it, but this is going to be a repeating problem for anyone merging commits on your behalf.

Fixed!

This removes the r7 exception because otherwise, LiveRegUnits will try to use that register.
@efriedma-quic efriedma-quic merged commit 9669aba into llvm:main Mar 27, 2024
@AZero13 AZero13 deleted the thumb-1 branch March 27, 2024 17:14
@AZero13
Copy link
Contributor Author

AZero13 commented Mar 29, 2024

Remove r7 exception because it messes up profilers and others.

@AZero13
Copy link
Contributor Author

AZero13 commented Mar 29, 2024

/pull-request 9669aba

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants