[llvm] r363981 - [InstSimplify] add tests for known-not-a-power-of-2; NFC
Sanjay Patel via llvm-commits
llvm-commits at lists.llvm.org
Thu Jun 20 14:04:15 PDT 2019
Author: spatel
Date: Thu Jun 20 14:04:14 2019
New Revision: 363981
URL: http://llvm.org/viewvc/llvm-project?rev=363981&view=rev
Log:
[InstSimplify] add tests for known-not-a-power-of-2; NFC
I added a canonicalization to create this general pattern in:
rL363956
But as noted in PR42314:
https://bugs.llvm.org/show_bug.cgi?id=42314#c11
...we have a (potentially expensive) simplification for the version
of the code that we just canonicalized away from, so we should
add/adjust that code to match.
Modified:
llvm/trunk/test/Transforms/InstSimplify/AndOrXor.ll
Modified: llvm/trunk/test/Transforms/InstSimplify/AndOrXor.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstSimplify/AndOrXor.ll?rev=363981&r1=363980&r2=363981&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstSimplify/AndOrXor.ll (original)
+++ llvm/trunk/test/Transforms/InstSimplify/AndOrXor.ll Thu Jun 20 14:04:14 2019
@@ -89,6 +89,34 @@ define i64 @pow2b(i32 %x) {
ret i64 %e2
}
+; Power-of-2-or-zero value has no bits in common with its decrement.
+
+define i32 @pow2_decrement(i32 %p) {
+; CHECK-LABEL: @pow2_decrement(
+; CHECK-NEXT: [[X:%.*]] = shl i32 1, [[P:%.*]]
+; CHECK-NEXT: [[A:%.*]] = add i32 [[X]], -1
+; CHECK-NEXT: [[R:%.*]] = and i32 [[A]], [[X]]
+; CHECK-NEXT: ret i32 [[R]]
+;
+ %x = shl i32 1, %p
+ %a = add i32 %x, -1
+ %r = and i32 %a, %x
+ ret i32 %r
+}
+
+define <2 x i32> @pow2_decrement_commute_vec(<2 x i32> %p) {
+; CHECK-LABEL: @pow2_decrement_commute_vec(
+; CHECK-NEXT: [[X:%.*]] = and <2 x i32> [[P:%.*]], <i32 2048, i32 2048>
+; CHECK-NEXT: [[A:%.*]] = add <2 x i32> [[X]], <i32 -1, i32 -1>
+; CHECK-NEXT: [[R:%.*]] = and <2 x i32> [[X]], [[A]]
+; CHECK-NEXT: ret <2 x i32> [[R]]
+;
+ %x = and <2 x i32> %p, <i32 2048, i32 2048>
+ %a = add <2 x i32> %x, <i32 -1, i32 -1>
+ %r = and <2 x i32> %x, %a
+ ret <2 x i32> %r
+}
+
define i1 @and_of_icmps0(i32 %b) {
; CHECK-LABEL: @and_of_icmps0(
; CHECK-NEXT: ret i1 false
More information about the llvm-commits
mailing list