[llvm] [SLP]Do not include the cost of and -1, <v> and emit just <v> after MinBitWidth. (PR #90739)

Alexey Bataev via llvm-commits llvm-commits at lists.llvm.org
Wed May 1 08:51:53 PDT 2024


================
@@ -9484,6 +9484,16 @@ BoUpSLP::getEntryCost(const TreeEntry *E, ArrayRef<Value *> VectorizedVals,
                                          Op1Info, Op2Info, Operands, VI);
     };
     auto GetVectorCost = [=](InstructionCost CommonCost) {
+      if (ShuffleOrOp == Instruction::And && It != MinBWs.end()) {
+        for (unsigned I : seq<unsigned>(0, E->getNumOperands())) {
+          ArrayRef<Value *> Ops = E->getOperand(I);
+          if (all_of(Ops, [&](Value *Op) {
+                auto *CI = dyn_cast<ConstantInt>(Op);
+                return CI && CI->getValue().countr_one() == It->second.first;
----------------
alexey-bataev wrote:

In the original bitwidth it might be not all-ones value, e.g.
```
  %conv.1 = trunc i64 %1 to i32
  %conv3.1 = and i32 %conv.1, 65535
```
With original i32 type 65535 is not all-ones. But SLP can transform it to <n x i16>, where 65535 becomes all-ones.

https://github.com/llvm/llvm-project/pull/90739


More information about the llvm-commits mailing list