Skip to content

Commit d893278

Browse files
[GlobalISel][InlineAsm] Fix matching input constraint to physreg
Add given input and mark it as tied. Doesn't create additional copy compared to matching input constraint to virtual register. Differential Revision: https://reviews.llvm.org/D85122
1 parent 5a07490 commit d893278

File tree

2 files changed

+23
-7
lines changed

2 files changed

+23
-7
lines changed

llvm/lib/CodeGen/GlobalISel/InlineAsmLowering.cpp

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -455,19 +455,23 @@ bool InlineAsmLowering::lowerInlineAsm(
455455
unsigned DefRegIdx = InstFlagIdx + 1;
456456
Register Def = Inst->getOperand(DefRegIdx).getReg();
457457

458-
// Copy input to new vreg with same reg class as Def
459-
const TargetRegisterClass *RC = MRI->getRegClass(Def);
460458
ArrayRef<Register> SrcRegs = GetOrCreateVRegs(*OpInfo.CallOperandVal);
461459
assert(SrcRegs.size() == 1 && "Single register is expected here");
462-
Register Tmp = MRI->createVirtualRegister(RC);
463-
if (!buildAnyextOrCopy(Tmp, SrcRegs[0], MIRBuilder))
464-
return false;
465460

466-
// Add Flag and input register operand (Tmp) to Inst. Tie Tmp to Def.
461+
// When Def is physreg: use given input.
462+
Register In = SrcRegs[0];
463+
// When Def is vreg: copy input to new vreg with same reg class as Def.
464+
if (Def.isVirtual()) {
465+
In = MRI->createVirtualRegister(MRI->getRegClass(Def));
466+
if (!buildAnyextOrCopy(In, SrcRegs[0], MIRBuilder))
467+
return false;
468+
}
469+
470+
// Add Flag and input register operand (In) to Inst. Tie In to Def.
467471
unsigned UseFlag = InlineAsm::getFlagWord(InlineAsm::Kind_RegUse, 1);
468472
unsigned Flag = InlineAsm::getFlagWordForMatchingOp(UseFlag, DefIdx);
469473
Inst.addImm(Flag);
470-
Inst.addReg(Tmp);
474+
Inst.addReg(In);
471475
Inst->tieOperands(DefRegIdx, Inst->getNumOperands() - 1);
472476
break;
473477
}

llvm/test/CodeGen/AArch64/GlobalISel/irtranslator-inline-asm.ll

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,3 +243,15 @@ define i16 @test_anyext_input_with_matching_constraint() {
243243
%1 = call i16 asm sideeffect "", "=r,0"(i16 1)
244244
ret i16 %1
245245
}
246+
247+
define i64 @test_input_with_matching_constraint_to_physical_register() {
248+
; CHECK-LABEL: name: test_input_with_matching_constraint_to_physical_register
249+
; CHECK: bb.1 (%ir-block.0):
250+
; CHECK: [[C:%[0-9]+]]:_(s64) = G_CONSTANT i64 0
251+
; CHECK: INLINEASM &"", 0 /* attdialect */, 10 /* regdef */, implicit-def $x2, 2147483657 /* reguse tiedto:$0 */, [[C]](tied-def 3)(s64)
252+
; CHECK: [[COPY:%[0-9]+]]:_(s64) = COPY $x2
253+
; CHECK: $x0 = COPY [[COPY]](s64)
254+
; CHECK: RET_ReallyLR implicit $x0
255+
%1 = tail call i64 asm "", "={x2},0"(i64 0)
256+
ret i64 %1
257+
}

0 commit comments

Comments
 (0)