This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Questions about match_scratch in machine description files


I'm just learning gcc internals and have a few questions about
match_scratch.

The documentation seems to imply that the sole purpose of adding
match_scratch to a template is to allocate a temporary for use in
expanding an instruction.  So for example using the following simple
template from mips.md:

  (define_insn "subdf3"
    [(set (match_operand:DF 0 "register_operand" "=f")
          (minus:DF (match_operand:DF 1 "register_operand" "f")
                    (match_operand:DF 2 "register_operand" "f")))]
    "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT"
    "sub.d\\t%0,%1,%2"
    [(set_attr "type"     "fadd")
     (set_attr "mode"     "DF")])

If I needed (for the sake of an example) to allocate a temporary
floating point register to pass to sub.d as a forth argument that is
written to by the sub.d instruction, I could change the template to
something like the following with the added/changed lines marked with
'*':

  (define_insn "subdf3"
    [(set (match_operand:DF 0 "register_operand" "=f")
          (minus:DF (match_operand:DF 1 "register_operand" "f")
                    (match_operand:DF 2 "register_operand" "f")))
 *   (clobber (match_scratch:DF 3 "=f"))
    ]
    "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT"
 *  "sub.d\\t%0,%1,%2,%3"
    [(set_attr "type"     "fadd")
     (set_attr "mode"     "DF")])

What would be the affect of adding the match_scratch and never using
the temporary, as long as a temporary register was available?  Would
this be expected to cause problems with code that is currently matched
or expanded by this define_insn?  My experiments seem to imply that
doing this does affect operand matching, so there must be some side
affects that aren't obvious.

Another thing I don't understand, again using mips.md as an example,
is that some templates use match_scratch but don't appear to use any
of the temporary operands.  For example:

  (define_insn "mulsi3_mult3"
    [(set (match_operand:SI 0 "register_operand" "=d,l")
          (mult:SI (match_operand:SI 1 "register_operand" "d,d")
                   (match_operand:SI 2 "register_operand" "d,d")))
     (clobber (match_scratch:SI 3 "=h,h"))
     (clobber (match_scratch:SI 4 "=l,X"))
     (clobber (match_scratch:SI 5 "=a,a"))]
    "GENERATE_MULT3_SI
     || TARGET_MAD"
    "*
  {
    if (which_alternative == 1)
      return \"mult\\t%1,%2\";
    if (TARGET_MAD
        || TARGET_MIPS5400
        || TARGET_MIPS5500
        || ISA_MIPS32
        || ISA_MIPS32R2
        || ISA_MIPS64)
      return \"mul\\t%0,%1,%2\";
    return \"mult\\t%0,%1,%2\";
  }"
    [(set_attr "type"     "imul")
     (set_attr "mode"     "SI")])

In the above, I don't see any use of %3, %4, or %5, so why are those
match_scratch expressions there?

Thanks for any help understanding what is going on.

-Fred


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]