[PATCH] D123484: [WebAssembly] Implement ref.is_null intrinstic
Paulo Matos via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Apr 11 00:20:11 PDT 2022
pmatos created this revision.
pmatos added reviewers: asb, tlively.
Herald added subscribers: StephenFan, wingo, ecnelises, sunfish, hiraditya, jgravelle-google, sbc100, dschuff.
Herald added a project: All.
pmatos requested review of this revision.
Herald added subscribers: llvm-commits, aheejin.
Herald added a project: LLVM.
Add support for intrinsic to generate ref.is_null.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D123484
Files:
llvm/include/llvm/IR/IntrinsicsWebAssembly.td
llvm/lib/Target/WebAssembly/WebAssemblyInstrRef.td
llvm/test/CodeGen/WebAssembly/ref-null.ll
llvm/test/MC/WebAssembly/reference-types.s
Index: llvm/test/MC/WebAssembly/reference-types.s
===================================================================
--- llvm/test/MC/WebAssembly/reference-types.s
+++ llvm/test/MC/WebAssembly/reference-types.s
@@ -1,6 +1,15 @@
# RUN: llvm-mc -show-encoding -triple=wasm32-unknown-unknown -mattr=+reference-types < %s | FileCheck %s
# RUN: llvm-mc -show-encoding -triple=wasm64-unknown-unknown -mattr=+reference-types < %s | FileCheck %s
+# CHECK-LABEL:ref_is_null:
+# CHECK: ref.is_null # encoding: [0xd1]
+ref_is_null:
+ .functype ref_is_null () -> ()
+ ref.null_func
+ ref.is_null
+ drop
+ end_function
+
# CHECK-LABEL: ref_null_test:
# CHECK: ref.null_func # encoding: [0xd0,0x70]
# CHECK: ref.null_extern # encoding: [0xd0,0x6f]
Index: llvm/test/CodeGen/WebAssembly/ref-null.ll
===================================================================
--- llvm/test/CodeGen/WebAssembly/ref-null.ll
+++ llvm/test/CodeGen/WebAssembly/ref-null.ll
@@ -6,6 +6,7 @@
declare %externref @llvm.wasm.ref.null.extern() nounwind
declare %funcref @llvm.wasm.ref.null.func() nounwind
+declare i32 @llvm.wasm.ref.is_null() nounwind
define %externref @get_null_extern() {
; CHECK-LABEL: get_null_extern:
@@ -24,3 +25,23 @@
%null = call %funcref @llvm.wasm.ref.null.func()
ret %funcref %null
}
+
+define i32 @ref_is_null_eref(%extenref %eref) {
+ ; CHECK-LABEL: ref_is_null:
+ ; CHECK-NEXT: .functype ref_is_null (externref) -> (i32)
+ %null = call %externref @llvm.wasm.ref.null.extern()
+ %is_null = call i32 @llvm.wasm.ref.is_null(%externref %null)
+ %arg_is_null = call i32 @llvm.wasm.ref.is_null(%externref %eref)
+ %res = i32 add nsw i32 %is_null, i32 %arg_is_null
+ ret i32 %res
+}
+
+define i32 @ref_is_null_fref(%funcref %fref) {
+ ; CHECK-LABEL: ref_is_null:
+ ; CHECK-NEXT: .functype ref_is_null (externref) -> (i32)
+ %null = call %funcref @llvm.wasm.ref.null.func()
+ %is_null = call i32 @llvm.wasm.ref.is_null(%funcref %null)
+ %arg_is_null = call i32 @llvm.wasm.ref.is_null(%funcref %fref)
+ %res = i32 add nsw i32 %is_null, i32 %arg_is_null
+ ret i32 %res
+}
\ No newline at end of file
Index: llvm/lib/Target/WebAssembly/WebAssemblyInstrRef.td
===================================================================
--- llvm/lib/Target/WebAssembly/WebAssemblyInstrRef.td
+++ llvm/lib/Target/WebAssembly/WebAssemblyInstrRef.td
@@ -27,6 +27,13 @@
vt#".select\t$dst, $lhs, $rhs, $cond",
vt#".select", 0x1b>,
Requires<[HasReferenceTypes]>;
+ defm REF_IS_NULL_#rc : I<(outs I32:$dst), (ins rc:$ref),
+ (outs I32:$dst), (ins),
+ [(set I32:$dst, (int_wasm_ref_is_null rc:$ref))],
+ "ref.is_null\t$ref",
+ "ref.is_null",
+ 0xd1>,
+ Requires<[HasReferenceTypes]>;
}
defm "" : REF_I<FUNCREF, funcref, "func">;
@@ -37,4 +44,4 @@
(!cast<Instruction>("SELECT_"#rc) rc:$lhs, rc:$rhs, I32:$cond)>;
def : Pat<(select (i32 (seteq I32:$cond, 0)), rc:$lhs, rc:$rhs),
(!cast<Instruction>("SELECT_"#rc) rc:$rhs, rc:$lhs, I32:$cond)>;
-}
+}
\ No newline at end of file
Index: llvm/include/llvm/IR/IntrinsicsWebAssembly.td
===================================================================
--- llvm/include/llvm/IR/IntrinsicsWebAssembly.td
+++ llvm/include/llvm/IR/IntrinsicsWebAssembly.td
@@ -31,6 +31,7 @@
//===----------------------------------------------------------------------===//
def int_wasm_ref_null_extern : Intrinsic<[llvm_externref_ty], [], [IntrNoMem]>;
def int_wasm_ref_null_func : Intrinsic<[llvm_funcref_ty], [], [IntrNoMem]>;
+def int_wasm_ref_is_null : Intrinsic<[llvm_i32_ty], [llvm_any_ty], [IntrNoMem]>;
//===----------------------------------------------------------------------===//
// Table intrinsics
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D123484.421840.patch
Type: text/x-patch
Size: 3914 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220411/28f5ac03/attachment.bin>
More information about the llvm-commits
mailing list