aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
diff options
context:
space:
mode:
authorXChy <xxs_chy@outlook.com>2025-08-12 20:37:56 +0800
committerGitHub <noreply@github.com>2025-08-12 12:37:56 +0000
commit2a4971952520b49d4db2bb734214ae2fe2e5ee34 (patch)
tree1f202dcac033d9faf5fb2884dd169603c774fb51 /llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
parent48da8489f2c1d416658527f6b806d618abd5ab73 (diff)
downloadllvm-2a4971952520b49d4db2bb734214ae2fe2e5ee34.zip
llvm-2a4971952520b49d4db2bb734214ae2fe2e5ee34.tar.gz
llvm-2a4971952520b49d4db2bb734214ae2fe2e5ee34.tar.bz2
[SelectionDAGBuilder] Look for appropriate INLINEASM_BR instruction to verify (#152591)
Partially fix #149023. The original code `MRI.def_begin(Reg)->getParent()` may return the incorrect MI, as the physical register `Reg` may have multiple definitions. This patch selects the correct MI to verify by comparing the MBB of each definition. New testcase hangs with -O1/2/3 enabled. The BranchFolding may be to blame.
Diffstat (limited to 'llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp')
-rw-r--r--llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp13
1 files changed, 9 insertions, 4 deletions
diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
index 7aa1fad..6256ebc 100644
--- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
@@ -12744,17 +12744,22 @@ static Register FollowCopyChain(MachineRegisterInfo &MRI, Register Reg) {
assert(MI->getOpcode() == TargetOpcode::COPY &&
"start of copy chain MUST be COPY");
Reg = MI->getOperand(1).getReg();
+
+ // If the copied register in the first copy must be virtual.
+ assert(Reg.isVirtual() && "expected COPY of virtual register");
MI = MRI.def_begin(Reg)->getParent();
+
// There may be an optional second copy.
if (MI->getOpcode() == TargetOpcode::COPY) {
assert(Reg.isVirtual() && "expected COPY of virtual register");
Reg = MI->getOperand(1).getReg();
assert(Reg.isPhysical() && "expected COPY of physical register");
- MI = MRI.def_begin(Reg)->getParent();
+ } else {
+ // The start of the chain must be an INLINEASM_BR.
+ assert(MI->getOpcode() == TargetOpcode::INLINEASM_BR &&
+ "end of copy chain MUST be INLINEASM_BR");
}
- // The start of the chain must be an INLINEASM_BR.
- assert(MI->getOpcode() == TargetOpcode::INLINEASM_BR &&
- "end of copy chain MUST be INLINEASM_BR");
+
return Reg;
}