[PATCH] D142271: [ValueTracking] Add KnownBits patterns `xor(x, x - 1)` and `and(x, -x)` for knowing upper bits to be zero

Noah Goldstein via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Jan 20 21:54:45 PST 2023


goldstein.w.n added inline comments.


================
Comment at: llvm/lib/Analysis/ValueTracking.cpp:1089
+    // above it.
+    // TODO: instcombine has a habit of commuting independent `and` which can
+    // hide this pattern. Try to match and(x, and(-x, y)) / and(and(x, y), -x).
----------------
craig.topper wrote:
> that sounds more like reassociating than commuting.
> that sounds more like reassociating than commuting.

Yup, yet again I get my properties wrong :(


================
Comment at: llvm/lib/Analysis/ValueTracking.cpp:1129
 
-    Known ^= Known2;
+    // Common idiom is blsmsk: xor(x, x + -1). This will clear all but lowest
+    // set bit. We can safely say any bit past the lowest known one must be
----------------
craig.topper wrote:
> The description of blsmsk says "Sets all the lower bits of the destination operand to “1” up to and including lowest set bit (=1) in the source operand".
> The description of blsmsk says "Sets all the lower bits of the destination operand to “1” up to and including lowest set bit (=1) in the source operand".

Err, yeah should be 'clear all bits above the lowest set bit'. Will fix.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142271



More information about the llvm-commits mailing list