Comparison Operations#
Comparison operators test a relation on two operands and are considered
to represent a machine-dependent nonzero value described by, but not
necessarily equal to, STORE_FLAG_VALUE (see Miscellaneous Parameters)
if the relation holds, or zero if it does not, for comparison operators
whose results have a ‘MODE_INT’ mode,
FLOAT_STORE_FLAG_VALUE (see Miscellaneous Parameters) if the relation holds, or
zero if it does not, for comparison operators that return floating-point
values, and a vector of either VECTOR_STORE_FLAG_VALUE (see Miscellaneous Parameters)
if the relation holds, or of zeros if it does not, for comparison operators
that return vector results.
The mode of the comparison operation is independent of the mode
of the data being compared. If the comparison operation is being tested
(e.g., the first operand of an if_then_else), the mode must be
VOIDmode.
A comparison operation compares two data objects. The mode of the comparison is determined by the operands; they must both be valid for a common machine mode. A comparison with both operands constant would be invalid as the machine mode could not be deduced from it, but such a comparison should never exist in RTL due to constant folding.
Usually only one style
of comparisons is supported on a particular machine, but the combine
pass will try to merge operations to produce code like
(eq xy),
in case it exists in the context of the particular insn involved.
Inequality comparisons come in two flavors, signed and unsigned. Thus,
there are distinct expression codes gt and gtu for signed and
unsigned greater-than. These can produce different results for the same
pair of integer values: for example, 1 is signed greater-than -1 but not
unsigned greater-than, because -1 when regarded as unsigned is actually
0xffffffff which is greater than 1.
The signed comparisons are also used for floating point values. Floating point comparisons are distinguished by the machine modes of the operands.
(eq:m x y)STORE_FLAG_VALUEif the values represented byxandyare equal, otherwise 0.(ne:m x y)STORE_FLAG_VALUEif the values represented byxandyare not equal, otherwise 0.(gt:m x y)STORE_FLAG_VALUEif thexis greater thany. If they are fixed-point, the comparison is done in a signed sense.(gtu:m x y)Like
gtbut does unsigned comparison, on fixed-point numbers only.(lt:m x y)(ltu:m x y)Like
gtandgtubut test for ‘less than’.(ge:m x y)(geu:m x y)Like
gtandgtubut test for ‘greater than or equal’.(le:m x y)(leu:m x y)Like
gtandgtubut test for ‘less than or equal’.(if_then_else cond then else)This is not a comparison operation but is listed here because it is always used in conjunction with a comparison operation. To be precise,
condis a comparison expression. This expression represents a choice, according tocond, between the value represented bythenand the one represented byelse.On most machines,
if_then_elseexpressions are valid only to express conditional jumps.(cond [test1 value1 test2 value2 ...] default)Similar to
if_then_else, but more general. Each oftest1,test2, … is performed in turn. The result of this expression is thevaluecorresponding to the first nonzero test, ordefaultif none of the tests are nonzero expressions.This is currently not valid for instruction patterns and is supported only for insn attributes. See Instruction Attributes.