[PATCH] D126040: [InstCombine] Fold a mul with bool value into and

Sanjay Patel via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun May 29 06:21:08 PDT 2022


spatel added a comment.

I added a couple of minor comments.
Please update, and if we don't hear any objections, then I think we are good. (If not, it can always be reverted.)



================
Comment at: llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp:306
+  //   1) i1 mul -> i1 and.
+  //   2) X * Y --> X & Y, iff X, Y can be only 1.
+  // Note: We could use known bits to generalize this and related patterns with
----------------
"...can be only {0,1}."


================
Comment at: llvm/test/Transforms/InstCombine/mul-masked-bits.ll:170
 ; Scalar tests
 define i64 @scalar_mul_bit_x0_y0(i64 %x, i64 %y) {
 ; CHECK-LABEL: @scalar_mul_bit_x0_y0(
----------------
Please add a test where both of the operands have an extra use. Something like this:

```
define i64 @scalar_mul_bit_x0_y0_uses(i64 %x, i64 %y) {
  %and1 = and i64 %x, 1
  call void @use(i64 %and1)
  %and2 = and i64 %y, 1
  call void @use(i64 %and2)
  %mul = mul i64 %and1, %and2
  ret i64 %mul
}
```


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

https://reviews.llvm.org/D126040



More information about the llvm-commits mailing list