Ensure that InstructionCost actually implements a total ordering
authorChristopher Tetreault <ctetreau@quicinc.com>
Tue, 2 Feb 2021 17:14:55 +0000 (09:14 -0800)
committerChristopher Tetreault <ctetreau@quicinc.com>
Tue, 2 Feb 2021 19:49:14 +0000 (11:49 -0800)
commitb481cd519e07b3ad2bd3e81c89b0dd8efd68d6bc
treefca6078150632ef6a228604d6db586972cff0c4c
parentaa39ddd0a320c1d615171fef98694e5726c3fa4f
Ensure that InstructionCost actually implements a total ordering

Previously, operator== would consider the actual equality of the pairs
(lhs.Value, lhs.State) == (rhs.Value, rhs.State). However, if an invalid
cost was involved in a call to operator<, only the state would be
compared. Thus, it was not the case that ({2, Invalid} < {3, Invalid} ||
{2, Invalid} > {3, Invalid} || {2, Invalid} == {3, Invalid}).

This patch implements a true total ordering, where cost state is
considered first, then value. While it's not really imporant that
{2, Invalid} be considered to be less than {3, Invalid}, it's not a
problem either. This patch also implements operator== in terms of
operator<, so the two definitions will be kept in sync.

Reviewed By: sdesmalen

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