[PATCH] D52914: [WebAssembly] Added test for inline assembly roundtrip.

Wouter van Oortmerssen via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 4 16:34:54 PDT 2018


aardappel created this revision.
aardappel added reviewers: dschuff, sunfish.
Herald added subscribers: llvm-commits, aheejin, eraman, jgravelle-google, sbc100.

Due to previous work to make WebAssembly MC by default stack-only
inline assembly now "just works" (previously it didn't since it had
no way to know types of registers), so no further work required.

So far we only have tests (in inline-asm.ll) which test with
non-existing instructions, so this adds a test that roundtrips
both the inline assembly and its surrounding code thru the assembler.


Repository:
  rL LLVM

https://reviews.llvm.org/D52914

Files:
  test/CodeGen/WebAssembly/inline-asm-roundtrip.ll


Index: test/CodeGen/WebAssembly/inline-asm-roundtrip.ll
===================================================================
--- /dev/null
+++ test/CodeGen/WebAssembly/inline-asm-roundtrip.ll
@@ -0,0 +1,53 @@
+; RUN: llc < %s | llvm-mc -triple=wasm32-unknown-unknown-wasm | FileCheck %s
+
+; Test basic inline assembly can actually be assembled by the assembler.
+
+; .ll code below is the result of this code run thru
+; clang -target wasm32-unknown-unknown-wasm -O2 -S -emit-llvm test.c
+
+; int main(int argc, const char *argv[]) {
+;   int src = 1;
+;   int dst;
+;   asm ("i32.const\t2\n"
+;      "\tget_local\t%1\n"
+;      "\ti32.add\n"
+;      "\tset_local\t%0"
+;       : "=r" (dst)
+;       : "r" (src));
+;   return dst != 3;
+; }
+
+source_filename = "test.c"
+target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128"
+target triple = "wasm32-unknown-unknown-wasm"
+
+; CHECK-LABEL: main:
+; CHECK-NEXT:	.param  	i32, i32{{$}}
+; CHECK-NEXT:	.local  	i32{{$}}
+; CHECK-NEXT:	i32.const	1{{$}}
+; CHECK-NEXT:	set_local	2{{$}}
+; CHECK-NEXT:	i32.const	2{{$}}
+; CHECK-NEXT:	get_local	2{{$}}
+; CHECK-NEXT:	i32.add {{$}}
+; CHECK-NEXT:	set_local	2{{$}}
+; CHECK-NEXT:	get_local	2{{$}}
+; CHECK-NEXT:	i32.const	3{{$}}
+; CHECK-NEXT:	i32.ne {{$}}
+
+define hidden i32 @main(i32 %argc, i8** nocapture readnone %argv) local_unnamed_addr #0 {
+entry:
+  %0 = tail call i32 asm "i32.const\092\0A\09get_local\09$1\0A\09i32.add\0A\09set_local\09$0", "=r,r"(i32 1) #1, !srcloc !2
+  %cmp = icmp ne i32 %0, 3
+  %conv = zext i1 %cmp to i32
+  ret i32 %conv
+}
+
+attributes #0 = { nounwind readnone "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="generic" "unsafe-fp-math"="false" "use-soft-float"="false" }
+attributes #1 = { nounwind readnone }
+
+!llvm.module.flags = !{!0}
+!llvm.ident = !{!1}
+
+!0 = !{i32 1, !"wchar_size", i32 4}
+!1 = !{!"clang version 8.0.0 (trunk 343492) (llvm/trunk 343501)"}
+!2 = !{i32 117, i32 140, i32 165, i32 184}


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D52914.168407.patch
Type: text/x-patch
Size: 2219 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20181004/984b264f/attachment-0001.bin>


More information about the llvm-commits mailing list