[PATCH] D141990: [InstSimplify] Add transform ctpop(X) -> 1 iff X is non-zero power of 2

Sanjay Patel via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Jan 18 10:50:03 PST 2023


spatel added inline comments.


================
Comment at: llvm/lib/Analysis/InstructionSimplify.cpp:5884
 
-static Value *simplifyUnaryIntrinsic(Function *F, Value *Op0,
+static Value *simplifyUnaryIntrinsic(Function *F, CallBase *Call,
                                      const SimplifyQuery &Q) {
----------------
Why change the parameter? The arg type must match the call return type for ctpop, so it shouldn't make a difference for this patch. If there's some other transform where it makes a difference, we could adjust it later?


================
Comment at: llvm/lib/Analysis/InstructionSimplify.cpp:5923-5924
   case Intrinsic::ctpop: {
+    // ctpop(X) -> 1 iff X is non-zero power of 2. Maybe better also to just
+    // return icmp X, 0 if its known power of 2 but not known non-zero.
+    if (isKnownToBeAPowerOfTwo(Op0, Q.DL, /*OrZero*/ false, 0, Q.AC, Q.CxtI,
----------------
Remove the "Maybe better..." statement because we can't do that in InstSimplify (can't create new instructions here). But that should happen in InstCombine if it's not already done there.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141990



More information about the llvm-commits mailing list