1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2 ; RUN: llc -mtriple=i686-unknown-linux-gnu < %s | FileCheck %s --check-prefix=X86
3 ; RUN: llc -mtriple=x86_64-unknown-linux-gnu < %s | FileCheck %s --check-prefix=X64
10 ; This needs to be a backend-level fold because only by now pointers
11 ; are just registers; in middle-end IR this can only be done via @llvm.ptrmask()
12 ; intrinsic which is not sufficiently widely-spread yet.
14 ; https://bugs.llvm.org/show_bug.cgi?id=44448
16 ; The basic positive tests
18 define i32 @t0_32(i32 %ptr) nounwind {
21 ; X86-NEXT: movl {{[0-9]+}}(%esp), %eax
22 ; X86-NEXT: andl $-16, %eax
27 ; X64-NEXT: movl %edi, %eax
28 ; X64-NEXT: andl $-16, %eax
30 %bias = and i32 %ptr, 15
31 %r = sub i32 %ptr, %bias
34 define i64 @t1_64(i64 %ptr) nounwind {
37 ; X86-NEXT: movl {{[0-9]+}}(%esp), %eax
38 ; X86-NEXT: movl {{[0-9]+}}(%esp), %edx
39 ; X86-NEXT: andl $-16, %eax
44 ; X64-NEXT: movq %rdi, %rax
45 ; X64-NEXT: andq $-16, %rax
47 %bias = and i64 %ptr, 15
48 %r = sub i64 %ptr, %bias
52 define i32 @t2_powerof2(i32 %ptr) nounwind {
53 ; X86-LABEL: t2_powerof2:
55 ; X86-NEXT: movl {{[0-9]+}}(%esp), %eax
56 ; X86-NEXT: andl $-17, %eax
59 ; X64-LABEL: t2_powerof2:
61 ; X64-NEXT: movl %edi, %eax
62 ; X64-NEXT: andl $-17, %eax
64 %bias = and i32 %ptr, 16
65 %r = sub i32 %ptr, %bias
68 define i32 @t3_random_constant(i32 %ptr) nounwind {
69 ; X86-LABEL: t3_random_constant:
71 ; X86-NEXT: movl {{[0-9]+}}(%esp), %eax
72 ; X86-NEXT: andl $-43, %eax
75 ; X64-LABEL: t3_random_constant:
77 ; X64-NEXT: movl %edi, %eax
78 ; X64-NEXT: andl $-43, %eax
80 %bias = and i32 %ptr, 42
81 %r = sub i32 %ptr, %bias
87 define i32 @t4_extrause(i32 %ptr, ptr %bias_storage) nounwind {
88 ; X86-LABEL: t4_extrause:
90 ; X86-NEXT: movl {{[0-9]+}}(%esp), %ecx
91 ; X86-NEXT: movl {{[0-9]+}}(%esp), %eax
92 ; X86-NEXT: movl %eax, %edx
93 ; X86-NEXT: andl $15, %edx
94 ; X86-NEXT: movl %edx, (%ecx)
95 ; X86-NEXT: andl $-16, %eax
98 ; X64-LABEL: t4_extrause:
100 ; X64-NEXT: movl %edi, %eax
101 ; X64-NEXT: movl %edi, %ecx
102 ; X64-NEXT: andl $15, %ecx
103 ; X64-NEXT: movl %ecx, (%rsi)
104 ; X64-NEXT: andl $-16, %eax
106 %bias = and i32 %ptr, 15
107 store i32 %bias, ptr %bias_storage
108 %r = sub i32 %ptr, %bias
114 define i32 @n5_different_ptrs(i32 %ptr0, i32 %ptr1) nounwind {
115 ; X86-LABEL: n5_different_ptrs:
117 ; X86-NEXT: movl {{[0-9]+}}(%esp), %eax
118 ; X86-NEXT: movl {{[0-9]+}}(%esp), %ecx
119 ; X86-NEXT: andl $15, %ecx
120 ; X86-NEXT: subl %ecx, %eax
123 ; X64-LABEL: n5_different_ptrs:
125 ; X64-NEXT: movl %edi, %eax
126 ; X64-NEXT: andl $15, %esi
127 ; X64-NEXT: subl %esi, %eax
129 %bias = and i32 %ptr1, 15 ; not %ptr0
130 %r = sub i32 %ptr0, %bias ; not %ptr1
134 define i32 @n6_sub_is_not_commutative(i32 %ptr) nounwind {
135 ; X86-LABEL: n6_sub_is_not_commutative:
137 ; X86-NEXT: movl {{[0-9]+}}(%esp), %ecx
138 ; X86-NEXT: movl %ecx, %eax
139 ; X86-NEXT: andl $15, %eax
140 ; X86-NEXT: subl %ecx, %eax
143 ; X64-LABEL: n6_sub_is_not_commutative:
145 ; X64-NEXT: movl %edi, %eax
146 ; X64-NEXT: andl $15, %eax
147 ; X64-NEXT: subl %edi, %eax
149 %bias = and i32 %ptr, 15
150 %r = sub i32 %bias, %ptr ; wrong order