1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2 ; RUN: llc -mtriple=aarch64-unknown-linux-gnu < %s | FileCheck %s
4 define i32 @fold_urem_positive_odd(i32 %x) {
5 ; CHECK-LABEL: fold_urem_positive_odd:
7 ; CHECK-NEXT: mov w8, #8969 // =0x2309
8 ; CHECK-NEXT: movk w8, #22765, lsl #16
9 ; CHECK-NEXT: umull x8, w0, w8
10 ; CHECK-NEXT: lsr x8, x8, #32
11 ; CHECK-NEXT: sub w9, w0, w8
12 ; CHECK-NEXT: add w8, w8, w9, lsr #1
13 ; CHECK-NEXT: mov w9, #95 // =0x5f
14 ; CHECK-NEXT: lsr w8, w8, #6
15 ; CHECK-NEXT: msub w0, w8, w9, w0
22 define i32 @fold_urem_positive_even(i32 %x) {
23 ; CHECK-LABEL: fold_urem_positive_even:
25 ; CHECK-NEXT: mov w8, #16323 // =0x3fc3
26 ; CHECK-NEXT: mov w9, #1060 // =0x424
27 ; CHECK-NEXT: movk w8, #63310, lsl #16
28 ; CHECK-NEXT: umull x8, w0, w8
29 ; CHECK-NEXT: lsr x8, x8, #42
30 ; CHECK-NEXT: msub w0, w8, w9, w0
32 %1 = urem i32 %x, 1060
37 ; Don't fold if we can combine urem with udiv.
38 define i32 @combine_urem_udiv(i32 %x) {
39 ; CHECK-LABEL: combine_urem_udiv:
41 ; CHECK-NEXT: mov w8, #8969 // =0x2309
42 ; CHECK-NEXT: movk w8, #22765, lsl #16
43 ; CHECK-NEXT: umull x8, w0, w8
44 ; CHECK-NEXT: lsr x8, x8, #32
45 ; CHECK-NEXT: sub w9, w0, w8
46 ; CHECK-NEXT: add w8, w8, w9, lsr #1
47 ; CHECK-NEXT: mov w9, #95 // =0x5f
48 ; CHECK-NEXT: lsr w8, w8, #6
49 ; CHECK-NEXT: msub w9, w8, w9, w0
50 ; CHECK-NEXT: add w0, w9, w8
58 ; Don't fold for divisors that are a power of two.
59 define i32 @dont_fold_urem_power_of_two(i32 %x) {
60 ; CHECK-LABEL: dont_fold_urem_power_of_two:
62 ; CHECK-NEXT: and w0, w0, #0x3f
68 ; Don't fold if the divisor is one.
69 define i32 @dont_fold_urem_one(i32 %x) {
70 ; CHECK-LABEL: dont_fold_urem_one:
72 ; CHECK-NEXT: mov w0, wzr
78 ; Don't fold if the divisor is 2^32.
79 define i32 @dont_fold_urem_i32_umax(i32 %x) {
80 ; CHECK-LABEL: dont_fold_urem_i32_umax:
83 %1 = urem i32 %x, 4294967296
88 define i64 @dont_fold_urem_i64(i64 %x) {
89 ; CHECK-LABEL: dont_fold_urem_i64:
91 ; CHECK-NEXT: mov x9, #58849 // =0xe5e1
92 ; CHECK-NEXT: lsr x8, x0, #1
93 ; CHECK-NEXT: movk x9, #48148, lsl #16
94 ; CHECK-NEXT: movk x9, #33436, lsl #32
95 ; CHECK-NEXT: movk x9, #21399, lsl #48
96 ; CHECK-NEXT: umulh x8, x8, x9
97 ; CHECK-NEXT: mov w9, #98 // =0x62
98 ; CHECK-NEXT: lsr x8, x8, #4
99 ; CHECK-NEXT: msub x0, x8, x9, x0