Patch: Fix match_dup handling in web.c

Bernd Schmidt bernds@codesourcery.com
Thu Mar 25 11:58:00 GMT 2010


On 03/25/2010 10:20 AM, Steven Bosscher wrote:

> Note that @code{match_dup} should not be used to tell the compiler that
> a particular register is being used for two operands (example:
> @code{add} that adds one register to another; the second register is
> both an input operand and the output operand).  Use a matching
> constraint (@pxref{Simple Constraints}) for those.
> 
> Are you sure your pattern shouldn't use a constraint instead of a
> match_dup?

I could have sworn I've seen this done elsewhere.  dj added that
paragraph (after "going through gcc training") in revision 38005, but
the documentation contains an example to the contrary to this day.

When you actually grep for it, it's quite easy to find examples in the
actual code, too:

frv.md:
(define_insn "movhi_lo_sum"
  [(set (match_operand:HI 0 "integer_register_operand" "+d")
        (lo_sum:HI (match_dup 0)
                   (match_operand:HI 1 "int_2word_operand" "i")))]
  ""
  "setlo #lo(%1), %0"
  [(set_attr "type" "setlo")
   (set_attr "length" "4")])

crx.md:
(define_insn "<sPat>madsidi3"
  [(set (match_operand:DI 0 "register_operand" "+k")
        (plus:DI
          (mult:DI (sz_xtnd:DI (match_operand:SI 1 "register_operand"
"%r"))
                   (sz_xtnd:DI (match_operand:SI 2 "register_operand"
"r")))
          (match_dup 0)))
   (clobber (reg:CC CC_REGNUM))]
  "TARGET_MAC"
  "mac<sPat>d\t%2, %1"
  [(set_attr "length" "4")]
)

i386.md:
(define_insn "*swapsi"
  [(set (match_operand:SI 0 "register_operand" "+r")
        (match_operand:SI 1 "register_operand" "+r"))
   (set (match_dup 1)
        (match_dup 0))]
  ""
  "xchg{l}\t%1, %0"
  [(set_attr "type" "imov")
   (set_attr "mode" "SI")
   (set_attr "pent_pair" "np")
   (set_attr "athlon_decode" "vector")
   (set_attr "amdfam10_decode" "double")])

etc. etc.

I think what dj means is that in normal cases, such as addsi, the
compiler has more freedom to perform transformations on the RTL if you
use a match_operand, so you should normally use that.

Feel free to submit a patch to correct the documentation.  It's
preapproved; please correct the doc example to use a "+" constraint though.


Bernd



More information about the Gcc-patches mailing list