[PATCH] D37073: [WebAssembly] FastISel : Lower constant calls as direct calls

Jacob Gravelle via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 23 09:45:18 PDT 2017


jgravelle-google created this revision.
Herald added subscribers: aheejin, sbc100, jfb.

We can avoid creating indirect function calls when the callee is a constant value.


https://reviews.llvm.org/D37073

Files:
  lib/Target/WebAssembly/WebAssemblyFastISel.cpp
  test/CodeGen/WebAssembly/call.ll


Index: test/CodeGen/WebAssembly/call.ll
===================================================================
--- test/CodeGen/WebAssembly/call.ll
+++ test/CodeGen/WebAssembly/call.ll
@@ -150,6 +150,18 @@
   ret void
 }
 
+; CHECK-LABEL: call_bitcast_vararg:
+; CHECK-NEXT: .result i32{{$}}
+; CHECK-NEXT: i32.const $push[[L0:[0-9]+]]=, 2{{$}}
+; CHECK-NEXT: i32.const $push[[L1:[0-9]+]]=, 3{{$}}
+; CHECK-NEXT: i32.call $push[[L2:[0-9]+]]=, vararg_func at FUNCTION, $pop[[L0]], $pop[[L1]]{{$}}
+; CHECK-NEXT: return $pop[[L2]]{{$}}
+declare i32 @vararg_func(...)
+define i32 @call_bitcast_vararg() {
+  %ret = call i32 bitcast (i32 (...)* @vararg_func to i32 (i32, i32)*)(i32 2, i32 3)
+  ret i32 %ret
+}
+
 ; TODO: test the following:
 ;  - More argument combinations.
 ;  - Tail call.
Index: lib/Target/WebAssembly/WebAssemblyFastISel.cpp
===================================================================
--- lib/Target/WebAssembly/WebAssemblyFastISel.cpp
+++ lib/Target/WebAssembly/WebAssemblyFastISel.cpp
@@ -700,6 +700,9 @@
   if (Func && Func->isIntrinsic())
     return false;
 
+  if (!Func && isa<Constant>(Call->getCalledValue()))
+    return false;
+
   FunctionType *FuncTy = Call->getFunctionType();
   unsigned Opc;
   bool IsDirect = Func != nullptr;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D37073.112392.patch
Type: text/x-patch
Size: 1264 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170823/caf94a0d/attachment.bin>


More information about the llvm-commits mailing list