mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-25 12:12:47 +01:00
24c9de9750
The fold 'A - (A & (B - 1))' -> 'A & (0 - B)' added in 8dab0a4a7d691f2704f1079538e0ef29548db159 is too specific. It should/can just be 'A - (A & B)' -> 'A & (~B)' Even if we don't manage to fold `~` into B, we have likely formed `ANDN` node. Also, this way there's less similar-but-duplicate folds. Name: X - (X & Y) -> X & (~Y) %o = and i32 %X, %Y %r = sub i32 %X, %o => %n = xor i32 %Y, -1 %r = and i32 %X, %n https://rise4fun.com/Alive/kOUl See https://bugs.llvm.org/show_bug.cgi?id=44448 https://reviews.llvm.org/D71499
104 lines
2.8 KiB
LLVM
104 lines
2.8 KiB
LLVM
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
|
|
; RUN: llc -mtriple=aarch64-unknown-linux-gnu < %s | FileCheck %s
|
|
|
|
; Fold
|
|
; ptr - (ptr & mask)
|
|
; To
|
|
; ptr & (~mask)
|
|
;
|
|
; This needs to be a backend-level fold because only by now pointers
|
|
; are just registers; in middle-end IR this can only be done via @llvm.ptrmask()
|
|
; intrinsic which is not sufficiently widely-spread yet.
|
|
;
|
|
; https://bugs.llvm.org/show_bug.cgi?id=44448
|
|
|
|
; The basic positive tests
|
|
|
|
define i32 @t0_32(i32 %ptr, i32 %mask) nounwind {
|
|
; CHECK-LABEL: t0_32:
|
|
; CHECK: // %bb.0:
|
|
; CHECK-NEXT: bic w0, w0, w1
|
|
; CHECK-NEXT: ret
|
|
%bias = and i32 %ptr, %mask
|
|
%r = sub i32 %ptr, %bias
|
|
ret i32 %r
|
|
}
|
|
define i64 @t1_64(i64 %ptr, i64 %mask) nounwind {
|
|
; CHECK-LABEL: t1_64:
|
|
; CHECK: // %bb.0:
|
|
; CHECK-NEXT: bic x0, x0, x1
|
|
; CHECK-NEXT: ret
|
|
%bias = and i64 %ptr, %mask
|
|
%r = sub i64 %ptr, %bias
|
|
ret i64 %r
|
|
}
|
|
|
|
define i32 @t2_commutative(i32 %ptr, i32 %mask) nounwind {
|
|
; CHECK-LABEL: t2_commutative:
|
|
; CHECK: // %bb.0:
|
|
; CHECK-NEXT: bic w0, w0, w1
|
|
; CHECK-NEXT: ret
|
|
%bias = and i32 %mask, %ptr ; swapped
|
|
%r = sub i32 %ptr, %bias
|
|
ret i32 %r
|
|
}
|
|
|
|
; Extra use tests
|
|
|
|
define i32 @n3_extrause1(i32 %ptr, i32 %mask, i32* %bias_storage) nounwind {
|
|
; CHECK-LABEL: n3_extrause1:
|
|
; CHECK: // %bb.0:
|
|
; CHECK-NEXT: and w8, w0, w1
|
|
; CHECK-NEXT: sub w0, w0, w8
|
|
; CHECK-NEXT: str w8, [x2]
|
|
; CHECK-NEXT: ret
|
|
%bias = and i32 %ptr, %mask ; has extra uses, can't fold
|
|
store i32 %bias, i32* %bias_storage
|
|
%r = sub i32 %ptr, %bias
|
|
ret i32 %r
|
|
}
|
|
|
|
; Negative tests
|
|
|
|
define i32 @n4_different_ptrs(i32 %ptr0, i32 %ptr1, i32 %mask) nounwind {
|
|
; CHECK-LABEL: n4_different_ptrs:
|
|
; CHECK: // %bb.0:
|
|
; CHECK-NEXT: and w8, w1, w2
|
|
; CHECK-NEXT: sub w0, w0, w8
|
|
; CHECK-NEXT: ret
|
|
%bias = and i32 %ptr1, %mask ; not %ptr0
|
|
%r = sub i32 %ptr0, %bias ; not %ptr1
|
|
ret i32 %r
|
|
}
|
|
define i32 @n5_different_ptrs_commutative(i32 %ptr0, i32 %ptr1, i32 %mask) nounwind {
|
|
; CHECK-LABEL: n5_different_ptrs_commutative:
|
|
; CHECK: // %bb.0:
|
|
; CHECK-NEXT: and w8, w2, w1
|
|
; CHECK-NEXT: sub w0, w0, w8
|
|
; CHECK-NEXT: ret
|
|
%bias = and i32 %mask, %ptr1 ; swapped, not %ptr0
|
|
%r = sub i32 %ptr0, %bias ; not %ptr1
|
|
ret i32 %r
|
|
}
|
|
|
|
define i32 @n6_not_lowbit_mask(i32 %ptr, i32 %mask) nounwind {
|
|
; CHECK-LABEL: n6_not_lowbit_mask:
|
|
; CHECK: // %bb.0:
|
|
; CHECK-NEXT: bic w0, w0, w1
|
|
; CHECK-NEXT: ret
|
|
%bias = and i32 %ptr, %mask
|
|
%r = sub i32 %ptr, %bias
|
|
ret i32 %r
|
|
}
|
|
|
|
define i32 @n7_sub_is_not_commutative(i32 %ptr, i32 %mask) nounwind {
|
|
; CHECK-LABEL: n7_sub_is_not_commutative:
|
|
; CHECK: // %bb.0:
|
|
; CHECK-NEXT: and w8, w0, w1
|
|
; CHECK-NEXT: sub w0, w8, w0
|
|
; CHECK-NEXT: ret
|
|
%bias = and i32 %ptr, %mask
|
|
%r = sub i32 %bias, %ptr ; wrong order
|
|
ret i32 %r
|
|
}
|