1 //===-- AMDGPUInstrInfo.td - AMDGPU DAG nodes --------------*- tablegen -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file contains DAG node defintions for the AMDGPU target.
12 //===----------------------------------------------------------------------===//
14 //===----------------------------------------------------------------------===//
15 // AMDGPU DAG Profiles
16 //===----------------------------------------------------------------------===//
18 def AMDGPUDTIntTernaryOp : SDTypeProfile<1, 3, [
19 SDTCisSameAs<0, 1>, SDTCisSameAs<0, 2>, SDTCisInt<0>, SDTCisInt<3>
22 def AMDGPUTrigPreOp : SDTypeProfile<1, 2,
23 [SDTCisSameAs<0, 1>, SDTCisFP<0>, SDTCisInt<2>]
26 def AMDGPULdExpOp : SDTypeProfile<1, 2,
27 [SDTCisSameAs<0, 1>, SDTCisFP<0>, SDTCisInt<2>]
30 def AMDGPUFPClassOp : SDTypeProfile<1, 2,
31 [SDTCisInt<0>, SDTCisFP<1>, SDTCisInt<2>]
34 def AMDGPUFPPackOp : SDTypeProfile<1, 2,
35 [SDTCisFP<1>, SDTCisSameAs<1, 2>]
38 def AMDGPUDivScaleOp : SDTypeProfile<2, 3,
39 [SDTCisFP<0>, SDTCisInt<1>, SDTCisSameAs<0, 2>, SDTCisSameAs<0, 3>, SDTCisSameAs<0, 4>]
42 // float, float, float, vcc
43 def AMDGPUFmasOp : SDTypeProfile<1, 4,
44 [SDTCisFP<0>, SDTCisSameAs<0, 1>, SDTCisSameAs<0, 2>, SDTCisSameAs<0, 3>, SDTCisInt<4>]
47 def AMDGPUKillSDT : SDTypeProfile<0, 1, [SDTCisInt<0>]>;
49 def AMDGPUIfOp : SDTypeProfile<1, 2,
50 [SDTCisVT<0, i64>, SDTCisVT<1, i1>, SDTCisVT<2, OtherVT>]
53 def AMDGPUElseOp : SDTypeProfile<1, 2,
54 [SDTCisVT<0, i64>, SDTCisVT<1, i64>, SDTCisVT<2, OtherVT>]
57 def AMDGPULoopOp : SDTypeProfile<0, 2,
58 [SDTCisVT<0, i64>, SDTCisVT<1, OtherVT>]
61 def AMDGPUBreakOp : SDTypeProfile<1, 1,
62 [SDTCisVT<0, i64>, SDTCisVT<1, i64>]
65 def AMDGPUIfBreakOp : SDTypeProfile<1, 2,
66 [SDTCisVT<0, i64>, SDTCisVT<1, i1>, SDTCisVT<2, i64>]
69 def AMDGPUElseBreakOp : SDTypeProfile<1, 2,
70 [SDTCisVT<0, i64>, SDTCisVT<1, i64>, SDTCisVT<2, i64>]
73 def AMDGPUAddeSubeOp : SDTypeProfile<2, 3,
74 [SDTCisSameAs<0, 2>, SDTCisSameAs<0, 3>, SDTCisVT<0, i32>, SDTCisVT<1, i1>, SDTCisVT<4, i1>]
77 //===----------------------------------------------------------------------===//
81 def AMDGPUif : SDNode<"AMDGPUISD::IF", AMDGPUIfOp, [SDNPHasChain]>;
82 def AMDGPUelse : SDNode<"AMDGPUISD::ELSE", AMDGPUElseOp, [SDNPHasChain]>;
83 def AMDGPUloop : SDNode<"AMDGPUISD::LOOP", AMDGPULoopOp, [SDNPHasChain]>;
85 def AMDGPUtrap : SDNode<"AMDGPUISD::TRAP",
86 SDTypeProfile<0, -1, [SDTCisVT<0, i16>]>,
87 [SDNPHasChain, SDNPVariadic, SDNPSideEffect, SDNPInGlue]
90 def AMDGPUconstdata_ptr : SDNode<
91 "AMDGPUISD::CONST_DATA_PTR", SDTypeProfile <1, 1, [SDTCisVT<0, iPTR>,
95 // This argument to this node is a dword address.
96 def AMDGPUdwordaddr : SDNode<"AMDGPUISD::DWORDADDR", SDTIntUnaryOp>;
98 // Force dependencies for vector trunc stores
99 def R600dummy_chain : SDNode<"AMDGPUISD::DUMMY_CHAIN", SDTNone, [SDNPHasChain]>;
101 def AMDGPUcos : SDNode<"AMDGPUISD::COS_HW", SDTFPUnaryOp>;
102 def AMDGPUsin : SDNode<"AMDGPUISD::SIN_HW", SDTFPUnaryOp>;
104 // out = a - floor(a)
105 def AMDGPUfract : SDNode<"AMDGPUISD::FRACT", SDTFPUnaryOp>;
108 def AMDGPUrcp : SDNode<"AMDGPUISD::RCP", SDTFPUnaryOp>;
110 // out = 1.0 / sqrt(a)
111 def AMDGPUrsq : SDNode<"AMDGPUISD::RSQ", SDTFPUnaryOp>;
113 // out = 1.0 / sqrt(a)
114 def AMDGPUrcp_legacy : SDNode<"AMDGPUISD::RCP_LEGACY", SDTFPUnaryOp>;
115 def AMDGPUrsq_legacy : SDNode<"AMDGPUISD::RSQ_LEGACY", SDTFPUnaryOp>;
117 // out = 1.0 / sqrt(a) result clamped to +/- max_float.
118 def AMDGPUrsq_clamp : SDNode<"AMDGPUISD::RSQ_CLAMP", SDTFPUnaryOp>;
120 def AMDGPUldexp : SDNode<"AMDGPUISD::LDEXP", AMDGPULdExpOp>;
122 def AMDGPUpkrtz_f16_f32 : SDNode<"AMDGPUISD::CVT_PKRTZ_F16_F32", AMDGPUFPPackOp>;
123 def AMDGPUfp_to_f16 : SDNode<"AMDGPUISD::FP_TO_FP16" , SDTFPToIntOp>;
124 def AMDGPUfp16_zext : SDNode<"AMDGPUISD::FP16_ZEXT" , SDTFPToIntOp>;
127 def AMDGPUfp_class : SDNode<"AMDGPUISD::FP_CLASS", AMDGPUFPClassOp>;
129 // out = max(a, b) a and b are floats, where a nan comparison fails.
130 // This is not commutative because this gives the second operand:
131 // x < nan ? x : nan -> nan
132 // nan < x ? nan : x -> x
133 def AMDGPUfmax_legacy : SDNode<"AMDGPUISD::FMAX_LEGACY", SDTFPBinOp,
137 def AMDGPUfmul_legacy : SDNode<"AMDGPUISD::FMUL_LEGACY", SDTFPBinOp,
138 [SDNPCommutative, SDNPAssociative]
141 def AMDGPUclamp : SDNode<"AMDGPUISD::CLAMP", SDTFPUnaryOp>;
143 // out = min(a, b) a and b are floats, where a nan comparison fails.
144 def AMDGPUfmin_legacy : SDNode<"AMDGPUISD::FMIN_LEGACY", SDTFPBinOp,
148 // FIXME: TableGen doesn't like commutative instructions with more
150 // out = max(a, b, c) a, b and c are floats
151 def AMDGPUfmax3 : SDNode<"AMDGPUISD::FMAX3", SDTFPTernaryOp,
152 [/*SDNPCommutative, SDNPAssociative*/]
155 // out = max(a, b, c) a, b, and c are signed ints
156 def AMDGPUsmax3 : SDNode<"AMDGPUISD::SMAX3", AMDGPUDTIntTernaryOp,
157 [/*SDNPCommutative, SDNPAssociative*/]
160 // out = max(a, b, c) a, b and c are unsigned ints
161 def AMDGPUumax3 : SDNode<"AMDGPUISD::UMAX3", AMDGPUDTIntTernaryOp,
162 [/*SDNPCommutative, SDNPAssociative*/]
165 // out = min(a, b, c) a, b and c are floats
166 def AMDGPUfmin3 : SDNode<"AMDGPUISD::FMIN3", SDTFPTernaryOp,
167 [/*SDNPCommutative, SDNPAssociative*/]
170 // out = min(a, b, c) a, b and c are signed ints
171 def AMDGPUsmin3 : SDNode<"AMDGPUISD::SMIN3", AMDGPUDTIntTernaryOp,
172 [/*SDNPCommutative, SDNPAssociative*/]
175 // out = min(a, b) a and b are unsigned ints
176 def AMDGPUumin3 : SDNode<"AMDGPUISD::UMIN3", AMDGPUDTIntTernaryOp,
177 [/*SDNPCommutative, SDNPAssociative*/]
180 // out = (src0 + src1 > 0xFFFFFFFF) ? 1 : 0
181 def AMDGPUcarry : SDNode<"AMDGPUISD::CARRY", SDTIntBinOp, []>;
183 // out = (src1 > src0) ? 1 : 0
184 def AMDGPUborrow : SDNode<"AMDGPUISD::BORROW", SDTIntBinOp, []>;
186 // TODO: remove AMDGPUadde/AMDGPUsube when ADDCARRY/SUBCARRY get their own
187 // nodes in TargetSelectionDAG.td.
188 def AMDGPUadde : SDNode<"ISD::ADDCARRY", AMDGPUAddeSubeOp, []>;
190 def AMDGPUsube : SDNode<"ISD::SUBCARRY", AMDGPUAddeSubeOp, []>;
192 def AMDGPUSetCCOp : SDTypeProfile<1, 3, [ // setcc
193 SDTCisVT<0, i64>, SDTCisSameAs<1, 2>, SDTCisVT<3, OtherVT>
196 def AMDGPUsetcc : SDNode<"AMDGPUISD::SETCC", AMDGPUSetCCOp>;
198 def AMDGPUSetRegOp : SDTypeProfile<0, 2, [
199 SDTCisInt<0>, SDTCisInt<1>
202 def AMDGPUsetreg : SDNode<"AMDGPUISD::SETREG", AMDGPUSetRegOp, [
203 SDNPHasChain, SDNPSideEffect, SDNPOptInGlue, SDNPOutGlue]>;
205 def AMDGPUfma : SDNode<"AMDGPUISD::FMA_W_CHAIN", SDTFPTernaryOp, [
206 SDNPHasChain, SDNPOptInGlue, SDNPOutGlue]>;
208 def AMDGPUmul : SDNode<"AMDGPUISD::FMUL_W_CHAIN", SDTFPBinOp, [
209 SDNPHasChain, SDNPOptInGlue, SDNPOutGlue]>;
211 def AMDGPUcvt_f32_ubyte0 : SDNode<"AMDGPUISD::CVT_F32_UBYTE0",
213 def AMDGPUcvt_f32_ubyte1 : SDNode<"AMDGPUISD::CVT_F32_UBYTE1",
215 def AMDGPUcvt_f32_ubyte2 : SDNode<"AMDGPUISD::CVT_F32_UBYTE2",
217 def AMDGPUcvt_f32_ubyte3 : SDNode<"AMDGPUISD::CVT_F32_UBYTE3",
221 // urecip - This operation is a helper for integer division, it returns the
222 // result of 1 / a as a fractional unsigned integer.
223 // out = (2^32 / a) + e
224 // e is rounding error
225 def AMDGPUurecip : SDNode<"AMDGPUISD::URECIP", SDTIntUnaryOp>;
227 // Special case divide preop and flags.
228 def AMDGPUdiv_scale : SDNode<"AMDGPUISD::DIV_SCALE", AMDGPUDivScaleOp>;
230 // Special case divide FMA with scale and flags (src0 = Quotient,
231 // src1 = Denominator, src2 = Numerator).
232 def AMDGPUdiv_fmas : SDNode<"AMDGPUISD::DIV_FMAS", AMDGPUFmasOp>;
234 // Single or double precision division fixup.
235 // Special case divide fixup and flags(src0 = Quotient, src1 =
236 // Denominator, src2 = Numerator).
237 def AMDGPUdiv_fixup : SDNode<"AMDGPUISD::DIV_FIXUP", SDTFPTernaryOp>;
239 def AMDGPUfmad_ftz : SDNode<"AMDGPUISD::FMAD_FTZ", SDTFPTernaryOp>;
241 // Look Up 2.0 / pi src0 with segment select src1[4:0]
242 def AMDGPUtrig_preop : SDNode<"AMDGPUISD::TRIG_PREOP", AMDGPUTrigPreOp>;
244 def AMDGPUregister_load : SDNode<"AMDGPUISD::REGISTER_LOAD",
245 SDTypeProfile<1, 2, [SDTCisPtrTy<1>, SDTCisInt<2>]>,
246 [SDNPHasChain, SDNPMayLoad]>;
248 def AMDGPUregister_store : SDNode<"AMDGPUISD::REGISTER_STORE",
249 SDTypeProfile<0, 3, [SDTCisPtrTy<1>, SDTCisInt<2>]>,
250 [SDNPHasChain, SDNPMayStore]>;
252 // MSKOR instructions are atomic memory instructions used mainly for storing
253 // 8-bit and 16-bit values. The definition is:
255 // MSKOR(dst, mask, src) MEM[dst] = ((MEM[dst] & ~mask) | src)
257 // src0: vec4(src, 0, 0, mask)
258 // src1: dst - rat offset (aka pointer) in dwords
259 def AMDGPUstore_mskor : SDNode<"AMDGPUISD::STORE_MSKOR",
260 SDTypeProfile<0, 2, []>,
261 [SDNPHasChain, SDNPMayStore, SDNPMemOperand]>;
263 def AMDGPUatomic_cmp_swap : SDNode<"AMDGPUISD::ATOMIC_CMP_SWAP",
264 SDTypeProfile<1, 2, [SDTCisPtrTy<1>, SDTCisVec<2>]>,
265 [SDNPHasChain, SDNPMayStore, SDNPMayLoad,
268 def AMDGPUround : SDNode<"ISD::FROUND",
269 SDTypeProfile<1, 1, [SDTCisFP<0>, SDTCisSameAs<0,1>]>>;
271 def AMDGPUbfe_u32 : SDNode<"AMDGPUISD::BFE_U32", AMDGPUDTIntTernaryOp>;
272 def AMDGPUbfe_i32 : SDNode<"AMDGPUISD::BFE_I32", AMDGPUDTIntTernaryOp>;
273 def AMDGPUbfi : SDNode<"AMDGPUISD::BFI", AMDGPUDTIntTernaryOp>;
274 def AMDGPUbfm : SDNode<"AMDGPUISD::BFM", SDTIntBinOp>;
276 def AMDGPUffbh_u32 : SDNode<"AMDGPUISD::FFBH_U32", SDTIntUnaryOp>;
277 def AMDGPUffbh_i32 : SDNode<"AMDGPUISD::FFBH_I32", SDTIntUnaryOp>;
279 // Signed and unsigned 24-bit multiply. The highest 8-bits are ignore
280 // when performing the mulitply. The result is a 32-bit value.
281 def AMDGPUmul_u24 : SDNode<"AMDGPUISD::MUL_U24", SDTIntBinOp,
282 [SDNPCommutative, SDNPAssociative]
284 def AMDGPUmul_i24 : SDNode<"AMDGPUISD::MUL_I24", SDTIntBinOp,
285 [SDNPCommutative, SDNPAssociative]
288 def AMDGPUmulhi_u24 : SDNode<"AMDGPUISD::MULHI_U24", SDTIntBinOp,
289 [SDNPCommutative, SDNPAssociative]
291 def AMDGPUmulhi_i24 : SDNode<"AMDGPUISD::MULHI_I24", SDTIntBinOp,
292 [SDNPCommutative, SDNPAssociative]
295 def AMDGPUmad_u24 : SDNode<"AMDGPUISD::MAD_U24", AMDGPUDTIntTernaryOp,
298 def AMDGPUmad_i24 : SDNode<"AMDGPUISD::MAD_I24", AMDGPUDTIntTernaryOp,
302 def AMDGPUsmed3 : SDNode<"AMDGPUISD::SMED3", AMDGPUDTIntTernaryOp,
306 def AMDGPUumed3 : SDNode<"AMDGPUISD::UMED3", AMDGPUDTIntTernaryOp,
310 def AMDGPUfmed3 : SDNode<"AMDGPUISD::FMED3", SDTFPTernaryOp, []>;
312 def AMDGPUinit_exec : SDNode<"AMDGPUISD::INIT_EXEC",
313 SDTypeProfile<0, 1, [SDTCisInt<0>]>,
314 [SDNPHasChain, SDNPInGlue]>;
316 def AMDGPUinit_exec_from_input : SDNode<"AMDGPUISD::INIT_EXEC_FROM_INPUT",
318 [SDTCisInt<0>, SDTCisInt<1>]>,
319 [SDNPHasChain, SDNPInGlue]>;
321 def AMDGPUsendmsg : SDNode<"AMDGPUISD::SENDMSG",
322 SDTypeProfile<0, 1, [SDTCisInt<0>]>,
323 [SDNPHasChain, SDNPInGlue]>;
325 def AMDGPUsendmsghalt : SDNode<"AMDGPUISD::SENDMSGHALT",
326 SDTypeProfile<0, 1, [SDTCisInt<0>]>,
327 [SDNPHasChain, SDNPInGlue]>;
329 def AMDGPUinterp_mov : SDNode<"AMDGPUISD::INTERP_MOV",
330 SDTypeProfile<1, 3, [SDTCisFP<0>]>,
333 def AMDGPUinterp_p1 : SDNode<"AMDGPUISD::INTERP_P1",
334 SDTypeProfile<1, 3, [SDTCisFP<0>]>,
335 [SDNPInGlue, SDNPOutGlue]>;
337 def AMDGPUinterp_p2 : SDNode<"AMDGPUISD::INTERP_P2",
338 SDTypeProfile<1, 4, [SDTCisFP<0>]>,
342 def AMDGPUkill : SDNode<"AMDGPUISD::KILL", AMDGPUKillSDT,
343 [SDNPHasChain, SDNPSideEffect]>;
346 def AMDGPUExportOp : SDTypeProfile<0, 8, [
347 SDTCisInt<0>, // i8 tgt
348 SDTCisInt<1>, // i8 en
350 SDTCisSameAs<3, 2>, // f32 src1
351 SDTCisSameAs<4, 2>, // f32 src2
352 SDTCisSameAs<5, 2>, // f32 src3
353 SDTCisInt<6>, // i1 compr
355 SDTCisInt<1> // i1 vm
359 def AMDGPUexport: SDNode<"AMDGPUISD::EXPORT", AMDGPUExportOp,
360 [SDNPHasChain, SDNPMayStore]>;
362 def AMDGPUexport_done: SDNode<"AMDGPUISD::EXPORT_DONE", AMDGPUExportOp,
363 [SDNPHasChain, SDNPMayLoad, SDNPMayStore]>;
366 def R600ExportOp : SDTypeProfile<0, 7, [SDTCisFP<0>, SDTCisInt<1>]>;
368 def R600_EXPORT: SDNode<"AMDGPUISD::R600_EXPORT", R600ExportOp,
369 [SDNPHasChain, SDNPSideEffect]>;
371 //===----------------------------------------------------------------------===//
372 // Flow Control Profile Types
373 //===----------------------------------------------------------------------===//
374 // Branch instruction where second and third are basic blocks
375 def SDTIL_BRCond : SDTypeProfile<0, 2, [
379 //===----------------------------------------------------------------------===//
380 // Flow Control DAG Nodes
381 //===----------------------------------------------------------------------===//
382 def IL_brcond : SDNode<"AMDGPUISD::BRANCH_COND", SDTIL_BRCond, [SDNPHasChain]>;
384 //===----------------------------------------------------------------------===//
385 // Call/Return DAG Nodes
386 //===----------------------------------------------------------------------===//
387 def AMDGPUendpgm : SDNode<"AMDGPUISD::ENDPGM", SDTNone,
388 [SDNPHasChain, SDNPOptInGlue]>;
390 def AMDGPUreturn_to_epilog : SDNode<"AMDGPUISD::RETURN_TO_EPILOG", SDTNone,
391 [SDNPHasChain, SDNPOptInGlue, SDNPVariadic]>;
393 def AMDGPUret_flag : SDNode<"AMDGPUISD::RET_FLAG", SDTypeProfile<0, 1, [SDTCisPtrTy<0>]>,
394 [SDNPHasChain, SDNPOptInGlue, SDNPVariadic]