Pipe potentially invalid InstructionCost through CodeMetrics
authorPhilip Reames <preames@rivosinc.com>
Thu, 9 Jun 2022 22:11:01 +0000 (15:11 -0700)
committerPhilip Reames <listmail@philipreames.com>
Thu, 9 Jun 2022 22:17:24 +0000 (15:17 -0700)
commitf85c5079b8d093ed9867733fac2946e3a50ed039
tree3db8eefff0039e4259bbf74415263d1aafeb6337
parentba79bb4973f963e9bd6a007e6508cdc6ec990051
Pipe potentially invalid InstructionCost through CodeMetrics

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.

Differential Revision: https://reviews.llvm.org/D127131
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
llvm/test/Transforms/LoopRotate/RISCV/invalid-cost.ll