Skip to content

Commit 46dbc84

Browse files
committed
[Clang][RISCV] Handle RVV tuple types correctly as InputOperand for inline asm
This commit flatten the input operand from an aggregate structure into separate arguments for RVV tuple types.
1 parent a825dc6 commit 46dbc84

File tree

2 files changed

+37
-5
lines changed

2 files changed

+37
-5
lines changed

clang/lib/CodeGen/CGStmt.cpp

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2709,10 +2709,40 @@ void CodeGenFunction::EmitAsmStmt(const AsmStmt &S) {
27092709
std::max((uint64_t)LargestVectorWidth,
27102710
VT->getPrimitiveSizeInBits().getKnownMinValue());
27112711

2712-
ArgTypes.push_back(Arg->getType());
2713-
ArgElemTypes.push_back(ArgElemType);
2714-
Args.push_back(Arg);
2715-
Constraints += InputConstraint;
2712+
// Expand RVV tuple type input operands.
2713+
if (InputExpr->getType()->isRVVType() && Arg->getType()->isStructTy()) {
2714+
std::string ExpandedInputContraint;
2715+
2716+
auto *STy = cast<llvm::StructType>(Arg->getType());
2717+
2718+
assert(STy->containsHomogeneousScalableVectorTypes() &&
2719+
isa<llvm::ScalableVectorType>(STy->getElementType(0)) &&
2720+
"Only aggregate type of homogeneous scalable vectors is handled "
2721+
"here");
2722+
2723+
auto *VTy = cast<llvm::ScalableVectorType>(STy->getElementType(0));
2724+
2725+
for (unsigned Idx = 0, TupleSize = STy->getNumElements();
2726+
Idx != TupleSize; ++Idx) {
2727+
if (ExpandedInputContraint.size())
2728+
ExpandedInputContraint += ",";
2729+
2730+
ExpandedInputContraint += InputConstraint;
2731+
ArgTypes.push_back(VTy);
2732+
ArgElemTypes.push_back(ArgElemType);
2733+
2734+
llvm::Value *SubVec = Builder.CreateExtractValue(Arg, {Idx});
2735+
2736+
Args.push_back(SubVec);
2737+
}
2738+
2739+
Constraints += ExpandedInputContraint;
2740+
} else {
2741+
ArgTypes.push_back(Arg->getType());
2742+
ArgElemTypes.push_back(ArgElemType);
2743+
Args.push_back(Arg);
2744+
Constraints += InputConstraint;
2745+
}
27162746
}
27172747

27182748
// Append the "input" part of inout constraints.

clang/test/CodeGen/RISCV/rvv-intrinsics-handcrafted/rvv-inline-asm.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ void bar() {
3131
// CHECK-LABEL: define dso_local void @baz(
3232
// CHECK-SAME: ) #[[ATTR0]] {
3333
// CHECK-NEXT: entry:
34-
// CHECK-NEXT: call void asm sideeffect "#NOP", "^vr"({ <vscale x 2 x i32>, <vscale x 2 x i32> } undef) #[[ATTR2:[0-9]+]], !srcloc !6
34+
// CHECK-NEXT: [[TMP0:%.*]] = extractvalue { <vscale x 2 x i32>, <vscale x 2 x i32> } undef, 0
35+
// CHECK-NEXT: [[TMP1:%.*]] = extractvalue { <vscale x 2 x i32>, <vscale x 2 x i32> } undef, 1
36+
// CHECK-NEXT: call void asm sideeffect "#NOP", "^vr,^vr"(<vscale x 2 x i32> [[TMP0]], <vscale x 2 x i32> [[TMP1]]) #[[ATTR2:[0-9]+]], !srcloc !6
3537
// CHECK-NEXT: ret void
3638
//
3739
void baz() {

0 commit comments

Comments
 (0)