[PATCH] D127131: Pipe potentially invalid InstructionCost through CodeMetrics

Philip Reames via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 6 10:54:48 PDT 2022


reames created this revision.
reames added reviewers: craig.topper, frasercrmck, kito-cheng, sdesmalen, nikic.
Herald added subscribers: jsji, luke957, snehasish, ormris, StephenFan, luismarques, pengfei, s.egerton, PkmX, zzheng, bollu, simoncook, hiraditya, arichardson, mcrosier.
Herald added a project: All.
reames requested review of this revision.
Herald added subscribers: alextsao1999, pcwang-thead.
Herald added a project: LLVM.

Per the documentation in Support/InstructionCost.h, the purpose of an invalid cost is so that clients can change behavior on impossible to cost inputs.  CodeMetrics was instead asserting that invalid costs never occurred.

On a target with an incomplete cost model - e.g. RISCV - this means that transformations would crash on (falsely) invalid constructs - e.g. scalable vectors.  While we certainly should improve the cost model - and I plan to do so in the near future - we also shouldn't be crashing.  This violates the explicitly stated purpose of an invalid InstructionCost.

I updated all of the "easy" consumers where bailouts were locally obvious.  I plan to follow up with loop unroll in a following change.

Testing wise, I don't have a good answer.  I'm about to update the RISC-V model which means that using riscv for tests won't work long term.  I could in theory pick some architecture without scalable support (e.g. x86), but that seems somewhat weird.  I'm tempted to just leave this untested in the patch.  Thoughts?


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D127131

Files:
  llvm/include/llvm/Analysis/CodeMetrics.h
  llvm/lib/Analysis/CodeMetrics.cpp
  llvm/lib/Transforms/IPO/FunctionSpecialization.cpp
  llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp
  llvm/lib/Transforms/Scalar/LoopDataPrefetch.cpp
  llvm/lib/Transforms/Scalar/LoopUnrollPass.cpp
  llvm/lib/Transforms/Utils/LoopRotationUtils.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D127131.434528.patch
Type: text/x-patch
Size: 7131 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220606/8a823735/attachment.bin>


More information about the llvm-commits mailing list