[InstructionCost] Add saturation support.
authorSander de Smalen <sander.desmalen@arm.com>
Sat, 10 Jul 2021 10:28:38 +0000 (11:28 +0100)
committerSander de Smalen <sander.desmalen@arm.com>
Sat, 10 Jul 2021 10:28:42 +0000 (11:28 +0100)
commit41b6057641720e6ba7d4b6c7c2905f2870a885d3
tree43ac561c63a5f88b9371b081bc62a91c087c5717
parent8cf7ddbdd4e5af966a369e170c73250f2e3920e7
[InstructionCost] Add saturation support.

This patch makes the operations on InstructionCost saturate, so that when
costs are accumulated they saturate to <max value>.

One of the compelling reasons for wanting to have saturation support
is because in various places, arbitrary values are used to represent
a 'high' cost, but when accumulating the cost of some set of operations
or a loop, overflow is not taken into account, which may lead to unexpected
results. By defining the operations to saturate, we can express the cost
of something 'very expensive' as InstructionCost::getMax().

Reviewed By: kparzysz, dmgreen

Differential Revision: https://reviews.llvm.org/D105108
llvm/include/llvm/Support/InstructionCost.h
llvm/unittests/Support/InstructionCostTest.cpp