blob: 29aac381951d3f840f4744d2fabaa953a6d863a0 [file] [log] [blame]
Wouter van Oortmerssen8a9cb242018-08-27 15:45:51 +00001; RUN: llc < %s -asm-verbose=false -wasm-keep-registers | FileCheck %s
Dan Gohmanb4c3c382016-05-18 14:29:42 +00002
3; Test that integer div and rem by constant are optimized appropriately.
4
5target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128"
Sam Clegga5908002018-05-10 17:49:11 +00006target triple = "wasm32-unknown-unknown"
Dan Gohmanb4c3c382016-05-18 14:29:42 +00007
8; CHECK-LABEL: test_udiv_2:
9; CHECK: i32.shr_u
10define i32 @test_udiv_2(i32 %x) {
11 %t = udiv i32 %x, 2
12 ret i32 %t
13}
14
15; CHECK-LABEL: test_udiv_5:
16; CHECK: i32.div_u
17define i32 @test_udiv_5(i32 %x) {
18 %t = udiv i32 %x, 5
19 ret i32 %t
20}
21
22; CHECK-LABEL: test_sdiv_2:
23; CHECK: i32.div_s
24define i32 @test_sdiv_2(i32 %x) {
25 %t = sdiv i32 %x, 2
26 ret i32 %t
27}
28
29; CHECK-LABEL: test_sdiv_5:
30; CHECK: i32.div_s
31define i32 @test_sdiv_5(i32 %x) {
32 %t = sdiv i32 %x, 5
33 ret i32 %t
34}
35
36; CHECK-LABEL: test_urem_2:
37; CHECK: i32.and
38define i32 @test_urem_2(i32 %x) {
39 %t = urem i32 %x, 2
40 ret i32 %t
41}
42
43; CHECK-LABEL: test_urem_5:
44; CHECK: i32.rem_u
45define i32 @test_urem_5(i32 %x) {
46 %t = urem i32 %x, 5
47 ret i32 %t
48}
49
50; CHECK-LABEL: test_srem_2:
51; CHECK: i32.rem_s
52define i32 @test_srem_2(i32 %x) {
53 %t = srem i32 %x, 2
54 ret i32 %t
55}
56
57; CHECK-LABEL: test_srem_5:
58; CHECK: i32.rem_s
59define i32 @test_srem_5(i32 %x) {
60 %t = srem i32 %x, 5
61 ret i32 %t
62}