summaryrefslogtreecommitdiff
path: root/gcc/config/arm/ldrdstrd.md
blob: d6e2be55a9265024178634e3f885813635c056c0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
;; ARM ldrd/strd peephole optimizations.
;;
;; Copyright (C) 2013-2021 Free Software Foundation, Inc.
;;
;; Written by Greta Yorsh <greta.yorsh@arm.com>

;; This file is part of GCC.
;;
;; GCC is free software; you can redistribute it and/or modify it
;; under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 3, or (at your option)
;; any later version.
;;
;; GCC is distributed in the hope that it will be useful, but
;; WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
;; General Public License for more details.
;;
;; You should have received a copy of the GNU General Public License
;; along with GCC; see the file COPYING3.  If not see
;; <http://www.gnu.org/licenses/>.

;; The following peephole optimizations identify consecutive memory
;; accesses, and try to rearrange the operands to enable generation of
;; ldrd/strd.
;;
;; In many cases they behave in the same way that patterns in ldmstm.md behave,
;; but there is extra logic in gen_operands_ldrd_strd to try and ensure the
;; registers used are an (r<N>, r<N + 1>) pair where N is even.

(define_peephole2 ; ldrd
  [(set (match_operand:SI 0 "arm_general_register_operand" "")
	(match_operand:SI 2 "memory_operand" ""))
   (set (match_operand:SI 1 "arm_general_register_operand" "")
	(match_operand:SI 3 "memory_operand" ""))]
  "TARGET_LDRD"
  [(parallel [(set (match_dup 0) (match_dup 2))
	      (set (match_dup 1) (match_dup 3))])]
{
  if (!gen_operands_ldrd_strd (operands, true, false, false))
    FAIL;
})

(define_peephole2 ; strd
  [(set (match_operand:SI 2 "memory_operand" "")
	(match_operand:SI 0 "arm_general_register_operand" ""))
   (set (match_operand:SI 3 "memory_operand" "")
	(match_operand:SI 1 "arm_general_register_operand" ""))]
  "TARGET_LDRD"
  [(parallel [(set (match_dup 2) (match_dup 0))
	      (set (match_dup 3) (match_dup 1))])]
{
  if (!gen_operands_ldrd_strd (operands, false, false, false))
    FAIL;
})

;; The following peepholes reorder registers to enable LDRD/STRD.
(define_peephole2 ; strd of constants
  [(set (match_operand:SI 0 "arm_general_register_operand" "")
	(match_operand:SI 4 "const_int_operand" ""))
   (set (match_operand:SI 2 "memory_operand" "")
	(match_dup 0))
   (set (match_operand:SI 1 "arm_general_register_operand" "")
	(match_operand:SI 5 "const_int_operand" ""))
   (set (match_operand:SI 3 "memory_operand" "")
	(match_dup 1))]
  "TARGET_LDRD"
  [(set (match_dup 0) (match_dup 4))
   (set (match_dup 1) (match_dup 5))
   (parallel [(set (match_dup 2) (match_dup 0))
	      (set (match_dup 3) (match_dup 1))])]
{
  if (!gen_operands_ldrd_strd (operands, false, true, false))
    FAIL;
})

(define_peephole2 ; strd of constants
  [(set (match_operand:SI 0 "arm_general_register_operand" "")
	(match_operand:SI 4 "const_int_operand" ""))
   (set (match_operand:SI 1 "arm_general_register_operand" "")
	(match_operand:SI 5 "const_int_operand" ""))
   (set (match_operand:SI 2 "memory_operand" "")
	(match_dup 0))
   (set (match_operand:SI 3 "memory_operand" "")
	(match_dup 1))]
  "TARGET_LDRD"
  [(set (match_dup 0) (match_dup 4))
   (set (match_dup 1) (match_dup 5))
   (parallel [(set (match_dup 2) (match_dup 0))
	      (set (match_dup 3) (match_dup 1))])]
{
  if (!gen_operands_ldrd_strd (operands, false, true, false))
     FAIL;
})

;; The following two peephole optimizations are only relevant for ARM
;; mode where LDRD/STRD require consecutive registers.

