[llvm] [CostModel][AArch64] Make extractelement, with fmul user, free whenev… (PR #111479)

David Green via llvm-commits llvm-commits at lists.llvm.org
Thu Nov 7 09:07:14 PST 2024


================
@@ -3177,10 +3178,10 @@ InstructionCost AArch64TTIImpl::getCFInstrCost(unsigned Opcode,
   return 0;
 }
 
-InstructionCost AArch64TTIImpl::getVectorInstrCostHelper(const Instruction *I,
-                                                         Type *Val,
-                                                         unsigned Index,
-                                                         bool HasRealUse) {
+InstructionCost AArch64TTIImpl::getVectorInstrCostHelper(
+    Type *Val, unsigned Index, bool HasRealUse, const Instruction *I,
+    std::optional<unsigned> Opcode, Value *Scalar,
----------------
davemgreen wrote:

Because of the way this is called from the 3 different places:
```
getVectorInstrCost(Opcode, Val, CostKind, Index, Op0, Op1)
getVectorInstrCost(Instruction, Val, CostKind, Index)
getVectorInstrCost(Opcode, Val, CostKind, Index, Scalar, ScalarUserAndIdx)
```
I would have the Opcode as always present and pass it from each of the 3 functions. I would make it the first argument, so that it matches the other calls.

The code to call it can drop the `if (I || Opcode)`, as it should always be present and just turn into:
```
  if (Opcode == Instruction::ExtractElement && ExtractCanFuseWithFmul())
    return 0;
```

Hopefully that should work and be a little bit cleaner. Let me know if it doesn't.

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


More information about the llvm-commits mailing list