[PATCH] D99718: [LoopVectorize] Simplify scalar cost calculation in getInstructionCost

David Sherwood via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 1 04:15:02 PDT 2021


david-arm created this revision.
david-arm added reviewers: sdesmalen, dmgreen, fhahn, peterwaller-arm.
Herald added a subscriber: hiraditya.
david-arm requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

This patch simplifies the calculation of certain costs in
getInstructionCost when isScalarAfterVectorization() returns a true value.
There are a few places where we multiply a cost by a number N, i.e.

  unsigned N = isScalarAfterVectorization(I, VF) ? VF.getKnownMinValue() : 1;
  return N * TTI.getArithmeticInstrCost(...

After some investigation it seems that there are only these cases that occur
in practice:

1. VF is a scalar, in which case N = 1.
2. VF is a vector. We can only get here if: a) the instruction is a

GEP/bitcast/PHI with scalar uses, or b) this is an update to an induction
variable that remains scalar.

I have changed the code so that N is assumed to always be 1. For GEPs
the cost is always 0, since this is calculated later on as part of the
load/store cost. PHI nodes are costed separately and were never previously
multiplied by VF. If new opcodes are introduced in future where we have to
take multiple copies into the account then we will underestimate the
cost, but this can be fixed easily by adding a new case to the switch
statement.

Only one test required fixing and I believe the original cost for the scalar
add instruction to have been wrong, since only one copy remains after
vectorisation.

I have also added a new test for the case when a pointer PHI feeds directly
into a store that will be scalarised as we were previously never testing it.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D99718

Files:
  llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
  llvm/test/Transforms/LoopVectorize/AArch64/no_vector_instructions.ll
  llvm/test/Transforms/LoopVectorize/AArch64/predication_costs.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D99718.334646.patch
Type: text/x-patch
Size: 6501 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210401/3b55bdf5/attachment.bin>


More information about the llvm-commits mailing list