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_srem_positive_odd(i32 %x) {
5 ; CHECK-LABEL: fold_srem_positive_odd:
7 ; CHECK-NEXT: mov w8, #37253 // =0x9185
8 ; CHECK-NEXT: movk w8, #44150, lsl #16
9 ; CHECK-NEXT: smull x8, w0, w8
10 ; CHECK-NEXT: lsr x8, x8, #32
11 ; CHECK-NEXT: add w8, w8, w0
12 ; CHECK-NEXT: asr w9, w8, #6
13 ; CHECK-NEXT: add w8, w9, w8, lsr #31
14 ; CHECK-NEXT: mov w9, #95 // =0x5f
15 ; CHECK-NEXT: msub w0, w8, w9, w0
22 define i32 @fold_srem_positive_even(i32 %x) {
23 ; CHECK-LABEL: fold_srem_positive_even:
25 ; CHECK-NEXT: mov w8, #36849 // =0x8ff1
26 ; CHECK-NEXT: mov w9, #1060 // =0x424
27 ; CHECK-NEXT: movk w8, #15827, lsl #16
28 ; CHECK-NEXT: smull x8, w0, w8
29 ; CHECK-NEXT: asr x8, x8, #40
30 ; CHECK-NEXT: add w8, w8, w8, lsr #31
31 ; CHECK-NEXT: msub w0, w8, w9, w0
33 %1 = srem i32 %x, 1060
38 define i32 @fold_srem_negative_odd(i32 %x) {
39 ; CHECK-LABEL: fold_srem_negative_odd:
41 ; CHECK-NEXT: mov w8, #65445 // =0xffa5
42 ; CHECK-NEXT: mov w9, #-723 // =0xfffffd2d
43 ; CHECK-NEXT: movk w8, #42330, lsl #16
44 ; CHECK-NEXT: smull x8, w0, w8
45 ; CHECK-NEXT: asr x8, x8, #40
46 ; CHECK-NEXT: add w8, w8, w8, lsr #31
47 ; CHECK-NEXT: msub w0, w8, w9, w0
49 %1 = srem i32 %x, -723
54 define i32 @fold_srem_negative_even(i32 %x) {
55 ; CHECK-LABEL: fold_srem_negative_even:
57 ; CHECK-NEXT: mov w8, #62439 // =0xf3e7
58 ; CHECK-NEXT: mov w9, #-22981 // =0xffffa63b
59 ; CHECK-NEXT: movk w8, #64805, lsl #16
60 ; CHECK-NEXT: smull x8, w0, w8
61 ; CHECK-NEXT: asr x8, x8, #40
62 ; CHECK-NEXT: add w8, w8, w8, lsr #31
63 ; CHECK-NEXT: msub w0, w8, w9, w0
65 %1 = srem i32 %x, -22981
70 ; Don't fold if we can combine srem with sdiv.
71 define i32 @combine_srem_sdiv(i32 %x) {
72 ; CHECK-LABEL: combine_srem_sdiv:
74 ; CHECK-NEXT: mov w8, #37253 // =0x9185
75 ; CHECK-NEXT: movk w8, #44150, lsl #16
76 ; CHECK-NEXT: smull x8, w0, w8
77 ; CHECK-NEXT: lsr x8, x8, #32
78 ; CHECK-NEXT: add w8, w8, w0
79 ; CHECK-NEXT: asr w9, w8, #6
80 ; CHECK-NEXT: add w8, w9, w8, lsr #31
81 ; CHECK-NEXT: mov w9, #95 // =0x5f
82 ; CHECK-NEXT: msub w9, w8, w9, w0
83 ; CHECK-NEXT: add w0, w9, w8
92 define i64 @dont_fold_srem_i64(i64 %x) {
93 ; CHECK-LABEL: dont_fold_srem_i64:
95 ; CHECK-NEXT: mov x8, #58849 // =0xe5e1
96 ; CHECK-NEXT: movk x8, #48148, lsl #16
97 ; CHECK-NEXT: movk x8, #33436, lsl #32
98 ; CHECK-NEXT: movk x8, #21399, lsl #48
99 ; CHECK-NEXT: smulh x8, x0, x8
100 ; CHECK-NEXT: asr x9, x8, #5
101 ; CHECK-NEXT: add x8, x9, x8, lsr #63
102 ; CHECK-NEXT: mov w9, #98 // =0x62
103 ; CHECK-NEXT: msub x0, x8, x9, x0