Skip to content

Commit e0e5b6e

Browse files
authored
[GISel][Inlineasm] Support inlineasm i/s constraint for symbols (#170094)
1 parent 76c3eed commit e0e5b6e

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

llvm/lib/CodeGen/GlobalISel/InlineAsmLowering.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -657,7 +657,18 @@ bool InlineAsmLowering::lowerAsmOperandForConstraint(
657657
switch (ConstraintLetter) {
658658
default:
659659
return false;
660+
case 's': // Integer immediate not known at compile time
661+
if (const auto *GV = dyn_cast<GlobalValue>(Val)) {
662+
Ops.push_back(MachineOperand::CreateGA(GV, /*Offset=*/0));
663+
return true;
664+
}
665+
return false;
660666
case 'i': // Simple Integer or Relocatable Constant
667+
if (const auto *GV = dyn_cast<GlobalValue>(Val)) {
668+
Ops.push_back(MachineOperand::CreateGA(GV, /*Offset=*/0));
669+
return true;
670+
}
671+
[[fallthrough]];
661672
case 'n': // immediate integer with a known value.
662673
if (ConstantInt *CI = dyn_cast<ConstantInt>(Val)) {
663674
assert(CI->getBitWidth() <= 64 &&

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,25 @@ define void @test_input_imm() {
183183
ret void
184184
}
185185

186+
@var = global i64 0, align 8
187+
define void @test_immediate_constraint_sym() {
188+
; CHECK-LABEL: name: test_immediate_constraint_sym
189+
; CHECK: bb.1 (%ir-block.0):
190+
; CHECK-NEXT: INLINEASM &"#TEST $0", 9 /* sideeffect mayload attdialect */, 13 /* imm */, @var
191+
; CHECK-NEXT: RET_ReallyLR
192+
call void asm sideeffect "#TEST $0", "i"(ptr @var)
193+
ret void
194+
}
195+
196+
define void @test_s_constraint() {
197+
; CHECK-LABEL: name: test_s_constraint
198+
; CHECK: bb.1 (%ir-block.0):
199+
; CHECK-NEXT: INLINEASM &"#TEST $0", 9 /* sideeffect mayload attdialect */, 13 /* imm */, @var
200+
; CHECK-NEXT: RET_ReallyLR
201+
call void asm sideeffect "#TEST $0", "s"(ptr @var)
202+
ret void
203+
}
204+
186205
define zeroext i8 @test_input_register(ptr %src) nounwind {
187206
; CHECK-LABEL: name: test_input_register
188207
; CHECK: bb.1.entry:

0 commit comments

Comments
 (0)