[llvm] [LoopVectorize] Add the cost of VPInstruction::AnyOf to vplan (PR #125058)

David Sherwood via llvm-commits llvm-commits at lists.llvm.org
Fri Jan 31 07:19:36 PST 2025


================
@@ -709,6 +709,20 @@ Value *VPInstruction::generate(VPTransformState &State) {
   }
 }
 
+InstructionCost VPInstruction::computeCost(ElementCount VF,
+                                           VPCostContext &Ctx) const {
+  switch (getOpcode()) {
+  case VPInstruction::AnyOf: {
+    auto *VecI1Ty = VectorType::get(Type::getInt1Ty(Ctx.LLVMCtx), VF);
+    return Ctx.TTI.getArithmeticReductionCost(Instruction::Or, VecI1Ty,
----------------
david-arm wrote:

Yeah so in `VPInstruction::generate` the AnyOf instruction is implemented as follows:

```
  case VPInstruction::AnyOf: {
    Value *A = State.get(getOperand(0));
    return Builder.CreateOrReduce(A);
  }
```

i.e. it's creating an `or` reduction across the input vector so I've just created a cost that matches the IR generated.

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


More information about the llvm-commits mailing list