-
Notifications
You must be signed in to change notification settings - Fork 10.8k
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
[AArch64] Resolve FIXME: Use scavengeRegisterBackwards to find the best unused register #78910
base: main
Are you sure you want to change the base?
Conversation
@llvm/pr-subscribers-llvm-regalloc @llvm/pr-subscribers-backend-aarch64 Author: AtariDreams (AtariDreams) ChangesFull diff: https://github.com/llvm/llvm-project/pull/78910.diff 1 Files Affected:
diff --git a/llvm/lib/Target/AArch64/AArch64SpeculationHardening.cpp b/llvm/lib/Target/AArch64/AArch64SpeculationHardening.cpp
index a991d645eb6f405..86135ef39d82148 100644
--- a/llvm/lib/Target/AArch64/AArch64SpeculationHardening.cpp
+++ b/llvm/lib/Target/AArch64/AArch64SpeculationHardening.cpp
@@ -300,13 +300,8 @@ bool AArch64SpeculationHardening::instrumentControlFlow(
RS.enterBasicBlock(MBB);
else
RS.backward(I);
- // FIXME: The below just finds *a* unused register. Maybe code could be
- // optimized more if this looks for the register that isn't used for the
- // longest time around this place, to enable more scheduling freedom. Not
- // sure if that would actually result in a big performance difference
- // though. Maybe RegisterScavenger::findSurvivorBackwards has some logic
- // already to do this - but it's unclear if that could easily be used here.
- Register TmpReg = RS.FindUnusedReg(&AArch64::GPR64commonRegClass);
+ Register TmpReg = RS.scavengeRegisterBackwards(AArch64::GPR64commonRegClass,
+ I, false, 0, false);
LLVM_DEBUG(dbgs() << "RS finds "
<< ((TmpReg == 0) ? "no register " : "register ");
if (TmpReg != 0) dbgs() << printReg(TmpReg, TRI) << " ";
|
3072356
to
5283ace
Compare
✅ With the latest revision this PR passed the C/C++ code formatter. |
if (I == MBB.begin()) { | ||
RS.enterBasicBlock(MBB); | ||
else | ||
// Cannot scavenge backwards as we are at the start of the basic block | ||
TmpReg = RS.FindUnusedReg(&AArch64::GPR64commonRegClass); | ||
} else { | ||
RS.backward(I); | ||
// FIXME: The below just finds *a* unused register. Maybe code could be | ||
// optimized more if this looks for the register that isn't used for the | ||
// longest time around this place, to enable more scheduling freedom. Not | ||
// sure if that would actually result in a big performance difference | ||
// though. Maybe RegisterScavenger::findSurvivorBackwards has some logic | ||
// already to do this - but it's unclear if that could easily be used here. | ||
Register TmpReg = RS.FindUnusedReg(&AArch64::GPR64commonRegClass); | ||
TmpReg = RS.scavengeRegisterBackwards(AArch64::GPR64commonRegClass, I, | ||
false, 0, false); | ||
} |
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.
I think you can call scavengeRegisterBackwards even at the start of a block - can't you?
if (I == MBB.begin())
RS.enterBasicBlock(MBB);
else
RS.backward(I);
TmpReg = RS.scavengeRegisterBackwards(AArch64::GPR64commonRegClass, I,
false, 0, false);
The only reason this code was special casing I == MBB.begin()
in the first place is for efficiency, not for correctness. The assumption is that enterBasicBlock
is more efficient than backward
which might have to step over arbitrarily many instructions.
@@ -11,34 +12,148 @@ | |||
# - other direct branches don't seem to be generated by the AArch64 codegen | |||
--- | | |||
define void @nobranch_fallthrough(i32 %a, i32 %b) speculative_load_hardening { | |||
; CHECK-LABEL: nobranch_fallthrough: |
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.
If you use the autogenerated test, make sure to clear the all check lines.
As is, there are labels that are repeated which may lead in weird failures with FileCheck. (e.g., the label nobranch_fallthrough appears twice.)
@@ -11,34 +12,148 @@ | |||
# - other direct branches don't seem to be generated by the AArch64 codegen | |||
--- | | |||
define void @nobranch_fallthrough(i32 %a, i32 %b) speculative_load_hardening { |
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.
Could you add a comment of what needs to happen or must not happen in the comment?
The manual checks were conveying this in a more direct way (but broken in its own way :P).
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.
Previous comments
899a5f1
to
09cc32d
Compare
// FIXME: The below just finds *a* unused register. Maybe code could be | ||
// optimized more if this looks for the register that isn't used for the | ||
// longest time around this place, to enable more scheduling freedom. Not | ||
// sure if that would actually result in a big performance difference | ||
// though. Maybe RegisterScavenger::findSurvivorBackwards has some logic | ||
// already to do this - but it's unclear if that could easily be used here. |
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.
This comment should probably be reserved, fundamentally the scavenge is still doing the same thing and not finding a "nicer" register
No description provided.