[PATCH] D152677: [InstCombine] If there is a known-bit transform is_pow2 check to just check for any other bits

Nikita Popov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 12 02:37:21 PDT 2023


nikic added inline comments.


================
Comment at: llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp:6772
 
+  {
+    // Power of 2 test:
----------------
Shouldn't this code be in foldICmpIntrinsicWithConstant?


================
Comment at: llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp:6774
+    // Power of 2 test:
+    //    isPow2OrZero : ctpop(X) u< 2
+    //    isPow2       : ctpop(X) == 1
----------------
Do you think it would make sense to canonicalize `ctpop(X) < 2` to `ctpop(X) == 1` if `isKnownNonZero(X)`? Or does this run into the issue that `ctpop(X) < 2` is actually the cheaper check once expanded, and we might not recover the non-zero fact at that point anymore?


================
Comment at: llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp:6791
+        Value *And = Builder.CreateAnd(
+            A, Constant::getIntegerValue(A->getType(), ~(AKnown.One)));
+        return new ICmpInst(
----------------



Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D152677/new/

https://reviews.llvm.org/D152677



More information about the llvm-commits mailing list