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