Skip to content

[SelectionDAGBuilder] Look for appropriate INLINEASM_BR instruction to verify #152591

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 2 commits into from
Aug 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12737,17 +12737,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;
}

Expand Down
47 changes: 47 additions & 0 deletions llvm/test/CodeGen/X86/callbr-asm-loop.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 5

; RUN: llc -O0 -mtriple=i686-- < %s | FileCheck %s

; Test that causes multiple defs of %eax.
; FIXME: The testcase hangs with -O1/2/3 enabled.
define i32 @loop1() nounwind {
; CHECK-LABEL: loop1:
; CHECK: # %bb.0: # %entry
; CHECK-NEXT: pushl %esi
; CHECK-NEXT: jmp .LBB0_1
; CHECK-NEXT: .LBB0_1: # %tailrecurse
; CHECK-NEXT: # =>This Inner Loop Header: Depth=1
; CHECK-NEXT: xorl %eax, %eax
; CHECK-NEXT: movl $1, %edx
; CHECK-NEXT: #APP
; CHECK-NEXT: #NO_APP
; CHECK-NEXT: movl %eax, %ecx
; CHECK-NEXT: movl %edx, %esi
; CHECK-NEXT: jmp .LBB0_3
; CHECK-NEXT: .LBB0_2: # Inline asm indirect target
; CHECK-NEXT: # %tailrecurse.tailrecurse.backedge_crit_edge
; CHECK-NEXT: # in Loop: Header=BB0_1 Depth=1
; CHECK-NEXT: # Label of block must be emitted
; CHECK-NEXT: .LBB0_3: # %tailrecurse.backedge
; CHECK-NEXT: # in Loop: Header=BB0_1 Depth=1
; CHECK-NEXT: jmp .LBB0_1
; CHECK-NEXT: .LBB0_4: # Inline asm indirect target
; CHECK-NEXT: # %lab2.split
; CHECK-NEXT: # Label of block must be emitted
; CHECK-NEXT: movl %edx, %eax
; CHECK-NEXT: popl %esi
; CHECK-NEXT: retl
entry:
br label %tailrecurse

tailrecurse:
%0 = callbr { i32, i32 } asm "", "={ax},={dx},0,1,!i,!i"(i32 0, i32 1) #1
to label %tailrecurse.backedge [label %tailrecurse.backedge, label %lab2.split]

tailrecurse.backedge:
br label %tailrecurse

lab2.split:
%asmresult5 = extractvalue { i32, i32 } %0, 1
ret i32 %asmresult5
}