[llvm] 9bb7122 - [RISCV][GlobalISel] Lower calls to variadic functions (#68271)

via llvm-commits llvm-commits at lists.llvm.org
Tue Oct 10 11:19:26 PDT 2023


Author: Nitin John Raj
Date: 2023-10-10T11:19:21-07:00
New Revision: 9bb71226e2c9cb2dd3122511b12cc46b949488ad

URL: https://github.com/llvm/llvm-project/commit/9bb71226e2c9cb2dd3122511b12cc46b949488ad
DIFF: https://github.com/llvm/llvm-project/commit/9bb71226e2c9cb2dd3122511b12cc46b949488ad.diff

LOG: [RISCV][GlobalISel] Lower calls to variadic functions (#68271)

Calls to variadic functions do not seem to require any special handling.

Added: 
    llvm/test/CodeGen/RISCV/GlobalISel/call-lowering/variadic-call.ll

Modified: 
    llvm/lib/Target/RISCV/GISel/RISCVCallLowering.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Target/RISCV/GISel/RISCVCallLowering.cpp b/llvm/lib/Target/RISCV/GISel/RISCVCallLowering.cpp
index 5505f89a32f21be..a362a709329d5df 100644
--- a/llvm/lib/Target/RISCV/GISel/RISCVCallLowering.cpp
+++ b/llvm/lib/Target/RISCV/GISel/RISCVCallLowering.cpp
@@ -252,10 +252,6 @@ bool RISCVCallLowering::lowerCall(MachineIRBuilder &MIRBuilder,
   const Function &F = MF.getFunction();
   CallingConv::ID CC = F.getCallingConv();
 
-  // TODO: Support vararg functions.
-  if (Info.IsVarArg)
-    return false;
-
   // TODO: Support all argument types.
   for (auto &AInfo : Info.OrigArgs) {
     if (AInfo.Ty->isIntegerTy())

diff  --git a/llvm/test/CodeGen/RISCV/GlobalISel/call-lowering/variadic-call.ll b/llvm/test/CodeGen/RISCV/GlobalISel/call-lowering/variadic-call.ll
new file mode 100644
index 000000000000000..d0f962c301130c5
--- /dev/null
+++ b/llvm/test/CodeGen/RISCV/GlobalISel/call-lowering/variadic-call.ll
@@ -0,0 +1,50 @@
+; NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py
+; RUN: llc -mtriple=riscv32 -global-isel --stop-before=legalizer < %s -o - \
+; RUN:   | FileCheck --check-prefix=RV32I %s
+; RUN: llc -mtriple=riscv64 -global-isel --stop-before=legalizer < %s -o - \
+; RUN:   | FileCheck --check-prefix=RV64I %s
+
+declare i32 @foo(i32 noundef signext, ...)
+
+define i32 @main() {
+  ; RV32I-LABEL: name: main
+  ; RV32I: bb.1.entry:
+  ; RV32I-NEXT:   [[C:%[0-9]+]]:_(s32) = G_CONSTANT i32 0
+  ; RV32I-NEXT:   [[C1:%[0-9]+]]:_(s32) = G_CONSTANT i32 1
+  ; RV32I-NEXT:   [[C2:%[0-9]+]]:_(s32) = G_CONSTANT i32 2
+  ; RV32I-NEXT:   [[C3:%[0-9]+]]:_(s32) = G_CONSTANT i32 3
+  ; RV32I-NEXT:   [[FRAME_INDEX:%[0-9]+]]:_(p0) = G_FRAME_INDEX %stack.0.retval
+  ; RV32I-NEXT:   G_STORE [[C]](s32), [[FRAME_INDEX]](p0) :: (store (s32) into %ir.retval)
+  ; RV32I-NEXT:   $x10 = COPY [[C]](s32)
+  ; RV32I-NEXT:   $x11 = COPY [[C1]](s32)
+  ; RV32I-NEXT:   $x12 = COPY [[C2]](s32)
+  ; RV32I-NEXT:   $x13 = COPY [[C3]](s32)
+  ; RV32I-NEXT:   PseudoCALL target-flags(riscv-call) @foo, implicit-def $x1, implicit $x10, implicit $x11, implicit $x12, implicit $x13, implicit-def $x10
+  ; RV32I-NEXT:   [[COPY:%[0-9]+]]:_(s32) = COPY $x10
+  ; RV32I-NEXT:   $x10 = COPY [[COPY]](s32)
+  ; RV32I-NEXT:   PseudoRET implicit $x10
+  ;
+  ; RV64I-LABEL: name: main
+  ; RV64I: bb.1.entry:
+  ; RV64I-NEXT:   [[C:%[0-9]+]]:_(s32) = G_CONSTANT i32 0
+  ; RV64I-NEXT:   [[FRAME_INDEX:%[0-9]+]]:_(p0) = G_FRAME_INDEX %stack.0.retval
+  ; RV64I-NEXT:   G_STORE [[C]](s32), [[FRAME_INDEX]](p0) :: (store (s32) into %ir.retval)
+  ; RV64I-NEXT:   [[C1:%[0-9]+]]:_(s64) = G_CONSTANT i64 0
+  ; RV64I-NEXT:   [[C2:%[0-9]+]]:_(s64) = G_CONSTANT i64 1
+  ; RV64I-NEXT:   [[C3:%[0-9]+]]:_(s64) = G_CONSTANT i64 2
+  ; RV64I-NEXT:   [[C4:%[0-9]+]]:_(s64) = G_CONSTANT i64 3
+  ; RV64I-NEXT:   $x10 = COPY [[C1]](s64)
+  ; RV64I-NEXT:   $x11 = COPY [[C2]](s64)
+  ; RV64I-NEXT:   $x12 = COPY [[C3]](s64)
+  ; RV64I-NEXT:   $x13 = COPY [[C4]](s64)
+  ; RV64I-NEXT:   PseudoCALL target-flags(riscv-call) @foo, implicit-def $x1, implicit $x10, implicit $x11, implicit $x12, implicit $x13, implicit-def $x10
+  ; RV64I-NEXT:   [[COPY:%[0-9]+]]:_(s64) = COPY $x10
+  ; RV64I-NEXT:   [[ASSERT_SEXT:%[0-9]+]]:_(s64) = G_ASSERT_SEXT [[COPY]], 32
+  ; RV64I-NEXT:   $x10 = COPY [[ASSERT_SEXT]](s64)
+  ; RV64I-NEXT:   PseudoRET implicit $x10
+entry:
+  %retval = alloca i32, align 4
+  store i32 0, ptr %retval, align 4
+  %call = call noundef signext i32 (i32, ...) @foo(i32 noundef signext 0, i32 noundef signext 1, i32 noundef signext 2, i32 noundef signext 3)
+  ret i32 %call
+}


        


More information about the llvm-commits mailing list