public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* Use of FLAGS_REGNUM clashes with generates insn
@ 2011-09-22 18:35 Paulo J. Matos
  2011-09-23  7:21 ` Joern Rennecke
  0 siblings, 1 reply; 12+ messages in thread
From: Paulo J. Matos @ 2011-09-22 18:35 UTC (permalink / raw)
  To: gcc

Hi,

After the discussion about the use of CCmode in:
http://gcc.gnu.org/ml/gcc/2011-07/msg00303.html

I am trying to ditch support for the only cc0 attr and add support for 
CC_REG.

There are two issues that are making the situation more complicated, 
both of similar nature.

My addition instruction sets all the flags. So I have:
(define_insn "addqi3"
   [(set (match_operand:QI 0 "nonimmediate_operand" "=c")
         (plus:QI (match_operand:QI 1 "nonmemory_operand" "%0")
                  (match_operand:QI 2 "general_operand" "cwmi")))
    (clobber (reg:CC RCC))]
   ""
   "add\\t%0,%f2")

(define_insn "*addqi3_flags"
   [(set (match_operand:QI 0 "nonimmediate_operand" "=c")
         (plus:QI (match_operand:QI 1 "nonmemory_operand" "%0")
                  (match_operand:QI 2 "general_operand" "cwmi")))
    (set (reg RCC)
         (compare (plus:QI (match_dup 1) (match_dup 2))
                  (const_int 0)))]
   "reload_completed && xap_match_ccmode(insn, CCmode)"
   "add\\t%0,%f2")

There's however a problem with this. GCC during reload, after register 
elimination (eliminating argument pointer for an offset from the stack 
pointer tries to output the instruction):
(set (reg ...) (plus:QI (reg ...) (const_int ...)))

However, it spills and fails because no rule matches this expression 
(it's missing the clobber). I fixed this with:

(define_insn_and_split "addqi3_noclobber"
   [(set (match_operand:QI 0 "register_operand" "=c")
         (plus:QI (match_operand:QI 1 "register_operand")
                  (match_operand:QI 2 "immediate_operand")))]
   "reload_in_progress"
   "#"
   "reload_completed"
   [(set (match_dup 0) (match_dup 1))
    (parallel [(set (match_dup 0) (plus:QI (match_dup 0) (match_dup 2)))
               (clobber (reg:CC RCC))])])

And it works. However, the more complex issue comes with register moves. 
A register move which ends up as a load or store, sets flags N, Z.

I have an expand movqi which expand to a move with the clobber like so:
(define_expand "movqi"
   [(parallel [(set (match_operand 0 "nonimmediate_operand")
                    (match_operand 1 "general_operand"))
               (clobber (reg:CC RCC))])]
   ""
{
    /* One of the ops has to be in a register.  */
    if (!register_operand(operands[0], QImode)
        && ! (register_operand(operands[1], QImode) || const0_rtx == 
operands[1]))
        operands[1] = copy_to_mode_reg(QImode, operands[1]);
})

And all my (define_insn "*mov..." are tagged with a (clobber (reg:CC 
RCC)). This generates all kinds of trouble since GCC generates moves 
internally without the clobber that fail to match.

I tried the same trick as above:

(define_insn_and_split "*movqi_noclobber"
   [(set (match_operand:QI 0 "nonimmediate_operand")
         (match_operand:QI 1 "general_operand"))]
   "!reload_completed"
   "#"
   ""
   [(parallel [(set (match_dup 0) (match_dup 1))
               (clobber (reg:CC RCC))])])

This doesn't fix the problem. It actually brings an internal compiler 
error. I am definitely not doing this the right way.

Any suggestions on how to correctly handle these?

Cheers,
-- 
PMatos

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

end of thread, other threads:[~2011-10-26  3:53 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-09-22 18:35 Use of FLAGS_REGNUM clashes with generates insn Paulo J. Matos
2011-09-23  7:21 ` Joern Rennecke
2011-09-23 12:17   ` Paulo J. Matos
2011-09-23 13:31     ` amylaar
2011-09-23 14:12       ` Paulo J. Matos
2011-10-17 10:50   ` Hans-Peter Nilsson
2011-10-18 13:57     ` amylaar
2011-10-26  2:58       ` Impact assessment of dse.c:emit_inc_dec_insn_before (Was: Re: Use of FLAGS_REGNUM clashes with generates insn) Joern Rennecke
2011-10-26  3:00         ` DJ Delorie
2011-10-26  3:53           ` Joern Rennecke
2011-10-26 13:18             ` DJ Delorie
2011-10-26 15:38               ` Joern Rennecke

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).