1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2 ; RUN: llc < %s -mtriple=x86_64-unknown-unknown | FileCheck %s --check-prefix=CHECK
4 define i32 @fold_urem_positive_odd(i32 %x) {
5 ; CHECK-LABEL: fold_urem_positive_odd:
7 ; CHECK-NEXT: movl %edi, %eax
8 ; CHECK-NEXT: movl %edi, %ecx
9 ; CHECK-NEXT: imulq $1491936009, %rcx, %rcx # imm = 0x58ED2309
10 ; CHECK-NEXT: shrq $32, %rcx
11 ; CHECK-NEXT: movl %edi, %edx
12 ; CHECK-NEXT: subl %ecx, %edx
13 ; CHECK-NEXT: shrl %edx
14 ; CHECK-NEXT: addl %ecx, %edx
15 ; CHECK-NEXT: shrl $6, %edx
16 ; CHECK-NEXT: imull $95, %edx, %ecx
17 ; CHECK-NEXT: subl %ecx, %eax
24 define i32 @fold_urem_positive_even(i32 %x) {
25 ; CHECK-LABEL: fold_urem_positive_even:
27 ; CHECK-NEXT: movl %edi, %eax
28 ; CHECK-NEXT: movl %edi, %ecx
29 ; CHECK-NEXT: movl $4149100483, %edx # imm = 0xF74E3FC3
30 ; CHECK-NEXT: imulq %rcx, %rdx
31 ; CHECK-NEXT: shrq $42, %rdx
32 ; CHECK-NEXT: imull $1060, %edx, %ecx # imm = 0x424
33 ; CHECK-NEXT: subl %ecx, %eax
35 %1 = urem i32 %x, 1060
40 ; Don't fold if we can combine urem with udiv.
41 define i32 @combine_urem_udiv(i32 %x) {
42 ; CHECK-LABEL: combine_urem_udiv:
44 ; CHECK-NEXT: # kill: def $edi killed $edi def $rdi
45 ; CHECK-NEXT: movl %edi, %eax
46 ; CHECK-NEXT: imulq $1491936009, %rax, %rax # imm = 0x58ED2309
47 ; CHECK-NEXT: shrq $32, %rax
48 ; CHECK-NEXT: movl %edi, %ecx
49 ; CHECK-NEXT: subl %eax, %ecx
50 ; CHECK-NEXT: shrl %ecx
51 ; CHECK-NEXT: addl %eax, %ecx
52 ; CHECK-NEXT: shrl $6, %ecx
53 ; CHECK-NEXT: imull $95, %ecx, %eax
54 ; CHECK-NEXT: subl %eax, %edi
55 ; CHECK-NEXT: leal (%rdi,%rcx), %eax
63 ; Don't fold for divisors that are a power of two.
64 define i32 @dont_fold_urem_power_of_two(i32 %x) {
65 ; CHECK-LABEL: dont_fold_urem_power_of_two:
67 ; CHECK-NEXT: movl %edi, %eax
68 ; CHECK-NEXT: andl $63, %eax
74 ; Don't fold if the divisor is one.
75 define i32 @dont_fold_urem_one(i32 %x) {
76 ; CHECK-LABEL: dont_fold_urem_one:
78 ; CHECK-NEXT: xorl %eax, %eax
84 ; Don't fold if the divisor is 2^32.
85 define i32 @dont_fold_urem_i32_umax(i32 %x) {
86 ; CHECK-LABEL: dont_fold_urem_i32_umax:
89 %1 = urem i32 %x, 4294967296
94 define i64 @dont_fold_urem_i64(i64 %x) {
95 ; CHECK-LABEL: dont_fold_urem_i64:
97 ; CHECK-NEXT: movq %rdi, %rax
98 ; CHECK-NEXT: shrq %rax
99 ; CHECK-NEXT: movabsq $6023426636313322977, %rcx # imm = 0x5397829CBC14E5E1
100 ; CHECK-NEXT: mulq %rcx
101 ; CHECK-NEXT: shrq $4, %rdx
102 ; CHECK-NEXT: imulq $98, %rdx, %rax
103 ; CHECK-NEXT: subq %rax, %rdi
104 ; CHECK-NEXT: movq %rdi, %rax