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]

Re: arm.md: define insn "loadhi_predec" -- why issue ldr, not ldrh?


Hi Dimitri,

: What is the reason behind issuing word-long loads/stores
: for loading/storing halfword values in ARM backend?
: 
: from arm.md:
: 
: (define_insn "*loadhi_preinc"
:   [(set (match_operand:HI 3 "s_register_operand" "=r")
:  (mem:HI (plus:SI (match_operand:SI 1 "s_register_operand" "%0")
:     (match_operand:SI 2 "index_operand" "rJ"))))
:    (set (match_operand:SI 0 "s_register_operand" "=r")
:  (plus:SI (match_dup 1) (match_dup 2)))]
:   "TARGET_ARM
:    && (! BYTES_BIG_ENDIAN)
:    && ! TARGET_MMU_TRAPS
:    && REGNO (operands[0]) != FRAME_POINTER_REGNUM
:    && REGNO (operands[1]) != FRAME_POINTER_REGNUM
:    && (GET_CODE (operands[2]) != REG
:        || REGNO (operands[2]) != FRAME_POINTER_REGNUM)"
:   "ldr%?\\t%3, [%0, %2]!\\t%@ loadhi"
: [(set_attr "type" "load")])
: 
: 
: Why not "ldr%?h\\t%3, [%0, %2]!\\t%@ loadhi" ?

Well for starters the LDRH instruction is only available on v4
architectures (and upwards).  In fact I suspect that this is the real
reason - the pattern was written back before the v4 architecture was
available and then not modified when the v4 was available.

I suppose that the pattern could be rewritten like this:

 (define_insn "*loadhi_preinc"
   [(set (match_operand:HI 3 "s_register_operand" "=r")
  (mem:HI (plus:SI (match_operand:SI 1 "s_register_operand" "%0")
     (match_operand:SI 2 "index_operand" "rJ"))))
    (set (match_operand:SI 0 "s_register_operand" "=r")
  (plus:SI (match_dup 1) (match_dup 2)))]
   "TARGET_ARM
    && ! BYTES_BIG_ENDIAN
    && (! TARGET_MMU_TRAPS || arm_arch4)
    && REGNO (operands[0]) != FRAME_POINTER_REGNUM
    && REGNO (operands[1]) != FRAME_POINTER_REGNUM
    && (GET_CODE (operands[2]) != REG
        || REGNO (operands[2]) != FRAME_POINTER_REGNUM)"
   "*
   if (arm_arch4)
     return \"ldr%?h\\t%3, [%0, %2]!\";
   else 
     return \"ldr%?\\t%3, [%0, %2]!\\t%@ loadhi\";"
 [(set_attr "type" "load")])


I expect Richard Earnshaw will have a better answer.

Cheers
	Nick

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