Next:Defining RTL Sequences for Code Generation, Previous:Defining Looping Instruction Patterns, Up:Machine Descriptions [Contents][Index]
There are often cases where multiple RTL expressions could represent anoperation performed by a single machine instruction. This situation ismost commonly encountered with logical, branch, and multiply-accumulateinstructions. In such cases, the compiler attempts to convert thesemultiple RTL expressions into a single canonical form to reduce thenumber of insn patterns required.
In addition to algebraic simplifications, following canonicalizationsare performed:
vec_merge with constant mask(the third operand), the firstand the second operand can be exchanged by inverting the mask. In such cases,a constant is always made the second operand, otherwise the least significantbit of the mask is always set(select the first operand first).pluscan itself be aplus.and,ior,xor,plus,mult,smin,smax,umin, andumax are associative when applied to integers, and sometimes tofloating-point.neg,not,mult,plus, orminus expression, it will be thefirst operand.neg,mult,plus, andminus, theneg operations (if any) will be moved insidethe operations as far as possible. For instance,(neg (mult A B)) is canonicalized as(mult (neg A) B), but(plus (mult (neg B) C) A) is canonicalized as(minus A (mult B C)).compare operator, a constant is always the second operandif the first argument is a condition code register.compare operator is always written as the first RTL expression oftheparallel instruction pattern. For example,(define_insn "" [(set (reg:CCZ FLAGS_REG)(compare:CCZ (plus:SI (match_operand:SI 1 "register_operand" "%r") (match_operand:SI 2 "register_operand" "r")) (const_int 0))) (set (match_operand:SI 0 "register_operand" "=r")(plus:SI (match_dup 1) (match_dup 2)))] "" "addl %0, %1, %2")
neg,not,mult,plus, orminus is made the first operand under the same conditions asabove.(ltu (plusab)b) is converted to(ltu (plusab)a). Likewise withgeu insteadofltu.(minusx (const_intn)) is converted to(plusx (const_int-n)).mem), a left shift isconverted into the appropriate multiplication by a power of two.not expression, it will be the first one.A machine that has an instruction that performs a bitwise logical-and of oneoperand with the bitwise negation of the other should specify the patternfor that instruction as
(define_insn "" [(set (match_operand:m 0 …) (and:m (not:m (match_operand:m 1 …)) (match_operand:m 2 …)))] "…" "…")
Similarly, a pattern for a “NAND” instruction should be written
(define_insn "" [(set (match_operand:m 0 …) (ior:m (not:m (match_operand:m 1 …)) (not:m (match_operand:m 2 …))))] "…" "…")
In both cases, it is not necessary to include patterns for the manylogically equivalent RTL expressions.
(xor:mxy)and(not:m (xor:mxy)).(plus:m (plus:mxy)constant)
zero_extract rather than the equivalentand orsign_extract operations.(sign_extend:m1 (mult:m2 (sign_extend:m2x)(sign_extend:m2y))) is converted to(mult:m1(sign_extend:m1x) (sign_extend:m1y)), and likewiseforzero_extend.(sign_extend:m1 (mult:m2 (ashiftrt:m2xs) (sign_extend:m2y))) is convertedto(mult:m1 (sign_extend:m1 (ashiftrt:m2xs)) (sign_extend:m1y)), and likewise forpatterns usingzero_extend andlshiftrt. If the secondoperand ofmult is also a shift, then that is extended also.This transformation is only applied when it can be proven that theoriginal operation had sufficient precision to prevent overflow.Further canonicalization rules are defined in the functioncommutative_operand_precedence ingcc/rtlanal.cc.
Next:Defining RTL Sequences for Code Generation, Previous:Defining Looping Instruction Patterns, Up:Machine Descriptions [Contents][Index]