[PATCH] D23139: Add popcount(n) == bitsize(n) -> n == -1 transformation.

Sanjay Patel via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 3 15:36:04 PDT 2016


spatel accepted this revision.
spatel added a comment.
This revision is now accepted and ready to land.

LGTM. See inline comments for a couple of nits.

Also, can you please add a vector regression test for more coverage and so we know that we're using the right bitwidth in that case?


================
Comment at: lib/Transforms/InstCombine/InstCombineCompares.cpp:2383
@@ -2382,2 +2382,3 @@
     // popcount(A) == 0  ->  A == 0 and likewise for !=
-    if (*Op1C == 0) {
+    // popcount(A) == bitwidth(a)  ->  A == -1 and likewise for !=
+    bool IsZero = *Op1C == 0;
----------------
bitwidth(A) - capitalize for consistency

================
Comment at: lib/Transforms/InstCombine/InstCombineCompares.cpp:2388
@@ -2385,2 +2387,3 @@
       ICI.setOperand(0, II->getArgOperand(0));
-      ICI.setOperand(1, ConstantInt::getNullValue(II->getType()));
+      auto NewOp = IsZero
+        ? ConstantInt::getNullValue(II->getType())
----------------
The coding standard recommends 'auto *' for pointers:
http://llvm.org/docs/CodingStandards.html#use-auto-type-deduction-to-make-code-more-readable


https://reviews.llvm.org/D23139





More information about the llvm-commits mailing list