Debug values in both IR and MIR have 3 distinct properties that are used to compute the underlying variable value; the DIExpression, a list of one or more machine value(s), and a "directness" flag, given by either the choice of intrinsic in IR (dbg.declare/dbg.addr being indirect, dbg.value being direct), or directly specified as an operand in MIR (the second operand to a DBG_VALUE instruction). The expressions themselves may optionally be variadic, which allows for more than one machine value to be used in the debug value, and changes the expression syntax to explicitly specify where in the expression those machine values appear, instead of implicitly inserting the sole machine value at the front of the expression.
This patch adds a new function that can be used to check all the properties, other than the machine values, of a pair of debug values for equivalence. This is done by folding the "directness" into the expression, converting the expression to variadic form if it is not already in that form, and then comparing directly. In a few places which check whether two debug values are identical to see if their ranges can be merged, this function will correctly identify cases where two debug values are expressed differently but have the same meaning, allowing those ranges to be correctly merged.