1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2 ; RUN: llc -verify-machineinstrs -mtriple=powerpc-unknown-linux-gnu -mcpu=ppc64 < %s | FileCheck -check-prefixes=CHECK,CHECK64 %s
3 ; RUN: llc -verify-machineinstrs -mtriple=powerpc-unknown-linux-gnu -mcpu=ppc < %s | FileCheck -check-prefixes=CHECK,CHECK32 %s
5 define i32 @fold_srem_positive_odd(i32 %x) {
6 ; CHECK-LABEL: fold_srem_positive_odd:
8 ; CHECK-NEXT: lis 4, -21386
9 ; CHECK-NEXT: ori 4, 4, 37253
10 ; CHECK-NEXT: mulhw 4, 3, 4
11 ; CHECK-NEXT: add 4, 4, 3
12 ; CHECK-NEXT: srwi 5, 4, 31
13 ; CHECK-NEXT: srawi 4, 4, 6
14 ; CHECK-NEXT: add 4, 4, 5
15 ; CHECK-NEXT: mulli 4, 4, 95
16 ; CHECK-NEXT: subf 3, 4, 3
23 define i32 @fold_srem_positive_even(i32 %x) {
24 ; CHECK-LABEL: fold_srem_positive_even:
26 ; CHECK-NEXT: lis 4, 15827
27 ; CHECK-NEXT: ori 4, 4, 36849
28 ; CHECK-NEXT: mulhw 4, 3, 4
29 ; CHECK-NEXT: srwi 5, 4, 31
30 ; CHECK-NEXT: srawi 4, 4, 8
31 ; CHECK-NEXT: add 4, 4, 5
32 ; CHECK-NEXT: mulli 4, 4, 1060
33 ; CHECK-NEXT: subf 3, 4, 3
35 %1 = srem i32 %x, 1060
40 define i32 @fold_srem_negative_odd(i32 %x) {
41 ; CHECK-LABEL: fold_srem_negative_odd:
43 ; CHECK-NEXT: lis 4, -23206
44 ; CHECK-NEXT: ori 4, 4, 65445
45 ; CHECK-NEXT: mulhw 4, 3, 4
46 ; CHECK-NEXT: srwi 5, 4, 31
47 ; CHECK-NEXT: srawi 4, 4, 8
48 ; CHECK-NEXT: add 4, 4, 5
49 ; CHECK-NEXT: mulli 4, 4, -723
50 ; CHECK-NEXT: subf 3, 4, 3
52 %1 = srem i32 %x, -723
57 define i32 @fold_srem_negative_even(i32 %x) {
58 ; CHECK-LABEL: fold_srem_negative_even:
60 ; CHECK-NEXT: lis 4, -731
61 ; CHECK-NEXT: ori 4, 4, 62439
62 ; CHECK-NEXT: mulhw 4, 3, 4
63 ; CHECK-NEXT: srwi 5, 4, 31
64 ; CHECK-NEXT: srawi 4, 4, 8
65 ; CHECK-NEXT: add 4, 4, 5
66 ; CHECK-NEXT: mulli 4, 4, -22981
67 ; CHECK-NEXT: subf 3, 4, 3
69 %1 = srem i32 %x, -22981
74 ; Don't fold if we can combine srem with sdiv.
75 define i32 @combine_srem_sdiv(i32 %x) {
76 ; CHECK-LABEL: combine_srem_sdiv:
78 ; CHECK-NEXT: lis 4, -21386
79 ; CHECK-NEXT: ori 4, 4, 37253
80 ; CHECK-NEXT: mulhw 4, 3, 4
81 ; CHECK-NEXT: add 4, 4, 3
82 ; CHECK-NEXT: srwi 5, 4, 31
83 ; CHECK-NEXT: srawi 4, 4, 6
84 ; CHECK-NEXT: add 4, 4, 5
85 ; CHECK-NEXT: mulli 5, 4, 95
86 ; CHECK-NEXT: subf 3, 5, 3
87 ; CHECK-NEXT: add 3, 3, 4
95 ; Don't fold for divisors that are a power of two.
96 define i32 @dont_fold_srem_power_of_two(i32 %x) {
97 ; CHECK-LABEL: dont_fold_srem_power_of_two:
99 ; CHECK-NEXT: srawi 4, 3, 6
100 ; CHECK-NEXT: addze 4, 4
101 ; CHECK-NEXT: slwi 4, 4, 6
102 ; CHECK-NEXT: subf 3, 4, 3
108 ; Don't fold if the divisor is one.
109 define i32 @dont_fold_srem_one(i32 %x) {
110 ; CHECK-LABEL: dont_fold_srem_one:
112 ; CHECK-NEXT: li 3, 0
118 ; Don't fold if the divisor is 2^31.
119 define i32 @dont_fold_srem_i32_smax(i32 %x) {
120 ; CHECK-LABEL: dont_fold_srem_i32_smax:
122 ; CHECK-NEXT: srawi 4, 3, 31
123 ; CHECK-NEXT: addze 4, 4
124 ; CHECK-NEXT: slwi 4, 4, 31
125 ; CHECK-NEXT: add 3, 3, 4
127 %1 = srem i32 %x, 2147483648
131 ; Don't fold i64 srem
132 define i64 @dont_fold_srem_i64(i64 %x) {
133 ; CHECK-LABEL: dont_fold_srem_i64:
136 ; CHECK-NEXT: stw 0, 4(1)
137 ; CHECK-NEXT: stwu 1, -16(1)
138 ; CHECK-NEXT: .cfi_def_cfa_offset 16
139 ; CHECK-NEXT: .cfi_offset lr, 4
140 ; CHECK-NEXT: li 5, 0
141 ; CHECK-NEXT: li 6, 98
142 ; CHECK-NEXT: bl __moddi3@PLT
143 ; CHECK-NEXT: lwz 0, 20(1)
144 ; CHECK-NEXT: addi 1, 1, 16