From: Sanjay Patel Date: Thu, 20 Jun 2019 21:04:14 +0000 (+0000) Subject: [InstSimplify] add tests for known-not-a-power-of-2; NFC X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=a0711e68bd029e1b24205e36985e9a74ef6e5032;p=llvm [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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@363981 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/test/Transforms/InstSimplify/AndOrXor.ll b/test/Transforms/InstSimplify/AndOrXor.ll index 8054eb04536..e2c17e24028 100644 --- a/test/Transforms/InstSimplify/AndOrXor.ll +++ b/test/Transforms/InstSimplify/AndOrXor.ll @@ -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:%.*]], +; CHECK-NEXT: [[A:%.*]] = add <2 x i32> [[X]], +; CHECK-NEXT: [[R:%.*]] = and <2 x i32> [[X]], [[A]] +; CHECK-NEXT: ret <2 x i32> [[R]] +; + %x = and <2 x i32> %p, + %a = add <2 x i32> %x, + %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