Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions llvm/lib/Target/WebAssembly/WebAssemblyInstrInteger.td
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,10 @@ def : Pat<(rotr I64:$lhs, (and I64:$rhs, 63)), (ROTR_I64 I64:$lhs, I64:$rhs)>;

def : Pat<(shl I64:$lhs, (zext (and I32:$rhs, 63))),
(SHL_I64 I64:$lhs, (I64_EXTEND_U_I32 I32:$rhs))>;
def : Pat<(sra I64:$lhs, (zext (and I32:$rhs, 63))),
(SHR_S_I64 I64:$lhs, (I64_EXTEND_U_I32 I32:$rhs))>;
def : Pat<(srl I64:$lhs, (zext (and I32:$rhs, 63))),
(SHR_U_I64 I64:$lhs, (I64_EXTEND_U_I32 I32:$rhs))>;

defm SELECT_I32 : I<(outs I32:$dst), (ins I32:$lhs, I32:$rhs, I32:$cond),
(outs), (ins),
Expand Down
30 changes: 30 additions & 0 deletions llvm/test/CodeGen/WebAssembly/masked-shifts.ll
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,21 @@ define i32 @sra_i32(i32 %v, i32 %x) {
ret i32 %a
}

define i64 @sra_i64_zext(i64 %v, i32 %x) {
; CHECK-LABEL: sra_i64_zext:
; CHECK: .functype sra_i64_zext (i64, i32) -> (i64)
; CHECK-NEXT: # %bb.0:
; CHECK-NEXT: local.get 0
; CHECK-NEXT: local.get 1
; CHECK-NEXT: i64.extend_i32_u
; CHECK-NEXT: i64.shr_s
; CHECK-NEXT: # fallthrough-return
%m = and i32 %x, 63
%z = zext i32 %m to i64
%a = ashr i64 %v, %z
ret i64 %a
}

define i32 @srl_i32(i32 %v, i32 %x) {
; CHECK-LABEL: srl_i32:
; CHECK: .functype srl_i32 (i32, i32) -> (i32)
Expand All @@ -59,6 +74,21 @@ define i32 @srl_i32(i32 %v, i32 %x) {
ret i32 %a
}

define i64 @srl_i64_zext(i64 %v, i32 %x) {
; CHECK-LABEL: srl_i64_zext:
; CHECK: .functype srl_i64_zext (i64, i32) -> (i64)
; CHECK-NEXT: # %bb.0:
; CHECK-NEXT: local.get 0
; CHECK-NEXT: local.get 1
; CHECK-NEXT: i64.extend_i32_u
; CHECK-NEXT: i64.shr_u
; CHECK-NEXT: # fallthrough-return
%m = and i32 %x, 63
%z = zext i32 %m to i64
%a = lshr i64 %v, %z
ret i64 %a
}

define i64 @shl_i64(i64 %v, i64 %x) {
; CHECK-LABEL: shl_i64:
; CHECK: .functype shl_i64 (i64, i64) -> (i64)
Expand Down
Loading