From c26771d7ab09a3b3b290abc135eb8352fc07c1da Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Mon, 24 Aug 2015 16:39:37 +0000 Subject: [PATCH] [WebAssembly] Implement the is_zero_undef forms of cttz and ctlz git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@245851 91177308-0d34-0410-b5e6-96231b3b80d8 --- .../WebAssembly/WebAssemblyInstrInteger.td | 6 ++++++ test/CodeGen/WebAssembly/integer32.ll | 18 ++++++++++++++++++ test/CodeGen/WebAssembly/integer64.ll | 18 ++++++++++++++++++ 3 files changed, 42 insertions(+) diff --git a/lib/Target/WebAssembly/WebAssemblyInstrInteger.td b/lib/Target/WebAssembly/WebAssemblyInstrInteger.td index cf2c6a38d51..16ed7acbb9d 100644 --- a/lib/Target/WebAssembly/WebAssemblyInstrInteger.td +++ b/lib/Target/WebAssembly/WebAssemblyInstrInteger.td @@ -40,3 +40,9 @@ defm UGE : ComparisonInt; defm CLZ : UnaryInt; defm CTZ : UnaryInt; defm POPCNT : UnaryInt; + +// Expand the "don't care" operations to supported operations. +def : Pat<(ctlz_zero_undef Int32:$src), (CLZ_I32 Int32:$src)>; +def : Pat<(ctlz_zero_undef Int64:$src), (CLZ_I64 Int64:$src)>; +def : Pat<(cttz_zero_undef Int32:$src), (CTZ_I32 Int32:$src)>; +def : Pat<(cttz_zero_undef Int64:$src), (CTZ_I64 Int64:$src)>; diff --git a/test/CodeGen/WebAssembly/integer32.ll b/test/CodeGen/WebAssembly/integer32.ll index e987f6eaa55..ab2d0b9497c 100644 --- a/test/CodeGen/WebAssembly/integer32.ll +++ b/test/CodeGen/WebAssembly/integer32.ll @@ -148,6 +148,15 @@ define i32 @clz32(i32 %x) { ret i32 %a } +; CHECK-LABEL: clz32_zero_undef: +; CHECK-NEXT: (setlocal @0 (argument 0)) +; CHECK-NEXT: (setlocal @1 (clz @0)) +; CHECK-NEXT: (return @1) +define i32 @clz32_zero_undef(i32 %x) { + %a = call i32 @llvm.ctlz.i32(i32 %x, i1 true) + ret i32 %a +} + ; CHECK-LABEL: ctz32: ; CHECK-NEXT: (setlocal @0 (argument 0)) ; CHECK-NEXT: (setlocal @1 (ctz @0)) @@ -157,6 +166,15 @@ define i32 @ctz32(i32 %x) { ret i32 %a } +; CHECK-LABEL: ctz32_zero_undef: +; CHECK-NEXT: (setlocal @0 (argument 0)) +; CHECK-NEXT: (setlocal @1 (ctz @0)) +; CHECK-NEXT: (return @1) +define i32 @ctz32_zero_undef(i32 %x) { + %a = call i32 @llvm.cttz.i32(i32 %x, i1 true) + ret i32 %a +} + ; CHECK-LABEL: popcnt32: ; CHECK-NEXT: (setlocal @0 (argument 0)) ; CHECK-NEXT: (setlocal @1 (popcnt @0)) diff --git a/test/CodeGen/WebAssembly/integer64.ll b/test/CodeGen/WebAssembly/integer64.ll index ba483552939..f902bced9d9 100644 --- a/test/CodeGen/WebAssembly/integer64.ll +++ b/test/CodeGen/WebAssembly/integer64.ll @@ -148,6 +148,15 @@ define i64 @clz64(i64 %x) { ret i64 %a } +; CHECK-LABEL: clz64_zero_undef: +; CHECK-NEXT: (setlocal @0 (argument 0)) +; CHECK-NEXT: (setlocal @1 (clz @0)) +; CHECK-NEXT: (return @1) +define i64 @clz64_zero_undef(i64 %x) { + %a = call i64 @llvm.ctlz.i64(i64 %x, i1 true) + ret i64 %a +} + ; CHECK-LABEL: ctz64: ; CHECK-NEXT: (setlocal @0 (argument 0)) ; CHECK-NEXT: (setlocal @1 (ctz @0)) @@ -157,6 +166,15 @@ define i64 @ctz64(i64 %x) { ret i64 %a } +; CHECK-LABEL: ctz64_zero_undef: +; CHECK-NEXT: (setlocal @0 (argument 0)) +; CHECK-NEXT: (setlocal @1 (ctz @0)) +; CHECK-NEXT: (return @1) +define i64 @ctz64_zero_undef(i64 %x) { + %a = call i64 @llvm.cttz.i64(i64 %x, i1 true) + ret i64 %a +} + ; CHECK-LABEL: popcnt64: ; CHECK-NEXT: (setlocal @0 (argument 0)) ; CHECK-NEXT: (setlocal @1 (popcnt @0)) -- 2.34.1