[all-commits] [llvm/llvm-project] 4afeda: [LoopVectorize] Simplify scalar cost calculation i...

david-arm via All-commits all-commits at lists.llvm.org
Tue Apr 27 07:26:52 PDT 2021


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 4afeda9157cffd2daa83f8075d73f1e11ea34c81
      https://github.com/llvm/llvm-project/commit/4afeda9157cffd2daa83f8075d73f1e11ea34c81
  Author: David Sherwood <david.sherwood at arm.com>
  Date:   2021-04-27 (Tue, 27 Apr 2021)

  Changed paths:
    M llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
    M llvm/test/Transforms/LoopVectorize/AArch64/no_vector_instructions.ll
    M llvm/test/Transforms/LoopVectorize/AArch64/predication_costs.ll

  Log Message:
  -----------
  [LoopVectorize] Simplify scalar cost calculation in getInstructionCost

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. For all other cases I have added an assert that none of
the users needs scalarising, which didn't fire in any unit tests.

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.

Differential Revision: https://reviews.llvm.org/D99718




More information about the All-commits mailing list