[PATCH] D89322: [LV] Initial VPlan cost modelling

Dave Green via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Oct 13 08:44:21 PDT 2020


dmgreen created this revision.
dmgreen added reviewers: fhahn, Ayal, gilr, hsaito, SjoerdMeijer.
Herald added subscribers: bmahjour, psnobl, rogfer01, bollu, hiraditya.
Herald added a reviewer: rengolin.
Herald added a project: LLVM.
dmgreen requested review of this revision.
Herald added a subscriber: vkmr.

This adds the initial skeleton and cost modelling needed to cost vplans. This replaces the current method of summing the cost of each instruction in the loop body.

It currently attempts to fairly precisely mimic the existing code model in order to not introduce too many regressions at once. As a result some of the decisions it makes are not optimal, notable in how predication is handled.

The basic scheme is to call cost() on VPlans, which recurses into VPBasicBlocks and into VPRecipes.  Most cost() methods for individual recipes currently call CostModel->getInstructionCost, which will be refactored to call TTI hooks directly in future patches. In order to mimic the existing model a ReciprocalPredBlockProb is added to VPBasicBlock to model the old method of reducing the scalar cost for predicated blocks. This is known to be rather inaccurate, but if removed can lead to regressions. I will hopefully improve this bit somehow..

It passes all the llvm tests but can still causes differences for some code, especially around loops which were already close to the same score between vector factors. One common place I've seen is that the backedge cost was often over-estimated in the past. It will now correctly cost VPReduction recipes, which is nice but should only effect MVE. VPInstructions will follow in a subsequent patch, but may need to start including type information.

The patch adds an option, "cost-using-vplan", that can be used pick between the old method and the new. The idea is to switch to the new method and remove the old code path once any regressions are addressed.


https://reviews.llvm.org/D89322

Files:
  llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h
  llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
  llvm/lib/Transforms/Vectorize/VPlan.h
  llvm/test/Analysis/CostModel/X86/interleave-load-i32.ll
  llvm/test/Analysis/CostModel/X86/interleave-store-i32.ll
  llvm/test/Analysis/CostModel/X86/interleaved-load-float.ll
  llvm/test/Analysis/CostModel/X86/interleaved-load-i8.ll
  llvm/test/Analysis/CostModel/X86/interleaved-load-store-double.ll
  llvm/test/Analysis/CostModel/X86/interleaved-load-store-i64.ll
  llvm/test/Analysis/CostModel/X86/interleaved-store-i8.ll
  llvm/test/Analysis/CostModel/X86/strided-load-i16.ll
  llvm/test/Analysis/CostModel/X86/strided-load-i32.ll
  llvm/test/Analysis/CostModel/X86/strided-load-i64.ll
  llvm/test/Analysis/CostModel/X86/strided-load-i8.ll
  llvm/test/Transforms/LoopVectorize/AArch64/aarch64-predication.ll
  llvm/test/Transforms/LoopVectorize/AArch64/costmodel.ll
  llvm/test/Transforms/LoopVectorize/AArch64/extractvalue-no-scalarization-required.ll
  llvm/test/Transforms/LoopVectorize/AArch64/interleaved-vs-scalar.ll
  llvm/test/Transforms/LoopVectorize/AArch64/interleaved_cost.ll
  llvm/test/Transforms/LoopVectorize/AArch64/no_vector_instructions.ll
  llvm/test/Transforms/LoopVectorize/AArch64/predication_costs.ll
  llvm/test/Transforms/LoopVectorize/ARM/interleaved_cost.ll
  llvm/test/Transforms/LoopVectorize/ARM/mve-interleaved-cost.ll
  llvm/test/Transforms/LoopVectorize/ARM/mve-shiftcost.ll
  llvm/test/Transforms/LoopVectorize/SystemZ/branch-for-predicated-block.ll
  llvm/test/Transforms/LoopVectorize/SystemZ/load-scalarization-cost-0.ll
  llvm/test/Transforms/LoopVectorize/SystemZ/load-scalarization-cost-1.ll
  llvm/test/Transforms/LoopVectorize/SystemZ/load-store-scalarization-cost.ll
  llvm/test/Transforms/LoopVectorize/SystemZ/mem-interleaving-costs-02.ll
  llvm/test/Transforms/LoopVectorize/SystemZ/mem-interleaving-costs.ll
  llvm/test/Transforms/LoopVectorize/X86/fneg-cost.ll
  llvm/test/Transforms/LoopVectorize/X86/fp_to_sint8-cost-model.ll
  llvm/test/Transforms/LoopVectorize/X86/mul_slm_16bit.ll
  llvm/test/Transforms/LoopVectorize/X86/reduction-small-size.ll
  llvm/test/Transforms/LoopVectorize/X86/redundant-vf2-cost.ll
  llvm/test/Transforms/LoopVectorize/X86/uint64_to_fp64-cost-model.ll
  llvm/test/Transforms/LoopVectorize/X86/uniformshift.ll
  llvm/test/Transforms/LoopVectorize/X86/vector-scalar-select-cost.ll
  llvm/test/Transforms/LoopVectorize/consecutive-ptr-uniforms.ll
  llvm/test/Transforms/LoopVectorize/loop-scalars.ll
  llvm/test/Transforms/LoopVectorize/phi-cost.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D89322.297867.patch
Type: text/x-patch
Size: 241923 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20201013/c7222538/attachment-0001.bin>


More information about the llvm-commits mailing list