[PATCH] D143368: [InstCombine] Look through truncate to fold icmp with intrinsics

Sanjay Patel via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Feb 8 11:16:55 PST 2023


spatel added a comment.

General proofs with Alive2 are probably not possible for a bitwidth constrained transform like this, but you can include proofs for the specific changes here. 
How can we test `ctpop`?
What happens if the trunc has an extra use?



================
Comment at: llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp:4920-4921
+    if (II->getIntrinsicID() == Intrinsic::ctpop ||
+        II->getIntrinsicID() == Intrinsic::cttz ||
+        II->getIntrinsicID() == Intrinsic::ctlz) {
+      // Make sure the dest bits is enough to save the intrinsic output's range
----------------
Require one less bit for cttz/ctlz when the "is_zero_poison" argument is true?


================
Comment at: llvm/test/Transforms/InstCombine/cmp-intrinsic.ll:548
   %tz = tail call i33 @llvm.cttz.i33(i33 %x, i1 false)
   %trunc = trunc i33 %tz to i15
   %cmp = icmp ult i15 %trunc, 7
----------------
Why truncate to i15? 

IIUC, the transform is valid on this example for truncate down to 6 bits, but not 5 bits. So we should have both of those variations. 

The source type width should be tested similarly, so if we start with i32, it is ok to truncate to i5, but not i4?


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

https://reviews.llvm.org/D143368



More information about the llvm-commits mailing list