(define_peephole2 ; swap the destination registers of two loads
		  ; before a commutative operation.
  [(set (match_operand:SI 0 "arm_general_register_operand" "")
	(match_operand:SI 2 "memory_operand" ""))
   (set (match_operand:SI 1 "arm_general_register_operand" "")
	(match_operand:SI 3 "memory_operand" ""))
   (set (match_operand:SI 4 "arm_general_register_operand" "")
	(match_operator:SI 5 "commutative_binary_operator"
			   [(match_operand 6 "arm_general_register_operand" "")
			    (match_operand 7 "arm_general_register_operand" "") ]))]
  "TARGET_LDRD && TARGET_ARM
   && (  ((rtx_equal_p(operands[0], operands[6])) && (rtx_equal_p(operands[1], operands[7])))
	||((rtx_equal_p(operands[0], operands[7])) && (rtx_equal_p(operands[1], operands[6]))))
   && (peep2_reg_dead_p (3, operands[0]) || rtx_equal_p (operands[0], operands[4]))
   && (peep2_reg_dead_p (3, operands[1]) || rtx_equal_p (operands[1], operands[4]))"
  [(parallel [(set (match_dup 0) (match_dup 2))
	      (set (match_dup 1) (match_dup 3))])
   (set (match_dup 4) (match_op_dup 5 [(match_dup 6) (match_dup 7)]))]
{
  if (!gen_operands_ldrd_strd (operands, true, false, true))
    FAIL;
})

(define_peephole2 ; swap the destination registers of two loads
		  ; before a commutative operation that sets the flags.
  [(set (match_operand:SI 0 "arm_general_register_operand" "")
	(match_operand:SI 2 "memory_operand" ""))
   (set (match_operand:SI 1 "arm_general_register_operand" "")
	(match_operand:SI 3 "memory_operand" ""))
   (parallel
      [(set (match_operand:SI 4 "arm_general_register_operand" "")
	    (match_operator:SI 5 "commutative_binary_operator"
			       [(match_operand 6 "arm_general_register_operand" "")
				(match_operand 7 "arm_general_register_operand" "") ]))
       (clobber (reg:CC CC_REGNUM))])]
  "TARGET_LDRD && TARGET_ARM
   && (  ((rtx_equal_p(operands[0], operands[6])) && (rtx_equal_p(operands[1], operands[7])))
       ||((rtx_equal_p(operands[0], operands[7])) && (rtx_equal_p(operands[1], operands[6]))))
   && (peep2_reg_dead_p (3, operands[0]) || rtx_equal_p (operands[0], operands[4]))
   && (peep2_reg_dead_p (3, operands[1]) || rtx_equal_p (operands[1], operands[4]))"
  [(parallel [(set (match_dup 0) (match_dup 2))
	      (set (match_dup 1) (match_dup 3))])
   (parallel
      [(set (match_dup 4)
	    (match_op_dup 5 [(match_dup 6) (match_dup 7)]))
       (clobber (reg:CC CC_REGNUM))])]
{
  if (!gen_operands_ldrd_strd (operands, true, false, true))
    FAIL;
})

;; TODO: Handle LDRD/STRD with writeback:
;; (a) memory operands can be POST_INC, POST_DEC, PRE_MODIFY, POST_MODIFY
;; (b) Patterns may be followed by an update of the base address.


;; insns matching the LDRD/STRD patterns that will get created by the above
;; peepholes.
;; We use gen_operands_ldrd_strd() with a modify argument as false so that the
;; operands are not changed.
(define_insn "*arm_ldrd"
  [(parallel [(set (match_operand:SI 0 "s_register_operand" "=r")
		   (match_operand:SI 2 "memory_operand" "m"))
	      (set (match_operand:SI 1 "s_register_operand" "=rk")
		   (match_operand:SI 3 "memory_operand" "m"))])]
  "TARGET_LDRD && TARGET_ARM && reload_completed
  && valid_operands_ldrd_strd (operands, true)"
  {
    rtx op[2];
    op[0] = gen_rtx_REG (DImode, REGNO (operands[0]));
    op[1] = adjust_address (operands[2], DImode, 0);
    return output_move_double (op, true, NULL);
  }
  [(set (attr "length")
	(symbol_ref "arm_count_ldrdstrd_insns (operands, true) * 4"))
   (set (attr "ce_count") (symbol_ref "get_attr_length (insn) / 4"))
   (set_attr "type" "load_8")
   (set_attr "predicable" "yes")]
)

(define_insn "*arm_strd"
  [(parallel [(set (match_operand:SI 2 "memory_operand" "=m")
		   (match_operand:SI 0 "s_register_operand" "r"))
	      (set (match_operand:SI 3 "memory_operand" "=m")
		   (match_operand:SI 1 "s_register_operand" "rk"))])]
  "TARGET_LDRD && TARGET_ARM && reload_completed
  && valid_operands_ldrd_strd (operands, false)"
  {
    rtx op[2];
    op[0] = adjust_address (operands[2], DImode, 0);
    op[1] = gen_rtx_REG (DImode, REGNO (operands[0]));
    return output_move_double (op, true, NULL);
  }
  [(set (attr "length")
	(symbol_ref "arm_count_ldrdstrd_insns (operands, false) * 4"))
   (set (attr "ce_count") (symbol_ref "get_attr_length (insn) / 4"))
   (set_attr "type" "store_8")
   (set_attr "predicable" "yes")]
)