Skip to content

Commit

Permalink
[WebAssembly] Implement the eqz instructions.
Browse files Browse the repository at this point in the history
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@263976 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
Dan Gohman committed Mar 21, 2016
1 parent dc7ed9f commit c13556c
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
7 changes: 7 additions & 0 deletions lib/Target/WebAssembly/WebAssemblyInstrInteger.td
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,13 @@ defm CLZ : UnaryInt<ctlz, "clz ">;
defm CTZ : UnaryInt<cttz, "ctz ">;
defm POPCNT : UnaryInt<ctpop, "popcnt">;

def EQZ_I32 : I<(outs I32:$dst), (ins I32:$src),
[(set I32:$dst, (setcc I32:$src, 0, SETEQ))],
"i32.eqz \t$dst, $src">;
def EQZ_I64 : I<(outs I32:$dst), (ins I64:$src),
[(set I32:$dst, (setcc I64:$src, 0, SETEQ))],
"i64.eqz \t$dst, $src">;

} // Defs = [ARGUMENTS]

// Expand the "don't care" operations to supported operations.
Expand Down
11 changes: 11 additions & 0 deletions test/CodeGen/WebAssembly/i32.ll
Original file line number Diff line number Diff line change
Expand Up @@ -188,3 +188,14 @@ define i32 @popcnt32(i32 %x) {
%a = call i32 @llvm.ctpop.i32(i32 %x)
ret i32 %a
}

; CHECK-LABEL: eqz32:
; CHECK-NEXT: .param i32{{$}}
; CHECK-NEXT: .result i32{{$}}
; CHECK-NEXT: i32.eqz $push0=, $0{{$}}
; CHECK-NEXT: return $pop0{{$}}
define i32 @eqz32(i32 %x) {
%a = icmp eq i32 %x, 0
%b = zext i1 %a to i32
ret i32 %b
}
11 changes: 11 additions & 0 deletions test/CodeGen/WebAssembly/i64.ll
Original file line number Diff line number Diff line change
Expand Up @@ -188,3 +188,14 @@ define i64 @popcnt64(i64 %x) {
%a = call i64 @llvm.ctpop.i64(i64 %x)
ret i64 %a
}

; CHECK-LABEL: eqz64:
; CHECK-NEXT: .param i64{{$}}
; CHECK-NEXT: .result i32{{$}}
; CHECK-NEXT: i64.eqz $push0=, $0{{$}}
; CHECK-NEXT: return $pop0{{$}}
define i32 @eqz64(i64 %x) {
%a = icmp eq i64 %x, 0
%b = zext i1 %a to i32
ret i32 %b
}

0 comments on commit c13556c

Please sign in to comment.