-
Notifications
You must be signed in to change notification settings - Fork 15.3k
[CodeGen] Introduce MI flag for Live Range split instructions #117543
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
base: main
Are you sure you want to change the base?
Conversation
This stack of pull requests is managed by Graphite. Learn more about stacking. |
|
@llvm/pr-subscribers-llvm-regalloc Author: Christudasan Devadasan (cdevadas) ChangesFor some targets, it is required to identify the COPY instruction Full diff: https://github.com/llvm/llvm-project/pull/117543.diff 2 Files Affected:
diff --git a/llvm/include/llvm/CodeGen/MachineInstr.h b/llvm/include/llvm/CodeGen/MachineInstr.h
index ead6bbe1d5f641..4545b205d07466 100644
--- a/llvm/include/llvm/CodeGen/MachineInstr.h
+++ b/llvm/include/llvm/CodeGen/MachineInstr.h
@@ -119,7 +119,8 @@ class MachineInstr
Disjoint = 1 << 19, // Each bit is zero in at least one of the inputs.
NoUSWrap = 1 << 20, // Instruction supports geps
// no unsigned signed wrap.
- SameSign = 1 << 21 // Both operands have the same sign.
+ SameSign = 1 << 21, // Both operands have the same sign.
+ LRSplit = 1 << 22 // Instruction for live range split.
};
private:
diff --git a/llvm/lib/CodeGen/SplitKit.cpp b/llvm/lib/CodeGen/SplitKit.cpp
index eb33b93c197d7c..5042f074c26c45 100644
--- a/llvm/lib/CodeGen/SplitKit.cpp
+++ b/llvm/lib/CodeGen/SplitKit.cpp
@@ -533,6 +533,7 @@ SlotIndex SplitEditor::buildSingleSubRegCopy(
| getInternalReadRegState(!FirstCopy), SubIdx)
.addReg(FromReg, 0, SubIdx);
+ CopyMI->setFlag(MachineInstr::LRSplit);
SlotIndexes &Indexes = *LIS.getSlotIndexes();
if (FirstCopy) {
Def = Indexes.insertMachineInstrInMaps(*CopyMI, Late).getRegSlot();
@@ -552,6 +553,7 @@ SlotIndex SplitEditor::buildCopy(Register FromReg, Register ToReg,
// The full vreg is copied.
MachineInstr *CopyMI =
BuildMI(MBB, InsertBefore, DebugLoc(), Desc, ToReg).addReg(FromReg);
+ CopyMI->setFlag(MachineInstr::LRSplit);
return Indexes.insertMachineInstrInMaps(*CopyMI, Late).getRegSlot();
}
|
qcolombet
left a comment
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.
Why do you need this information?
At the end of the day this is just a regular copy.
Can you see the other PR in the stack? #117544 |
|
Ping |
My point is why do you have to distinguish them to begin with? |
For AMDGPU the bb prolog instructions are the RA inserted spills and LR split copies. Any other instruction included as part of BBProlog would result in wrong insertion point leading to buggy CodeGen. PHI elimination pass, for instance, uses the same hook to identify the insertion point while inserting copies at the predecessor blocks. Any COPY at a block begin that was part of regular CodeGen would then be included in the prolog leading to incorrect insertion points. |
|
Ping |
|
Ping @qcolombet. |
|
Ping. |
|
Ping. @qcolombet this patch addresses a critical bug in the AMDGPU codegen. Please take a look. |
|
I verified that when making all copy instructions part of the BB prologue, we see LIT regressions pointing to incorrect instruction scheduling (the program semantics is changed). but I get this out This instruction:
but it is not anymore (buffer loads are conditionally executed based on exec reg value). There are also a bunch of unhappy stack traces, such as Bad machine code: Using an undefined physical register in test basic-loop.ll. This is due to isBasicBlockPrologue being used across different functionalities, such as PHIElimination, MachineIRSink, and others. I think this patch and the associated #117544 are the minimum viable to fix this issue. |
|
I verified that this PR and the one associate to it also fix: |
For some targets, it is required to identify the COPY instruction corresponds to the RA inserted live range split. Adding the new flag `MachineInstr::LRSplit` to serve the purpose.
90f830f to
a9587c1
Compare

For some targets, it is required to identify the COPY instruction
corresponds to the RA inserted live range split. Adding the new
flag
MachineInstr::LRSplitto serve the purpose.