1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2 ; RUN: llc -mtriple=aarch64-unknown-linux-gnu < %s | FileCheck %s
9 ; This needs to be a backend-level fold because only by now pointers
10 ; are just registers; in middle-end IR this can only be done via @llvm.ptrmask()
11 ; intrinsic which is not sufficiently widely-spread yet.
13 ; https://bugs.llvm.org/show_bug.cgi?id=44448
15 ; The basic positive tests
17 define i32 @t0_32(i32 %ptr, i32 %mask) nounwind {
20 ; CHECK-NEXT: bic w0, w0, w1
22 %bias = and i32 %ptr, %mask
23 %r = sub i32 %ptr, %bias
26 define i64 @t1_64(i64 %ptr, i64 %mask) nounwind {
29 ; CHECK-NEXT: bic x0, x0, x1
31 %bias = and i64 %ptr, %mask
32 %r = sub i64 %ptr, %bias
36 define i32 @t2_commutative(i32 %ptr, i32 %mask) nounwind {
37 ; CHECK-LABEL: t2_commutative:
39 ; CHECK-NEXT: bic w0, w0, w1
41 %bias = and i32 %mask, %ptr ; swapped
42 %r = sub i32 %ptr, %bias
48 define i32 @n3_extrause1(i32 %ptr, i32 %mask, i32* %bias_storage) nounwind {
49 ; CHECK-LABEL: n3_extrause1:
51 ; CHECK-NEXT: and w8, w0, w1
52 ; CHECK-NEXT: sub w0, w0, w8
53 ; CHECK-NEXT: str w8, [x2]
55 %bias = and i32 %ptr, %mask ; has extra uses, can't fold
56 store i32 %bias, i32* %bias_storage
57 %r = sub i32 %ptr, %bias
63 define i32 @n4_different_ptrs(i32 %ptr0, i32 %ptr1, i32 %mask) nounwind {
64 ; CHECK-LABEL: n4_different_ptrs:
66 ; CHECK-NEXT: and w8, w1, w2
67 ; CHECK-NEXT: sub w0, w0, w8
69 %bias = and i32 %ptr1, %mask ; not %ptr0
70 %r = sub i32 %ptr0, %bias ; not %ptr1
73 define i32 @n5_different_ptrs_commutative(i32 %ptr0, i32 %ptr1, i32 %mask) nounwind {
74 ; CHECK-LABEL: n5_different_ptrs_commutative:
76 ; CHECK-NEXT: and w8, w2, w1
77 ; CHECK-NEXT: sub w0, w0, w8
79 %bias = and i32 %mask, %ptr1 ; swapped, not %ptr0
80 %r = sub i32 %ptr0, %bias ; not %ptr1
84 define i32 @n6_not_lowbit_mask(i32 %ptr, i32 %mask) nounwind {
85 ; CHECK-LABEL: n6_not_lowbit_mask:
87 ; CHECK-NEXT: bic w0, w0, w1
89 %bias = and i32 %ptr, %mask
90 %r = sub i32 %ptr, %bias
94 define i32 @n7_sub_is_not_commutative(i32 %ptr, i32 %mask) nounwind {
95 ; CHECK-LABEL: n7_sub_is_not_commutative:
97 ; CHECK-NEXT: and w8, w0, w1
98 ; CHECK-NEXT: sub w0, w8, w0
100 %bias = and i32 %ptr, %mask
101 %r = sub i32 %bias, %ptr ; wrong order