[SystemZ] Extend memcpy and memset support to all constant lengths
[oota-llvm.git] / lib / Target / SystemZ / SystemZOperators.td
1 //===-- SystemZOperators.td - SystemZ-specific operators ------*- tblgen-*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 //===----------------------------------------------------------------------===//
11 // Type profiles
12 //===----------------------------------------------------------------------===//
13 def SDT_CallSeqStart        : SDCallSeqStart<[SDTCisVT<0, i64>]>;
14 def SDT_CallSeqEnd          : SDCallSeqEnd<[SDTCisVT<0, i64>,
15                                             SDTCisVT<1, i64>]>;
16 def SDT_ZCall               : SDTypeProfile<0, -1, [SDTCisPtrTy<0>]>;
17 def SDT_ZCmp                : SDTypeProfile<0, 2, [SDTCisSameAs<0, 1>]>;
18 def SDT_ZBRCCMask           : SDTypeProfile<0, 3,
19                                             [SDTCisVT<0, i8>,
20                                              SDTCisVT<1, i8>,
21                                              SDTCisVT<2, OtherVT>]>;
22 def SDT_ZSelectCCMask       : SDTypeProfile<1, 4,
23                                             [SDTCisSameAs<0, 1>,
24                                              SDTCisSameAs<1, 2>,
25                                              SDTCisVT<3, i8>,
26                                              SDTCisVT<4, i8>]>;
27 def SDT_ZWrapPtr            : SDTypeProfile<1, 1,
28                                             [SDTCisSameAs<0, 1>,
29                                              SDTCisPtrTy<0>]>;
30 def SDT_ZAdjDynAlloc        : SDTypeProfile<1, 0, [SDTCisVT<0, i64>]>;
31 def SDT_ZExtractAccess      : SDTypeProfile<1, 1,
32                                             [SDTCisVT<0, i32>,
33                                              SDTCisVT<1, i8>]>;
34 def SDT_ZGR128Binary32      : SDTypeProfile<1, 2,
35                                             [SDTCisVT<0, untyped>,
36                                              SDTCisVT<1, untyped>,
37                                              SDTCisVT<2, i32>]>;
38 def SDT_ZGR128Binary64      : SDTypeProfile<1, 2,
39                                             [SDTCisVT<0, untyped>,
40                                              SDTCisVT<1, untyped>,
41                                              SDTCisVT<2, i64>]>;
42 def SDT_ZAtomicLoadBinaryW  : SDTypeProfile<1, 5,
43                                             [SDTCisVT<0, i32>,
44                                              SDTCisPtrTy<1>,
45                                              SDTCisVT<2, i32>,
46                                              SDTCisVT<3, i32>,
47                                              SDTCisVT<4, i32>,
48                                              SDTCisVT<5, i32>]>;
49 def SDT_ZAtomicCmpSwapW     : SDTypeProfile<1, 6,
50                                             [SDTCisVT<0, i32>,
51                                              SDTCisPtrTy<1>,
52                                              SDTCisVT<2, i32>,
53                                              SDTCisVT<3, i32>,
54                                              SDTCisVT<4, i32>,
55                                              SDTCisVT<5, i32>,
56                                              SDTCisVT<6, i32>]>;
57 def SDT_ZMemMemLength       : SDTypeProfile<0, 3,
58                                             [SDTCisPtrTy<0>,
59                                              SDTCisPtrTy<1>,
60                                              SDTCisVT<2, i64>]>;
61 def SDT_ZMemMemLoop         : SDTypeProfile<0, 4,
62                                             [SDTCisPtrTy<0>,
63                                              SDTCisPtrTy<1>,
64                                              SDTCisVT<2, i64>,
65                                              SDTCisVT<3, i64>]>;
66 def SDT_ZString             : SDTypeProfile<1, 3,
67                                             [SDTCisPtrTy<0>,
68                                              SDTCisPtrTy<1>,
69                                              SDTCisPtrTy<2>,
70                                              SDTCisVT<3, i32>]>;
71 def SDT_ZI32Intrinsic       : SDTypeProfile<1, 0, [SDTCisVT<0, i32>]>;
72 def SDT_ZPrefetch           : SDTypeProfile<0, 2,
73                                             [SDTCisVT<0, i8>,
74                                              SDTCisPtrTy<1>]>;
75
76 //===----------------------------------------------------------------------===//
77 // Node definitions
78 //===----------------------------------------------------------------------===//
79
80 // These are target-independent nodes, but have target-specific formats.
81 def callseq_start       : SDNode<"ISD::CALLSEQ_START", SDT_CallSeqStart,
82                                  [SDNPHasChain, SDNPSideEffect, SDNPOutGlue]>;
83 def callseq_end         : SDNode<"ISD::CALLSEQ_END",   SDT_CallSeqEnd,
84                                  [SDNPHasChain, SDNPSideEffect, SDNPOptInGlue,
85                                   SDNPOutGlue]>;
86
87 // Nodes for SystemZISD::*.  See SystemZISelLowering.h for more details.
88 def z_retflag           : SDNode<"SystemZISD::RET_FLAG", SDTNone,
89                                  [SDNPHasChain, SDNPOptInGlue, SDNPVariadic]>;
90 def z_call              : SDNode<"SystemZISD::CALL", SDT_ZCall,
91                                  [SDNPHasChain, SDNPOutGlue, SDNPOptInGlue,
92                                   SDNPVariadic]>;
93 def z_sibcall           : SDNode<"SystemZISD::SIBCALL", SDT_ZCall,
94                                  [SDNPHasChain, SDNPOutGlue, SDNPOptInGlue,
95                                   SDNPVariadic]>;
96 def z_pcrel_wrapper     : SDNode<"SystemZISD::PCREL_WRAPPER", SDT_ZWrapPtr, []>;
97 def z_cmp               : SDNode<"SystemZISD::CMP", SDT_ZCmp, [SDNPOutGlue]>;
98 def z_ucmp              : SDNode<"SystemZISD::UCMP", SDT_ZCmp, [SDNPOutGlue]>;
99 def z_br_ccmask         : SDNode<"SystemZISD::BR_CCMASK", SDT_ZBRCCMask,
100                                  [SDNPHasChain, SDNPInGlue]>;
101 def z_select_ccmask     : SDNode<"SystemZISD::SELECT_CCMASK", SDT_ZSelectCCMask,
102                                  [SDNPInGlue]>;
103 def z_adjdynalloc       : SDNode<"SystemZISD::ADJDYNALLOC", SDT_ZAdjDynAlloc>;
104 def z_extract_access    : SDNode<"SystemZISD::EXTRACT_ACCESS",
105                                  SDT_ZExtractAccess>;
106 def z_umul_lohi64       : SDNode<"SystemZISD::UMUL_LOHI64", SDT_ZGR128Binary64>;
107 def z_sdivrem32         : SDNode<"SystemZISD::SDIVREM32", SDT_ZGR128Binary32>;
108 def z_sdivrem64         : SDNode<"SystemZISD::SDIVREM64", SDT_ZGR128Binary64>;
109 def z_udivrem32         : SDNode<"SystemZISD::UDIVREM32", SDT_ZGR128Binary32>;
110 def z_udivrem64         : SDNode<"SystemZISD::UDIVREM64", SDT_ZGR128Binary64>;
111
112 class AtomicWOp<string name, SDTypeProfile profile = SDT_ZAtomicLoadBinaryW>
113   : SDNode<"SystemZISD::"##name, profile,
114            [SDNPHasChain, SDNPMayStore, SDNPMayLoad, SDNPMemOperand]>;
115
116 def z_atomic_swapw      : AtomicWOp<"ATOMIC_SWAPW">;
117 def z_atomic_loadw_add  : AtomicWOp<"ATOMIC_LOADW_ADD">;
118 def z_atomic_loadw_sub  : AtomicWOp<"ATOMIC_LOADW_SUB">;
119 def z_atomic_loadw_and  : AtomicWOp<"ATOMIC_LOADW_AND">;
120 def z_atomic_loadw_or   : AtomicWOp<"ATOMIC_LOADW_OR">;
121 def z_atomic_loadw_xor  : AtomicWOp<"ATOMIC_LOADW_XOR">;
122 def z_atomic_loadw_nand : AtomicWOp<"ATOMIC_LOADW_NAND">;
123 def z_atomic_loadw_min  : AtomicWOp<"ATOMIC_LOADW_MIN">;
124 def z_atomic_loadw_max  : AtomicWOp<"ATOMIC_LOADW_MAX">;
125 def z_atomic_loadw_umin : AtomicWOp<"ATOMIC_LOADW_UMIN">;
126 def z_atomic_loadw_umax : AtomicWOp<"ATOMIC_LOADW_UMAX">;
127 def z_atomic_cmp_swapw  : AtomicWOp<"ATOMIC_CMP_SWAPW", SDT_ZAtomicCmpSwapW>;
128
129 def z_mvc               : SDNode<"SystemZISD::MVC", SDT_ZMemMemLength,
130                                  [SDNPHasChain, SDNPMayStore, SDNPMayLoad]>;
131 def z_mvc_loop          : SDNode<"SystemZISD::MVC_LOOP", SDT_ZMemMemLoop,
132                                  [SDNPHasChain, SDNPMayStore, SDNPMayLoad]>;
133 def z_clc               : SDNode<"SystemZISD::CLC", SDT_ZMemMemLength,
134                                  [SDNPHasChain, SDNPOutGlue, SDNPMayLoad]>;
135 def z_clc_loop          : SDNode<"SystemZISD::CLC_LOOP", SDT_ZMemMemLoop,
136                                  [SDNPHasChain, SDNPOutGlue, SDNPMayLoad]>;
137 def z_strcmp            : SDNode<"SystemZISD::STRCMP", SDT_ZString,
138                                  [SDNPHasChain, SDNPOutGlue, SDNPMayLoad]>;
139 def z_stpcpy            : SDNode<"SystemZISD::STPCPY", SDT_ZString,
140                                  [SDNPHasChain, SDNPMayStore, SDNPMayLoad]>;
141 def z_search_string     : SDNode<"SystemZISD::SEARCH_STRING", SDT_ZString,
142                                  [SDNPHasChain, SDNPOutGlue, SDNPMayLoad]>;
143 def z_ipm               : SDNode<"SystemZISD::IPM", SDT_ZI32Intrinsic,
144                                  [SDNPInGlue]>;
145 def z_prefetch          : SDNode<"SystemZISD::PREFETCH", SDT_ZPrefetch,
146                                  [SDNPHasChain, SDNPMayLoad, SDNPMayStore,
147                                   SDNPMemOperand]>;
148
149 //===----------------------------------------------------------------------===//
150 // Pattern fragments
151 //===----------------------------------------------------------------------===//
152
153 // Register sign-extend operations.  Sub-32-bit values are represented as i32s.
154 def sext8  : PatFrag<(ops node:$src), (sext_inreg node:$src, i8)>;
155 def sext16 : PatFrag<(ops node:$src), (sext_inreg node:$src, i16)>;
156 def sext32 : PatFrag<(ops node:$src), (sext (i32 node:$src))>;
157
158 // Register zero-extend operations.  Sub-32-bit values are represented as i32s.
159 def zext8  : PatFrag<(ops node:$src), (and node:$src, 0xff)>;
160 def zext16 : PatFrag<(ops node:$src), (and node:$src, 0xffff)>;
161 def zext32 : PatFrag<(ops node:$src), (zext (i32 node:$src))>;
162
163 // Typed floating-point loads.
164 def loadf32 : PatFrag<(ops node:$src), (f32 (load node:$src))>;
165 def loadf64 : PatFrag<(ops node:$src), (f64 (load node:$src))>;
166
167 // Extending loads in which the extension type doesn't matter.
168 def anyextload : PatFrag<(ops node:$ptr), (unindexedload node:$ptr), [{
169   return cast<LoadSDNode>(N)->getExtensionType() != ISD::NON_EXTLOAD;
170 }]>;
171 def anyextloadi8 : PatFrag<(ops node:$ptr), (anyextload node:$ptr), [{
172   return cast<LoadSDNode>(N)->getMemoryVT() == MVT::i8;
173 }]>;
174 def anyextloadi16 : PatFrag<(ops node:$ptr), (anyextload node:$ptr), [{
175   return cast<LoadSDNode>(N)->getMemoryVT() == MVT::i16;
176 }]>;
177 def anyextloadi32 : PatFrag<(ops node:$ptr), (anyextload node:$ptr), [{
178   return cast<LoadSDNode>(N)->getMemoryVT() == MVT::i32;
179 }]>;
180
181 // Aligned loads.
182 class AlignedLoad<SDPatternOperator load>
183   : PatFrag<(ops node:$addr), (load node:$addr), [{
184   LoadSDNode *Load = cast<LoadSDNode>(N);
185   return Load->getAlignment() >= Load->getMemoryVT().getStoreSize();
186 }]>;
187 def aligned_load        : AlignedLoad<load>;
188 def aligned_sextloadi16 : AlignedLoad<sextloadi16>;
189 def aligned_sextloadi32 : AlignedLoad<sextloadi32>;
190 def aligned_zextloadi16 : AlignedLoad<zextloadi16>;
191 def aligned_zextloadi32 : AlignedLoad<zextloadi32>;
192
193 // Aligned stores.
194 class AlignedStore<SDPatternOperator store>
195   : PatFrag<(ops node:$src, node:$addr), (store node:$src, node:$addr), [{
196   StoreSDNode *Store = cast<StoreSDNode>(N);
197   return Store->getAlignment() >= Store->getMemoryVT().getStoreSize();
198 }]>;
199 def aligned_store         : AlignedStore<store>;
200 def aligned_truncstorei16 : AlignedStore<truncstorei16>;
201 def aligned_truncstorei32 : AlignedStore<truncstorei32>;
202
203 // Non-volatile loads.  Used for instructions that might access the storage
204 // location multiple times.
205 class NonvolatileLoad<SDPatternOperator load>
206   : PatFrag<(ops node:$addr), (load node:$addr), [{
207   LoadSDNode *Load = cast<LoadSDNode>(N);
208   return !Load->isVolatile();
209 }]>;
210 def nonvolatile_load          : NonvolatileLoad<load>;
211 def nonvolatile_anyextloadi8  : NonvolatileLoad<anyextloadi8>;
212 def nonvolatile_anyextloadi16 : NonvolatileLoad<anyextloadi16>;
213 def nonvolatile_anyextloadi32 : NonvolatileLoad<anyextloadi32>;
214
215 // Non-volatile stores.
216 class NonvolatileStore<SDPatternOperator store>
217   : PatFrag<(ops node:$src, node:$addr), (store node:$src, node:$addr), [{
218   StoreSDNode *Store = cast<StoreSDNode>(N);
219   return !Store->isVolatile();
220 }]>;
221 def nonvolatile_store         : NonvolatileStore<store>;
222 def nonvolatile_truncstorei8  : NonvolatileStore<truncstorei8>;
223 def nonvolatile_truncstorei16 : NonvolatileStore<truncstorei16>;
224 def nonvolatile_truncstorei32 : NonvolatileStore<truncstorei32>;
225
226 // Insertions.
227 def inserti8 : PatFrag<(ops node:$src1, node:$src2),
228                        (or (and node:$src1, -256), node:$src2)>;
229 def insertll : PatFrag<(ops node:$src1, node:$src2),
230                        (or (and node:$src1, 0xffffffffffff0000), node:$src2)>;
231 def insertlh : PatFrag<(ops node:$src1, node:$src2),
232                        (or (and node:$src1, 0xffffffff0000ffff), node:$src2)>;
233 def inserthl : PatFrag<(ops node:$src1, node:$src2),
234                        (or (and node:$src1, 0xffff0000ffffffff), node:$src2)>;
235 def inserthh : PatFrag<(ops node:$src1, node:$src2),
236                        (or (and node:$src1, 0x0000ffffffffffff), node:$src2)>;
237 def insertlf : PatFrag<(ops node:$src1, node:$src2),
238                        (or (and node:$src1, 0xffffffff00000000), node:$src2)>;
239 def inserthf : PatFrag<(ops node:$src1, node:$src2),
240                        (or (and node:$src1, 0x00000000ffffffff), node:$src2)>;
241
242 // ORs that can be treated as insertions.
243 def or_as_inserti8 : PatFrag<(ops node:$src1, node:$src2),
244                              (or node:$src1, node:$src2), [{
245   unsigned BitWidth = N->getValueType(0).getScalarType().getSizeInBits();
246   return CurDAG->MaskedValueIsZero(N->getOperand(0),
247                                    APInt::getLowBitsSet(BitWidth, 8));
248 }]>;
249
250 // ORs that can be treated as reversed insertions.
251 def or_as_revinserti8 : PatFrag<(ops node:$src1, node:$src2),
252                                 (or node:$src1, node:$src2), [{
253   unsigned BitWidth = N->getValueType(0).getScalarType().getSizeInBits();
254   return CurDAG->MaskedValueIsZero(N->getOperand(1),
255                                    APInt::getLowBitsSet(BitWidth, 8));
256 }]>;
257
258 // Integer absolute, matching the canonical form generated by DAGCombiner.
259 def z_iabs32 : PatFrag<(ops node:$src),
260                        (xor (add node:$src, (sra node:$src, (i32 31))),
261                             (sra node:$src, (i32 31)))>;
262 def z_iabs64 : PatFrag<(ops node:$src),
263                        (xor (add node:$src, (sra node:$src, (i32 63))),
264                             (sra node:$src, (i32 63)))>;
265 def z_inegabs32 : PatFrag<(ops node:$src), (ineg (z_iabs32 node:$src))>;
266 def z_inegabs64 : PatFrag<(ops node:$src), (ineg (z_iabs64 node:$src))>;
267
268 // Fused multiply-add and multiply-subtract, but with the order of the
269 // operands matching SystemZ's MA and MS instructions.
270 def z_fma : PatFrag<(ops node:$src1, node:$src2, node:$src3),
271                     (fma node:$src2, node:$src3, node:$src1)>;
272 def z_fms : PatFrag<(ops node:$src1, node:$src2, node:$src3),
273                     (fma node:$src2, node:$src3, (fneg node:$src1))>;
274
275 // Floating-point negative absolute.
276 def fnabs : PatFrag<(ops node:$ptr), (fneg (fabs node:$ptr))>;
277
278 // Create a unary operator that loads from memory and then performs
279 // the given operation on it.
280 class loadu<SDPatternOperator operator, SDPatternOperator load = load>
281   : PatFrag<(ops node:$addr), (operator (load node:$addr))>;
282
283 // Create a store operator that performs the given unary operation
284 // on the value before storing it.
285 class storeu<SDPatternOperator operator, SDPatternOperator store = store>
286   : PatFrag<(ops node:$value, node:$addr),
287             (store (operator node:$value), node:$addr)>;