Home | History | Annotate | Download | only in WebAssembly
      1 ; RUN: llc < %s -asm-verbose=false | FileCheck %s
      2 
      3 ; Test that integer div and rem by constant are optimized appropriately.
      4 
      5 target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128"
      6 target triple = "wasm32-unknown-unknown"
      7 
      8 ; CHECK-LABEL: test_udiv_2:
      9 ; CHECK: i32.shr_u
     10 define 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
     17 define 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
     24 define 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
     31 define 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
     38 define 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
     45 define 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
     52 define 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
     59 define i32 @test_srem_5(i32 %x) {
     60     %t = srem i32 %x, 5
     61     ret i32 %t
     62 }
     63