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: movl %edi, %eax
45 ; CHECK-NEXT: imulq $1491936009, %rax, %rcx # imm = 0x58ED2309
46 ; CHECK-NEXT: shrq $32, %rcx
47 ; CHECK-NEXT: movl %edi, %eax
48 ; CHECK-NEXT: subl %ecx, %eax
49 ; CHECK-NEXT: shrl %eax
50 ; CHECK-NEXT: addl %ecx, %eax
51 ; CHECK-NEXT: shrl $6, %eax
52 ; CHECK-NEXT: imull $95, %eax, %ecx
53 ; CHECK-NEXT: subl %ecx, %edi
54 ; CHECK-NEXT: addl %edi, %eax
62 ; Don't fold for divisors that are a power of two.
63 define i32 @dont_fold_urem_power_of_two(i32 %x) {
64 ; CHECK-LABEL: dont_fold_urem_power_of_two:
66 ; CHECK-NEXT: movl %edi, %eax
67 ; CHECK-NEXT: andl $63, %eax
73 ; Don't fold if the divisor is one.
74 define i32 @dont_fold_urem_one(i32 %x) {
75 ; CHECK-LABEL: dont_fold_urem_one:
77 ; CHECK-NEXT: xorl %eax, %eax
83 ; Don't fold if the divisor is 2^32.
84 define i32 @dont_fold_urem_i32_umax(i32 %x) {
85 ; CHECK-LABEL: dont_fold_urem_i32_umax:
88 %1 = urem i32 %x, 4294967296
93 define i64 @dont_fold_urem_i64(i64 %x) {
94 ; CHECK-LABEL: dont_fold_urem_i64:
96 ; CHECK-NEXT: movq %rdi, %rax
97 ; CHECK-NEXT: shrq %rax
98 ; CHECK-NEXT: movabsq $6023426636313322977, %rcx # imm = 0x5397829CBC14E5E1
99 ; CHECK-NEXT: mulq %rcx
100 ; CHECK-NEXT: shrq $4, %rdx
101 ; CHECK-NEXT: imulq $98, %rdx, %rax
102 ; CHECK-NEXT: subq %rax, %rdi
103 ; CHECK-NEXT: movq %rdi, %rax