public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug rtl-optimization/52235] New: rtlanal: commutative_operand_precedence should prioritize regs
@ 2012-02-13 16:55 Paulo.Matos at csr dot com
  2012-02-13 16:58 ` [Bug rtl-optimization/52235] " Paulo.Matos at csr dot com
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: Paulo.Matos at csr dot com @ 2012-02-13 16:55 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52235

             Bug #: 52235
           Summary: rtlanal: commutative_operand_precedence should
                    prioritize regs
    Classification: Unclassified
           Product: gcc
           Version: 4.6.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: rtl-optimization
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: Paulo.Matos@csr.com


I noticed the combine receives insns of the form:
(set (reg ...) (ior (mem (reg ...)) (reg ...)))

(in my specific case the reg inside mem was an argument pointer that later
would be eliminated in terms of a function pointer.

After an initial discussion in the mailing list:
http://www.mail-archive.com/gcc@gcc.gnu.org/msg62132.html
Richard pointed me to commutative_operand_precedence. Both him and I expected
to see the register come first.

Having the register come first is more intuitive and under my backend it
performs much better. The whole reason to look into this stemmed from the fact
that commutative operations like ior were not being correctly combined since
the backend rule looked like:
(define_insn "iorqi3"
  [(set (match_operand:QI 0 "register_operand" "=c")
        (ior:QI (match_operand:QI 1 "register_operand" "%0")
                (match_operand:QI 2 "general_operand" "cwmi")))
   (clobber (reg:CC RCC))]
  ""
  "or\\t%0,%f2")

Makes sense for operand1 to be a register_operand because it will be forced to
be the same as operand0. However, if we can't assume registers come first a lot
of rule duplication has to occur in order to achieve the same effect. I would
guess in this case I would need to have instead of the above:
(define_insn "iorqi3"
  [(set (match_operand:QI 0 "register_operand" "=c")
        (ior:QI (match_operand:QI 1 "register_operand" "0")
                (match_operand:QI 2 "general_operand" "cwmi")))
   (clobber (reg:CC RCC))]
  ""
  "or\\t%0,%f2")

(define_insn "iorqi3"
  [(set (match_operand:QI 0 "register_operand" "=c")
        (ior:QI (match_operand:QI 1 "general_operand" "cwmi")
                (match_operand:QI 2 "register_operand" "0")))
   (clobber (reg:CC RCC))]
  ""
  "or\\t%0,%f1")

The simple fix of making registers have priority over everything else works
like a charm. Patch follows.


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2013-05-08 20:20 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-02-13 16:55 [Bug rtl-optimization/52235] New: rtlanal: commutative_operand_precedence should prioritize regs Paulo.Matos at csr dot com
2012-02-13 16:58 ` [Bug rtl-optimization/52235] " Paulo.Matos at csr dot com
2012-02-13 21:10 ` steven at gcc dot gnu.org
2012-02-14  7:28 ` Paulo.Matos at csr dot com
2013-05-08 18:56 ` steven at gcc dot gnu.org
2013-05-08 20:20 ` paulo@matos-sorge.com

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).