This is the mail archive of the gcc-patches@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]

Re: PATCH for [ARM] subsequent use of plus and minus operators could be improved


> Richard Earnshaw <rearnsha at arm dot com> writes:
> 
> >> > +       /* Try to transform 
> >> > +            (set (regX) (plus\minus (regY) (constA)))
> >> > +            (set (regX) (plus\minus (regX) (constB)))
> >> > +          to
> >> > +            (set (regX) (plus\minus (regY) (constA +\- constB))) */
> >> 
> >> You should use forward slashes (/) here, not backslashes (\).  
> >
> > In fact, because of canonicalization there should never be a MINUS with a 
> > constant as the second operand -- this should always be transformed into 
> > addition of the negated constant.  So there's no need to check for that 
> > case.
> 
> What if (minus (reg) (imm)) is a valid insn but (plus (reg) (-imm))
> isn't?
> 
> zw

Then you've got a broken machine description.  This is a standard 
canonicalization -- you have to handle this case when emitting 
instructions.  For example on ARM we have:


(define_insn_and_split "*arm_addsi3"
  [(set (match_operand:SI          0 "s_register_operand" "=r,r,r")
        (plus:SI (match_operand:SI 1 "s_register_operand" "%r,r,r")
                 (match_operand:SI 2 "reg_or_int_operand" "rI,L,?n")))]
  "TARGET_ARM"
  "@
   add%?\\t%0, %1, %2
   sub%?\\t%0, %1, #%n2
   #"

Note the second alternative matches the "negative constant" case.

R.


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