Skip to content

Commit 7759232

Browse files
committed
[TargetLowering] Use Correct VT for Multi-out Asm
This was overlooked in 7d94043 - when inline assembly has multiple outputs, they are returned as members of a struct, and the `getAsmOperandType` needs to be called for each member of struct. I noticed this when trying to use the same mechanism in the RISC-V backend. Committing two tests: - One that shows a crash before this change, which is fixed by this change. - One (commented out) that shows a different crash with tied inputs/outputs. This is commented as it is not fixed by this change and needs more work in target-independent inline asm handling code.
1 parent be89e79 commit 7759232

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5753,7 +5753,7 @@ TargetLowering::ParseConstraints(const DataLayout &DL,
57535753
assert(!Call.getType()->isVoidTy() && "Bad inline asm!");
57545754
if (auto *STy = dyn_cast<StructType>(Call.getType())) {
57555755
OpInfo.ConstraintVT =
5756-
getSimpleValueType(DL, STy->getElementType(ResNo));
5756+
getAsmOperandValueType(DL, STy->getElementType(ResNo)).getSimpleVT();
57575757
} else {
57585758
assert(ResNo == 0 && "Asm only has one result!");
57595759
OpInfo.ConstraintVT =

llvm/test/CodeGen/AArch64/ls64-inline-asm.ll

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,3 +103,37 @@ entry:
103103
call void asm sideeffect "st64b $0,[$1]", "r,r,~{memory}"(i512 %s.sroa.0.0.insert.insert, ptr %addr)
104104
ret void
105105
}
106+
107+
define void @multi_output(ptr %addr) {
108+
; CHECK-LABEL: multi_output:
109+
; CHECK: // %bb.0: // %entry
110+
; CHECK-NEXT: //APP
111+
; CHECK-NEXT: ld64b x0, [x0]
112+
; CHECK-NEXT: mov x8, x0
113+
; CHECK-NEXT: //NO_APP
114+
; CHECK-NEXT: stp x6, x7, [x8, #48]
115+
; CHECK-NEXT: stp x4, x5, [x8, #32]
116+
; CHECK-NEXT: stp x2, x3, [x8, #16]
117+
; CHECK-NEXT: stp x0, x1, [x8]
118+
; CHECK-NEXT: ret
119+
entry:
120+
%val = call { i512, ptr } asm sideeffect "ld64b $0, [$2]; mov $1, $2", "=r,=r,r,~{memory}"(ptr %addr)
121+
%val0 = extractvalue { i512, ptr } %val, 0
122+
%val1 = extractvalue { i512, ptr } %val, 1
123+
store i512 %val0, ptr %val1, align 8
124+
ret void
125+
}
126+
127+
; FIXME: This case still crashes in RegsForValue::AddInlineAsmOperands without
128+
; additional changes. I believe this is a bug in target-independent code, that
129+
; is worked around in the RISC-V and SystemZ backends, but should almost
130+
; certainly be fixed instead.
131+
; define void @tied_constraints(ptr %addr) {
132+
; entry:
133+
; %in = load i512, ptr %addr, align 8
134+
; %val = call { i512, ptr } asm sideeffect "nop", "=r,=r,0,1,~{memory}"(i512 %in, ptr %addr)
135+
; %val0 = extractvalue { i512, ptr } %val, 0
136+
; %val1 = extractvalue { i512, ptr } %val, 1
137+
; store i512 %val0, ptr %val1, align 8
138+
; ret void
139+
; }

0 commit comments

Comments
 (0)