]> granicus.if.org Git - llvm/commitdiff
[InstSimplify] add tests for known-not-a-power-of-2; NFC
authorSanjay Patel <spatel@rotateright.com>
Thu, 20 Jun 2019 21:04:14 +0000 (21:04 +0000)
committerSanjay Patel <spatel@rotateright.com>
Thu, 20 Jun 2019 21:04:14 +0000 (21:04 +0000)
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

test/Transforms/InstSimplify/AndOrXor.ll

index 8054eb045364b39ccc19b9678630961d57940677..e2c17e2402848fe1794c3e2b3ae2244f75c2923a 100644 (file)
@@ -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