LLVM 23.0.0git
NVPTXISelLowering.cpp
Go to the documentation of this file.
1//===-- NVPTXISelLowering.cpp - NVPTX DAG Lowering Implementation ---------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file defines the interfaces that NVPTX uses to lower LLVM code into a
10// selection DAG.
11//
12//===----------------------------------------------------------------------===//
13
14#include "NVPTXISelLowering.h"
16#include "NVPTX.h"
17#include "NVPTXISelDAGToDAG.h"
19#include "NVPTXSubtarget.h"
20#include "NVPTXTargetMachine.h"
22#include "NVPTXUtilities.h"
23#include "llvm/ADT/APFloat.h"
24#include "llvm/ADT/APInt.h"
25#include "llvm/ADT/STLExtras.h"
27#include "llvm/ADT/StringRef.h"
40#include "llvm/IR/Argument.h"
41#include "llvm/IR/Attributes.h"
42#include "llvm/IR/Constants.h"
43#include "llvm/IR/DataLayout.h"
46#include "llvm/IR/FPEnv.h"
47#include "llvm/IR/Function.h"
48#include "llvm/IR/GlobalValue.h"
49#include "llvm/IR/IRBuilder.h"
50#include "llvm/IR/Instruction.h"
52#include "llvm/IR/IntrinsicsNVPTX.h"
53#include "llvm/IR/Module.h"
54#include "llvm/IR/Type.h"
55#include "llvm/IR/Value.h"
67#include <algorithm>
68#include <cassert>
69#include <cmath>
70#include <cstdint>
71#include <iterator>
72#include <optional>
73#include <string>
74#include <tuple>
75#include <utility>
76#include <vector>
77
78#define DEBUG_TYPE "nvptx-lower"
79
80using namespace llvm;
81
83 "nvptx-sched4reg",
84 cl::desc("NVPTX Specific: schedule for register pressue"), cl::init(false));
85
87 "nvptx-fma-level", cl::Hidden,
88 cl::desc("NVPTX Specific: FMA contraction (0: don't do it"
89 " 1: do it 2: do it aggressively"),
90 cl::init(2));
91
93 "nvptx-prec-divf32", cl::Hidden,
95 "NVPTX Specific: Override the precision of the lowering for f32 fdiv"),
97 clEnumValN(NVPTX::DivPrecisionLevel::Approx, "0", "Use div.approx"),
98 clEnumValN(NVPTX::DivPrecisionLevel::Full, "1", "Use div.full"),
100 "Use IEEE Compliant F32 div.rnd if available (default)"),
102 "Use IEEE Compliant F32 div.rnd if available, no FTZ")),
104
106 "nvptx-prec-sqrtf32", cl::Hidden,
107 cl::desc("NVPTX Specific: 0 use sqrt.approx, 1 use sqrt.rn."),
108 cl::init(true));
109
110/// Whereas CUDA's implementation (see libdevice) uses ex2.approx for exp2(), it
111/// does NOT use lg2.approx for log2, so this is disabled by default.
113 "nvptx-approx-log2f32",
114 cl::desc("NVPTX Specific: whether to use lg2.approx for log2"),
115 cl::init(false));
116
118 "nvptx-force-min-byval-param-align", cl::Hidden,
119 cl::desc("NVPTX Specific: force 4-byte minimal alignment for byval"
120 " params of device functions."),
121 cl::init(false));
122
125 const SDNode &N) const {
126 // If nvptx-prec-div32=N is used on the command-line, always honor it
127 if (UsePrecDivF32.getNumOccurrences() > 0)
128 return UsePrecDivF32;
129
130 const SDNodeFlags Flags = N.getFlags();
131 if (Flags.hasApproximateFuncs())
133
135}
136
138 // If nvptx-prec-sqrtf32 is used on the command-line, always honor it
139 if (UsePrecSqrtF32.getNumOccurrences() > 0)
140 return UsePrecSqrtF32;
141
142 if (N) {
143 const SDNodeFlags Flags = N->getFlags();
144 if (Flags.hasApproximateFuncs())
145 return false;
146 }
147
148 return true;
149}
150
155
156static bool IsPTXVectorType(MVT VT) {
157 switch (VT.SimpleTy) {
158 default:
159 return false;
160 case MVT::v2i1:
161 case MVT::v4i1:
162 case MVT::v2i8:
163 case MVT::v4i8:
164 case MVT::v8i8: // <2 x i8x4>
165 case MVT::v16i8: // <4 x i8x4>
166 case MVT::v2i16:
167 case MVT::v4i16:
168 case MVT::v8i16: // <4 x i16x2>
169 case MVT::v2i32:
170 case MVT::v4i32:
171 case MVT::v2i64:
172 case MVT::v2f16:
173 case MVT::v4f16:
174 case MVT::v8f16: // <4 x f16x2>
175 case MVT::v2bf16:
176 case MVT::v4bf16:
177 case MVT::v8bf16: // <4 x bf16x2>
178 case MVT::v2f32:
179 case MVT::v4f32:
180 case MVT::v2f64:
181 case MVT::v4i64:
182 case MVT::v4f64:
183 case MVT::v8i32:
184 case MVT::v8f32:
185 case MVT::v16f16: // <8 x f16x2>
186 case MVT::v16bf16: // <8 x bf16x2>
187 case MVT::v16i16: // <8 x i16x2>
188 case MVT::v32i8: // <8 x i8x4>
189 return true;
190 }
191}
192
193// When legalizing vector loads/stores, this function is called, which does two
194// things:
195// 1. Determines Whether the vector is something we want to custom lower,
196// std::nullopt is returned if we do not want to custom lower it.
197// 2. If we do want to handle it, returns two parameters:
198// - unsigned int NumElts - The number of elements in the final vector
199// - EVT EltVT - The type of the elements in the final vector
200static std::optional<std::pair<unsigned int, MVT>>
202 unsigned AddressSpace) {
203 const bool CanLowerTo256Bit = STI.has256BitVectorLoadStore(AddressSpace);
204
205 if (CanLowerTo256Bit && VectorEVT.isScalarInteger() &&
206 VectorEVT.getSizeInBits() == 256)
207 return {{4, MVT::i64}};
208
209 if (!VectorEVT.isSimple())
210 return std::nullopt;
211 const MVT VectorVT = VectorEVT.getSimpleVT();
212
213 if (!VectorVT.isVector()) {
214 if (VectorVT == MVT::i128 || VectorVT == MVT::f128)
215 return {{2, MVT::i64}};
216 return std::nullopt;
217 }
218
219 const MVT EltVT = VectorVT.getVectorElementType();
220 const unsigned NumElts = VectorVT.getVectorNumElements();
221
222 // The size of the PTX virtual register that holds a packed type.
223 unsigned PackRegSize;
224
225 // We only handle "native" vector sizes for now, e.g. <4 x double> is not
226 // legal. We can (and should) split that into 2 stores of <2 x double> here
227 // but I'm leaving that as a TODO for now.
228 switch (VectorVT.SimpleTy) {
229 default:
230 return std::nullopt;
231
232 case MVT::v4i64:
233 case MVT::v4f64:
234 // This is a "native" vector type iff the address space is global and the
235 // target supports 256-bit loads/stores
236 if (!CanLowerTo256Bit)
237 return std::nullopt;
238 [[fallthrough]];
239 case MVT::v2i8:
240 case MVT::v2i64:
241 case MVT::v2f64:
242 // This is a "native" vector type
243 return std::pair(NumElts, EltVT);
244
245 case MVT::v16f16: // <8 x f16x2>
246 case MVT::v16bf16: // <8 x bf16x2>
247 case MVT::v16i16: // <8 x i16x2>
248 case MVT::v32i8: // <8 x i8x4>
249 // This can be upsized into a "native" vector type iff the address space is
250 // global and the target supports 256-bit loads/stores.
251 if (!CanLowerTo256Bit)
252 return std::nullopt;
253 [[fallthrough]];
254 case MVT::v2i16: // <1 x i16x2>
255 case MVT::v2f16: // <1 x f16x2>
256 case MVT::v2bf16: // <1 x bf16x2>
257 case MVT::v4i8: // <1 x i8x4>
258 case MVT::v4i16: // <2 x i16x2>
259 case MVT::v4f16: // <2 x f16x2>
260 case MVT::v4bf16: // <2 x bf16x2>
261 case MVT::v8i8: // <2 x i8x4>
262 case MVT::v8f16: // <4 x f16x2>
263 case MVT::v8bf16: // <4 x bf16x2>
264 case MVT::v8i16: // <4 x i16x2>
265 case MVT::v16i8: // <4 x i8x4>
266 PackRegSize = 32;
267 break;
268
269 case MVT::v8f32: // <4 x f32x2>
270 case MVT::v8i32: // <4 x i32x2>
271 // This is a "native" vector type iff the address space is global and the
272 // target supports 256-bit loads/stores
273 if (!CanLowerTo256Bit)
274 return std::nullopt;
275 [[fallthrough]];
276 case MVT::v2f32: // <1 x f32x2>
277 case MVT::v4f32: // <2 x f32x2>
278 case MVT::v2i32: // <1 x i32x2>
279 case MVT::v4i32: // <2 x i32x2>
280 if (!STI.hasF32x2Instructions())
281 return std::pair(NumElts, EltVT);
282 PackRegSize = 64;
283 break;
284 }
285
286 // If we reach here, then we can pack 2 or more elements into a single 32-bit
287 // or 64-bit PTX register and treat the vector as a new vector containing
288 // packed elements.
289
290 // Number of elements to pack in one word.
291 const unsigned NPerReg = PackRegSize / EltVT.getSizeInBits();
292
293 return std::pair(NumElts / NPerReg, MVT::getVectorVT(EltVT, NPerReg));
294}
295
296/// ComputePTXValueVTs - For the given Type \p Ty, returns the set of primitive
297/// legal-ish MVTs that compose it. Unlike ComputeValueVTs, this will legalize
298/// the types as required by the calling convention (with special handling for
299/// i8s).
300/// NOTE: This is a band-aid for code that expects ComputeValueVTs to return the
301/// same number of types as the Ins/Outs arrays in LowerFormalArguments,
302/// LowerCall, and LowerReturn.
303static void ComputePTXValueVTs(const TargetLowering &TLI, const DataLayout &DL,
304 LLVMContext &Ctx, CallingConv::ID CallConv,
305 Type *Ty, SmallVectorImpl<EVT> &ValueVTs,
307 uint64_t StartingOffset = 0) {
308 SmallVector<EVT, 16> TempVTs;
309 SmallVector<uint64_t, 16> TempOffsets;
310 ComputeValueVTs(TLI, DL, Ty, TempVTs, /*MemVTs=*/nullptr, &TempOffsets,
311 StartingOffset);
312
313 for (const auto [VT, Off] : zip(TempVTs, TempOffsets)) {
314 MVT RegisterVT = TLI.getRegisterTypeForCallingConv(Ctx, CallConv, VT);
315 unsigned NumRegs = TLI.getNumRegistersForCallingConv(Ctx, CallConv, VT);
316
317 // Since we actually can load/store b8, we need to ensure that we'll use
318 // the original sized type for any i8s or i8 vectors.
319 if (VT.getScalarType() == MVT::i8) {
320 if (RegisterVT == MVT::i16)
321 RegisterVT = MVT::i8;
322 else if (RegisterVT == MVT::v2i16)
323 RegisterVT = MVT::v2i8;
324 else
325 assert(RegisterVT == MVT::v4i8 &&
326 "Expected v4i8, v2i16, or i16 for i8 RegisterVT");
327 }
328
329 // TODO: This is horribly incorrect for cases where the vector elements are
330 // not a multiple of bytes (ex i1) and legal or i8. However, this problem
331 // has existed for as long as NVPTX has and no one has complained, so we'll
332 // leave it for now.
333 for (unsigned I : seq(NumRegs)) {
334 ValueVTs.push_back(RegisterVT);
335 Offsets.push_back(Off + I * RegisterVT.getStoreSize());
336 }
337 }
338}
339
340// We return an EVT that can hold N VTs
341// If the VT is a vector, the resulting EVT is a flat vector with the same
342// element type as VT's element type.
343static EVT getVectorizedVT(EVT VT, unsigned N, LLVMContext &C) {
344 if (N == 1)
345 return VT;
346
347 return VT.isVector() ? EVT::getVectorVT(C, VT.getScalarType(),
348 VT.getVectorNumElements() * N)
349 : EVT::getVectorVT(C, VT, N);
350}
351
353 const SDLoc &dl, SelectionDAG &DAG) {
354 if (V.getValueType() == VT) {
355 assert(I == 0 && "Index must be 0 for scalar value");
356 return V;
357 }
358
359 if (!VT.isVector())
360 return DAG.getNode(ISD::EXTRACT_VECTOR_ELT, dl, VT, V,
361 DAG.getVectorIdxConstant(I, dl));
362
363 return DAG.getNode(
364 ISD::EXTRACT_SUBVECTOR, dl, VT, V,
366}
367
368template <typename T>
369static inline SDValue getBuildVectorizedValue(unsigned N, const SDLoc &dl,
370 SelectionDAG &DAG, T GetElement) {
371 if (N == 1)
372 return GetElement(0);
373
375 for (const unsigned I : llvm::seq(N)) {
376 SDValue Val = GetElement(I);
377 if (Val.getValueType().isVector())
378 DAG.ExtractVectorElements(Val, Values);
379 else
380 Values.push_back(Val);
381 }
382
383 EVT VT = EVT::getVectorVT(*DAG.getContext(), Values[0].getValueType(),
384 Values.size());
385 return DAG.getBuildVector(VT, dl, Values);
386}
387
388/// PromoteScalarIntegerPTX
389/// Used to make sure the arguments/returns are suitable for passing
390/// and promote them to a larger size if they're not.
391///
392/// The promoted type is placed in \p PromoteVT if the function returns true.
394 if (VT.isScalarInteger()) {
395 switch (PowerOf2Ceil(VT.getFixedSizeInBits())) {
396 default:
398 "Promotion is not suitable for scalars of size larger than 64-bits");
399 case 1:
400 return MVT::i1;
401 case 2:
402 case 4:
403 case 8:
404 return MVT::i8;
405 case 16:
406 return MVT::i16;
407 case 32:
408 return MVT::i32;
409 case 64:
410 return MVT::i64;
411 }
412 }
413 return VT;
414}
415
416// Check whether we can merge loads/stores of some of the pieces of a
417// flattened function parameter or return value into a single vector
418// load/store.
419//
420// The flattened parameter is represented as a list of EVTs and
421// offsets, and the whole structure is aligned to ParamAlignment. This
422// function determines whether we can load/store pieces of the
423// parameter starting at index Idx using a single vectorized op of
424// size AccessSize. If so, it returns the number of param pieces
425// covered by the vector op. Otherwise, it returns 1.
426template <typename T>
428 unsigned Idx, uint32_t AccessSize, const SmallVectorImpl<EVT> &ValueVTs,
429 const SmallVectorImpl<T> &Offsets, Align ParamAlignment) {
430
431 // Can't vectorize if param alignment is not sufficient.
432 if (ParamAlignment < AccessSize)
433 return 1;
434 // Can't vectorize if offset is not aligned.
435 if (Offsets[Idx] & (AccessSize - 1))
436 return 1;
437
438 EVT EltVT = ValueVTs[Idx];
439 unsigned EltSize = EltVT.getStoreSize();
440
441 // Element is too large to vectorize.
442 if (EltSize >= AccessSize)
443 return 1;
444
445 unsigned NumElts = AccessSize / EltSize;
446 // Can't vectorize if AccessBytes if not a multiple of EltSize.
447 if (AccessSize != EltSize * NumElts)
448 return 1;
449
450 // We don't have enough elements to vectorize.
451 if (Idx + NumElts > ValueVTs.size())
452 return 1;
453
454 // PTX ISA can only deal with 2- and 4-element vector ops.
455 if (NumElts != 4 && NumElts != 2)
456 return 1;
457
458 for (unsigned j = Idx + 1; j < Idx + NumElts; ++j) {
459 // Types do not match.
460 if (ValueVTs[j] != EltVT)
461 return 1;
462
463 // Elements are not contiguous.
464 if (Offsets[j] - Offsets[j - 1] != EltSize)
465 return 1;
466 }
467 // OK. We can vectorize ValueVTs[i..i+NumElts)
468 return NumElts;
469}
470
471// Computes whether and how we can vectorize the loads/stores of a
472// flattened function parameter or return value.
473//
474// The flattened parameter is represented as the list of ValueVTs and
475// Offsets, and is aligned to ParamAlignment bytes. We return a vector
476// of the same size as ValueVTs indicating how each piece should be
477// loaded/stored (i.e. as a scalar, or as part of a vector
478// load/store).
479template <typename T>
482 const SmallVectorImpl<T> &Offsets, Align ParamAlignment,
483 bool IsVAArg = false) {
484 // Set vector size to match ValueVTs and mark all elements as
485 // scalars by default.
486
487 if (IsVAArg)
488 return SmallVector<unsigned>(ValueVTs.size(), 1);
489
490 SmallVector<unsigned, 16> VectorInfo;
491
492 const auto GetNumElts = [&](unsigned I) -> unsigned {
493 for (const unsigned AccessSize : {16, 8, 4, 2}) {
494 const unsigned NumElts = canMergeParamLoadStoresStartingAt(
495 I, AccessSize, ValueVTs, Offsets, ParamAlignment);
496 assert((NumElts == 1 || NumElts == 2 || NumElts == 4) &&
497 "Unexpected vectorization size");
498 if (NumElts != 1)
499 return NumElts;
500 }
501 return 1;
502 };
503
504 // Check what we can vectorize using 128/64/32-bit accesses.
505 for (unsigned I = 0, E = ValueVTs.size(); I != E;) {
506 const unsigned NumElts = GetNumElts(I);
507 VectorInfo.push_back(NumElts);
508 I += NumElts;
509 }
510 assert(std::accumulate(VectorInfo.begin(), VectorInfo.end(), 0u) ==
511 ValueVTs.size());
512 return VectorInfo;
513}
514
515// NVPTXTargetLowering Constructor.
517 const NVPTXSubtarget &STI)
518 : TargetLowering(TM, STI), nvTM(&TM), STI(STI), GlobalUniqueCallSite(0) {
519 // always lower memset, memcpy, and memmove intrinsics to load/store
520 // instructions, rather
521 // then generating calls to memset, mempcy or memmove.
525
528
529 // Jump is Expensive. Don't create extra control flow for 'and', 'or'
530 // condition branches.
531 setJumpIsExpensive(true);
532
533 // Wide divides are _very_ slow. Try to reduce the width of the divide if
534 // possible.
535 addBypassSlowDiv(64, 32);
536
537 // By default, use the Source scheduling
538 if (sched4reg)
540 else
542
543 auto setFP16OperationAction = [&](unsigned Op, MVT VT, LegalizeAction Action,
544 LegalizeAction NoF16Action) {
545 bool IsOpSupported = STI.allowFP16Math();
546 switch (Op) {
547 // Several FP16 instructions are available on sm_80 only.
548 case ISD::FMINNUM:
549 case ISD::FMAXNUM:
552 case ISD::FMAXIMUM:
553 case ISD::FMINIMUM:
554 case ISD::FMAXIMUMNUM:
555 case ISD::FMINIMUMNUM:
556 IsOpSupported &= STI.getSmVersion() >= 80 && STI.getPTXVersion() >= 70;
557 break;
558 case ISD::FEXP2:
559 IsOpSupported &= STI.getSmVersion() >= 75 && STI.getPTXVersion() >= 70;
560 break;
561 }
562 setOperationAction(Op, VT, IsOpSupported ? Action : NoF16Action);
563 };
564
565 auto setBF16OperationAction = [&](unsigned Op, MVT VT, LegalizeAction Action,
566 LegalizeAction NoBF16Action) {
567 bool IsOpSupported = STI.hasNativeBF16Support(Op);
569 Op, VT, IsOpSupported ? Action : NoBF16Action);
570 };
571
572 auto setI16x2OperationAction = [&](unsigned Op, MVT VT, LegalizeAction Action,
573 LegalizeAction NoI16x2Action) {
574 bool IsOpSupported = false;
575 // instructions are available on sm_90 only
576 switch (Op) {
577 case ISD::ADD:
578 case ISD::SMAX:
579 case ISD::SMIN:
580 case ISD::UMIN:
581 case ISD::UMAX:
582 IsOpSupported = STI.getSmVersion() >= 90 && STI.getPTXVersion() >= 80;
583 break;
584 }
585 setOperationAction(Op, VT, IsOpSupported ? Action : NoI16x2Action);
586 };
587
588 addRegisterClass(MVT::i1, &NVPTX::B1RegClass);
589 addRegisterClass(MVT::i16, &NVPTX::B16RegClass);
590 addRegisterClass(MVT::v2i16, &NVPTX::B32RegClass);
591 addRegisterClass(MVT::v4i8, &NVPTX::B32RegClass);
592 addRegisterClass(MVT::i32, &NVPTX::B32RegClass);
593 addRegisterClass(MVT::i64, &NVPTX::B64RegClass);
594 addRegisterClass(MVT::f32, &NVPTX::B32RegClass);
595 addRegisterClass(MVT::f64, &NVPTX::B64RegClass);
596 addRegisterClass(MVT::f16, &NVPTX::B16RegClass);
597 addRegisterClass(MVT::v2f16, &NVPTX::B32RegClass);
598 addRegisterClass(MVT::bf16, &NVPTX::B16RegClass);
599 addRegisterClass(MVT::v2bf16, &NVPTX::B32RegClass);
600
601 if (STI.hasF32x2Instructions()) {
602 addRegisterClass(MVT::v2f32, &NVPTX::B64RegClass);
603 addRegisterClass(MVT::v2i32, &NVPTX::B64RegClass);
604 }
605
606 // Conversion to/from FP16/FP16x2 is always legal.
611
613 if (STI.getSmVersion() >= 30 && STI.getPTXVersion() > 31)
615
616 setFP16OperationAction(ISD::SETCC, MVT::f16, Legal, Promote);
617 setFP16OperationAction(ISD::SETCC, MVT::v2f16, Legal, Expand);
618
619 // Conversion to/from BFP16/BFP16x2 is always legal.
624
625 setBF16OperationAction(ISD::SETCC, MVT::v2bf16, Legal, Expand);
626 setBF16OperationAction(ISD::SETCC, MVT::bf16, Legal, Promote);
627 if (getOperationAction(ISD::SETCC, MVT::bf16) == Promote)
628 AddPromotedToType(ISD::SETCC, MVT::bf16, MVT::f32);
629
630 // Conversion to/from i16/i16x2 is always legal.
635
640
641 // No support for these operations with v2f32/v2i32
642 setOperationAction(ISD::INSERT_VECTOR_ELT, {MVT::v2f32, MVT::v2i32}, Expand);
643 setOperationAction(ISD::VECTOR_SHUFFLE, {MVT::v2f32, MVT::v2i32}, Expand);
644
647 MVT::v2i32, Expand);
648
649 // Need custom lowering in case the index is dynamic.
650 if (STI.hasF32x2Instructions())
651 setOperationAction(ISD::EXTRACT_VECTOR_ELT, {MVT::v2f32, MVT::v2i32},
652 Custom);
653
654 // Custom conversions to/from v2i8.
656
657 // Only logical ops can be done on v4i8/v2i32 directly, others must be done
658 // elementwise.
675 {MVT::v4i8, MVT::v2i32}, Expand);
676
677 // Operations not directly supported by NVPTX.
678 for (MVT VT : {MVT::bf16, MVT::f16, MVT::v2bf16, MVT::v2f16, MVT::f32,
679 MVT::v2f32, MVT::f64, MVT::i1, MVT::i8, MVT::i16, MVT::v2i16,
680 MVT::v4i8, MVT::i32, MVT::v2i32, MVT::i64}) {
683 }
684
685 // We don't want ops like FMINIMUM or UMAX to be lowered to SETCC+VSELECT.
686 setOperationAction(ISD::VSELECT, {MVT::v2f32, MVT::v2i32}, Expand);
687
688 // Some SIGN_EXTEND_INREG can be done using cvt instruction.
689 // For others we will expand to a SHL/SRA pair.
695 setOperationAction(ISD::SIGN_EXTEND_INREG, {MVT::v2i16, MVT::v2i32}, Expand);
696
703
706
708 {MVT::i8, MVT::i16, MVT::v2i16, MVT::i32, MVT::i64},
709 Expand);
710
711 if (STI.hasHWROT32()) {
714 Custom);
715 }
716
717 setOperationAction(ISD::BR_JT, MVT::Other, STI.hasBrx() ? Legal : Expand);
719
720 // We want to legalize constant related memmove and memcopy
721 // intrinsics.
723
724 // FP extload/truncstore is not legal in PTX. We need to expand all these.
725 for (auto FloatVTs :
727 for (MVT ValVT : FloatVTs) {
728 for (MVT MemVT : FloatVTs) {
729 setLoadExtAction(ISD::EXTLOAD, ValVT, MemVT, Expand);
730 setTruncStoreAction(ValVT, MemVT, Expand);
731 }
732 }
733 }
734
735 // To improve CodeGen we'll legalize any-extend loads to zext loads. This is
736 // how they'll be lowered in ISel anyway, and by doing this a little earlier
737 // we allow for more DAG combine opportunities.
738 for (auto IntVTs :
740 for (MVT ValVT : IntVTs)
741 for (MVT MemVT : IntVTs)
742 if (isTypeLegal(ValVT))
743 setLoadExtAction(ISD::EXTLOAD, ValVT, MemVT, Custom);
744
745 // PTX does not support load / store predicate registers
747 for (MVT VT : MVT::integer_valuetypes()) {
749 Promote);
750 setTruncStoreAction(VT, MVT::i1, Expand);
751 }
752
753 // Disable generations of extload/truncstore for v2i32/v2i16/v2i8. The generic
754 // expansion for these nodes when they are unaligned is incorrect if the
755 // type is a vector.
756 //
757 // TODO: Fix the generic expansion for these nodes found in
758 // TargetLowering::expandUnalignedLoad/Store.
760 MVT::v2i8, Expand);
762 {MVT::v2i8, MVT::v2i16}, Expand);
763 setTruncStoreAction(MVT::v2i16, MVT::v2i8, Expand);
764 setTruncStoreAction(MVT::v2i32, MVT::v2i16, Expand);
765 setTruncStoreAction(MVT::v2i32, MVT::v2i8, Expand);
766
767 // Register custom handling for illegal type loads/stores. We'll try to custom
768 // lower almost all illegal types and logic in the lowering will discard cases
769 // we can't handle.
770 setOperationAction({ISD::LOAD, ISD::STORE}, {MVT::i128, MVT::i256, MVT::f128},
771 Custom);
773 if (!isTypeLegal(VT) && VT.getStoreSizeInBits() <= 256)
775 Custom);
776
777 // Custom legalization for LDU intrinsics.
778 // TODO: The logic to lower these is not very robust and we should rewrite it.
779 // Perhaps LDU should not be represented as an intrinsic at all.
782 if (IsPTXVectorType(VT))
784
788 MVT::i1, Expand);
789
790 // This is legal in NVPTX
795
796 setOperationAction(ISD::DYNAMIC_STACKALLOC, {MVT::i32, MVT::i64}, Custom);
798
799 // TRAP can be lowered to PTX trap
800 setOperationAction(ISD::TRAP, MVT::Other, Legal);
801 // DEBUGTRAP can be lowered to PTX brkpt
803
804 // Support varargs.
809
811 {MVT::i16, MVT::i32, MVT::i64}, Legal);
812
814 Promote);
817
818 setI16x2OperationAction(ISD::ABS, MVT::v2i16, Legal, Custom);
819 setI16x2OperationAction(ISD::SMIN, MVT::v2i16, Legal, Custom);
820 setI16x2OperationAction(ISD::SMAX, MVT::v2i16, Legal, Custom);
821 setI16x2OperationAction(ISD::UMIN, MVT::v2i16, Legal, Custom);
822 setI16x2OperationAction(ISD::UMAX, MVT::v2i16, Legal, Custom);
823 setI16x2OperationAction(ISD::CTPOP, MVT::v2i16, Legal, Expand);
824 setI16x2OperationAction(ISD::CTLZ, MVT::v2i16, Legal, Expand);
825
826 setI16x2OperationAction(ISD::ADD, MVT::v2i16, Legal, Custom);
827 setI16x2OperationAction(ISD::SUB, MVT::v2i16, Legal, Custom);
828 setI16x2OperationAction(ISD::MUL, MVT::v2i16, Legal, Custom);
829 setI16x2OperationAction(ISD::SHL, MVT::v2i16, Legal, Custom);
830 setI16x2OperationAction(ISD::SREM, MVT::v2i16, Legal, Custom);
831 setI16x2OperationAction(ISD::UREM, MVT::v2i16, Legal, Custom);
832
833 // Other arithmetic and logic ops are unsupported.
837 {MVT::v2i16, MVT::v2i32}, Expand);
838
839 // v2i32 is not supported for any arithmetic operations
844 MVT::v2i32, Expand);
845
850 if (STI.getPTXVersion() >= 43) {
855 }
856
858 setOperationAction(ISD::CTTZ, {MVT::v2i16, MVT::v2i32}, Expand);
861
862 // PTX does not directly support SELP of i1, so promote to i32 first
864
865 // PTX cannot multiply two i64s in a single instruction.
868
869 // We have some custom DAG combine patterns for these nodes
871 ISD::AND,
873 ISD::FADD,
880 ISD::MUL,
882 ISD::SHL,
883 ISD::SREM,
884 ISD::UREM,
888 ISD::LOAD,
893
894 // If the vector operands require register coalescing, scalarize instead
895 if (STI.hasF32x2Instructions())
897
898 // setcc for f16x2 and bf16x2 needs special handling to prevent
899 // legalizer's attempt to scalarize it due to v2i1 not being legal.
900 if (STI.allowFP16Math() || STI.hasBF16Math())
902
903 // Vector reduction operations. These may be turned into shuffle or tree
904 // reductions depending on what instructions are available for each type.
906 MVT EltVT = VT.getVectorElementType();
907 if (EltVT == MVT::f32 || EltVT == MVT::f64) {
910 VT, Custom);
911 }
912 }
913
914 // Promote fp16 arithmetic if fp16 hardware isn't available or the
915 // user passed --nvptx-no-fp16-math. The flag is useful because,
916 // although sm_53+ GPUs have some sort of FP16 support in
917 // hardware, only sm_53 and sm_60 have full implementation. Others
918 // only have token amount of hardware and are likely to run faster
919 // by using fp32 units instead.
920 for (const auto &Op : {ISD::FADD, ISD::FMUL, ISD::FSUB, ISD::FMA}) {
921 setFP16OperationAction(Op, MVT::f16, Legal, Promote);
922 setFP16OperationAction(Op, MVT::v2f16, Legal, Expand);
923 setBF16OperationAction(Op, MVT::v2bf16, Legal, Expand);
924 // bf16 must be promoted to f32.
925 setBF16OperationAction(Op, MVT::bf16, Legal, Promote);
926 if (getOperationAction(Op, MVT::bf16) == Promote)
927 AddPromotedToType(Op, MVT::bf16, MVT::f32);
928 setOperationAction(Op, MVT::v2f32,
929 STI.hasF32x2Instructions() ? Legal : Expand);
930 }
931
932 // On SM80, we select add/mul/sub as fma to avoid promotion to float
933 for (const auto &Op : {ISD::FADD, ISD::FMUL, ISD::FSUB}) {
934 for (const auto &VT : {MVT::bf16, MVT::v2bf16}) {
935 if (!STI.hasNativeBF16Support(Op) && STI.hasNativeBF16Support(ISD::FMA)) {
937 }
938 }
939 }
940
941 // f16/f16x2 neg was introduced in PTX 60, SM_53.
942 const bool IsFP16FP16x2NegAvailable = STI.getSmVersion() >= 53 &&
943 STI.getPTXVersion() >= 60 &&
944 STI.allowFP16Math();
945 for (const auto &VT : {MVT::f16, MVT::v2f16})
947 IsFP16FP16x2NegAvailable ? Legal : Expand);
948
949 setBF16OperationAction(ISD::FNEG, MVT::bf16, Legal, Expand);
950 setBF16OperationAction(ISD::FNEG, MVT::v2bf16, Legal, Expand);
951 setOperationAction(ISD::FNEG, MVT::v2f32, Expand);
952 // (would be) Library functions.
953
954 // These map to conversion instructions for scalar FP types.
955 for (const auto &Op : {ISD::FCEIL, ISD::FFLOOR, ISD::FNEARBYINT, ISD::FRINT,
957 setOperationAction(Op, MVT::f16, Legal);
958 setOperationAction(Op, MVT::f32, Legal);
959 setOperationAction(Op, MVT::f64, Legal);
960 setOperationAction(Op, MVT::v2f16, Expand);
961 setOperationAction(Op, MVT::v2bf16, Expand);
962 setOperationAction(Op, MVT::v2f32, Expand);
963 setBF16OperationAction(Op, MVT::bf16, Legal, Promote);
964 if (getOperationAction(Op, MVT::bf16) == Promote)
965 AddPromotedToType(Op, MVT::bf16, MVT::f32);
966 }
967
968 if (STI.getSmVersion() < 80 || STI.getPTXVersion() < 71) {
970 }
971 if (STI.getSmVersion() < 90 || STI.getPTXVersion() < 78) {
972 for (MVT VT : {MVT::bf16, MVT::f32, MVT::f64}) {
975 }
976 }
977
978 // Expand v2f32 = fp_extend
980 // Expand v2[b]f16 = fp_round v2f32
981 setOperationAction(ISD::FP_ROUND, {MVT::v2bf16, MVT::v2f16}, Expand);
982
983 // sm_80 only has conversions between f32 and bf16. Custom lower all other
984 // bf16 conversions.
985 if (STI.getSmVersion() < 90 || STI.getPTXVersion() < 78) {
986 for (MVT VT : {MVT::i1, MVT::i16, MVT::i32, MVT::i64}) {
989 VT, Custom);
990 }
993 MVT::bf16, Custom);
994 }
995
1002 AddPromotedToType(ISD::FROUND, MVT::bf16, MVT::f32);
1003
1004 // 'Expand' implements FCOPYSIGN without calling an external library.
1011
1012 // These map to corresponding instructions for f32/f64. f16 must be
1013 // promoted to f32. v2f16 is expanded to f16, which is then promoted
1014 // to f32.
1015 for (const auto &Op :
1017 setOperationAction(Op, MVT::f16, Promote);
1018 setOperationAction(Op, MVT::f32, Legal);
1019 // only div/rem/sqrt are legal for f64
1020 if (Op == ISD::FDIV || Op == ISD::FREM || Op == ISD::FSQRT) {
1021 setOperationAction(Op, MVT::f64, Legal);
1022 }
1023 setOperationAction(Op, {MVT::v2f16, MVT::v2bf16, MVT::v2f32}, Expand);
1024 setOperationAction(Op, MVT::bf16, Promote);
1025 AddPromotedToType(Op, MVT::bf16, MVT::f32);
1026 }
1027 setOperationAction(ISD::FREM, {MVT::f32, MVT::f64}, Custom);
1028
1029 setOperationAction(ISD::FABS, {MVT::f32, MVT::f64}, Legal);
1030 setOperationAction(ISD::FABS, MVT::v2f32, Expand);
1031 if (STI.getPTXVersion() >= 65) {
1032 setFP16OperationAction(ISD::FABS, MVT::f16, Legal, Promote);
1033 setFP16OperationAction(ISD::FABS, MVT::v2f16, Legal, Expand);
1034 } else {
1036 setOperationAction(ISD::FABS, MVT::v2f16, Expand);
1037 }
1038 setBF16OperationAction(ISD::FABS, MVT::v2bf16, Legal, Expand);
1039 setBF16OperationAction(ISD::FABS, MVT::bf16, Legal, Promote);
1040 if (getOperationAction(ISD::FABS, MVT::bf16) == Promote)
1041 AddPromotedToType(ISD::FABS, MVT::bf16, MVT::f32);
1042
1043 for (const auto &Op :
1045 setOperationAction(Op, MVT::f32, Legal);
1046 setOperationAction(Op, MVT::f64, Legal);
1047 setFP16OperationAction(Op, MVT::f16, Legal, Promote);
1048 setFP16OperationAction(Op, MVT::v2f16, Legal, Expand);
1049 setBF16OperationAction(Op, MVT::v2bf16, Legal, Expand);
1050 setBF16OperationAction(Op, MVT::bf16, Legal, Promote);
1051 if (getOperationAction(Op, MVT::bf16) == Promote)
1052 AddPromotedToType(Op, MVT::bf16, MVT::f32);
1053 setOperationAction(Op, MVT::v2f32, Expand);
1054 }
1055 bool SupportsF32MinMaxNaN =
1056 STI.getSmVersion() >= 80 && STI.getPTXVersion() >= 70;
1057 for (const auto &Op : {ISD::FMINIMUM, ISD::FMAXIMUM}) {
1058 setOperationAction(Op, MVT::f32, SupportsF32MinMaxNaN ? Legal : Expand);
1059 setFP16OperationAction(Op, MVT::f16, Legal, Expand);
1060 setFP16OperationAction(Op, MVT::v2f16, Legal, Expand);
1061 setBF16OperationAction(Op, MVT::bf16, Legal, Expand);
1062 setBF16OperationAction(Op, MVT::v2bf16, Legal, Expand);
1063 setOperationAction(Op, MVT::v2f32, Expand);
1064 }
1065
1066 // Custom lowering for inline asm with 128-bit operands
1069
1070 // FEXP2 support:
1071 // - f32
1072 // - f16/f16x2 (sm_70+, PTX 7.0+)
1073 // - bf16/bf16x2 (sm_90+, PTX 7.8+)
1074 // When f16/bf16 types aren't supported, they are promoted/expanded to f32.
1076 setOperationAction(ISD::FEXP2, MVT::v2f32, Expand);
1077 setFP16OperationAction(ISD::FEXP2, MVT::f16, Legal, Promote);
1078 setFP16OperationAction(ISD::FEXP2, MVT::v2f16, Legal, Expand);
1079 setBF16OperationAction(ISD::FEXP2, MVT::bf16, Legal, Promote);
1080 setBF16OperationAction(ISD::FEXP2, MVT::v2bf16, Legal, Expand);
1081
1082 // FLOG2 supports f32 only
1083 // f16/bf16 types aren't supported, but they are promoted/expanded to f32.
1084 if (UseApproxLog2F32) {
1086 setOperationPromotedToType(ISD::FLOG2, MVT::f16, MVT::f32);
1087 setOperationPromotedToType(ISD::FLOG2, MVT::bf16, MVT::f32);
1088 setOperationAction(ISD::FLOG2, {MVT::v2f16, MVT::v2bf16, MVT::v2f32},
1089 Expand);
1090 }
1091
1092 setOperationAction(ISD::ADDRSPACECAST, {MVT::i32, MVT::i64}, Custom);
1093
1094 setOperationAction(ISD::ATOMIC_LOAD_SUB, {MVT::i32, MVT::i64}, Expand);
1095
1096 // atom.b128 is legal in PTX but since we don't represent i128 as a legal
1097 // type, we need to custom lower it.
1099 Custom);
1100
1101 // Now deduce the information based on the above mentioned
1102 // actions
1103 computeRegisterProperties(STI.getRegisterInfo());
1104
1105 // PTX support for 16-bit CAS is emulated. Only use 32+
1106 setMinCmpXchgSizeInBits(STI.getMinCmpXchgSizeInBits());
1107 setMaxAtomicSizeInBitsSupported(STI.hasAtomSwap128() ? 128 : 64);
1109
1110 // Custom lowering for tcgen05.ld vector operands
1112 {MVT::v2i32, MVT::v4i32, MVT::v8i32, MVT::v16i32,
1113 MVT::v32i32, MVT::v64i32, MVT::v128i32, MVT::v2f32,
1114 MVT::v4f32, MVT::v8f32, MVT::v16f32, MVT::v32f32,
1115 MVT::v64f32, MVT::v128f32},
1116 Custom);
1117
1118 // Custom lowering for tcgen05.st vector operands
1120 {MVT::v2i32, MVT::v4i32, MVT::v8i32, MVT::v16i32,
1121 MVT::v32i32, MVT::v64i32, MVT::v128i32, MVT::Other},
1122 Custom);
1123
1124 // Enable custom lowering for the following:
1125 // * MVT::i128 - clusterlaunchcontrol
1126 // * MVT::i32 - prmt
1127 // * MVT::v4f32 - cvt_rs fp{4/6/8}x4 intrinsics
1128 // * MVT::Other - internal.addrspace.wrap
1130 {MVT::i32, MVT::i128, MVT::v4f32, MVT::Other}, Custom);
1131
1132 // Custom lowering for bswap
1133 setOperationAction(ISD::BSWAP, {MVT::i16, MVT::i32, MVT::i64, MVT::v2i16},
1134 Custom);
1135}
1136
1139 if (!VT.isScalableVector() && VT.getVectorNumElements() != 1 &&
1140 VT.getScalarType() == MVT::i1)
1141 return TypeSplitVector;
1143}
1144
1146 int Enabled, int &ExtraSteps,
1147 bool &UseOneConst,
1148 bool Reciprocal) const {
1151 return SDValue();
1152
1153 if (ExtraSteps == ReciprocalEstimate::Unspecified)
1154 ExtraSteps = 0;
1155
1156 SDLoc DL(Operand);
1157 EVT VT = Operand.getValueType();
1158 bool Ftz = useF32FTZ(DAG.getMachineFunction());
1159
1160 auto MakeIntrinsicCall = [&](Intrinsic::ID IID) {
1161 return DAG.getNode(ISD::INTRINSIC_WO_CHAIN, DL, VT,
1162 DAG.getConstant(IID, DL, MVT::i32), Operand);
1163 };
1164
1165 // The sqrt and rsqrt refinement processes assume we always start out with an
1166 // approximation of the rsqrt. Therefore, if we're going to do any refinement
1167 // (i.e. ExtraSteps > 0), we must return an rsqrt. But if we're *not* doing
1168 // any refinement, we must return a regular sqrt.
1169 if (Reciprocal || ExtraSteps > 0) {
1170 if (VT == MVT::f32)
1171 return MakeIntrinsicCall(Ftz ? Intrinsic::nvvm_rsqrt_approx_ftz_f
1172 : Intrinsic::nvvm_rsqrt_approx_f);
1173 else if (VT == MVT::f64)
1174 return MakeIntrinsicCall(Intrinsic::nvvm_rsqrt_approx_d);
1175 else
1176 return SDValue();
1177 } else {
1178 if (VT == MVT::f32)
1179 return MakeIntrinsicCall(Ftz ? Intrinsic::nvvm_sqrt_approx_ftz_f
1180 : Intrinsic::nvvm_sqrt_approx_f);
1181 else {
1182 // There's no sqrt.approx.f64 instruction, so we emit
1183 // reciprocal(rsqrt(x)). This is faster than
1184 // select(x == 0, 0, x * rsqrt(x)). (In fact, it's faster than plain
1185 // x * rsqrt(x).)
1186 return DAG.getNode(
1188 DAG.getConstant(Intrinsic::nvvm_rcp_approx_ftz_d, DL, MVT::i32),
1189 MakeIntrinsicCall(Intrinsic::nvvm_rsqrt_approx_d));
1190 }
1191 }
1192}
1193
1195 const DataLayout &DL, Type *RetTy, const ArgListTy &Args,
1197 std::optional<unsigned> FirstVAArg, const CallBase &CB,
1198 unsigned UniqueCallSite) const {
1199 auto PtrVT = getPointerTy(DL);
1200
1201 std::string Prototype;
1202 raw_string_ostream O(Prototype);
1203 O << "prototype_" << UniqueCallSite << " : .callprototype ";
1204
1205 if (RetTy->isVoidTy()) {
1206 O << "()";
1207 } else {
1208 O << "(";
1209 if (shouldPassAsArray(RetTy)) {
1210 const Align RetAlign = getArgumentAlignment(&CB, RetTy, 0, DL);
1211 O << ".param .align " << RetAlign.value() << " .b8 _["
1212 << DL.getTypeAllocSize(RetTy) << "]";
1213 } else if (RetTy->isFloatingPointTy() || RetTy->isIntegerTy()) {
1214 unsigned size = 0;
1215 if (auto *ITy = dyn_cast<IntegerType>(RetTy)) {
1216 size = ITy->getBitWidth();
1217 } else {
1218 assert(RetTy->isFloatingPointTy() &&
1219 "Floating point type expected here");
1220 size = RetTy->getPrimitiveSizeInBits();
1221 }
1222 // PTX ABI requires all scalar return values to be at least 32
1223 // bits in size. fp16 normally uses .b16 as its storage type in
1224 // PTX, so its size must be adjusted here, too.
1226
1227 O << ".param .b" << size << " _";
1228 } else if (isa<PointerType>(RetTy)) {
1229 O << ".param .b" << PtrVT.getSizeInBits() << " _";
1230 } else {
1231 llvm_unreachable("Unknown return type");
1232 }
1233 O << ") ";
1234 }
1235 O << "_ (";
1236
1237 bool first = true;
1238
1239 const unsigned NumArgs = FirstVAArg.value_or(Args.size());
1240 auto AllOuts = ArrayRef(Outs);
1241 for (const unsigned I : llvm::seq(NumArgs)) {
1242 const auto ArgOuts =
1243 AllOuts.take_while([I](auto O) { return O.OrigArgIndex == I; });
1244 AllOuts = AllOuts.drop_front(ArgOuts.size());
1245
1246 Type *Ty = Args[I].Ty;
1247 if (!first) {
1248 O << ", ";
1249 }
1250 first = false;
1251
1252 if (ArgOuts[0].Flags.isByVal()) {
1253 // Indirect calls need strict ABI alignment so we disable optimizations by
1254 // not providing a function to optimize.
1255 Type *ETy = Args[I].IndirectType;
1256 Align InitialAlign = ArgOuts[0].Flags.getNonZeroByValAlign();
1257 Align ParamByValAlign =
1258 getFunctionByValParamAlign(/*F=*/nullptr, ETy, InitialAlign, DL);
1259
1260 O << ".param .align " << ParamByValAlign.value() << " .b8 _["
1261 << ArgOuts[0].Flags.getByValSize() << "]";
1262 } else {
1263 if (shouldPassAsArray(Ty)) {
1264 Align ParamAlign =
1265 getArgumentAlignment(&CB, Ty, I + AttributeList::FirstArgIndex, DL);
1266 O << ".param .align " << ParamAlign.value() << " .b8 _["
1267 << DL.getTypeAllocSize(Ty) << "]";
1268 continue;
1269 }
1270 // i8 types in IR will be i16 types in SDAG
1271 assert((getValueType(DL, Ty) == ArgOuts[0].VT ||
1272 (getValueType(DL, Ty) == MVT::i8 && ArgOuts[0].VT == MVT::i16)) &&
1273 "type mismatch between callee prototype and arguments");
1274 // scalar type
1275 unsigned sz = 0;
1276 if (auto *ITy = dyn_cast<IntegerType>(Ty)) {
1277 sz = promoteScalarArgumentSize(ITy->getBitWidth());
1278 } else if (isa<PointerType>(Ty)) {
1279 sz = PtrVT.getSizeInBits();
1280 } else {
1281 sz = Ty->getPrimitiveSizeInBits();
1282 }
1283 O << ".param .b" << sz << " _";
1284 }
1285 }
1286
1287 if (FirstVAArg)
1288 O << (first ? "" : ",") << " .param .align "
1289 << STI.getMaxRequiredAlignment() << " .b8 _[]";
1290 O << ")";
1291 if (shouldEmitPTXNoReturn(&CB, *nvTM))
1292 O << " .noreturn";
1293 O << ";";
1294
1295 return Prototype;
1296}
1297
1299 const Function *F, Type *Ty, unsigned Idx, const DataLayout &DL) const {
1300 return getAlign(*F, Idx).value_or(getFunctionParamOptimizedAlign(F, Ty, DL));
1301}
1302
1303Align NVPTXTargetLowering::getArgumentAlignment(const CallBase *CB, Type *Ty,
1304 unsigned Idx,
1305 const DataLayout &DL) const {
1306 if (!CB) {
1307 // CallSite is zero, fallback to ABI type alignment
1308 return DL.getABITypeAlign(Ty);
1309 }
1310
1311 const Function *DirectCallee = CB->getCalledFunction();
1312
1313 if (!DirectCallee) {
1314 // We don't have a direct function symbol, but that may be because of
1315 // constant cast instructions in the call.
1316
1317 // With bitcast'd call targets, the instruction will be the call
1318 if (const auto *CI = dyn_cast<CallInst>(CB)) {
1319 // Check if we have call alignment metadata
1320 if (MaybeAlign StackAlign = getAlign(*CI, Idx))
1321 return StackAlign.value();
1322 }
1323 DirectCallee = getMaybeBitcastedCallee(CB);
1324 }
1325
1326 // Check for function alignment information if we found that the
1327 // ultimate target is a Function
1328 if (DirectCallee)
1329 return getFunctionArgumentAlignment(DirectCallee, Ty, Idx, DL);
1330
1331 // Call is indirect, fall back to the ABI type alignment
1332 return DL.getABITypeAlign(Ty);
1333}
1334
1336 const GlobalAddressSDNode *Func) {
1337 if (!Func)
1338 return false;
1339 if (auto *CalleeFunc = dyn_cast<Function>(Func->getGlobal()))
1340 return CB->getFunctionType() != CalleeFunc->getFunctionType();
1341 return false;
1342}
1343
1345 const DataLayout &DL,
1346 const TargetLowering &TL) {
1347 if (Ptr->getOpcode() == ISD::FrameIndex) {
1348 auto Ty = TL.getPointerTy(DL, ADDRESS_SPACE_LOCAL);
1349 Ptr = DAG.getAddrSpaceCast(SDLoc(), Ty, Ptr, ADDRESS_SPACE_GENERIC,
1351
1353 }
1354
1355 // Peel of an addrspacecast to generic and load directly from the specific
1356 // address space.
1357 if (Ptr->getOpcode() == ISD::ADDRSPACECAST) {
1358 const auto *ASC = cast<AddrSpaceCastSDNode>(Ptr);
1359 if (ASC->getDestAddressSpace() == ADDRESS_SPACE_GENERIC) {
1360 Ptr = ASC->getOperand(0);
1361 return MachinePointerInfo(ASC->getSrcAddressSpace());
1362 }
1363 }
1364
1365 return MachinePointerInfo();
1366}
1367
1369 if (Flags.isSExt())
1370 return ISD::SIGN_EXTEND;
1371 if (Flags.isZExt())
1372 return ISD::ZERO_EXTEND;
1373 return ISD::ANY_EXTEND;
1374}
1375
1377 ISD::ArgFlagsTy Flags, SelectionDAG &DAG,
1378 SDLoc dl) {
1379 const EVT ActualVT = V.getValueType();
1380 assert((ActualVT == ExpectedVT ||
1381 (ExpectedVT.isInteger() && ActualVT.isInteger())) &&
1382 "Non-integer argument type size mismatch");
1383 if (ExpectedVT.bitsGT(ActualVT))
1384 return DAG.getNode(getExtOpcode(Flags), dl, ExpectedVT, V);
1385 if (ExpectedVT.bitsLT(ActualVT))
1386 return DAG.getNode(ISD::TRUNCATE, dl, ExpectedVT, V);
1387
1388 return V;
1389}
1390
1392 SmallVectorImpl<SDValue> &InVals) const {
1393
1394 if (CLI.IsVarArg && (STI.getPTXVersion() < 60 || STI.getSmVersion() < 30))
1396 "Support for variadic functions (unsized array parameter) introduced "
1397 "in PTX ISA version 6.0 and requires target sm_30.");
1398
1399 SelectionDAG &DAG = CLI.DAG;
1400 SDLoc dl = CLI.DL;
1401 const SmallVectorImpl<ISD::InputArg> &Ins = CLI.Ins;
1402 SDValue Callee = CLI.Callee;
1403 ArgListTy &Args = CLI.getArgs();
1404 Type *RetTy = CLI.RetTy;
1405 const CallBase *CB = CLI.CB;
1406 const DataLayout &DL = DAG.getDataLayout();
1407 LLVMContext &Ctx = *DAG.getContext();
1408
1409 const auto GetI32 = [&](const unsigned I) {
1410 return DAG.getConstant(I, dl, MVT::i32);
1411 };
1412
1413 const unsigned UniqueCallSite = GlobalUniqueCallSite++;
1414 const SDValue CallChain = CLI.Chain;
1415 const SDValue StartChain =
1416 DAG.getCALLSEQ_START(CallChain, UniqueCallSite, 0, dl);
1417 SDValue DeclareGlue = StartChain.getValue(1);
1418
1419 SmallVector<SDValue, 16> CallPrereqs{StartChain};
1420
1421 const auto MakeDeclareScalarParam = [&](SDValue Symbol, unsigned Size) {
1422 // PTX ABI requires integral types to be at least 32 bits in size. FP16 is
1423 // loaded/stored using i16, so it's handled here as well.
1424 const unsigned SizeBits = promoteScalarArgumentSize(Size * 8);
1425 SDValue Declare =
1426 DAG.getNode(NVPTXISD::DeclareScalarParam, dl, {MVT::Other, MVT::Glue},
1427 {StartChain, Symbol, GetI32(SizeBits), DeclareGlue});
1428 CallPrereqs.push_back(Declare);
1429 DeclareGlue = Declare.getValue(1);
1430 return Declare;
1431 };
1432
1433 const auto MakeDeclareArrayParam = [&](SDValue Symbol, Align Align,
1434 unsigned Size) {
1435 SDValue Declare = DAG.getNode(
1436 NVPTXISD::DeclareArrayParam, dl, {MVT::Other, MVT::Glue},
1437 {StartChain, Symbol, GetI32(Align.value()), GetI32(Size), DeclareGlue});
1438 CallPrereqs.push_back(Declare);
1439 DeclareGlue = Declare.getValue(1);
1440 return Declare;
1441 };
1442
1443 // Variadic arguments.
1444 //
1445 // Normally, for each argument, we declare a param scalar or a param
1446 // byte array in the .param space, and store the argument value to that
1447 // param scalar or array starting at offset 0.
1448 //
1449 // In the case of the first variadic argument, we declare a vararg byte array
1450 // with size 0. The exact size of this array isn't known at this point, so
1451 // it'll be patched later. All the variadic arguments will be stored to this
1452 // array at a certain offset (which gets tracked by 'VAOffset'). The offset is
1453 // initially set to 0, so it can be used for non-variadic arguments (which use
1454 // 0 offset) to simplify the code.
1455 //
1456 // After all vararg is processed, 'VAOffset' holds the size of the
1457 // vararg byte array.
1458 assert((CLI.IsVarArg || CLI.Args.size() == CLI.NumFixedArgs) &&
1459 "Non-VarArg function with extra arguments");
1460
1461 const unsigned FirstVAArg = CLI.NumFixedArgs; // position of first variadic
1462 unsigned VAOffset = 0; // current offset in the param array
1463
1464 const SDValue VADeclareParam =
1465 CLI.Args.size() > FirstVAArg
1466 ? MakeDeclareArrayParam(getCallParamSymbol(DAG, FirstVAArg, MVT::i32),
1467 Align(STI.getMaxRequiredAlignment()), 0)
1468 : SDValue();
1469
1470 // Args.size() and Outs.size() need not match.
1471 // Outs.size() will be larger
1472 // * if there is an aggregate argument with multiple fields (each field
1473 // showing up separately in Outs)
1474 // * if there is a vector argument with more than typical vector-length
1475 // elements (generally if more than 4) where each vector element is
1476 // individually present in Outs.
1477 // So a different index should be used for indexing into Outs/OutVals.
1478 // See similar issue in LowerFormalArguments.
1479 auto AllOuts = ArrayRef(CLI.Outs);
1480 auto AllOutVals = ArrayRef(CLI.OutVals);
1481 assert(AllOuts.size() == AllOutVals.size() &&
1482 "Outs and OutVals must be the same size");
1483 // Declare the .params or .reg need to pass values
1484 // to the function
1485 for (const auto E : llvm::enumerate(Args)) {
1486 const auto ArgI = E.index();
1487 const auto Arg = E.value();
1488 const auto ArgOuts =
1489 AllOuts.take_while([&](auto O) { return O.OrigArgIndex == ArgI; });
1490 const auto ArgOutVals = AllOutVals.take_front(ArgOuts.size());
1491 AllOuts = AllOuts.drop_front(ArgOuts.size());
1492 AllOutVals = AllOutVals.drop_front(ArgOuts.size());
1493
1494 const bool IsVAArg = (ArgI >= FirstVAArg);
1495 const bool IsByVal = Arg.IsByVal;
1496
1497 const SDValue ParamSymbol =
1498 getCallParamSymbol(DAG, IsVAArg ? FirstVAArg : ArgI, MVT::i32);
1499
1500 assert((!IsByVal || Arg.IndirectType) &&
1501 "byval arg must have indirect type");
1502 Type *ETy = (IsByVal ? Arg.IndirectType : Arg.Ty);
1503
1504 const Align ArgAlign = [&]() {
1505 if (IsByVal) {
1506 // The ByValAlign in the Outs[OIdx].Flags is always set at this point,
1507 // so we don't need to worry whether it's naturally aligned or not.
1508 // See TargetLowering::LowerCallTo().
1509 const Align InitialAlign = ArgOuts[0].Flags.getNonZeroByValAlign();
1511 InitialAlign, DL);
1512 }
1513 return getArgumentAlignment(CB, Arg.Ty, ArgI + 1, DL);
1514 }();
1515
1516 const unsigned TySize = DL.getTypeAllocSize(ETy);
1517 assert((!IsByVal || TySize == ArgOuts[0].Flags.getByValSize()) &&
1518 "type size mismatch");
1519
1520 const SDValue ArgDeclare = [&]() {
1521 if (IsVAArg)
1522 return VADeclareParam;
1523
1524 if (IsByVal || shouldPassAsArray(Arg.Ty))
1525 return MakeDeclareArrayParam(ParamSymbol, ArgAlign, TySize);
1526
1527 assert(ArgOuts.size() == 1 && "We must pass only one value as non-array");
1528 assert((ArgOuts[0].VT.isInteger() || ArgOuts[0].VT.isFloatingPoint()) &&
1529 "Only int and float types are supported as non-array arguments");
1530
1531 return MakeDeclareScalarParam(ParamSymbol, TySize);
1532 }();
1533
1534 if (IsByVal) {
1535 assert(ArgOutVals.size() == 1 && "We must pass only one value as byval");
1536 SDValue SrcPtr = ArgOutVals[0];
1537 const auto PointerInfo = refinePtrAS(SrcPtr, DAG, DL, *this);
1538 const Align BaseSrcAlign = ArgOuts[0].Flags.getNonZeroByValAlign();
1539
1540 if (IsVAArg)
1541 VAOffset = alignTo(VAOffset, ArgAlign);
1542
1543 SmallVector<EVT, 4> ValueVTs, MemVTs;
1545 ComputeValueVTs(*this, DL, ETy, ValueVTs, &MemVTs, &Offsets);
1546
1547 unsigned J = 0;
1548 const auto VI = VectorizePTXValueVTs(MemVTs, Offsets, ArgAlign, IsVAArg);
1549 for (const unsigned NumElts : VI) {
1550 EVT LoadVT = getVectorizedVT(MemVTs[J], NumElts, Ctx);
1551 Align SrcAlign = commonAlignment(BaseSrcAlign, Offsets[J]);
1552 SDValue SrcAddr = DAG.getObjectPtrOffset(dl, SrcPtr, Offsets[J]);
1553 SDValue SrcLoad =
1554 DAG.getLoad(LoadVT, dl, CallChain, SrcAddr, PointerInfo, SrcAlign);
1555
1556 TypeSize ParamOffset = Offsets[J].getWithIncrement(VAOffset);
1557 Align ParamAlign = commonAlignment(ArgAlign, ParamOffset);
1558 SDValue ParamAddr =
1559 DAG.getObjectPtrOffset(dl, ParamSymbol, ParamOffset);
1560 SDValue StoreParam =
1561 DAG.getStore(ArgDeclare, dl, SrcLoad, ParamAddr,
1563 CallPrereqs.push_back(StoreParam);
1564
1565 J += NumElts;
1566 }
1567 if (IsVAArg)
1568 VAOffset += TySize;
1569 } else {
1572 ComputePTXValueVTs(*this, DL, Ctx, CLI.CallConv, Arg.Ty, VTs, Offsets,
1573 VAOffset);
1574 assert(VTs.size() == Offsets.size() && "Size mismatch");
1575 assert(VTs.size() == ArgOuts.size() && "Size mismatch");
1576
1577 // PTX Interoperability Guide 3.3(A): [Integer] Values shorter
1578 // than 32-bits are sign extended or zero extended, depending on
1579 // whether they are signed or unsigned types. This case applies
1580 // only to scalar parameters and not to aggregate values.
1581 const bool ExtendIntegerParam =
1582 Arg.Ty->isIntegerTy() && DL.getTypeAllocSizeInBits(Arg.Ty) < 32;
1583
1584 const auto GetStoredValue = [&](const unsigned I) {
1585 SDValue StVal = ArgOutVals[I];
1587 StVal.getValueType() &&
1588 "OutVal type should always be legal");
1589
1590 const EVT VTI = promoteScalarIntegerPTX(VTs[I]);
1591 const EVT StoreVT =
1592 ExtendIntegerParam ? MVT::i32 : (VTI == MVT::i1 ? MVT::i8 : VTI);
1593
1594 return correctParamType(StVal, StoreVT, ArgOuts[I].Flags, DAG, dl);
1595 };
1596
1597 unsigned J = 0;
1598 const auto VI = VectorizePTXValueVTs(VTs, Offsets, ArgAlign, IsVAArg);
1599 for (const unsigned NumElts : VI) {
1600 const EVT EltVT = promoteScalarIntegerPTX(VTs[J]);
1601
1602 unsigned Offset;
1603 if (IsVAArg) {
1604 // TODO: We may need to support vector types that can be passed
1605 // as scalars in variadic arguments.
1606 assert(NumElts == 1 &&
1607 "Vectorization should be disabled for vaargs.");
1608
1609 // Align each part of the variadic argument to their type.
1610 VAOffset = alignTo(VAOffset, DAG.getEVTAlign(EltVT));
1611 Offset = VAOffset;
1612
1613 const EVT TheStoreType = ExtendIntegerParam ? MVT::i32 : EltVT;
1614 VAOffset += DL.getTypeAllocSize(TheStoreType.getTypeForEVT(Ctx));
1615 } else {
1616 assert(VAOffset == 0 && "VAOffset must be 0 for non-VA args");
1617 Offset = Offsets[J];
1618 }
1619
1620 SDValue Ptr =
1621 DAG.getObjectPtrOffset(dl, ParamSymbol, TypeSize::getFixed(Offset));
1622
1623 const MaybeAlign CurrentAlign = ExtendIntegerParam
1624 ? MaybeAlign(std::nullopt)
1625 : commonAlignment(ArgAlign, Offset);
1626
1627 SDValue Val =
1628 getBuildVectorizedValue(NumElts, dl, DAG, [&](unsigned K) {
1629 return GetStoredValue(J + K);
1630 });
1631
1632 SDValue StoreParam =
1633 DAG.getStore(ArgDeclare, dl, Val, Ptr,
1635 CallPrereqs.push_back(StoreParam);
1636
1637 J += NumElts;
1638 }
1639 }
1640 }
1641
1642 // Handle Result
1643 if (!Ins.empty()) {
1644 const SDValue RetSymbol = DAG.getExternalSymbol("retval0", MVT::i32);
1645 const unsigned ResultSize = DL.getTypeAllocSize(RetTy);
1646 if (shouldPassAsArray(RetTy)) {
1647 const Align RetAlign = getArgumentAlignment(CB, RetTy, 0, DL);
1648 MakeDeclareArrayParam(RetSymbol, RetAlign, ResultSize);
1649 } else {
1650 MakeDeclareScalarParam(RetSymbol, ResultSize);
1651 }
1652 }
1653
1654 // Set the size of the vararg param byte array if the callee is a variadic
1655 // function and the variadic part is not empty.
1656 if (VADeclareParam) {
1657 SDValue DeclareParamOps[] = {VADeclareParam.getOperand(0),
1658 VADeclareParam.getOperand(1),
1659 VADeclareParam.getOperand(2), GetI32(VAOffset),
1660 VADeclareParam.getOperand(4)};
1661 DAG.MorphNodeTo(VADeclareParam.getNode(), VADeclareParam.getOpcode(),
1662 VADeclareParam->getVTList(), DeclareParamOps);
1663 }
1664
1665 const auto *Func = dyn_cast<GlobalAddressSDNode>(Callee.getNode());
1666 // If the type of the callsite does not match that of the function, convert
1667 // the callsite to an indirect call.
1668 const bool ConvertToIndirectCall = shouldConvertToIndirectCall(CB, Func);
1669
1670 // Both indirect calls and libcalls have nullptr Func. In order to distinguish
1671 // between them we must rely on the call site value which is valid for
1672 // indirect calls but is always null for libcalls.
1673 const bool IsIndirectCall = (!Func && CB) || ConvertToIndirectCall;
1674
1675 if (isa<ExternalSymbolSDNode>(Callee)) {
1676 Function* CalleeFunc = nullptr;
1677
1678 // Try to find the callee in the current module.
1679 Callee = DAG.getSymbolFunctionGlobalAddress(Callee, &CalleeFunc);
1680 assert(CalleeFunc != nullptr && "Libcall callee must be set.");
1681
1682 // Set the "libcall callee" attribute to indicate that the function
1683 // must always have a declaration.
1684 CalleeFunc->addFnAttr("nvptx-libcall-callee", "true");
1685 }
1686
1687 if (IsIndirectCall) {
1688 // This is indirect function call case : PTX requires a prototype of the
1689 // form
1690 // proto_0 : .callprototype(.param .b32 _) _ (.param .b32 _);
1691 // to be emitted, and the label has to used as the last arg of call
1692 // instruction.
1693 // The prototype is embedded in a string and put as the operand for a
1694 // CallPrototype SDNode which will print out to the value of the string.
1695 const bool HasVAArgs = CLI.IsVarArg && (CLI.Args.size() > CLI.NumFixedArgs);
1696 std::string Proto =
1697 getPrototype(DL, RetTy, Args, CLI.Outs,
1698 HasVAArgs ? std::optional(FirstVAArg) : std::nullopt, *CB,
1699 UniqueCallSite);
1700 const char *ProtoStr = nvTM->getStrPool().save(Proto).data();
1701 const SDValue PrototypeDeclare = DAG.getNode(
1702 NVPTXISD::CallPrototype, dl, MVT::Other,
1703 {StartChain, DAG.getTargetExternalSymbol(ProtoStr, MVT::i32)});
1704 CallPrereqs.push_back(PrototypeDeclare);
1705 }
1706
1707 const unsigned Proto = IsIndirectCall ? UniqueCallSite : 0;
1708 const unsigned NumArgs =
1709 std::min<unsigned>(CLI.NumFixedArgs + 1, Args.size());
1710 /// CALL(Chain, IsConvergent, IsIndirectCall/IsUniform, NumReturns,
1711 /// NumParams, Callee, Proto)
1712 const SDValue CallToken = DAG.getTokenFactor(dl, CallPrereqs);
1713 const SDValue Call = DAG.getNode(
1714 NVPTXISD::CALL, dl, MVT::Other,
1715 {CallToken, GetI32(CLI.IsConvergent), GetI32(IsIndirectCall),
1716 GetI32(Ins.empty() ? 0 : 1), GetI32(NumArgs), Callee, GetI32(Proto)});
1717
1718 SmallVector<SDValue, 16> LoadChains{Call};
1719 SmallVector<SDValue, 16> ProxyRegOps;
1720 if (!Ins.empty()) {
1723 ComputePTXValueVTs(*this, DL, Ctx, CLI.CallConv, RetTy, VTs, Offsets);
1724 assert(VTs.size() == Ins.size() && "Bad value decomposition");
1725
1726 const Align RetAlign = getArgumentAlignment(CB, RetTy, 0, DL);
1727 const SDValue RetSymbol = DAG.getExternalSymbol("retval0", MVT::i32);
1728
1729 // PTX Interoperability Guide 3.3(A): [Integer] Values shorter than
1730 // 32-bits are sign extended or zero extended, depending on whether
1731 // they are signed or unsigned types.
1732 const bool ExtendIntegerRetVal =
1733 RetTy->isIntegerTy() && DL.getTypeAllocSizeInBits(RetTy) < 32;
1734
1735 unsigned I = 0;
1736 const auto VI = VectorizePTXValueVTs(VTs, Offsets, RetAlign);
1737 for (const unsigned NumElts : VI) {
1738 const MaybeAlign CurrentAlign =
1739 ExtendIntegerRetVal ? MaybeAlign(std::nullopt)
1740 : commonAlignment(RetAlign, Offsets[I]);
1741
1742 const EVT VTI = promoteScalarIntegerPTX(VTs[I]);
1743 const EVT LoadVT =
1744 ExtendIntegerRetVal ? MVT::i32 : (VTI == MVT::i1 ? MVT::i8 : VTI);
1745 const EVT VecVT = getVectorizedVT(LoadVT, NumElts, Ctx);
1746 SDValue Ptr =
1747 DAG.getObjectPtrOffset(dl, RetSymbol, TypeSize::getFixed(Offsets[I]));
1748
1749 SDValue R =
1750 DAG.getLoad(VecVT, dl, Call, Ptr,
1752
1753 LoadChains.push_back(R.getValue(1));
1754 for (const unsigned J : llvm::seq(NumElts))
1755 ProxyRegOps.push_back(getExtractVectorizedValue(R, J, LoadVT, dl, DAG));
1756 I += NumElts;
1757 }
1758 }
1759
1760 const SDValue EndToken = DAG.getTokenFactor(dl, LoadChains);
1761 const SDValue CallEnd = DAG.getCALLSEQ_END(EndToken, UniqueCallSite,
1762 UniqueCallSite + 1, SDValue(), dl);
1763
1764 // Append ProxyReg instructions to the chain to make sure that `callseq_end`
1765 // will not get lost. Otherwise, during libcalls expansion, the nodes can become
1766 // dangling.
1767 for (const auto [I, Reg] : llvm::enumerate(ProxyRegOps)) {
1768 SDValue Proxy =
1769 DAG.getNode(NVPTXISD::ProxyReg, dl, Reg.getValueType(), {CallEnd, Reg});
1770 SDValue Ret = correctParamType(Proxy, Ins[I].VT, Ins[I].Flags, DAG, dl);
1771 InVals.push_back(Ret);
1772 }
1773
1774 // set IsTailCall to false for now, until we figure out how to express
1775 // tail call optimization in PTX
1776 CLI.IsTailCall = false;
1777 return CallEnd;
1778}
1779
1781 SelectionDAG &DAG) const {
1782
1783 if (STI.getPTXVersion() < 73 || STI.getSmVersion() < 52) {
1784 const Function &Fn = DAG.getMachineFunction().getFunction();
1785
1787 Fn,
1788 "Support for dynamic alloca introduced in PTX ISA version 7.3 and "
1789 "requires target sm_52.",
1790 SDLoc(Op).getDebugLoc()));
1791 auto Ops = {DAG.getConstant(0, SDLoc(), Op.getValueType()),
1792 Op.getOperand(0)};
1793 return DAG.getMergeValues(Ops, SDLoc());
1794 }
1795
1796 SDLoc DL(Op.getNode());
1797 SDValue Chain = Op.getOperand(0);
1798 SDValue Size = Op.getOperand(1);
1799 uint64_t Align = Op.getConstantOperandVal(2);
1800
1801 // The alignment on a ISD::DYNAMIC_STACKALLOC node may be 0 to indicate that
1802 // the default stack alignment should be used.
1803 if (Align == 0)
1805
1806 // The size for ptx alloca instruction is 64-bit for m64 and 32-bit for m32.
1807 const MVT LocalVT = getPointerTy(DAG.getDataLayout(), ADDRESS_SPACE_LOCAL);
1808
1809 SDValue Alloc =
1810 DAG.getNode(NVPTXISD::DYNAMIC_STACKALLOC, DL, {LocalVT, MVT::Other},
1811 {Chain, DAG.getZExtOrTrunc(Size, DL, LocalVT),
1812 DAG.getTargetConstant(Align, DL, MVT::i32)});
1813
1814 SDValue ASC = DAG.getAddrSpaceCast(
1816
1817 return DAG.getMergeValues({ASC, SDValue(Alloc.getNode(), 1)}, DL);
1818}
1819
1821 SelectionDAG &DAG) const {
1822 SDLoc DL(Op.getNode());
1823 if (STI.getPTXVersion() < 73 || STI.getSmVersion() < 52) {
1824 const Function &Fn = DAG.getMachineFunction().getFunction();
1825
1827 Fn,
1828 "Support for stackrestore requires PTX ISA version >= 7.3 and target "
1829 ">= sm_52.",
1830 DL.getDebugLoc()));
1831 return Op.getOperand(0);
1832 }
1833
1834 const MVT LocalVT = getPointerTy(DAG.getDataLayout(), ADDRESS_SPACE_LOCAL);
1835 SDValue Chain = Op.getOperand(0);
1836 SDValue Ptr = Op.getOperand(1);
1837 SDValue ASC = DAG.getAddrSpaceCast(DL, LocalVT, Ptr, ADDRESS_SPACE_GENERIC,
1839 return DAG.getNode(NVPTXISD::STACKRESTORE, DL, MVT::Other, {Chain, ASC});
1840}
1841
1843 SelectionDAG &DAG) const {
1844 SDLoc DL(Op.getNode());
1845 if (STI.getPTXVersion() < 73 || STI.getSmVersion() < 52) {
1846 const Function &Fn = DAG.getMachineFunction().getFunction();
1847
1849 Fn,
1850 "Support for stacksave requires PTX ISA version >= 7.3 and target >= "
1851 "sm_52.",
1852 DL.getDebugLoc()));
1853 auto Ops = {DAG.getConstant(0, DL, Op.getValueType()), Op.getOperand(0)};
1854 return DAG.getMergeValues(Ops, DL);
1855 }
1856
1857 const MVT LocalVT = getPointerTy(DAG.getDataLayout(), ADDRESS_SPACE_LOCAL);
1858 SDValue Chain = Op.getOperand(0);
1859 SDValue SS =
1860 DAG.getNode(NVPTXISD::STACKSAVE, DL, {LocalVT, MVT::Other}, Chain);
1861 SDValue ASC = DAG.getAddrSpaceCast(
1862 DL, Op.getValueType(), SS, ADDRESS_SPACE_LOCAL, ADDRESS_SPACE_GENERIC);
1863 return DAG.getMergeValues({ASC, SDValue(SS.getNode(), 1)}, DL);
1864}
1865
1866// By default CONCAT_VECTORS is lowered by ExpandVectorBuildThroughStack()
1867// (see LegalizeDAG.cpp). This is slow and uses local memory.
1868// We use extract/insert/build vector just as what LegalizeOp() does in llvm 2.5
1869SDValue
1870NVPTXTargetLowering::LowerCONCAT_VECTORS(SDValue Op, SelectionDAG &DAG) const {
1871 SDNode *Node = Op.getNode();
1872 SDLoc dl(Node);
1874 unsigned NumOperands = Node->getNumOperands();
1875 for (unsigned i = 0; i < NumOperands; ++i) {
1876 SDValue SubOp = Node->getOperand(i);
1877 EVT VVT = SubOp.getNode()->getValueType(0);
1878 EVT EltVT = VVT.getVectorElementType();
1879 unsigned NumSubElem = VVT.getVectorNumElements();
1880 for (unsigned j = 0; j < NumSubElem; ++j) {
1881 Ops.push_back(DAG.getNode(ISD::EXTRACT_VECTOR_ELT, dl, EltVT, SubOp,
1882 DAG.getIntPtrConstant(j, dl)));
1883 }
1884 }
1885 return DAG.getBuildVector(Node->getValueType(0), dl, Ops);
1886}
1887
1889 SelectionDAG &DAG,
1890 unsigned Mode = NVPTX::PTXPrmtMode::NONE) {
1891 assert(A.getValueType() == MVT::i32 && B.getValueType() == MVT::i32 &&
1892 Selector.getValueType() == MVT::i32 && "PRMT must have i32 operands");
1893 return DAG.getNode(NVPTXISD::PRMT, DL, MVT::i32,
1894 {A, B, Selector, DAG.getConstant(Mode, DL, MVT::i32)});
1895}
1896
1898 SelectionDAG &DAG,
1899 unsigned Mode = NVPTX::PTXPrmtMode::NONE) {
1900 return getPRMT(A, B, DAG.getConstant(Selector, DL, MVT::i32), DL, DAG, Mode);
1901}
1902
1903/// Reduces the elements using the scalar operations provided. The operations
1904/// are sorted descending in number of inputs they take. The flags on the
1905/// original reduction operation will be propagated to each scalar operation.
1906/// Nearby elements are grouped in tree reduction, unlike the shuffle reduction
1907/// used in ExpandReductions and SelectionDAG.
1909 const SmallVector<SDValue> &Elements, EVT EltTy,
1910 ArrayRef<std::pair<unsigned /*NodeType*/, unsigned /*NumInputs*/>> Ops,
1911 const SDLoc &DL, const SDNodeFlags Flags, SelectionDAG &DAG) {
1912 // Build the reduction tree at each level, starting with all the elements.
1913 SmallVector<SDValue> Level = Elements;
1914
1915 unsigned OpIdx = 0;
1916 while (Level.size() > 1) {
1917 // Try to reduce this level using the current operator.
1918 const auto [Op, NumInputs] = Ops[OpIdx];
1919
1920 // Build the next level by partially reducing all elements.
1921 SmallVector<SDValue> ReducedLevel;
1922 unsigned I = 0, E = Level.size();
1923 for (; I + NumInputs <= E; I += NumInputs) {
1924 // Reduce elements in groups of [NumInputs], as much as possible.
1925 ReducedLevel.push_back(DAG.getNode(
1926 Op, DL, EltTy, ArrayRef<SDValue>(Level).slice(I, NumInputs), Flags));
1927 }
1928
1929 if (I < E) {
1930 // Handle leftover elements.
1931
1932 if (ReducedLevel.empty()) {
1933 // We didn't reduce anything at this level. We need to pick a smaller
1934 // operator.
1935 ++OpIdx;
1936 assert(OpIdx < Ops.size() && "no smaller operators for reduction");
1937 continue;
1938 }
1939
1940 // We reduced some things but there's still more left, meaning the
1941 // operator's number of inputs doesn't evenly divide this level size. Move
1942 // these elements to the next level.
1943 for (; I < E; ++I)
1944 ReducedLevel.push_back(Level[I]);
1945 }
1946
1947 // Process the next level.
1948 Level = ReducedLevel;
1949 }
1950
1951 return *Level.begin();
1952}
1953
1954// Get scalar reduction opcode
1955static ISD::NodeType getScalarOpcodeForReduction(unsigned ReductionOpcode) {
1956 switch (ReductionOpcode) {
1958 return ISD::FMAXNUM;
1960 return ISD::FMINNUM;
1962 return ISD::FMAXIMUM;
1964 return ISD::FMINIMUM;
1965 default:
1966 llvm_unreachable("unhandled reduction opcode");
1967 }
1968}
1969
1970/// Get 3-input scalar reduction opcode
1971static std::optional<unsigned>
1972getScalar3OpcodeForReduction(unsigned ReductionOpcode) {
1973 switch (ReductionOpcode) {
1975 return NVPTXISD::FMAXNUM3;
1977 return NVPTXISD::FMINNUM3;
1979 return NVPTXISD::FMAXIMUM3;
1981 return NVPTXISD::FMINIMUM3;
1982 default:
1983 return std::nullopt;
1984 }
1985}
1986
1987/// Lower reductions to either a sequence of operations or a tree if
1988/// reassociations are allowed. This method will use larger operations like
1989/// max3/min3 when the target supports them.
1990SDValue NVPTXTargetLowering::LowerVECREDUCE(SDValue Op,
1991 SelectionDAG &DAG) const {
1992 SDLoc DL(Op);
1993 const SDNodeFlags Flags = Op->getFlags();
1994 SDValue Vector = Op.getOperand(0);
1995
1996 const unsigned Opcode = Op->getOpcode();
1997 const EVT EltTy = Vector.getValueType().getVectorElementType();
1998
1999 // Whether we can use 3-input min/max when expanding the reduction.
2000 const bool CanUseMinMax3 =
2001 EltTy == MVT::f32 && STI.getSmVersion() >= 100 &&
2002 STI.getPTXVersion() >= 88 &&
2003 (Opcode == ISD::VECREDUCE_FMAX || Opcode == ISD::VECREDUCE_FMIN ||
2004 Opcode == ISD::VECREDUCE_FMAXIMUM || Opcode == ISD::VECREDUCE_FMINIMUM);
2005
2006 // A list of SDNode opcodes with equivalent semantics, sorted descending by
2007 // number of inputs they take.
2008 SmallVector<std::pair<unsigned /*Op*/, unsigned /*NumIn*/>, 2> ScalarOps;
2009
2010 if (auto Opcode3Elem = getScalar3OpcodeForReduction(Opcode);
2011 CanUseMinMax3 && Opcode3Elem)
2012 ScalarOps.push_back({*Opcode3Elem, 3});
2013 ScalarOps.push_back({getScalarOpcodeForReduction(Opcode), 2});
2014
2016 DAG.ExtractVectorElements(Vector, Elements);
2017
2018 return buildTreeReduction(Elements, EltTy, ScalarOps, DL, Flags, DAG);
2019}
2020
2021SDValue NVPTXTargetLowering::LowerBITCAST(SDValue Op, SelectionDAG &DAG) const {
2022 // Handle bitcasting from v2i8 without hitting the default promotion
2023 // strategy which goes through stack memory.
2024 EVT FromVT = Op->getOperand(0)->getValueType(0);
2025 if (FromVT != MVT::v2i8) {
2026 return Op;
2027 }
2028
2029 // Pack vector elements into i16 and bitcast to final type
2030 SDLoc DL(Op);
2031 SDValue Vec0 = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, DL, MVT::i8,
2032 Op->getOperand(0), DAG.getIntPtrConstant(0, DL));
2033 SDValue Vec1 = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, DL, MVT::i8,
2034 Op->getOperand(0), DAG.getIntPtrConstant(1, DL));
2035 SDValue Extend0 = DAG.getNode(ISD::ZERO_EXTEND, DL, MVT::i16, Vec0);
2036 SDValue Extend1 = DAG.getNode(ISD::ZERO_EXTEND, DL, MVT::i16, Vec1);
2037 SDValue Const8 = DAG.getConstant(8, DL, MVT::i16);
2038 SDValue AsInt = DAG.getNode(
2039 ISD::OR, DL, MVT::i16,
2040 {Extend0, DAG.getNode(ISD::SHL, DL, MVT::i16, {Extend1, Const8})});
2041 EVT ToVT = Op->getValueType(0);
2042 return DAG.getBitcast(ToVT, AsInt);
2043}
2044
2045// We can init constant f16x2/v2i16/v4i8 with a single .b32 move. Normally it
2046// would get lowered as two constant loads and vector-packing move.
2047// Instead we want just a constant move:
2048// mov.b32 %r2, 0x40003C00
2049SDValue NVPTXTargetLowering::LowerBUILD_VECTOR(SDValue Op,
2050 SelectionDAG &DAG) const {
2051 EVT VT = Op->getValueType(0);
2052 if (!(NVPTX::isPackedVectorTy(VT) && VT.is32BitVector()))
2053 return Op;
2054 SDLoc DL(Op);
2055
2056 if (!llvm::all_of(Op->ops(), [](SDValue Operand) {
2057 return Operand->isUndef() || isa<ConstantSDNode>(Operand) ||
2058 isa<ConstantFPSDNode>(Operand);
2059 })) {
2060 if (VT != MVT::v4i8)
2061 return Op;
2062 // Lower non-const v4i8 vector as byte-wise constructed i32, which allows us
2063 // to optimize calculation of constant parts.
2064 auto GetPRMT = [&](const SDValue Left, const SDValue Right, bool Cast,
2065 uint64_t SelectionValue) -> SDValue {
2066 SDValue L = Left;
2067 SDValue R = Right;
2068 if (Cast) {
2069 L = DAG.getAnyExtOrTrunc(L, DL, MVT::i32);
2070 R = DAG.getAnyExtOrTrunc(R, DL, MVT::i32);
2071 }
2072 return getPRMT(L, R, SelectionValue, DL, DAG);
2073 };
2074 auto PRMT__10 = GetPRMT(Op->getOperand(0), Op->getOperand(1), true, 0x3340);
2075 auto PRMT__32 = GetPRMT(Op->getOperand(2), Op->getOperand(3), true, 0x3340);
2076 auto PRMT3210 = GetPRMT(PRMT__10, PRMT__32, false, 0x5410);
2077 return DAG.getBitcast(VT, PRMT3210);
2078 }
2079
2080 // Get value or the Nth operand as an APInt(32). Undef values treated as 0.
2081 auto GetOperand = [](SDValue Op, int N) -> APInt {
2082 const SDValue &Operand = Op->getOperand(N);
2083 EVT VT = Op->getValueType(0);
2084 if (Operand->isUndef())
2085 return APInt(32, 0);
2086 APInt Value;
2087 if (VT == MVT::v2f16 || VT == MVT::v2bf16)
2088 Value = cast<ConstantFPSDNode>(Operand)->getValueAPF().bitcastToAPInt();
2089 else if (VT == MVT::v2i16 || VT == MVT::v4i8)
2090 Value = Operand->getAsAPIntVal();
2091 else
2092 llvm_unreachable("Unsupported type");
2093 // i8 values are carried around as i16, so we need to zero out upper bits,
2094 // so they do not get in the way of combining individual byte values
2095 if (VT == MVT::v4i8)
2096 Value = Value.trunc(8);
2097 return Value.zext(32);
2098 };
2099
2100 // Construct a 32-bit constant by shifting into place smaller values
2101 // (elements of the vector type VT).
2102 // For example, if VT has 2 elements, then N == 2:
2103 // ShiftAmount = 32 / N = 16
2104 // Value |= Op0 (b16) << 0
2105 // Value |= Op1 (b16) << 16
2106 // If N == 4:
2107 // ShiftAmount = 32 / N = 8
2108 // Value |= Op0 (b8) << 0
2109 // Value |= Op1 (b8) << 8
2110 // Value |= Op2 (b8) << 16
2111 // Value |= Op3 (b8) << 24
2112 // ...etc
2113 APInt Value(32, 0);
2114 const unsigned NumElements = VT.getVectorNumElements();
2115 assert(32 % NumElements == 0 && "must evenly divide bit length");
2116 const unsigned ShiftAmount = 32 / NumElements;
2117 for (unsigned ElementNo : seq(NumElements))
2118 Value |= GetOperand(Op, ElementNo).shl(ElementNo * ShiftAmount);
2119 SDValue Const = DAG.getConstant(Value, DL, MVT::i32);
2120 return DAG.getNode(ISD::BITCAST, DL, Op->getValueType(0), Const);
2121}
2122
2123SDValue NVPTXTargetLowering::LowerEXTRACT_VECTOR_ELT(SDValue Op,
2124 SelectionDAG &DAG) const {
2125 SDValue Index = Op->getOperand(1);
2126 SDValue Vector = Op->getOperand(0);
2127 SDLoc DL(Op);
2128 EVT VectorVT = Vector.getValueType();
2129
2130 if (VectorVT == MVT::v4i8) {
2131 SDValue Selector = DAG.getNode(ISD::OR, DL, MVT::i32,
2132 DAG.getZExtOrTrunc(Index, DL, MVT::i32),
2133 DAG.getConstant(0x7770, DL, MVT::i32));
2134 SDValue PRMT = getPRMT(DAG.getBitcast(MVT::i32, Vector),
2135 DAG.getConstant(0, DL, MVT::i32), Selector, DL, DAG);
2136 SDValue Ext = DAG.getAnyExtOrTrunc(PRMT, DL, Op->getValueType(0));
2137 SDNodeFlags Flags;
2138 Flags.setNoSignedWrap(Ext.getScalarValueSizeInBits() > 8);
2139 Flags.setNoUnsignedWrap(Ext.getScalarValueSizeInBits() >= 8);
2140 Ext->setFlags(Flags);
2141 return Ext;
2142 }
2143
2144 // Constant index will be matched by tablegen.
2145 if (isa<ConstantSDNode>(Index.getNode()))
2146 return Op;
2147
2148 // Extract individual elements and select one of them.
2149 assert(NVPTX::isPackedVectorTy(VectorVT) &&
2150 VectorVT.getVectorNumElements() == 2 && "Unexpected vector type.");
2151 EVT EltVT = VectorVT.getVectorElementType();
2152
2153 SDLoc dl(Op.getNode());
2154 SDValue E0 = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, dl, EltVT, Vector,
2155 DAG.getIntPtrConstant(0, dl));
2156 SDValue E1 = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, dl, EltVT, Vector,
2157 DAG.getIntPtrConstant(1, dl));
2158 return DAG.getSelectCC(dl, Index, DAG.getIntPtrConstant(0, dl), E0, E1,
2160}
2161
2162SDValue NVPTXTargetLowering::LowerINSERT_VECTOR_ELT(SDValue Op,
2163 SelectionDAG &DAG) const {
2164 SDValue Vector = Op->getOperand(0);
2165 EVT VectorVT = Vector.getValueType();
2166
2167 if (VectorVT != MVT::v4i8)
2168 return Op;
2169 SDLoc DL(Op);
2170 SDValue Value = Op->getOperand(1);
2171 if (Value->isUndef())
2172 return Vector;
2173
2174 SDValue Index = Op->getOperand(2);
2175
2176 SDValue BFI =
2177 DAG.getNode(NVPTXISD::BFI, DL, MVT::i32,
2178 {DAG.getZExtOrTrunc(Value, DL, MVT::i32), Vector,
2179 DAG.getNode(ISD::MUL, DL, MVT::i32,
2180 DAG.getZExtOrTrunc(Index, DL, MVT::i32),
2181 DAG.getConstant(8, DL, MVT::i32)),
2182 DAG.getConstant(8, DL, MVT::i32)});
2183 return DAG.getNode(ISD::BITCAST, DL, Op->getValueType(0), BFI);
2184}
2185
2186SDValue NVPTXTargetLowering::LowerVECTOR_SHUFFLE(SDValue Op,
2187 SelectionDAG &DAG) const {
2188 SDValue V1 = Op.getOperand(0);
2189 EVT VectorVT = V1.getValueType();
2190 if (VectorVT != MVT::v4i8 || Op.getValueType() != MVT::v4i8)
2191 return Op;
2192
2193 // Lower shuffle to PRMT instruction.
2194 const ShuffleVectorSDNode *SVN = cast<ShuffleVectorSDNode>(Op.getNode());
2195 SDValue V2 = Op.getOperand(1);
2196 uint32_t Selector = 0;
2197 for (auto I : llvm::enumerate(SVN->getMask())) {
2198 if (I.value() != -1) // -1 is a placeholder for undef.
2199 Selector |= (I.value() << (I.index() * 4));
2200 }
2201
2202 SDLoc DL(Op);
2203 SDValue PRMT = getPRMT(DAG.getBitcast(MVT::i32, V1),
2204 DAG.getBitcast(MVT::i32, V2), Selector, DL, DAG);
2205 return DAG.getBitcast(Op.getValueType(), PRMT);
2206}
2207/// LowerShiftRightParts - Lower SRL_PARTS, SRA_PARTS, which
2208/// 1) returns two i32 values and take a 2 x i32 value to shift plus a shift
2209/// amount, or
2210/// 2) returns two i64 values and take a 2 x i64 value to shift plus a shift
2211/// amount.
2212SDValue NVPTXTargetLowering::LowerShiftRightParts(SDValue Op,
2213 SelectionDAG &DAG) const {
2214 assert(Op.getNumOperands() == 3 && "Not a double-shift!");
2215 assert(Op.getOpcode() == ISD::SRA_PARTS || Op.getOpcode() == ISD::SRL_PARTS);
2216
2217 EVT VT = Op.getValueType();
2218 unsigned VTBits = VT.getSizeInBits();
2219 SDLoc dl(Op);
2220 SDValue ShOpLo = Op.getOperand(0);
2221 SDValue ShOpHi = Op.getOperand(1);
2222 SDValue ShAmt = Op.getOperand(2);
2223 unsigned Opc = (Op.getOpcode() == ISD::SRA_PARTS) ? ISD::SRA : ISD::SRL;
2224
2225 if (VTBits == 32 && STI.getSmVersion() >= 35) {
2226 // For 32bit and sm35, we can use the funnel shift 'shf' instruction.
2227 // {dHi, dLo} = {aHi, aLo} >> Amt
2228 // dHi = aHi >> Amt
2229 // dLo = shf.r.clamp aLo, aHi, Amt
2230
2231 SDValue Hi = DAG.getNode(Opc, dl, VT, ShOpHi, ShAmt);
2232 SDValue Lo =
2233 DAG.getNode(NVPTXISD::FSHR_CLAMP, dl, VT, ShOpHi, ShOpLo, ShAmt);
2234
2235 SDValue Ops[2] = { Lo, Hi };
2236 return DAG.getMergeValues(Ops, dl);
2237 }
2238 else {
2239 // {dHi, dLo} = {aHi, aLo} >> Amt
2240 // - if (Amt>=size) then
2241 // dLo = aHi >> (Amt-size)
2242 // dHi = aHi >> Amt (this is either all 0 or all 1)
2243 // else
2244 // dLo = (aLo >>logic Amt) | (aHi << (size-Amt))
2245 // dHi = aHi >> Amt
2246
2247 SDValue RevShAmt = DAG.getNode(ISD::SUB, dl, MVT::i32,
2248 DAG.getConstant(VTBits, dl, MVT::i32),
2249 ShAmt);
2250 SDValue Tmp1 = DAG.getNode(ISD::SRL, dl, VT, ShOpLo, ShAmt);
2251 SDValue ExtraShAmt = DAG.getNode(ISD::SUB, dl, MVT::i32, ShAmt,
2252 DAG.getConstant(VTBits, dl, MVT::i32));
2253 SDValue Tmp2 = DAG.getNode(ISD::SHL, dl, VT, ShOpHi, RevShAmt);
2254 SDValue FalseVal = DAG.getNode(ISD::OR, dl, VT, Tmp1, Tmp2);
2255 SDValue TrueVal = DAG.getNode(Opc, dl, VT, ShOpHi, ExtraShAmt);
2256
2257 SDValue Cmp = DAG.getSetCC(dl, MVT::i1, ShAmt,
2258 DAG.getConstant(VTBits, dl, MVT::i32),
2259 ISD::SETGE);
2260 SDValue Hi = DAG.getNode(Opc, dl, VT, ShOpHi, ShAmt);
2261 SDValue Lo = DAG.getNode(ISD::SELECT, dl, VT, Cmp, TrueVal, FalseVal);
2262
2263 SDValue Ops[2] = { Lo, Hi };
2264 return DAG.getMergeValues(Ops, dl);
2265 }
2266}
2267
2268/// LowerShiftLeftParts - Lower SHL_PARTS, which
2269/// 1) returns two i32 values and take a 2 x i32 value to shift plus a shift
2270/// amount, or
2271/// 2) returns two i64 values and take a 2 x i64 value to shift plus a shift
2272/// amount.
2273SDValue NVPTXTargetLowering::LowerShiftLeftParts(SDValue Op,
2274 SelectionDAG &DAG) const {
2275 assert(Op.getNumOperands() == 3 && "Not a double-shift!");
2276 assert(Op.getOpcode() == ISD::SHL_PARTS);
2277
2278 EVT VT = Op.getValueType();
2279 unsigned VTBits = VT.getSizeInBits();
2280 SDLoc dl(Op);
2281 SDValue ShOpLo = Op.getOperand(0);
2282 SDValue ShOpHi = Op.getOperand(1);
2283 SDValue ShAmt = Op.getOperand(2);
2284
2285 if (VTBits == 32 && STI.getSmVersion() >= 35) {
2286 // For 32bit and sm35, we can use the funnel shift 'shf' instruction.
2287 // {dHi, dLo} = {aHi, aLo} << Amt
2288 // dHi = shf.l.clamp aLo, aHi, Amt
2289 // dLo = aLo << Amt
2290
2291 SDValue Hi =
2292 DAG.getNode(NVPTXISD::FSHL_CLAMP, dl, VT, ShOpHi, ShOpLo, ShAmt);
2293 SDValue Lo = DAG.getNode(ISD::SHL, dl, VT, ShOpLo, ShAmt);
2294
2295 SDValue Ops[2] = { Lo, Hi };
2296 return DAG.getMergeValues(Ops, dl);
2297 }
2298 else {
2299 // {dHi, dLo} = {aHi, aLo} << Amt
2300 // - if (Amt>=size) then
2301 // dLo = aLo << Amt (all 0)
2302 // dLo = aLo << (Amt-size)
2303 // else
2304 // dLo = aLo << Amt
2305 // dHi = (aHi << Amt) | (aLo >> (size-Amt))
2306
2307 SDValue RevShAmt = DAG.getNode(ISD::SUB, dl, MVT::i32,
2308 DAG.getConstant(VTBits, dl, MVT::i32),
2309 ShAmt);
2310 SDValue Tmp1 = DAG.getNode(ISD::SHL, dl, VT, ShOpHi, ShAmt);
2311 SDValue ExtraShAmt = DAG.getNode(ISD::SUB, dl, MVT::i32, ShAmt,
2312 DAG.getConstant(VTBits, dl, MVT::i32));
2313 SDValue Tmp2 = DAG.getNode(ISD::SRL, dl, VT, ShOpLo, RevShAmt);
2314 SDValue FalseVal = DAG.getNode(ISD::OR, dl, VT, Tmp1, Tmp2);
2315 SDValue TrueVal = DAG.getNode(ISD::SHL, dl, VT, ShOpLo, ExtraShAmt);
2316
2317 SDValue Cmp = DAG.getSetCC(dl, MVT::i1, ShAmt,
2318 DAG.getConstant(VTBits, dl, MVT::i32),
2319 ISD::SETGE);
2320 SDValue Lo = DAG.getNode(ISD::SHL, dl, VT, ShOpLo, ShAmt);
2321 SDValue Hi = DAG.getNode(ISD::SELECT, dl, VT, Cmp, TrueVal, FalseVal);
2322
2323 SDValue Ops[2] = { Lo, Hi };
2324 return DAG.getMergeValues(Ops, dl);
2325 }
2326}
2327
2328/// If the types match, convert the generic copysign to the NVPTXISD version,
2329/// otherwise bail ensuring that mismatched cases are properly expaned.
2330SDValue NVPTXTargetLowering::LowerFCOPYSIGN(SDValue Op,
2331 SelectionDAG &DAG) const {
2332 EVT VT = Op.getValueType();
2333 SDLoc DL(Op);
2334
2335 SDValue In1 = Op.getOperand(0);
2336 SDValue In2 = Op.getOperand(1);
2337 EVT SrcVT = In2.getValueType();
2338
2339 if (!SrcVT.bitsEq(VT))
2340 return SDValue();
2341
2342 return DAG.getNode(NVPTXISD::FCOPYSIGN, DL, VT, In1, In2);
2343}
2344
2345SDValue NVPTXTargetLowering::LowerFROUND(SDValue Op, SelectionDAG &DAG) const {
2346 EVT VT = Op.getValueType();
2347
2348 if (VT == MVT::f32)
2349 return LowerFROUND32(Op, DAG);
2350
2351 if (VT == MVT::f64)
2352 return LowerFROUND64(Op, DAG);
2353
2354 llvm_unreachable("unhandled type");
2355}
2356
2357// This is the the rounding method used in CUDA libdevice in C like code:
2358// float roundf(float A)
2359// {
2360// float RoundedA = (float) (int) ( A > 0 ? (A + 0.5f) : (A - 0.5f));
2361// RoundedA = abs(A) > 0x1.0p23 ? A : RoundedA;
2362// return abs(A) < 0.5 ? (float)(int)A : RoundedA;
2363// }
2364SDValue NVPTXTargetLowering::LowerFROUND32(SDValue Op,
2365 SelectionDAG &DAG) const {
2366 SDLoc SL(Op);
2367 SDValue A = Op.getOperand(0);
2368 EVT VT = Op.getValueType();
2369
2370 SDValue AbsA = DAG.getNode(ISD::FABS, SL, VT, A);
2371
2372 // RoundedA = (float) (int) ( A > 0 ? (A + 0.5f) : (A - 0.5f))
2373 SDValue Bitcast = DAG.getNode(ISD::BITCAST, SL, MVT::i32, A);
2374 const unsigned SignBitMask = 0x80000000;
2375 SDValue Sign = DAG.getNode(ISD::AND, SL, MVT::i32, Bitcast,
2376 DAG.getConstant(SignBitMask, SL, MVT::i32));
2377 const unsigned PointFiveInBits = 0x3F000000;
2378 SDValue PointFiveWithSignRaw =
2379 DAG.getNode(ISD::OR, SL, MVT::i32, Sign,
2380 DAG.getConstant(PointFiveInBits, SL, MVT::i32));
2381 SDValue PointFiveWithSign =
2382 DAG.getNode(ISD::BITCAST, SL, VT, PointFiveWithSignRaw);
2383 SDValue AdjustedA = DAG.getNode(ISD::FADD, SL, VT, A, PointFiveWithSign);
2384 SDValue RoundedA = DAG.getNode(ISD::FTRUNC, SL, VT, AdjustedA);
2385
2386 // RoundedA = abs(A) > 0x1.0p23 ? A : RoundedA;
2387 EVT SetCCVT = getSetCCResultType(DAG.getDataLayout(), *DAG.getContext(), VT);
2388 SDValue IsLarge =
2389 DAG.getSetCC(SL, SetCCVT, AbsA, DAG.getConstantFP(pow(2.0, 23.0), SL, VT),
2390 ISD::SETOGT);
2391 RoundedA = DAG.getNode(ISD::SELECT, SL, VT, IsLarge, A, RoundedA);
2392
2393 // return abs(A) < 0.5 ? (float)(int)A : RoundedA;
2394 SDValue IsSmall =DAG.getSetCC(SL, SetCCVT, AbsA,
2395 DAG.getConstantFP(0.5, SL, VT), ISD::SETOLT);
2396 SDValue RoundedAForSmallA = DAG.getNode(ISD::FTRUNC, SL, VT, A);
2397 return DAG.getNode(ISD::SELECT, SL, VT, IsSmall, RoundedAForSmallA, RoundedA);
2398}
2399
2400// The implementation of round(double) is similar to that of round(float) in
2401// that they both separate the value range into three regions and use a method
2402// specific to the region to round the values. However, round(double) first
2403// calculates the round of the absolute value and then adds the sign back while
2404// round(float) directly rounds the value with sign.
2405SDValue NVPTXTargetLowering::LowerFROUND64(SDValue Op,
2406 SelectionDAG &DAG) const {
2407 SDLoc SL(Op);
2408 SDValue A = Op.getOperand(0);
2409 EVT VT = Op.getValueType();
2410
2411 SDValue AbsA = DAG.getNode(ISD::FABS, SL, VT, A);
2412
2413 // double RoundedA = (double) (int) (abs(A) + 0.5f);
2414 SDValue AdjustedA = DAG.getNode(ISD::FADD, SL, VT, AbsA,
2415 DAG.getConstantFP(0.5, SL, VT));
2416 SDValue RoundedA = DAG.getNode(ISD::FTRUNC, SL, VT, AdjustedA);
2417
2418 // RoundedA = abs(A) < 0.5 ? (double)0 : RoundedA;
2419 EVT SetCCVT = getSetCCResultType(DAG.getDataLayout(), *DAG.getContext(), VT);
2420 SDValue IsSmall =DAG.getSetCC(SL, SetCCVT, AbsA,
2421 DAG.getConstantFP(0.5, SL, VT), ISD::SETOLT);
2422 RoundedA = DAG.getNode(ISD::SELECT, SL, VT, IsSmall,
2423 DAG.getConstantFP(0, SL, VT),
2424 RoundedA);
2425
2426 // Add sign to rounded_A
2427 RoundedA = DAG.getNode(ISD::FCOPYSIGN, SL, VT, RoundedA, A);
2428 DAG.getNode(ISD::FTRUNC, SL, VT, A);
2429
2430 // RoundedA = abs(A) > 0x1.0p52 ? A : RoundedA;
2431 SDValue IsLarge =
2432 DAG.getSetCC(SL, SetCCVT, AbsA, DAG.getConstantFP(pow(2.0, 52.0), SL, VT),
2433 ISD::SETOGT);
2434 return DAG.getNode(ISD::SELECT, SL, VT, IsLarge, A, RoundedA);
2435}
2436
2438 EVT VT = N->getValueType(0);
2439 EVT NVT = MVT::f32;
2440 if (VT.isVector()) {
2441 NVT = EVT::getVectorVT(*DAG.getContext(), NVT, VT.getVectorElementCount());
2442 }
2443 SDLoc DL(N);
2444 SDValue Tmp0 = DAG.getFPExtendOrRound(N->getOperand(0), DL, NVT);
2445 SDValue Tmp1 = DAG.getFPExtendOrRound(N->getOperand(1), DL, NVT);
2446 SDValue Res = DAG.getNode(N->getOpcode(), DL, NVT, Tmp0, Tmp1, N->getFlags());
2447 return DAG.getFPExtendOrRound(Res, DL, VT);
2448}
2449
2450SDValue NVPTXTargetLowering::PromoteBinOpIfF32FTZ(SDValue Op,
2451 SelectionDAG &DAG) const {
2452 if (useF32FTZ(DAG.getMachineFunction())) {
2453 return PromoteBinOpToF32(Op.getNode(), DAG);
2454 }
2455 return Op;
2456}
2457
2458SDValue NVPTXTargetLowering::LowerINT_TO_FP(SDValue Op,
2459 SelectionDAG &DAG) const {
2460 assert(STI.getSmVersion() < 90 || STI.getPTXVersion() < 78);
2461
2462 if (Op.getValueType() == MVT::bf16) {
2463 SDLoc Loc(Op);
2464 return DAG.getNode(
2465 ISD::FP_ROUND, Loc, MVT::bf16,
2466 DAG.getNode(Op.getOpcode(), Loc, MVT::f32, Op.getOperand(0)),
2467 DAG.getIntPtrConstant(0, Loc, /*isTarget=*/true));
2468 }
2469
2470 // Everything else is considered legal.
2471 return Op;
2472}
2473
2474SDValue NVPTXTargetLowering::LowerFP_TO_INT(SDValue Op,
2475 SelectionDAG &DAG) const {
2476 assert(STI.getSmVersion() < 90 || STI.getPTXVersion() < 78);
2477
2478 if (Op.getOperand(0).getValueType() == MVT::bf16) {
2479 SDLoc Loc(Op);
2480 return DAG.getNode(
2481 Op.getOpcode(), Loc, Op.getValueType(),
2482 DAG.getNode(ISD::FP_EXTEND, Loc, MVT::f32, Op.getOperand(0)));
2483 }
2484
2485 // Everything else is considered legal.
2486 return Op;
2487}
2488
2489SDValue NVPTXTargetLowering::LowerFP_ROUND(SDValue Op,
2490 SelectionDAG &DAG) const {
2491 EVT NarrowVT = Op.getValueType();
2492 SDValue Wide = Op.getOperand(0);
2493 EVT WideVT = Wide.getValueType();
2494 if (NarrowVT.getScalarType() == MVT::bf16) {
2495 const TargetLowering *TLI = STI.getTargetLowering();
2496 if (STI.getSmVersion() < 80 || STI.getPTXVersion() < 70) {
2497 return TLI->expandFP_ROUND(Op.getNode(), DAG);
2498 }
2499 if (STI.getSmVersion() < 90 || STI.getPTXVersion() < 78) {
2500 // This combination was the first to support f32 -> bf16.
2501 if (STI.getSmVersion() >= 80 && STI.getPTXVersion() >= 70) {
2502 if (WideVT.getScalarType() == MVT::f32) {
2503 return Op;
2504 }
2505 if (WideVT.getScalarType() == MVT::f64) {
2506 SDLoc Loc(Op);
2507 // Round-inexact-to-odd f64 to f32, then do the final rounding using
2508 // the hardware f32 -> bf16 instruction.
2510 WideVT.changeElementType(*DAG.getContext(), MVT::f32), Wide, Loc,
2511 DAG);
2512 return DAG.getFPExtendOrRound(rod, Loc, NarrowVT);
2513 }
2514 }
2515 return TLI->expandFP_ROUND(Op.getNode(), DAG);
2516 }
2517 }
2518
2519 // Everything else is considered legal.
2520 return Op;
2521}
2522
2523SDValue NVPTXTargetLowering::LowerFP_EXTEND(SDValue Op,
2524 SelectionDAG &DAG) const {
2525 SDValue Narrow = Op.getOperand(0);
2526 EVT NarrowVT = Narrow.getValueType();
2527 EVT WideVT = Op.getValueType();
2528 if (NarrowVT.getScalarType() == MVT::bf16) {
2529 if (WideVT.getScalarType() == MVT::f32 &&
2530 (STI.getSmVersion() < 80 || STI.getPTXVersion() < 71)) {
2531 SDLoc Loc(Op);
2532 return DAG.getNode(ISD::BF16_TO_FP, Loc, WideVT, Narrow);
2533 }
2534 if (WideVT.getScalarType() == MVT::f64 &&
2535 (STI.getSmVersion() < 90 || STI.getPTXVersion() < 78)) {
2536 EVT F32 = NarrowVT.changeElementType(*DAG.getContext(), MVT::f32);
2537 SDLoc Loc(Op);
2538 if (STI.getSmVersion() >= 80 && STI.getPTXVersion() >= 71) {
2539 Op = DAG.getNode(ISD::FP_EXTEND, Loc, F32, Narrow);
2540 } else {
2541 Op = DAG.getNode(ISD::BF16_TO_FP, Loc, F32, Narrow);
2542 }
2543 return DAG.getNode(ISD::FP_EXTEND, Loc, WideVT, Op);
2544 }
2545 }
2546
2547 // Everything else is considered legal.
2548 return Op;
2549}
2550
2552 SDLoc DL(Op);
2553 if (Op.getValueType() != MVT::v2i16)
2554 return Op;
2555 EVT EltVT = Op.getValueType().getVectorElementType();
2556 SmallVector<SDValue> VecElements;
2557 for (int I = 0, E = Op.getValueType().getVectorNumElements(); I < E; I++) {
2558 SmallVector<SDValue> ScalarArgs;
2559 llvm::transform(Op->ops(), std::back_inserter(ScalarArgs),
2560 [&](const SDUse &O) {
2561 return DAG.getNode(ISD::EXTRACT_VECTOR_ELT, DL, EltVT,
2562 O.get(), DAG.getIntPtrConstant(I, DL));
2563 });
2564 VecElements.push_back(DAG.getNode(Op.getOpcode(), DL, EltVT, ScalarArgs));
2565 }
2566 SDValue V =
2567 DAG.getNode(ISD::BUILD_VECTOR, DL, Op.getValueType(), VecElements);
2568 return V;
2569}
2570
2572 bool hasOffset = false) {
2573 // skip lowering if the vector operand is already legalized
2574 if (!Op->getOperand(hasOffset ? 4 : 3).getValueType().isVector())
2575 return Op;
2576
2577 SDNode *N = Op.getNode();
2578 SDLoc DL(N);
2580
2581 // split the vector argument
2582 for (size_t I = 0; I < N->getNumOperands(); I++) {
2583 SDValue Val = N->getOperand(I);
2584 EVT ValVT = Val.getValueType();
2585 if (ValVT.isVector()) {
2586 EVT EltVT = ValVT.getVectorElementType();
2587 for (unsigned J = 0, NElts = ValVT.getVectorNumElements(); J < NElts; J++)
2588 Ops.push_back(DAG.getNode(ISD::EXTRACT_VECTOR_ELT, DL, EltVT, Val,
2589 DAG.getIntPtrConstant(J, DL)));
2590 } else
2591 Ops.push_back(Val);
2592 }
2593
2595 SDValue Tcgen05StNode =
2596 DAG.getMemIntrinsicNode(ISD::INTRINSIC_VOID, DL, N->getVTList(), Ops,
2597 MemSD->getMemoryVT(), MemSD->getMemOperand());
2598
2599 return Tcgen05StNode;
2600}
2601
2603 SDLoc DL(Op);
2604 SDValue Src = Op.getOperand(0);
2605 EVT VT = Op.getValueType();
2606
2607 switch (VT.getSimpleVT().SimpleTy) {
2608 case MVT::i16: {
2609 SDValue Extended = DAG.getNode(ISD::ANY_EXTEND, DL, MVT::i32, Src);
2610 SDValue Swapped =
2611 getPRMT(Extended, DAG.getConstant(0, DL, MVT::i32), 0x7701, DL, DAG);
2612 return DAG.getNode(ISD::TRUNCATE, DL, MVT::i16, Swapped);
2613 }
2614 case MVT::i32: {
2615 return getPRMT(Src, DAG.getConstant(0, DL, MVT::i32), 0x0123, DL, DAG);
2616 }
2617 case MVT::v2i16: {
2618 SDValue Converted = DAG.getBitcast(MVT::i32, Src);
2619 SDValue Swapped =
2620 getPRMT(Converted, DAG.getConstant(0, DL, MVT::i32), 0x2301, DL, DAG);
2621 return DAG.getNode(ISD::BITCAST, DL, MVT::v2i16, Swapped);
2622 }
2623 case MVT::i64: {
2624 SDValue UnpackSrc =
2625 DAG.getNode(NVPTXISD::UNPACK_VECTOR, DL, {MVT::i32, MVT::i32}, Src);
2626 SDValue SwappedLow =
2627 getPRMT(UnpackSrc.getValue(0), DAG.getConstant(0, DL, MVT::i32), 0x0123,
2628 DL, DAG);
2629 SDValue SwappedHigh =
2630 getPRMT(UnpackSrc.getValue(1), DAG.getConstant(0, DL, MVT::i32), 0x0123,
2631 DL, DAG);
2632 return DAG.getNode(NVPTXISD::BUILD_VECTOR, DL, MVT::i64,
2633 {SwappedHigh, SwappedLow});
2634 }
2635 default:
2636 llvm_unreachable("unsupported type for bswap");
2637 }
2638}
2639
2640static unsigned getTcgen05MMADisableOutputLane(unsigned IID) {
2641 switch (IID) {
2642 case Intrinsic::nvvm_tcgen05_mma_shared_disable_output_lane_cg1:
2643 return NVPTXISD::TCGEN05_MMA_SHARED_DISABLE_OUTPUT_LANE_CG1;
2644 case Intrinsic::nvvm_tcgen05_mma_shared_disable_output_lane_cg2:
2645 return NVPTXISD::TCGEN05_MMA_SHARED_DISABLE_OUTPUT_LANE_CG2;
2646 case Intrinsic::nvvm_tcgen05_mma_shared_scale_d_disable_output_lane_cg1:
2647 return NVPTXISD::TCGEN05_MMA_SHARED_SCALE_D_DISABLE_OUTPUT_LANE_CG1;
2648 case Intrinsic::nvvm_tcgen05_mma_shared_scale_d_disable_output_lane_cg2:
2649 return NVPTXISD::TCGEN05_MMA_SHARED_SCALE_D_DISABLE_OUTPUT_LANE_CG2;
2650 case Intrinsic::nvvm_tcgen05_mma_tensor_disable_output_lane_cg1:
2651 return NVPTXISD::TCGEN05_MMA_TENSOR_DISABLE_OUTPUT_LANE_CG1;
2652 case Intrinsic::nvvm_tcgen05_mma_tensor_disable_output_lane_cg2:
2653 return NVPTXISD::TCGEN05_MMA_TENSOR_DISABLE_OUTPUT_LANE_CG2;
2654 case Intrinsic::nvvm_tcgen05_mma_tensor_scale_d_disable_output_lane_cg1:
2655 return NVPTXISD::TCGEN05_MMA_TENSOR_SCALE_D_DISABLE_OUTPUT_LANE_CG1;
2656 case Intrinsic::nvvm_tcgen05_mma_tensor_scale_d_disable_output_lane_cg2:
2657 return NVPTXISD::TCGEN05_MMA_TENSOR_SCALE_D_DISABLE_OUTPUT_LANE_CG2;
2658 case Intrinsic::nvvm_tcgen05_mma_tensor_disable_output_lane_cg1_ashift:
2659 return NVPTXISD::TCGEN05_MMA_TENSOR_DISABLE_OUTPUT_LANE_CG1_ASHIFT;
2660 case Intrinsic::nvvm_tcgen05_mma_tensor_disable_output_lane_cg2_ashift:
2661 return NVPTXISD::TCGEN05_MMA_TENSOR_DISABLE_OUTPUT_LANE_CG2_ASHIFT;
2662 case Intrinsic::
2663 nvvm_tcgen05_mma_tensor_scale_d_disable_output_lane_cg1_ashift:
2664 return NVPTXISD::TCGEN05_MMA_TENSOR_SCALE_D_DISABLE_OUTPUT_LANE_CG1_ASHIFT;
2665 case Intrinsic::
2666 nvvm_tcgen05_mma_tensor_scale_d_disable_output_lane_cg2_ashift:
2667 return NVPTXISD::TCGEN05_MMA_TENSOR_SCALE_D_DISABLE_OUTPUT_LANE_CG2_ASHIFT;
2668 case Intrinsic::nvvm_tcgen05_mma_sp_shared_disable_output_lane_cg1:
2669 return NVPTXISD::TCGEN05_MMA_SP_SHARED_DISABLE_OUTPUT_LANE_CG1;
2670 case Intrinsic::nvvm_tcgen05_mma_sp_shared_disable_output_lane_cg2:
2671 return NVPTXISD::TCGEN05_MMA_SP_SHARED_DISABLE_OUTPUT_LANE_CG2;
2672 case Intrinsic::nvvm_tcgen05_mma_sp_shared_scale_d_disable_output_lane_cg1:
2673 return NVPTXISD::TCGEN05_MMA_SP_SHARED_SCALE_D_DISABLE_OUTPUT_LANE_CG1;
2674 case Intrinsic::nvvm_tcgen05_mma_sp_shared_scale_d_disable_output_lane_cg2:
2675 return NVPTXISD::TCGEN05_MMA_SP_SHARED_SCALE_D_DISABLE_OUTPUT_LANE_CG2;
2676 case Intrinsic::nvvm_tcgen05_mma_sp_tensor_disable_output_lane_cg1:
2677 return NVPTXISD::TCGEN05_MMA_SP_TENSOR_DISABLE_OUTPUT_LANE_CG1;
2678 case Intrinsic::nvvm_tcgen05_mma_sp_tensor_disable_output_lane_cg2:
2679 return NVPTXISD::TCGEN05_MMA_SP_TENSOR_DISABLE_OUTPUT_LANE_CG2;
2680 case Intrinsic::nvvm_tcgen05_mma_sp_tensor_disable_output_lane_cg1_ashift:
2681 return NVPTXISD::TCGEN05_MMA_SP_TENSOR_DISABLE_OUTPUT_LANE_CG1_ASHIFT;
2682 case Intrinsic::nvvm_tcgen05_mma_sp_tensor_disable_output_lane_cg2_ashift:
2683 return NVPTXISD::TCGEN05_MMA_SP_TENSOR_DISABLE_OUTPUT_LANE_CG2_ASHIFT;
2684 case Intrinsic::nvvm_tcgen05_mma_sp_tensor_scale_d_disable_output_lane_cg1:
2685 return NVPTXISD::TCGEN05_MMA_SP_TENSOR_SCALE_D_DISABLE_OUTPUT_LANE_CG1;
2686 case Intrinsic::nvvm_tcgen05_mma_sp_tensor_scale_d_disable_output_lane_cg2:
2687 return NVPTXISD::TCGEN05_MMA_SP_TENSOR_SCALE_D_DISABLE_OUTPUT_LANE_CG2;
2688 case Intrinsic::
2689 nvvm_tcgen05_mma_sp_tensor_scale_d_disable_output_lane_cg1_ashift:
2690 return NVPTXISD::
2691 TCGEN05_MMA_SP_TENSOR_SCALE_D_DISABLE_OUTPUT_LANE_CG1_ASHIFT;
2692 case Intrinsic::
2693 nvvm_tcgen05_mma_sp_tensor_scale_d_disable_output_lane_cg2_ashift:
2694 return NVPTXISD::
2695 TCGEN05_MMA_SP_TENSOR_SCALE_D_DISABLE_OUTPUT_LANE_CG2_ASHIFT;
2696 };
2697 llvm_unreachable("unhandled tcgen05.mma.disable_output_lane intrinsic");
2698}
2699
2701 SDNode *N = Op.getNode();
2702 SDLoc DL(N);
2703 unsigned IID = cast<ConstantSDNode>(N->getOperand(1))->getZExtValue();
2704
2706 // split the vector argument
2707 for (size_t I = 0; I < N->getNumOperands(); I++) {
2708 if (I == 1)
2709 continue; // skip IID
2710 SDValue Val = N->getOperand(I);
2711 EVT ValVT = Val.getValueType();
2712 if (ValVT.isVector()) {
2713 EVT EltVT = ValVT.getVectorElementType();
2714 for (unsigned J = 0, NElts = ValVT.getVectorNumElements(); J < NElts; J++)
2715 Ops.push_back(DAG.getNode(ISD::EXTRACT_VECTOR_ELT, DL, EltVT, Val,
2716 DAG.getIntPtrConstant(J, DL)));
2717 } else
2718 Ops.push_back(Val);
2719 }
2720
2722 SDValue Tcgen05MMANode = DAG.getMemIntrinsicNode(
2723 getTcgen05MMADisableOutputLane(IID), DL, N->getVTList(), Ops,
2724 MemSD->getMemoryVT(), MemSD->getMemOperand());
2725
2726 return Tcgen05MMANode;
2727}
2728
2729// Lower vector return type of tcgen05.ld intrinsics
2730static std::optional<std::pair<SDValue, SDValue>>
2731lowerTcgen05Ld(SDNode *N, SelectionDAG &DAG, bool HasOffset = false) {
2732 SDLoc DL(N);
2733 EVT ResVT = N->getValueType(0);
2734 if (!ResVT.isVector())
2735 return {}; // already legalized.
2736
2737 const unsigned NumElts = ResVT.getVectorNumElements();
2738
2739 // Create the return type of the instructions
2740 SmallVector<EVT, 5> ListVTs;
2741 for (unsigned i = 0; i < NumElts; ++i)
2742 ListVTs.push_back(MVT::i32);
2743
2744 ListVTs.push_back(N->getValueType(1)); // Chain
2745
2746 SDVTList ResVTs = DAG.getVTList(ListVTs);
2747
2748 SmallVector<SDValue, 8> Ops{N->getOperand(0), N->getOperand(1),
2749 N->getOperand(2)};
2750
2751 if (HasOffset) {
2752 Ops.push_back(N->getOperand(3)); // offset
2753 Ops.push_back(N->getOperand(4)); // Pack flag
2754 } else
2755 Ops.push_back(N->getOperand(3)); // Pack flag
2756
2758 SDValue NewNode =
2760 MemSD->getMemoryVT(), MemSD->getMemOperand());
2761
2762 // split the vector result
2763 SmallVector<SDValue, 4> ScalarRes;
2764 for (unsigned i = 0; i < NumElts; ++i) {
2765 SDValue Res = NewNode.getValue(i);
2766 ScalarRes.push_back(Res);
2767 }
2768
2769 SDValue Chain = NewNode.getValue(NumElts);
2770 SDValue BuildVector = DAG.getNode(ISD::BUILD_VECTOR, DL, ResVT, ScalarRes);
2771 return {{BuildVector, Chain}};
2772}
2773
2775 unsigned Val) {
2776 SDNode *N = Op.getNode();
2777 SDLoc DL(N);
2778
2779 const Function &Fn = DAG.getMachineFunction().getFunction();
2780
2781 unsigned AS = 0;
2782 if (auto *MemN = dyn_cast<MemIntrinsicSDNode>(N))
2783 AS = MemN->getAddressSpace();
2784 Type *PtrTy = PointerType::get(*DAG.getContext(), AS);
2786
2788 Fn,
2789 "Intrinsic " +
2790 Intrinsic::getName(N->getConstantOperandVal(1), {PtrTy}, M) +
2791 " with value " + Twine(Val) +
2792 " is not supported on the given target.",
2793 DL.getDebugLoc()));
2794 return Op.getOperand(0);
2795}
2796
2798 SDNode *N = Op.getNode();
2799 SDLoc DL(N);
2800
2801 // immediate argument representing elemtype
2802 unsigned Val = N->getConstantOperandVal(3);
2803
2805 Val))
2806 return reportInvalidTensormapReplaceUsage(Op, DAG, Val);
2807
2808 return Op;
2809}
2810
2812 SDNode *N = Op.getNode();
2813 SDLoc DL(N);
2814
2815 // immediate argument representing swizzle mode
2816 unsigned Val = N->getConstantOperandVal(3);
2817
2819 Val))
2820 return reportInvalidTensormapReplaceUsage(Op, DAG, Val);
2821
2822 return Op;
2823}
2824
2826 SDNode *N = Op.getNode();
2827 SDValue Intrin = N->getOperand(1);
2828
2829 // Get the intrinsic ID
2830 unsigned IntrinNo = cast<ConstantSDNode>(Intrin.getNode())->getZExtValue();
2831 switch (IntrinNo) {
2832 default:
2833 break;
2834 case Intrinsic::nvvm_tcgen05_st_16x64b_x2:
2835 case Intrinsic::nvvm_tcgen05_st_16x64b_x4:
2836 case Intrinsic::nvvm_tcgen05_st_16x64b_x8:
2837 case Intrinsic::nvvm_tcgen05_st_16x64b_x16:
2838 case Intrinsic::nvvm_tcgen05_st_16x64b_x32:
2839 case Intrinsic::nvvm_tcgen05_st_16x64b_x128:
2840 case Intrinsic::nvvm_tcgen05_st_16x128b_x1:
2841 case Intrinsic::nvvm_tcgen05_st_16x128b_x2:
2842 case Intrinsic::nvvm_tcgen05_st_16x128b_x4:
2843 case Intrinsic::nvvm_tcgen05_st_16x128b_x8:
2844 case Intrinsic::nvvm_tcgen05_st_16x128b_x16:
2845 case Intrinsic::nvvm_tcgen05_st_16x128b_x32:
2846 case Intrinsic::nvvm_tcgen05_st_16x128b_x64:
2847 case Intrinsic::nvvm_tcgen05_st_16x256b_x1:
2848 case Intrinsic::nvvm_tcgen05_st_16x256b_x2:
2849 case Intrinsic::nvvm_tcgen05_st_16x256b_x4:
2850 case Intrinsic::nvvm_tcgen05_st_16x256b_x8:
2851 case Intrinsic::nvvm_tcgen05_st_16x256b_x16:
2852 case Intrinsic::nvvm_tcgen05_st_16x256b_x32:
2853 case Intrinsic::nvvm_tcgen05_st_32x32b_x2:
2854 case Intrinsic::nvvm_tcgen05_st_32x32b_x4:
2855 case Intrinsic::nvvm_tcgen05_st_32x32b_x8:
2856 case Intrinsic::nvvm_tcgen05_st_32x32b_x16:
2857 case Intrinsic::nvvm_tcgen05_st_32x32b_x32:
2858 case Intrinsic::nvvm_tcgen05_st_16x64b_x64:
2859 case Intrinsic::nvvm_tcgen05_st_32x32b_x64:
2860 case Intrinsic::nvvm_tcgen05_st_32x32b_x128:
2861 return lowerTcgen05St(Op, DAG);
2862 case Intrinsic::nvvm_tcgen05_st_16x32bx2_x2:
2863 case Intrinsic::nvvm_tcgen05_st_16x32bx2_x4:
2864 case Intrinsic::nvvm_tcgen05_st_16x32bx2_x8:
2865 case Intrinsic::nvvm_tcgen05_st_16x32bx2_x16:
2866 case Intrinsic::nvvm_tcgen05_st_16x32bx2_x32:
2867 case Intrinsic::nvvm_tcgen05_st_16x32bx2_x64:
2868 case Intrinsic::nvvm_tcgen05_st_16x32bx2_x128:
2869 return lowerTcgen05St(Op, DAG, /* hasOffset */ true);
2870 case Intrinsic::nvvm_tcgen05_mma_shared_disable_output_lane_cg1:
2871 case Intrinsic::nvvm_tcgen05_mma_shared_disable_output_lane_cg2:
2872 case Intrinsic::nvvm_tcgen05_mma_shared_scale_d_disable_output_lane_cg1:
2873 case Intrinsic::nvvm_tcgen05_mma_shared_scale_d_disable_output_lane_cg2:
2874 case Intrinsic::nvvm_tcgen05_mma_sp_shared_disable_output_lane_cg1:
2875 case Intrinsic::nvvm_tcgen05_mma_sp_shared_disable_output_lane_cg2:
2876 case Intrinsic::nvvm_tcgen05_mma_sp_shared_scale_d_disable_output_lane_cg1:
2877 case Intrinsic::nvvm_tcgen05_mma_sp_shared_scale_d_disable_output_lane_cg2:
2878 case Intrinsic::nvvm_tcgen05_mma_tensor_disable_output_lane_cg1:
2879 case Intrinsic::nvvm_tcgen05_mma_tensor_disable_output_lane_cg2:
2880 case Intrinsic::nvvm_tcgen05_mma_tensor_scale_d_disable_output_lane_cg1:
2881 case Intrinsic::nvvm_tcgen05_mma_tensor_scale_d_disable_output_lane_cg2:
2882 case Intrinsic::nvvm_tcgen05_mma_sp_tensor_disable_output_lane_cg1:
2883 case Intrinsic::nvvm_tcgen05_mma_sp_tensor_disable_output_lane_cg2:
2884 case Intrinsic::nvvm_tcgen05_mma_sp_tensor_scale_d_disable_output_lane_cg1:
2885 case Intrinsic::nvvm_tcgen05_mma_sp_tensor_scale_d_disable_output_lane_cg2:
2886 case Intrinsic::nvvm_tcgen05_mma_tensor_disable_output_lane_cg1_ashift:
2887 case Intrinsic::nvvm_tcgen05_mma_tensor_disable_output_lane_cg2_ashift:
2888 case Intrinsic::
2889 nvvm_tcgen05_mma_tensor_scale_d_disable_output_lane_cg1_ashift:
2890 case Intrinsic::
2891 nvvm_tcgen05_mma_tensor_scale_d_disable_output_lane_cg2_ashift:
2892 case Intrinsic::nvvm_tcgen05_mma_sp_tensor_disable_output_lane_cg1_ashift:
2893 case Intrinsic::nvvm_tcgen05_mma_sp_tensor_disable_output_lane_cg2_ashift:
2894 case Intrinsic::
2895 nvvm_tcgen05_mma_sp_tensor_scale_d_disable_output_lane_cg1_ashift:
2896 case Intrinsic::
2897 nvvm_tcgen05_mma_sp_tensor_scale_d_disable_output_lane_cg2_ashift:
2899 case Intrinsic::nvvm_tensormap_replace_elemtype:
2900 return lowerTensormapReplaceElemtype(Op, DAG);
2901 case Intrinsic::nvvm_tensormap_replace_swizzle_mode:
2903 }
2904 return Op;
2905}
2906
2908 SelectionDAG &DAG) {
2909
2910 SDNode *N = Op.getNode();
2911 if (N->getOperand(1).getValueType() != MVT::i128) {
2912 // return, if the operand is already lowered
2913 return SDValue();
2914 }
2915
2916 unsigned IID =
2917 cast<ConstantSDNode>(N->getOperand(0).getNode())->getZExtValue();
2918 auto Opcode = [&]() {
2919 switch (IID) {
2920 case Intrinsic::nvvm_clusterlaunchcontrol_query_cancel_is_canceled:
2921 return NVPTXISD::CLUSTERLAUNCHCONTROL_QUERY_CANCEL_IS_CANCELED;
2922 case Intrinsic::nvvm_clusterlaunchcontrol_query_cancel_get_first_ctaid_x:
2923 return NVPTXISD::CLUSTERLAUNCHCONTROL_QUERY_CANCEL_GET_FIRST_CTAID_X;
2924 case Intrinsic::nvvm_clusterlaunchcontrol_query_cancel_get_first_ctaid_y:
2925 return NVPTXISD::CLUSTERLAUNCHCONTROL_QUERY_CANCEL_GET_FIRST_CTAID_Y;
2926 case Intrinsic::nvvm_clusterlaunchcontrol_query_cancel_get_first_ctaid_z:
2927 return NVPTXISD::CLUSTERLAUNCHCONTROL_QUERY_CANCEL_GET_FIRST_CTAID_Z;
2928 default:
2929 llvm_unreachable("unsupported/unhandled intrinsic");
2930 }
2931 }();
2932
2933 SDLoc DL(N);
2934 SDValue TryCancelResponse = N->getOperand(1);
2935 SDValue Cast = DAG.getNode(ISD::BITCAST, DL, MVT::v2i64, TryCancelResponse);
2936 SDValue TryCancelResponse0 =
2937 DAG.getNode(ISD::EXTRACT_VECTOR_ELT, DL, MVT::i64, Cast,
2938 DAG.getIntPtrConstant(0, DL));
2939 SDValue TryCancelResponse1 =
2940 DAG.getNode(ISD::EXTRACT_VECTOR_ELT, DL, MVT::i64, Cast,
2941 DAG.getIntPtrConstant(1, DL));
2942
2943 return DAG.getNode(Opcode, DL, N->getVTList(),
2944 {TryCancelResponse0, TryCancelResponse1});
2945}
2946
2948 SDNode *N = Op.getNode();
2949 SDLoc DL(N);
2950 SDValue F32Vec = N->getOperand(1);
2951 SDValue RBits = N->getOperand(2);
2952
2953 unsigned IntrinsicID = N->getConstantOperandVal(0);
2954
2955 // Extract the 4 float elements from the vector
2957 for (unsigned i = 0; i < 4; ++i)
2958 Ops.push_back(DAG.getNode(ISD::EXTRACT_VECTOR_ELT, DL, MVT::f32, F32Vec,
2959 DAG.getIntPtrConstant(i, DL)));
2960
2962
2963 auto [OpCode, RetTy, CvtModeFlag] =
2964 [&]() -> std::tuple<unsigned, MVT::SimpleValueType, uint32_t> {
2965 switch (IntrinsicID) {
2966 case Intrinsic::nvvm_f32x4_to_e4m3x4_rs_relu_satfinite:
2967 return {NVPTXISD::CVT_E4M3X4_F32X4_RS_SF, MVT::v4i8,
2968 CvtMode::RS | CvtMode::RELU_FLAG};
2969 case Intrinsic::nvvm_f32x4_to_e4m3x4_rs_satfinite:
2970 return {NVPTXISD::CVT_E4M3X4_F32X4_RS_SF, MVT::v4i8, CvtMode::RS};
2971 case Intrinsic::nvvm_f32x4_to_e5m2x4_rs_relu_satfinite:
2972 return {NVPTXISD::CVT_E5M2X4_F32X4_RS_SF, MVT::v4i8,
2973 CvtMode::RS | CvtMode::RELU_FLAG};
2974 case Intrinsic::nvvm_f32x4_to_e5m2x4_rs_satfinite:
2975 return {NVPTXISD::CVT_E5M2X4_F32X4_RS_SF, MVT::v4i8, CvtMode::RS};
2976 case Intrinsic::nvvm_f32x4_to_e2m3x4_rs_relu_satfinite:
2977 return {NVPTXISD::CVT_E2M3X4_F32X4_RS_SF, MVT::v4i8,
2978 CvtMode::RS | CvtMode::RELU_FLAG};
2979 case Intrinsic::nvvm_f32x4_to_e2m3x4_rs_satfinite:
2980 return {NVPTXISD::CVT_E2M3X4_F32X4_RS_SF, MVT::v4i8, CvtMode::RS};
2981 case Intrinsic::nvvm_f32x4_to_e3m2x4_rs_relu_satfinite:
2982 return {NVPTXISD::CVT_E3M2X4_F32X4_RS_SF, MVT::v4i8,
2983 CvtMode::RS | CvtMode::RELU_FLAG};
2984 case Intrinsic::nvvm_f32x4_to_e3m2x4_rs_satfinite:
2985 return {NVPTXISD::CVT_E3M2X4_F32X4_RS_SF, MVT::v4i8, CvtMode::RS};
2986 case Intrinsic::nvvm_f32x4_to_e2m1x4_rs_relu_satfinite:
2987 return {NVPTXISD::CVT_E2M1X4_F32X4_RS_SF, MVT::i16,
2988 CvtMode::RS | CvtMode::RELU_FLAG};
2989 case Intrinsic::nvvm_f32x4_to_e2m1x4_rs_satfinite:
2990 return {NVPTXISD::CVT_E2M1X4_F32X4_RS_SF, MVT::i16, CvtMode::RS};
2991 default:
2992 llvm_unreachable("unsupported/unhandled intrinsic");
2993 }
2994 }();
2995
2996 Ops.push_back(RBits);
2997 Ops.push_back(DAG.getConstant(CvtModeFlag, DL, MVT::i32));
2998
2999 return DAG.getNode(OpCode, DL, RetTy, Ops);
3000}
3001
3003 const unsigned Mode = [&]() {
3004 switch (Op->getConstantOperandVal(0)) {
3005 case Intrinsic::nvvm_prmt:
3007 case Intrinsic::nvvm_prmt_b4e:
3009 case Intrinsic::nvvm_prmt_ecl:
3011 case Intrinsic::nvvm_prmt_ecr:
3013 case Intrinsic::nvvm_prmt_f4e:
3015 case Intrinsic::nvvm_prmt_rc16:
3017 case Intrinsic::nvvm_prmt_rc8:
3019 default:
3020 llvm_unreachable("unsupported/unhandled intrinsic");
3021 }
3022 }();
3023 SDLoc DL(Op);
3024 SDValue A = Op->getOperand(1);
3025 SDValue B = Op.getNumOperands() == 4 ? Op.getOperand(2)
3026 : DAG.getConstant(0, DL, MVT::i32);
3027 SDValue Selector = (Op->op_end() - 1)->get();
3028 return getPRMT(A, B, Selector, DL, DAG, Mode);
3029}
3030
3031#define TCGEN05_LD_RED_INTR(SHAPE, NUM, TYPE) \
3032 Intrinsic::nvvm_tcgen05_ld_red_##SHAPE##_x##NUM##_##TYPE
3033
3034#define TCGEN05_LD_RED_INST(SHAPE, NUM, TYPE) \
3035 NVPTXISD::TCGEN05_LD_RED_##SHAPE##_X##NUM##_##TYPE
3036
3037static unsigned getTcgen05LdRedID(Intrinsic::ID IID) {
3038 switch (IID) {
3039 case TCGEN05_LD_RED_INTR(32x32b, 2, f32):
3040 return TCGEN05_LD_RED_INST(32x32b, 2, F32);
3041 case TCGEN05_LD_RED_INTR(32x32b, 4, f32):
3042 return TCGEN05_LD_RED_INST(32x32b, 4, F32);
3043 case TCGEN05_LD_RED_INTR(32x32b, 8, f32):
3044 return TCGEN05_LD_RED_INST(32x32b, 8, F32);
3045 case TCGEN05_LD_RED_INTR(32x32b, 16, f32):
3046 return TCGEN05_LD_RED_INST(32x32b, 16, F32);
3047 case TCGEN05_LD_RED_INTR(32x32b, 32, f32):
3048 return TCGEN05_LD_RED_INST(32x32b, 32, F32);
3049 case TCGEN05_LD_RED_INTR(32x32b, 64, f32):
3050 return TCGEN05_LD_RED_INST(32x32b, 64, F32);
3051 case TCGEN05_LD_RED_INTR(32x32b, 128, f32):
3052 return TCGEN05_LD_RED_INST(32x32b, 128, F32);
3053 case TCGEN05_LD_RED_INTR(16x32bx2, 2, f32):
3054 return TCGEN05_LD_RED_INST(16x32bx2, 2, F32);
3055 case TCGEN05_LD_RED_INTR(16x32bx2, 4, f32):
3056 return TCGEN05_LD_RED_INST(16x32bx2, 4, F32);
3057 case TCGEN05_LD_RED_INTR(16x32bx2, 8, f32):
3058 return TCGEN05_LD_RED_INST(16x32bx2, 8, F32);
3059 case TCGEN05_LD_RED_INTR(16x32bx2, 16, f32):
3060 return TCGEN05_LD_RED_INST(16x32bx2, 16, F32);
3061 case TCGEN05_LD_RED_INTR(16x32bx2, 32, f32):
3062 return TCGEN05_LD_RED_INST(16x32bx2, 32, F32);
3063 case TCGEN05_LD_RED_INTR(16x32bx2, 64, f32):
3064 return TCGEN05_LD_RED_INST(16x32bx2, 64, F32);
3065 case TCGEN05_LD_RED_INTR(16x32bx2, 128, f32):
3066 return TCGEN05_LD_RED_INST(16x32bx2, 128, F32);
3067 case TCGEN05_LD_RED_INTR(32x32b, 2, i32):
3068 return TCGEN05_LD_RED_INST(32x32b, 2, I32);
3069 case TCGEN05_LD_RED_INTR(32x32b, 4, i32):
3070 return TCGEN05_LD_RED_INST(32x32b, 4, I32);
3071 case TCGEN05_LD_RED_INTR(32x32b, 8, i32):
3072 return TCGEN05_LD_RED_INST(32x32b, 8, I32);
3073 case TCGEN05_LD_RED_INTR(32x32b, 16, i32):
3074 return TCGEN05_LD_RED_INST(32x32b, 16, I32);
3075 case TCGEN05_LD_RED_INTR(32x32b, 32, i32):
3076 return TCGEN05_LD_RED_INST(32x32b, 32, I32);
3077 case TCGEN05_LD_RED_INTR(32x32b, 64, i32):
3078 return TCGEN05_LD_RED_INST(32x32b, 64, I32);
3079 case TCGEN05_LD_RED_INTR(32x32b, 128, i32):
3080 return TCGEN05_LD_RED_INST(32x32b, 128, I32);
3081 case TCGEN05_LD_RED_INTR(16x32bx2, 2, i32):
3082 return TCGEN05_LD_RED_INST(16x32bx2, 2, I32);
3083 case TCGEN05_LD_RED_INTR(16x32bx2, 4, i32):
3084 return TCGEN05_LD_RED_INST(16x32bx2, 4, I32);
3085 case TCGEN05_LD_RED_INTR(16x32bx2, 8, i32):
3086 return TCGEN05_LD_RED_INST(16x32bx2, 8, I32);
3087 case TCGEN05_LD_RED_INTR(16x32bx2, 16, i32):
3088 return TCGEN05_LD_RED_INST(16x32bx2, 16, I32);
3089 case TCGEN05_LD_RED_INTR(16x32bx2, 32, i32):
3090 return TCGEN05_LD_RED_INST(16x32bx2, 32, I32);
3091 case TCGEN05_LD_RED_INTR(16x32bx2, 64, i32):
3092 return TCGEN05_LD_RED_INST(16x32bx2, 64, I32);
3093 case TCGEN05_LD_RED_INTR(16x32bx2, 128, i32):
3094 return TCGEN05_LD_RED_INST(16x32bx2, 128, I32);
3095 default:
3096 llvm_unreachable("Invalid tcgen05.ld.red intrinsic ID");
3097 }
3098}
3099
3100// Lower vector return type of tcgen05.ld intrinsics
3101static std::optional<std::tuple<SDValue, SDValue, SDValue>>
3103 SDLoc DL(N);
3104 EVT ResVT = N->getValueType(0);
3105 if (!ResVT.isVector())
3106 return {}; // already legalized.
3107
3108 const unsigned NumElts = ResVT.getVectorNumElements();
3109
3110 // Create the return type of the instructions
3111 // +1 represents the reduction value
3112 SmallVector<EVT, 132> ListVTs{
3113 NumElts + 1,
3114 ResVT.getVectorElementType().isFloatingPoint() ? MVT::f32 : MVT::i32};
3115
3116 ListVTs.push_back(MVT::Other); // Chain
3117
3118 SDVTList ResVTs = DAG.getVTList(ListVTs);
3119
3120 // Prepare the Operands
3121 SmallVector<SDValue, 8> Ops{N->getOperand(0)}; // Chain
3122
3123 // skip IID at index 1
3124 for (unsigned i = 2; i < N->getNumOperands(); i++)
3125 Ops.push_back(N->getOperand(i));
3126
3127 unsigned IID = cast<ConstantSDNode>(N->getOperand(1))->getZExtValue();
3129 SDValue NewNode =
3130 DAG.getMemIntrinsicNode(getTcgen05LdRedID(IID), DL, ResVTs, Ops,
3131 MemSD->getMemoryVT(), MemSD->getMemOperand());
3132
3133 // Split vector result
3134 SmallVector<SDValue, 132> ScalarRes;
3135 for (unsigned i = 0; i < NumElts; ++i) {
3136 SDValue Res = NewNode.getValue(i);
3137 ScalarRes.push_back(Res);
3138 }
3139
3140 SDValue BuildVector = DAG.getNode(ISD::BUILD_VECTOR, DL, ResVT, ScalarRes);
3141 SDValue RedResult = NewNode.getValue(NumElts);
3142 SDValue Chain = NewNode.getValue(NumElts + 1);
3143 return {{BuildVector, RedResult, Chain}};
3144}
3145
3147 switch (Op->getConstantOperandVal(1)) {
3148 default:
3149 return Op;
3150
3151 // These tcgen05 intrinsics return a v2i32, which is legal, so we have to
3152 // lower them through LowerOperation() instead of ReplaceNodeResults().
3153 case Intrinsic::nvvm_tcgen05_ld_16x64b_x2:
3154 case Intrinsic::nvvm_tcgen05_ld_16x128b_x1:
3155 case Intrinsic::nvvm_tcgen05_ld_32x32b_x2:
3156 if (auto Res = lowerTcgen05Ld(Op.getNode(), DAG))
3157 return DAG.getMergeValues({Res->first, Res->second}, SDLoc(Op));
3158 return SDValue();
3159
3160 case Intrinsic::nvvm_tcgen05_ld_16x32bx2_x2:
3161 if (auto Res = lowerTcgen05Ld(Op.getNode(), DAG, /*HasOffset=*/true))
3162 return DAG.getMergeValues({Res->first, Res->second}, SDLoc(Op));
3163 return SDValue();
3164
3165 case Intrinsic::nvvm_tcgen05_ld_red_32x32b_x2_f32:
3166 case Intrinsic::nvvm_tcgen05_ld_red_32x32b_x2_i32:
3167 case Intrinsic::nvvm_tcgen05_ld_red_16x32bx2_x2_f32:
3168 case Intrinsic::nvvm_tcgen05_ld_red_16x32bx2_x2_i32:
3169 if (auto Res = lowerTcgen05LdRed(Op.getNode(), DAG))
3170 return DAG.getMergeValues(
3171 {std::get<0>(*Res), std::get<1>(*Res), std::get<2>(*Res)}, SDLoc(Op));
3172 return SDValue();
3173 }
3174}
3175
3177 switch (Op->getConstantOperandVal(0)) {
3178 default:
3179 return Op;
3180 case Intrinsic::nvvm_prmt:
3181 case Intrinsic::nvvm_prmt_b4e:
3182 case Intrinsic::nvvm_prmt_ecl:
3183 case Intrinsic::nvvm_prmt_ecr:
3184 case Intrinsic::nvvm_prmt_f4e:
3185 case Intrinsic::nvvm_prmt_rc16:
3186 case Intrinsic::nvvm_prmt_rc8:
3187 return lowerPrmtIntrinsic(Op, DAG);
3188 case Intrinsic::nvvm_internal_addrspace_wrap:
3189 return Op.getOperand(1);
3190 case Intrinsic::nvvm_clusterlaunchcontrol_query_cancel_is_canceled:
3191 case Intrinsic::nvvm_clusterlaunchcontrol_query_cancel_get_first_ctaid_x:
3192 case Intrinsic::nvvm_clusterlaunchcontrol_query_cancel_get_first_ctaid_y:
3193 case Intrinsic::nvvm_clusterlaunchcontrol_query_cancel_get_first_ctaid_z:
3195 case Intrinsic::nvvm_f32x4_to_e4m3x4_rs_satfinite:
3196 case Intrinsic::nvvm_f32x4_to_e4m3x4_rs_relu_satfinite:
3197 case Intrinsic::nvvm_f32x4_to_e5m2x4_rs_satfinite:
3198 case Intrinsic::nvvm_f32x4_to_e5m2x4_rs_relu_satfinite:
3199 case Intrinsic::nvvm_f32x4_to_e2m3x4_rs_satfinite:
3200 case Intrinsic::nvvm_f32x4_to_e2m3x4_rs_relu_satfinite:
3201 case Intrinsic::nvvm_f32x4_to_e3m2x4_rs_satfinite:
3202 case Intrinsic::nvvm_f32x4_to_e3m2x4_rs_relu_satfinite:
3203 case Intrinsic::nvvm_f32x4_to_e2m1x4_rs_satfinite:
3204 case Intrinsic::nvvm_f32x4_to_e2m1x4_rs_relu_satfinite:
3205 return lowerCvtRSIntrinsics(Op, DAG);
3206 }
3207}
3208
3209// In PTX 64-bit CTLZ and CTPOP are supported, but they return a 32-bit value.
3210// Lower these into a node returning the correct type which is zero-extended
3211// back to the correct size.
3213 SDValue V = Op->getOperand(0);
3214 assert(V.getValueType() == MVT::i64 &&
3215 "Unexpected CTLZ/CTPOP type to legalize");
3216
3217 SDLoc DL(Op);
3218 SDValue CT = DAG.getNode(Op->getOpcode(), DL, MVT::i32, V);
3219 return DAG.getNode(ISD::ZERO_EXTEND, DL, MVT::i64, CT, SDNodeFlags::NonNeg);
3220}
3221
3223 unsigned Opcode, SelectionDAG &DAG) {
3224 assert(A.getValueType() == MVT::i64 && B.getValueType() == MVT::i64);
3225
3226 const auto *AmtConst = dyn_cast<ConstantSDNode>(ShiftAmount);
3227 if (!AmtConst)
3228 return SDValue();
3229 const auto Amt = AmtConst->getZExtValue() & 63;
3230
3231 SDValue UnpackA =
3232 DAG.getNode(NVPTXISD::UNPACK_VECTOR, DL, {MVT::i32, MVT::i32}, A);
3233 SDValue UnpackB =
3234 DAG.getNode(NVPTXISD::UNPACK_VECTOR, DL, {MVT::i32, MVT::i32}, B);
3235
3236 // Arch is Little endiain: 0 = low bits, 1 = high bits
3237 SDValue ALo = UnpackA.getValue(0);
3238 SDValue AHi = UnpackA.getValue(1);
3239 SDValue BLo = UnpackB.getValue(0);
3240 SDValue BHi = UnpackB.getValue(1);
3241
3242 // The bitfeild consists of { AHi : ALo : BHi : BLo }
3243 //
3244 // * FSHL, Amt < 32 - The window will contain { AHi : ALo : BHi }
3245 // * FSHL, Amt >= 32 - The window will contain { ALo : BHi : BLo }
3246 // * FSHR, Amt < 32 - The window will contain { ALo : BHi : BLo }
3247 // * FSHR, Amt >= 32 - The window will contain { AHi : ALo : BHi }
3248 //
3249 // Note that Amt = 0 and Amt = 32 are special cases where 32-bit funnel shifts
3250 // are not needed at all. Amt = 0 is a no-op producing either A or B depending
3251 // on the direction. Amt = 32 can be implemented by a packing and unpacking
3252 // move to select and arrange the 32bit values. For simplicity, these cases
3253 // are not handled here explicitly and instead we rely on DAGCombiner to
3254 // remove the no-op funnel shifts we insert.
3255 auto [High, Mid, Low] = ((Opcode == ISD::FSHL) == (Amt < 32))
3256 ? std::make_tuple(AHi, ALo, BHi)
3257 : std::make_tuple(ALo, BHi, BLo);
3258
3259 SDValue NewAmt = DAG.getConstant(Amt & 31, DL, MVT::i32);
3260 SDValue RHi = DAG.getNode(Opcode, DL, MVT::i32, {High, Mid, NewAmt});
3261 SDValue RLo = DAG.getNode(Opcode, DL, MVT::i32, {Mid, Low, NewAmt});
3262
3263 return DAG.getNode(NVPTXISD::BUILD_VECTOR, DL, MVT::i64, {RLo, RHi});
3264}
3265
3267 return expandFSH64(Op->getOperand(0), Op->getOperand(1), Op->getOperand(2),
3268 SDLoc(Op), Op->getOpcode(), DAG);
3269}
3270
3272 unsigned Opcode = Op->getOpcode() == ISD::ROTL ? ISD::FSHL : ISD::FSHR;
3273 return expandFSH64(Op->getOperand(0), Op->getOperand(0), Op->getOperand(1),
3274 SDLoc(Op), Opcode, DAG);
3275}
3276
3278 // Lower (frem x, y) into (sub x, (mul (ftrunc (div x, y)) y)),
3279 // i.e. "poor man's fmod()". When y is infinite, x is returned. This matches
3280 // the semantics of LLVM's frem.
3281 SDLoc DL(Op);
3282 SDValue X = Op->getOperand(0);
3283 SDValue Y = Op->getOperand(1);
3284 EVT Ty = Op.getValueType();
3285 SDNodeFlags Flags = Op->getFlags();
3286
3287 SDValue Div = DAG.getNode(ISD::FDIV, DL, Ty, X, Y, Flags);
3288 SDValue Trunc = DAG.getNode(ISD::FTRUNC, DL, Ty, Div, Flags);
3289 SDValue Mul = DAG.getNode(ISD::FMUL, DL, Ty, Trunc, Y,
3291 SDValue Sub = DAG.getNode(ISD::FSUB, DL, Ty, X, Mul,
3293
3294 if (Flags.hasNoInfs())
3295 return Sub;
3296
3297 // If Y is infinite, return X
3298 SDValue AbsY = DAG.getNode(ISD::FABS, DL, Ty, Y);
3299 SDValue Inf =
3300 DAG.getConstantFP(APFloat::getInf(Ty.getFltSemantics()), DL, Ty);
3301 SDValue IsInf = DAG.getSetCC(DL, MVT::i1, AbsY, Inf, ISD::SETEQ);
3302 return DAG.getSelect(DL, Ty, IsInf, X, Sub);
3303}
3304
3306 assert(Op.getValueType() == MVT::i1 && "Custom lowering enabled only for i1");
3307
3308 SDValue Cond = Op->getOperand(0);
3309 SDValue TrueVal = Op->getOperand(1);
3310 SDValue FalseVal = Op->getOperand(2);
3311 SDLoc DL(Op);
3312
3313 // If both operands are truncated, we push the select through the truncates.
3314 if (TrueVal.getOpcode() == ISD::TRUNCATE &&
3315 FalseVal.getOpcode() == ISD::TRUNCATE) {
3316 TrueVal = TrueVal.getOperand(0);
3317 FalseVal = FalseVal.getOperand(0);
3318
3319 EVT VT = TrueVal.getSimpleValueType().bitsLE(FalseVal.getSimpleValueType())
3320 ? TrueVal.getValueType()
3321 : FalseVal.getValueType();
3322 TrueVal = DAG.getAnyExtOrTrunc(TrueVal, DL, VT);
3323 FalseVal = DAG.getAnyExtOrTrunc(FalseVal, DL, VT);
3324 SDValue Select = DAG.getSelect(DL, VT, Cond, TrueVal, FalseVal);
3325 return DAG.getNode(ISD::TRUNCATE, DL, MVT::i1, Select);
3326 }
3327
3328 // Otherwise, expand the select into a series of logical operations. These
3329 // often can be folded into other operations either by us or ptxas.
3330 TrueVal = DAG.getFreeze(TrueVal);
3331 FalseVal = DAG.getFreeze(FalseVal);
3332 SDValue And1 = DAG.getNode(ISD::AND, DL, MVT::i1, Cond, TrueVal);
3333 SDValue NotCond = DAG.getNOT(DL, Cond, MVT::i1);
3334 SDValue And2 = DAG.getNode(ISD::AND, DL, MVT::i1, NotCond, FalseVal);
3335 SDValue Or = DAG.getNode(ISD::OR, DL, MVT::i1, And1, And2);
3336 return Or;
3337}
3338
3340 SDNode *N = Op.getNode();
3341
3342 SDValue Chain = N->getOperand(0);
3343 SDValue Val = N->getOperand(1);
3344 SDValue BasePtr = N->getOperand(2);
3345 SDValue Offset = N->getOperand(3);
3346 SDValue Mask = N->getOperand(4);
3347
3348 SDLoc DL(N);
3349 EVT ValVT = Val.getValueType();
3350 MemSDNode *MemSD = cast<MemSDNode>(N);
3351 assert(ValVT.isVector() && "Masked vector store must have vector type");
3352 assert(MemSD->getAlign() >= DAG.getEVTAlign(ValVT) &&
3353 "Unexpected alignment for masked store");
3354
3355 unsigned Opcode = 0;
3356 switch (ValVT.getSimpleVT().SimpleTy) {
3357 default:
3358 llvm_unreachable("Unexpected masked vector store type");
3359 case MVT::v4i64:
3360 case MVT::v4f64: {
3361 Opcode = NVPTXISD::StoreV4;
3362 break;
3363 }
3364 case MVT::v8i32:
3365 case MVT::v8f32: {
3366 Opcode = NVPTXISD::StoreV8;
3367 break;
3368 }
3369 }
3370
3372
3373 // Construct the new SDNode. First operand is the chain.
3374 Ops.push_back(Chain);
3375
3376 // The next N operands are the values to store. Encode the mask into the
3377 // values using the sentinel register 0 to represent a masked-off element.
3378 assert(Mask.getValueType().isVector() &&
3379 Mask.getValueType().getVectorElementType() == MVT::i1 &&
3380 "Mask must be a vector of i1");
3381 assert(Mask.getOpcode() == ISD::BUILD_VECTOR &&
3382 "Mask expected to be a BUILD_VECTOR");
3383 assert(Mask.getValueType().getVectorNumElements() ==
3384 ValVT.getVectorNumElements() &&
3385 "Mask size must be the same as the vector size");
3386 for (auto [I, Op] : enumerate(Mask->ops())) {
3387 // Mask elements must be constants.
3388 if (Op.getNode()->getAsZExtVal() == 0) {
3389 // Append a sentinel register 0 to the Ops vector to represent a masked
3390 // off element, this will be handled in tablegen
3392 ValVT.getVectorElementType()));
3393 } else {
3394 // Extract the element from the vector to store
3395 SDValue ExtVal =
3397 Val, DAG.getIntPtrConstant(I, DL));
3398 Ops.push_back(ExtVal);
3399 }
3400 }
3401
3402 // Next, the pointer operand.
3403 Ops.push_back(BasePtr);
3404
3405 // Finally, the offset operand. We expect this to always be undef, and it will
3406 // be ignored in lowering, but to mirror the handling of the other vector
3407 // store instructions we include it in the new SDNode.
3408 assert(Offset.getOpcode() == ISD::UNDEF &&
3409 "Offset operand expected to be undef");
3410 Ops.push_back(Offset);
3411
3412 SDValue NewSt =
3413 DAG.getMemIntrinsicNode(Opcode, DL, DAG.getVTList(MVT::Other), Ops,
3414 MemSD->getMemoryVT(), MemSD->getMemOperand());
3415
3416 return NewSt;
3417}
3418
3419SDValue
3421 switch (Op.getOpcode()) {
3422 case ISD::RETURNADDR:
3423 return SDValue();
3424 case ISD::FRAMEADDR:
3425 return SDValue();
3426 case ISD::ADDRSPACECAST:
3427 return LowerADDRSPACECAST(Op, DAG);
3429 return lowerIntrinsicWChain(Op, DAG);
3431 return lowerIntrinsicWOChain(Op, DAG);
3433 return lowerIntrinsicVoid(Op, DAG);
3434 case ISD::BUILD_VECTOR:
3435 return LowerBUILD_VECTOR(Op, DAG);
3436 case ISD::BITCAST:
3437 return LowerBITCAST(Op, DAG);
3439 return Op;
3441 return LowerEXTRACT_VECTOR_ELT(Op, DAG);
3443 return LowerINSERT_VECTOR_ELT(Op, DAG);
3445 return LowerVECTOR_SHUFFLE(Op, DAG);
3447 return LowerCONCAT_VECTORS(Op, DAG);
3452 return LowerVECREDUCE(Op, DAG);
3453 case ISD::STORE:
3454 return LowerSTORE(Op, DAG);
3455 case ISD::MSTORE: {
3456 assert(STI.has256BitVectorLoadStore(
3457 cast<MemSDNode>(Op.getNode())->getAddressSpace()) &&
3458 "Masked store vector not supported on subtarget.");
3459 return lowerMSTORE(Op, DAG);
3460 }
3461 case ISD::LOAD:
3462 return LowerLOAD(Op, DAG);
3463 case ISD::MLOAD:
3464 return LowerMLOAD(Op, DAG);
3465 case ISD::SHL_PARTS:
3466 return LowerShiftLeftParts(Op, DAG);
3467 case ISD::SRA_PARTS:
3468 case ISD::SRL_PARTS:
3469 return LowerShiftRightParts(Op, DAG);
3470 case ISD::SELECT:
3471 return lowerSELECT(Op, DAG);
3472 case ISD::FROUND:
3473 return LowerFROUND(Op, DAG);
3474 case ISD::FCOPYSIGN:
3475 return LowerFCOPYSIGN(Op, DAG);
3476 case ISD::SINT_TO_FP:
3477 case ISD::UINT_TO_FP:
3478 return LowerINT_TO_FP(Op, DAG);
3479 case ISD::FP_TO_SINT:
3480 case ISD::FP_TO_UINT:
3481 return LowerFP_TO_INT(Op, DAG);
3482 case ISD::FP_ROUND:
3483 return LowerFP_ROUND(Op, DAG);
3484 case ISD::FP_EXTEND:
3485 return LowerFP_EXTEND(Op, DAG);
3486 case ISD::VAARG:
3487 return LowerVAARG(Op, DAG);
3488 case ISD::VASTART:
3489 return LowerVASTART(Op, DAG);
3490 case ISD::FSHL:
3491 case ISD::FSHR:
3492 return lowerFSH(Op, DAG);
3493 case ISD::ROTL:
3494 case ISD::ROTR:
3495 return lowerROT(Op, DAG);
3496 case ISD::ABS:
3497 case ISD::SMIN:
3498 case ISD::SMAX:
3499 case ISD::UMIN:
3500 case ISD::UMAX:
3501 case ISD::ADD:
3502 case ISD::SUB:
3503 case ISD::MUL:
3504 case ISD::SHL:
3505 case ISD::SREM:
3506 case ISD::UREM:
3507 return LowerVectorArith(Op, DAG);
3509 return LowerDYNAMIC_STACKALLOC(Op, DAG);
3510 case ISD::STACKRESTORE:
3511 return LowerSTACKRESTORE(Op, DAG);
3512 case ISD::STACKSAVE:
3513 return LowerSTACKSAVE(Op, DAG);
3514 case ISD::CopyToReg:
3515 return LowerCopyToReg_128(Op, DAG);
3516 case ISD::FADD:
3517 case ISD::FSUB:
3518 case ISD::FMUL:
3519 // Used only for bf16 on SM80, where we select fma for non-ftz operation
3520 return PromoteBinOpIfF32FTZ(Op, DAG);
3521 case ISD::CTPOP:
3522 case ISD::CTLZ:
3523 return lowerCTLZCTPOP(Op, DAG);
3524 case ISD::FREM:
3525 return lowerFREM(Op, DAG);
3526 case ISD::BSWAP:
3527 return lowerBSWAP(Op, DAG);
3528 default:
3529 llvm_unreachable("Custom lowering not defined for operation");
3530 }
3531}
3532
3533// This will prevent AsmPrinter from trying to print the jump tables itself.
3537
3538SDValue NVPTXTargetLowering::LowerADDRSPACECAST(SDValue Op,
3539 SelectionDAG &DAG) const {
3541 unsigned SrcAS = N->getSrcAddressSpace();
3542 unsigned DestAS = N->getDestAddressSpace();
3543 if (SrcAS != llvm::ADDRESS_SPACE_GENERIC &&
3544 DestAS != llvm::ADDRESS_SPACE_GENERIC) {
3545 // Shared and SharedCluster can be converted to each other through generic
3546 // space
3547 if ((SrcAS == llvm::ADDRESS_SPACE_SHARED &&
3550 DestAS == llvm::ADDRESS_SPACE_SHARED)) {
3551 SDLoc DL(Op.getNode());
3552 const MVT GenerictVT =
3554 SDValue GenericConversion = DAG.getAddrSpaceCast(
3555 DL, GenerictVT, Op.getOperand(0), SrcAS, ADDRESS_SPACE_GENERIC);
3556 SDValue SharedClusterConversion =
3557 DAG.getAddrSpaceCast(DL, Op.getValueType(), GenericConversion,
3558 ADDRESS_SPACE_GENERIC, DestAS);
3559 return SharedClusterConversion;
3560 }
3561
3562 return DAG.getUNDEF(Op.getValueType());
3563 }
3564
3565 return Op;
3566}
3567
3568// This function is almost a copy of SelectionDAG::expandVAArg().
3569// The only diff is that this one produces loads from local address space.
3570SDValue NVPTXTargetLowering::LowerVAARG(SDValue Op, SelectionDAG &DAG) const {
3571 const TargetLowering *TLI = STI.getTargetLowering();
3572 SDLoc DL(Op);
3573
3574 SDNode *Node = Op.getNode();
3575 const Value *V = cast<SrcValueSDNode>(Node->getOperand(2))->getValue();
3576 EVT VT = Node->getValueType(0);
3577 auto *Ty = VT.getTypeForEVT(*DAG.getContext());
3578 SDValue Tmp1 = Node->getOperand(0);
3579 SDValue Tmp2 = Node->getOperand(1);
3580 const MaybeAlign MA(Node->getConstantOperandVal(3));
3581
3582 SDValue VAListLoad = DAG.getLoad(TLI->getPointerTy(DAG.getDataLayout()), DL,
3583 Tmp1, Tmp2, MachinePointerInfo(V));
3584 SDValue VAList = VAListLoad;
3585
3586 if (MA && *MA > TLI->getMinStackArgumentAlignment()) {
3587 VAList = DAG.getNode(
3588 ISD::ADD, DL, VAList.getValueType(), VAList,
3589 DAG.getConstant(MA->value() - 1, DL, VAList.getValueType()));
3590
3591 VAList = DAG.getNode(ISD::AND, DL, VAList.getValueType(), VAList,
3592 DAG.getSignedConstant(-(int64_t)MA->value(), DL,
3593 VAList.getValueType()));
3594 }
3595
3596 // Increment the pointer, VAList, to the next vaarg
3597 Tmp1 = DAG.getNode(ISD::ADD, DL, VAList.getValueType(), VAList,
3599 DL, VAList.getValueType()));
3600
3601 // Store the incremented VAList to the legalized pointer
3602 Tmp1 = DAG.getStore(VAListLoad.getValue(1), DL, Tmp1, Tmp2,
3603 MachinePointerInfo(V));
3604
3605 const Value *SrcV = Constant::getNullValue(
3607
3608 // Load the actual argument out of the pointer VAList
3609 return DAG.getLoad(VT, DL, Tmp1, VAList, MachinePointerInfo(SrcV));
3610}
3611
3612SDValue NVPTXTargetLowering::LowerVASTART(SDValue Op, SelectionDAG &DAG) const {
3613 const TargetLowering *TLI = STI.getTargetLowering();
3614 SDLoc DL(Op);
3615 EVT PtrVT = TLI->getPointerTy(DAG.getDataLayout());
3616
3617 // Store the address of unsized array <function>_vararg[] in the ap object.
3618 SDValue VAReg = getParamSymbol(DAG, /* vararg */ -1, PtrVT);
3619
3620 const Value *SV = cast<SrcValueSDNode>(Op.getOperand(2))->getValue();
3621 return DAG.getStore(Op.getOperand(0), DL, VAReg, Op.getOperand(1),
3622 MachinePointerInfo(SV));
3623}
3624
3625static std::pair<MemSDNode *, uint32_t>
3627 const NVPTXSubtarget &STI) {
3628 SDValue Chain = N->getOperand(0);
3629 SDValue BasePtr = N->getOperand(1);
3630 SDValue Mask = N->getOperand(3);
3631 [[maybe_unused]] SDValue Passthru = N->getOperand(4);
3632
3633 SDLoc DL(N);
3634 EVT ResVT = N->getValueType(0);
3635 assert(ResVT.isVector() && "Masked vector load must have vector type");
3636 // While we only expect poison passthru vectors as an input to the backend,
3637 // when the legalization framework splits a poison vector in half, it creates
3638 // two undef vectors, so we can technically expect those too.
3639 assert((Passthru.getOpcode() == ISD::POISON ||
3640 Passthru.getOpcode() == ISD::UNDEF) &&
3641 "Passthru operand expected to be poison or undef");
3642
3643 // Extract the mask and convert it to a uint32_t representing the used bytes
3644 // of the entire vector load
3645 uint32_t UsedBytesMask = 0;
3646 uint32_t ElementSizeInBits = ResVT.getVectorElementType().getSizeInBits();
3647 assert(ElementSizeInBits % 8 == 0 && "Unexpected element size");
3648 uint32_t ElementSizeInBytes = ElementSizeInBits / 8;
3649 uint32_t ElementMask = (1u << ElementSizeInBytes) - 1u;
3650
3651 for (SDValue Op : reverse(Mask->ops())) {
3652 // We technically only want to do this shift for every
3653 // iteration *but* the first, but in the first iteration UsedBytesMask is 0,
3654 // so this shift is a no-op.
3655 UsedBytesMask <<= ElementSizeInBytes;
3656
3657 // Mask elements must be constants.
3658 if (Op->getAsZExtVal() != 0)
3659 UsedBytesMask |= ElementMask;
3660 }
3661
3662 assert(UsedBytesMask != 0 && UsedBytesMask != UINT32_MAX &&
3663 "Unexpected masked load with elements masked all on or all off");
3664
3665 // Create a new load sd node to be handled normally by ReplaceLoadVector.
3666 MemSDNode *NewLD = cast<MemSDNode>(
3667 DAG.getLoad(ResVT, DL, Chain, BasePtr, N->getMemOperand()).getNode());
3668
3669 // If our subtarget does not support the used bytes mask pragma, "drop" the
3670 // mask by setting it to UINT32_MAX
3671 if (!STI.hasUsedBytesMaskPragma())
3672 UsedBytesMask = UINT32_MAX;
3673
3674 return {NewLD, UsedBytesMask};
3675}
3676
3677/// replaceLoadVector - Convert vector loads into multi-output scalar loads.
3678static std::optional<std::pair<SDValue, SDValue>>
3681 const EVT ResVT = LD->getValueType(0);
3682 const EVT MemVT = LD->getMemoryVT();
3683
3684 // If we're doing sign/zero extension as part of the load, avoid lowering to
3685 // a LoadV node. TODO: consider relaxing this restriction.
3686 if (ResVT != MemVT)
3687 return std::nullopt;
3688
3689 const auto NumEltsAndEltVT =
3690 getVectorLoweringShape(ResVT, STI, LD->getAddressSpace());
3691 if (!NumEltsAndEltVT)
3692 return std::nullopt;
3693 const auto [NumElts, EltVT] = NumEltsAndEltVT.value();
3694
3695 Align Alignment = LD->getAlign();
3696 const auto &TD = DAG.getDataLayout();
3697 Align PrefAlign = TD.getPrefTypeAlign(MemVT.getTypeForEVT(*DAG.getContext()));
3698 if (Alignment < PrefAlign) {
3699 // This load is not sufficiently aligned, so bail out and let this vector
3700 // load be scalarized. Note that we may still be able to emit smaller
3701 // vector loads. For example, if we are loading a <4 x float> with an
3702 // alignment of 8, this check will fail but the legalizer will try again
3703 // with 2 x <2 x float>, which will succeed with an alignment of 8.
3704 return std::nullopt;
3705 }
3706
3707 // If we have a masked load, convert it to a normal load now
3708 std::optional<uint32_t> UsedBytesMask = std::nullopt;
3709 if (LD->getOpcode() == ISD::MLOAD)
3710 std::tie(LD, UsedBytesMask) =
3712
3713 // Since LoadV2 is a target node, we cannot rely on DAG type legalization.
3714 // Therefore, we must ensure the type is legal. For i1 and i8, we set the
3715 // loaded type to i16 and propagate the "real" type as the memory type.
3716 const MVT LoadEltVT = (EltVT.getSizeInBits() < 16) ? MVT::i16 : EltVT;
3717
3718 unsigned Opcode;
3719 switch (NumElts) {
3720 default:
3721 return std::nullopt;
3722 case 2:
3723 Opcode = NVPTXISD::LoadV2;
3724 break;
3725 case 4:
3726 Opcode = NVPTXISD::LoadV4;
3727 break;
3728 case 8:
3729 Opcode = NVPTXISD::LoadV8;
3730 break;
3731 }
3732 auto ListVTs = SmallVector<EVT, 9>(NumElts, LoadEltVT);
3733 ListVTs.push_back(MVT::Other);
3734 SDVTList LdResVTs = DAG.getVTList(ListVTs);
3735
3736 SDLoc DL(LD);
3737
3738 // Copy regular operands
3739 SmallVector<SDValue, 8> OtherOps(LD->ops());
3740
3741 OtherOps.push_back(
3742 DAG.getConstant(UsedBytesMask.value_or(UINT32_MAX), DL, MVT::i32));
3743
3744 // The select routine does not have access to the LoadSDNode instance, so
3745 // pass along the extension information
3746 OtherOps.push_back(
3747 DAG.getIntPtrConstant(cast<LoadSDNode>(LD)->getExtensionType(), DL));
3748
3749 SDValue NewLD = DAG.getMemIntrinsicNode(Opcode, DL, LdResVTs, OtherOps, MemVT,
3750 LD->getMemOperand());
3751
3752 SmallVector<SDValue> ScalarRes;
3753 if (EltVT.isVector()) {
3755 assert(NumElts * EltVT.getVectorNumElements() ==
3756 ResVT.getVectorNumElements());
3757 // Generate EXTRACT_VECTOR_ELTs to split v2[i,f,bf]16/v4i8 subvectors back
3758 // into individual elements.
3759 for (const unsigned I : llvm::seq(NumElts)) {
3760 SDValue SubVector = NewLD.getValue(I);
3761 DAG.ExtractVectorElements(SubVector, ScalarRes);
3762 }
3763 } else {
3764 for (const unsigned I : llvm::seq(NumElts)) {
3765 SDValue Res = NewLD.getValue(I);
3766 if (LoadEltVT != EltVT)
3767 Res = DAG.getNode(ISD::TRUNCATE, DL, EltVT, Res);
3768 ScalarRes.push_back(Res);
3769 }
3770 }
3771
3772 SDValue LoadChain = NewLD.getValue(NumElts);
3773
3774 const MVT BuildVecVT =
3775 MVT::getVectorVT(EltVT.getScalarType(), ScalarRes.size());
3776 SDValue BuildVec = DAG.getBuildVector(BuildVecVT, DL, ScalarRes);
3777 SDValue LoadValue = DAG.getBitcast(ResVT, BuildVec);
3778
3779 return {{LoadValue, LoadChain}};
3780}
3781
3784 const NVPTXSubtarget &STI) {
3785 if (auto Res = replaceLoadVector(N, DAG, STI))
3786 Results.append({Res->first, Res->second});
3787}
3788
3790 const NVPTXSubtarget &STI) {
3791 if (auto Res = replaceLoadVector(N, DAG, STI))
3792 return DAG.getMergeValues({Res->first, Res->second}, SDLoc(N));
3793 return SDValue();
3794}
3795
3796// v = ld i1* addr
3797// =>
3798// v1 = ld i8* addr (-> i16)
3799// v = trunc i16 to i1
3801 SDLoc dl(LD);
3802 assert(LD->getExtensionType() == ISD::NON_EXTLOAD);
3803 assert(LD->getValueType(0) == MVT::i1 && "Custom lowering for i1 load only");
3804 SDValue newLD = DAG.getExtLoad(ISD::ZEXTLOAD, dl, MVT::i16, LD->getChain(),
3805 LD->getBasePtr(), LD->getPointerInfo(),
3806 MVT::i8, LD->getAlign(),
3807 LD->getMemOperand()->getFlags());
3808 SDValue result = DAG.getNode(ISD::TRUNCATE, dl, MVT::i1, newLD);
3809 // The legalizer (the caller) is expecting two values from the legalized
3810 // load, so we build a MergeValues node for it. See ExpandUnalignedLoad()
3811 // in LegalizeDAG.cpp which also uses MergeValues.
3812 return DAG.getMergeValues({result, LD->getChain()}, dl);
3813}
3814
3815SDValue NVPTXTargetLowering::LowerLOAD(SDValue Op, SelectionDAG &DAG) const {
3816 LoadSDNode *LD = cast<LoadSDNode>(Op);
3817
3818 if (Op.getValueType() == MVT::i1)
3819 return lowerLOADi1(LD, DAG);
3820
3821 // To improve CodeGen we'll legalize any-extend loads to zext loads. This is
3822 // how they'll be lowered in ISel anyway, and by doing this a little earlier
3823 // we allow for more DAG combine opportunities.
3824 if (LD->getExtensionType() == ISD::EXTLOAD) {
3825 assert(LD->getValueType(0).isInteger() && LD->getMemoryVT().isInteger() &&
3826 "Unexpected fpext-load");
3827 return DAG.getExtLoad(ISD::ZEXTLOAD, SDLoc(Op), Op.getValueType(),
3828 LD->getChain(), LD->getBasePtr(), LD->getMemoryVT(),
3829 LD->getMemOperand());
3830 }
3831
3832 llvm_unreachable("Unexpected custom lowering for load");
3833}
3834
3835SDValue NVPTXTargetLowering::LowerMLOAD(SDValue Op, SelectionDAG &DAG) const {
3836 // v2f16/v2bf16/v2i16/v4i8 are legal, so we can't rely on legalizer to handle
3837 // masked loads of these types and have to handle them here.
3838 // v2f32 also needs to be handled here if the subtarget has f32x2
3839 // instructions, making it legal.
3840 //
3841 // Note: misaligned masked loads should never reach this point
3842 // because the override of isLegalMaskedLoad in NVPTXTargetTransformInfo.cpp
3843 // will validate alignment. Therefore, we do not need to special case handle
3844 // them here.
3845 EVT VT = Op.getValueType();
3846 if (NVPTX::isPackedVectorTy(VT)) {
3848 cast<MemSDNode>(Op.getNode()), DAG, STI);
3849 MemSDNode *LD = std::get<0>(Result);
3850 uint32_t UsedBytesMask = std::get<1>(Result);
3851
3852 SDLoc DL(LD);
3853
3854 // Copy regular operands
3855 SmallVector<SDValue, 8> OtherOps(LD->ops());
3856
3857 OtherOps.push_back(DAG.getConstant(UsedBytesMask, DL, MVT::i32));
3858
3859 // We currently are not lowering extending loads, but pass the extension
3860 // type anyway as later handling expects it.
3861 OtherOps.push_back(
3862 DAG.getIntPtrConstant(cast<LoadSDNode>(LD)->getExtensionType(), DL));
3863 SDValue NewLD =
3864 DAG.getMemIntrinsicNode(NVPTXISD::MLoad, DL, LD->getVTList(), OtherOps,
3865 LD->getMemoryVT(), LD->getMemOperand());
3866 return NewLD;
3867 }
3868 return SDValue();
3869}
3870
3872 const NVPTXSubtarget &STI) {
3873 MemSDNode *N = cast<MemSDNode>(Op.getNode());
3874 SDValue Val = N->getOperand(1);
3875 SDLoc DL(N);
3876 const EVT ValVT = Val.getValueType();
3877 const EVT MemVT = N->getMemoryVT();
3878
3879 // If we're truncating as part of the store, avoid lowering to a StoreV node.
3880 // TODO: consider relaxing this restriction.
3881 if (ValVT != MemVT)
3882 return SDValue();
3883
3884 const auto NumEltsAndEltVT =
3885 getVectorLoweringShape(ValVT, STI, N->getAddressSpace());
3886 if (!NumEltsAndEltVT)
3887 return SDValue();
3888 const auto [NumElts, EltVT] = NumEltsAndEltVT.value();
3889
3890 const DataLayout &TD = DAG.getDataLayout();
3891
3892 Align Alignment = N->getAlign();
3893 Align PrefAlign = TD.getPrefTypeAlign(ValVT.getTypeForEVT(*DAG.getContext()));
3894 if (Alignment < PrefAlign) {
3895 // This store is not sufficiently aligned, so bail out and let this vector
3896 // store be scalarized. Note that we may still be able to emit smaller
3897 // vector stores. For example, if we are storing a <4 x float> with an
3898 // alignment of 8, this check will fail but the legalizer will try again
3899 // with 2 x <2 x float>, which will succeed with an alignment of 8.
3900 return SDValue();
3901 }
3902
3903 unsigned Opcode;
3904 switch (NumElts) {
3905 default:
3906 return SDValue();
3907 case 2:
3908 Opcode = NVPTXISD::StoreV2;
3909 break;
3910 case 4:
3911 Opcode = NVPTXISD::StoreV4;
3912 break;
3913 case 8:
3914 Opcode = NVPTXISD::StoreV8;
3915 break;
3916 }
3917
3919
3920 // First is the chain
3921 Ops.push_back(N->getOperand(0));
3922
3923 // Then the split values
3924 if (EltVT.isVector()) {
3926 assert(NumElts * EltVT.getVectorNumElements() ==
3927 ValVT.getVectorNumElements());
3928 // Combine individual elements into v2[i,f,bf]16/v4i8 subvectors to be
3929 // stored as b32s
3930 const unsigned NumEltsPerSubVector = EltVT.getVectorNumElements();
3931 for (const unsigned I : llvm::seq(NumElts)) {
3932 SmallVector<SDValue, 4> SubVectorElts;
3933 DAG.ExtractVectorElements(Val, SubVectorElts, I * NumEltsPerSubVector,
3934 NumEltsPerSubVector);
3935 Ops.push_back(DAG.getBuildVector(EltVT, DL, SubVectorElts));
3936 }
3937 } else {
3938 SDValue V = DAG.getBitcast(MVT::getVectorVT(EltVT, NumElts), Val);
3939 for (const unsigned I : llvm::seq(NumElts)) {
3940 SDValue ExtVal = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, DL, EltVT, V,
3941 DAG.getIntPtrConstant(I, DL));
3942
3943 // Since StoreV2 is a target node, we cannot rely on DAG type
3944 // legalization. Therefore, we must ensure the type is legal. For i1 and
3945 // i8, we set the stored type to i16 and propagate the "real" type as the
3946 // memory type.
3947 if (EltVT.getSizeInBits() < 16)
3948 ExtVal = DAG.getNode(ISD::ANY_EXTEND, DL, MVT::i16, ExtVal);
3949 Ops.push_back(ExtVal);
3950 }
3951 }
3952
3953 // Then any remaining arguments
3954 Ops.append(N->op_begin() + 2, N->op_end());
3955
3956 SDValue NewSt =
3957 DAG.getMemIntrinsicNode(Opcode, DL, DAG.getVTList(MVT::Other), Ops,
3958 N->getMemoryVT(), N->getMemOperand());
3959
3960 // return DCI.CombineTo(N, NewSt, true);
3961 return NewSt;
3962}
3963
3964SDValue NVPTXTargetLowering::LowerSTORE(SDValue Op, SelectionDAG &DAG) const {
3965 StoreSDNode *Store = cast<StoreSDNode>(Op);
3966 EVT VT = Store->getMemoryVT();
3967
3968 if (VT == MVT::i1)
3969 return LowerSTOREi1(Op, DAG);
3970
3971 // Lower store of any other vector type, including v2f32 as we want to break
3972 // it apart since this is not a widely-supported type.
3973 return lowerSTOREVector(Op, DAG, STI);
3974}
3975
3976// st i1 v, addr
3977// =>
3978// v1 = zxt v to i16
3979// st.u8 i16, addr
3980SDValue NVPTXTargetLowering::LowerSTOREi1(SDValue Op, SelectionDAG &DAG) const {
3981 SDNode *Node = Op.getNode();
3982 SDLoc dl(Node);
3983 StoreSDNode *ST = cast<StoreSDNode>(Node);
3984 SDValue Tmp1 = ST->getChain();
3985 SDValue Tmp2 = ST->getBasePtr();
3986 SDValue Tmp3 = ST->getValue();
3987 assert(Tmp3.getValueType() == MVT::i1 && "Custom lowering for i1 store only");
3988 Tmp3 = DAG.getNode(ISD::ZERO_EXTEND, dl, MVT::i16, Tmp3);
3989 SDValue Result =
3990 DAG.getTruncStore(Tmp1, dl, Tmp3, Tmp2, ST->getPointerInfo(), MVT::i8,
3991 ST->getAlign(), ST->getMemOperand()->getFlags());
3992 return Result;
3993}
3994
3995SDValue NVPTXTargetLowering::LowerCopyToReg_128(SDValue Op,
3996 SelectionDAG &DAG) const {
3997 // Change the CopyToReg to take in two 64-bit operands instead of a 128-bit
3998 // operand so that it can pass the legalization.
3999
4000 assert(Op.getOperand(1).getValueType() == MVT::i128 &&
4001 "Custom lowering for 128-bit CopyToReg only");
4002
4003 SDNode *Node = Op.getNode();
4004 SDLoc DL(Node);
4005
4006 SDValue Cast = DAG.getBitcast(MVT::v2i64, Op->getOperand(2));
4007 SDValue Lo = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, DL, MVT::i64, Cast,
4008 DAG.getIntPtrConstant(0, DL));
4009 SDValue Hi = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, DL, MVT::i64, Cast,
4010 DAG.getIntPtrConstant(1, DL));
4011
4013 SmallVector<EVT, 3> ResultsType(Node->values());
4014
4015 NewOps[0] = Op->getOperand(0); // Chain
4016 NewOps[1] = Op->getOperand(1); // Dst Reg
4017 NewOps[2] = Lo; // Lower 64-bit
4018 NewOps[3] = Hi; // Higher 64-bit
4019 if (Op.getNumOperands() == 4)
4020 NewOps[4] = Op->getOperand(3); // Glue if exists
4021
4022 return DAG.getNode(ISD::CopyToReg, DL, ResultsType, NewOps);
4023}
4024
4025unsigned NVPTXTargetLowering::getNumRegisters(
4026 LLVMContext &Context, EVT VT,
4027 std::optional<MVT> RegisterVT = std::nullopt) const {
4028 if (VT == MVT::i128 && RegisterVT == MVT::i128)
4029 return 1;
4030 return TargetLoweringBase::getNumRegisters(Context, VT, RegisterVT);
4031}
4032
4033bool NVPTXTargetLowering::splitValueIntoRegisterParts(
4034 SelectionDAG &DAG, const SDLoc &DL, SDValue Val, SDValue *Parts,
4035 unsigned NumParts, MVT PartVT, std::optional<CallingConv::ID> CC) const {
4036 if (Val.getValueType() == MVT::i128 && NumParts == 1) {
4037 Parts[0] = Val;
4038 return true;
4039 }
4040 return false;
4041}
4042
4043// This creates target external symbol for a function parameter.
4044// Name of the symbol is composed from its index and the function name.
4045// Negative index corresponds to special parameter (unsized array) used for
4046// passing variable arguments.
4047SDValue NVPTXTargetLowering::getParamSymbol(SelectionDAG &DAG, int I,
4048 EVT T) const {
4049 StringRef SavedStr = nvTM->getStrPool().save(
4051 return DAG.getExternalSymbol(SavedStr.data(), T);
4052}
4053
4054SDValue NVPTXTargetLowering::getCallParamSymbol(SelectionDAG &DAG, int I,
4055 EVT T) const {
4056 const StringRef SavedStr = nvTM->getStrPool().save("param" + Twine(I));
4057 return DAG.getExternalSymbol(SavedStr.data(), T);
4058}
4059
4061 SDValue Chain, CallingConv::ID CallConv, bool isVarArg,
4062 const SmallVectorImpl<ISD::InputArg> &Ins, const SDLoc &dl,
4063 SelectionDAG &DAG, SmallVectorImpl<SDValue> &InVals) const {
4064 const DataLayout &DL = DAG.getDataLayout();
4065 LLVMContext &Ctx = *DAG.getContext();
4066 auto PtrVT = getPointerTy(DAG.getDataLayout());
4067
4068 const Function &F = DAG.getMachineFunction().getFunction();
4069
4070 SDValue Root = DAG.getRoot();
4071 SmallVector<SDValue, 16> OutChains;
4072
4073 // argTypes.size() (or theArgs.size()) and Ins.size() need not match.
4074 // Ins.size() will be larger
4075 // * if there is an aggregate argument with multiple fields (each field
4076 // showing up separately in Ins)
4077 // * if there is a vector argument with more than typical vector-length
4078 // elements (generally if more than 4) where each vector element is
4079 // individually present in Ins.
4080 // So a different index should be used for indexing into Ins.
4081 // See similar issue in LowerCall.
4082
4083 auto AllIns = ArrayRef(Ins);
4084 for (const auto &Arg : F.args()) {
4085 const auto ArgIns = AllIns.take_while(
4086 [&](auto I) { return I.OrigArgIndex == Arg.getArgNo(); });
4087 AllIns = AllIns.drop_front(ArgIns.size());
4088
4089 Type *Ty = Arg.getType();
4090
4091 if (ArgIns.empty())
4092 report_fatal_error("Empty parameter types are not supported");
4093
4094 if (Arg.use_empty()) {
4095 // argument is dead
4096 for (const auto &In : ArgIns) {
4097 assert(!In.Used && "Arg.use_empty() is true but Arg is used?");
4098 InVals.push_back(DAG.getUNDEF(In.VT));
4099 }
4100 continue;
4101 }
4102
4103 SDValue ArgSymbol = getParamSymbol(DAG, Arg.getArgNo(), PtrVT);
4104
4105 // In the following cases, assign a node order of "i+1"
4106 // to newly created nodes. The SDNodes for params have to
4107 // appear in the same order as their order of appearance
4108 // in the original function. "i+1" holds that order.
4109 if (Arg.hasByValAttr()) {
4110 // Param has ByVal attribute
4111 // Return MoveParam(param symbol).
4112 // Ideally, the param symbol can be returned directly,
4113 // but when SDNode builder decides to use it in a CopyToReg(),
4114 // machine instruction fails because TargetExternalSymbol
4115 // (not lowered) is target dependent, and CopyToReg assumes
4116 // the source is lowered.
4117 assert(ArgIns.size() == 1 && "ByVal argument must be a pointer");
4118 const auto &ByvalIn = ArgIns[0];
4119 assert(getValueType(DL, Ty) == ByvalIn.VT &&
4120 "Ins type did not match function type");
4121 assert(ByvalIn.VT == PtrVT && "ByVal argument must be a pointer");
4122
4123 SDValue P;
4124 if (isKernelFunction(F)) {
4125 assert(isParamGridConstant(Arg) && "ByVal argument must be lowered to "
4126 "grid_constant by NVPTXLowerArgs");
4127 P = ArgSymbol;
4128 P.getNode()->setIROrder(Arg.getArgNo() + 1);
4129 } else {
4130 P = DAG.getNode(NVPTXISD::MoveParam, dl, ByvalIn.VT, ArgSymbol);
4131 P.getNode()->setIROrder(Arg.getArgNo() + 1);
4132 P = DAG.getAddrSpaceCast(dl, ByvalIn.VT, P, ADDRESS_SPACE_LOCAL,
4134 }
4135 InVals.push_back(P);
4136 } else {
4139 ComputePTXValueVTs(*this, DL, Ctx, CallConv, Ty, VTs, Offsets);
4140 assert(VTs.size() == ArgIns.size() && "Size mismatch");
4141 assert(VTs.size() == Offsets.size() && "Size mismatch");
4142
4143 const Align ArgAlign = getFunctionArgumentAlignment(
4144 &F, Ty, Arg.getArgNo() + AttributeList::FirstArgIndex, DL);
4145
4146 unsigned I = 0;
4147 const auto VI = VectorizePTXValueVTs(VTs, Offsets, ArgAlign);
4148 for (const unsigned NumElts : VI) {
4149 // i1 is loaded/stored as i8
4150 const EVT LoadVT = VTs[I] == MVT::i1 ? MVT::i8 : VTs[I];
4151 const EVT VecVT = getVectorizedVT(LoadVT, NumElts, Ctx);
4152
4153 SDValue VecAddr = DAG.getObjectPtrOffset(
4154 dl, ArgSymbol, TypeSize::getFixed(Offsets[I]));
4155
4156 const Align PartAlign = commonAlignment(ArgAlign, Offsets[I]);
4157 SDValue P =
4158 DAG.getLoad(VecVT, dl, Root, VecAddr,
4162 P.getNode()->setIROrder(Arg.getArgNo() + 1);
4163 for (const unsigned J : llvm::seq(NumElts)) {
4164 SDValue Elt = getExtractVectorizedValue(P, J, LoadVT, dl, DAG);
4165
4166 Elt = correctParamType(Elt, ArgIns[I + J].VT, ArgIns[I + J].Flags,
4167 DAG, dl);
4168 InVals.push_back(Elt);
4169 }
4170 I += NumElts;
4171 }
4172 }
4173 }
4174
4175 if (!OutChains.empty())
4176 DAG.setRoot(DAG.getTokenFactor(dl, OutChains));
4177
4178 return Chain;
4179}
4180
4181SDValue
4183 bool isVarArg,
4185 const SmallVectorImpl<SDValue> &OutVals,
4186 const SDLoc &dl, SelectionDAG &DAG) const {
4187 const Function &F = DAG.getMachineFunction().getFunction();
4188 Type *RetTy = F.getReturnType();
4189
4190 if (RetTy->isVoidTy()) {
4191 assert(OutVals.empty() && Outs.empty() && "Return value expected for void");
4192 return DAG.getNode(NVPTXISD::RET_GLUE, dl, MVT::Other, Chain);
4193 }
4194
4195 const DataLayout &DL = DAG.getDataLayout();
4196 LLVMContext &Ctx = *DAG.getContext();
4197
4198 const SDValue RetSymbol = DAG.getExternalSymbol("func_retval0", MVT::i32);
4199 const auto RetAlign = getFunctionParamOptimizedAlign(&F, RetTy, DL);
4200
4201 // PTX Interoperability Guide 3.3(A): [Integer] Values shorter than
4202 // 32-bits are sign extended or zero extended, depending on whether
4203 // they are signed or unsigned types.
4204 const bool ExtendIntegerRetVal =
4205 RetTy->isIntegerTy() && DL.getTypeAllocSizeInBits(RetTy) < 32;
4206
4209 ComputePTXValueVTs(*this, DL, Ctx, CallConv, RetTy, VTs, Offsets);
4210 assert(VTs.size() == OutVals.size() && "Bad return value decomposition");
4211
4212 const auto GetRetVal = [&](unsigned I) -> SDValue {
4213 SDValue RetVal = OutVals[I];
4215 RetVal.getValueType() &&
4216 "OutVal type should always be legal");
4217
4218 const EVT VTI = promoteScalarIntegerPTX(VTs[I]);
4219 const EVT StoreVT =
4220 ExtendIntegerRetVal ? MVT::i32 : (VTI == MVT::i1 ? MVT::i8 : VTI);
4221 return correctParamType(RetVal, StoreVT, Outs[I].Flags, DAG, dl);
4222 };
4223
4224 unsigned I = 0;
4225 const auto VI = VectorizePTXValueVTs(VTs, Offsets, RetAlign);
4226 for (const unsigned NumElts : VI) {
4227 const MaybeAlign CurrentAlign = ExtendIntegerRetVal
4228 ? MaybeAlign(std::nullopt)
4229 : commonAlignment(RetAlign, Offsets[I]);
4230
4232 NumElts, dl, DAG, [&](unsigned K) { return GetRetVal(I + K); });
4233
4234 SDValue Ptr =
4235 DAG.getObjectPtrOffset(dl, RetSymbol, TypeSize::getFixed(Offsets[I]));
4236
4237 Chain = DAG.getStore(Chain, dl, Val, Ptr,
4239
4240 I += NumElts;
4241 }
4242
4243 return DAG.getNode(NVPTXISD::RET_GLUE, dl, MVT::Other, Chain);
4244}
4245
4247 SDValue Op, StringRef Constraint, std::vector<SDValue> &Ops,
4248 SelectionDAG &DAG) const {
4249 if (Constraint.size() > 1)
4250 return;
4252}
4253
4254// llvm.ptx.memcpy.const and llvm.ptx.memmove.const need to be modeled as
4255// TgtMemIntrinsic
4256// because we need the information that is only available in the "Value" type
4257// of destination
4258// pointer. In particular, the address space information.
4261 MachineFunction &MF, unsigned Intrinsic) const {
4262 IntrinsicInfo Info;
4263 switch (Intrinsic) {
4264 default:
4265 return;
4266 case Intrinsic::nvvm_match_all_sync_i32p:
4267 case Intrinsic::nvvm_match_all_sync_i64p:
4268 Info.opc = ISD::INTRINSIC_W_CHAIN;
4269 // memVT is bogus. These intrinsics have IntrInaccessibleMemOnly attribute
4270 // in order to model data exchange with other threads, but perform no real
4271 // memory accesses.
4272 Info.memVT = MVT::i1;
4273
4274 // Our result depends on both our and other thread's arguments.
4276 Infos.push_back(Info);
4277 return;
4278 case Intrinsic::nvvm_wmma_m16n16k16_load_a_f16_col:
4279 case Intrinsic::nvvm_wmma_m16n16k16_load_a_f16_row:
4280 case Intrinsic::nvvm_wmma_m16n16k16_load_a_f16_col_stride:
4281 case Intrinsic::nvvm_wmma_m16n16k16_load_a_f16_row_stride:
4282 case Intrinsic::nvvm_wmma_m16n16k16_load_b_f16_col:
4283 case Intrinsic::nvvm_wmma_m16n16k16_load_b_f16_row:
4284 case Intrinsic::nvvm_wmma_m16n16k16_load_b_f16_col_stride:
4285 case Intrinsic::nvvm_wmma_m16n16k16_load_b_f16_row_stride:
4286 case Intrinsic::nvvm_wmma_m32n8k16_load_a_f16_col:
4287 case Intrinsic::nvvm_wmma_m32n8k16_load_a_f16_row:
4288 case Intrinsic::nvvm_wmma_m32n8k16_load_a_f16_col_stride:
4289 case Intrinsic::nvvm_wmma_m32n8k16_load_a_f16_row_stride:
4290 case Intrinsic::nvvm_wmma_m32n8k16_load_b_f16_col:
4291 case Intrinsic::nvvm_wmma_m32n8k16_load_b_f16_row:
4292 case Intrinsic::nvvm_wmma_m32n8k16_load_b_f16_col_stride:
4293 case Intrinsic::nvvm_wmma_m32n8k16_load_b_f16_row_stride:
4294 case Intrinsic::nvvm_wmma_m8n32k16_load_a_f16_col:
4295 case Intrinsic::nvvm_wmma_m8n32k16_load_a_f16_row:
4296 case Intrinsic::nvvm_wmma_m8n32k16_load_a_f16_col_stride:
4297 case Intrinsic::nvvm_wmma_m8n32k16_load_a_f16_row_stride:
4298 case Intrinsic::nvvm_wmma_m8n32k16_load_b_f16_col:
4299 case Intrinsic::nvvm_wmma_m8n32k16_load_b_f16_row:
4300 case Intrinsic::nvvm_wmma_m8n32k16_load_b_f16_col_stride:
4301 case Intrinsic::nvvm_wmma_m8n32k16_load_b_f16_row_stride: {
4302 Info.opc = ISD::INTRINSIC_W_CHAIN;
4303 Info.memVT = MVT::v8f16;
4304 Info.ptrVal = I.getArgOperand(0);
4305 Info.offset = 0;
4306 Info.flags = MachineMemOperand::MOLoad;
4307 Info.align = Align(16);
4308 Infos.push_back(Info);
4309 return;
4310 }
4311 case Intrinsic::nvvm_wmma_m16n16k16_load_a_s8_col:
4312 case Intrinsic::nvvm_wmma_m16n16k16_load_a_s8_col_stride:
4313 case Intrinsic::nvvm_wmma_m16n16k16_load_a_u8_col_stride:
4314 case Intrinsic::nvvm_wmma_m16n16k16_load_a_u8_col:
4315 case Intrinsic::nvvm_wmma_m16n16k16_load_a_s8_row:
4316 case Intrinsic::nvvm_wmma_m16n16k16_load_a_s8_row_stride:
4317 case Intrinsic::nvvm_wmma_m16n16k16_load_a_u8_row_stride:
4318 case Intrinsic::nvvm_wmma_m16n16k16_load_a_u8_row:
4319 case Intrinsic::nvvm_wmma_m8n32k16_load_a_bf16_col:
4320 case Intrinsic::nvvm_wmma_m8n32k16_load_a_bf16_col_stride:
4321 case Intrinsic::nvvm_wmma_m8n32k16_load_a_bf16_row:
4322 case Intrinsic::nvvm_wmma_m8n32k16_load_a_bf16_row_stride:
4323 case Intrinsic::nvvm_wmma_m16n16k16_load_b_s8_col:
4324 case Intrinsic::nvvm_wmma_m16n16k16_load_b_s8_col_stride:
4325 case Intrinsic::nvvm_wmma_m16n16k16_load_b_u8_col_stride:
4326 case Intrinsic::nvvm_wmma_m16n16k16_load_b_u8_col:
4327 case Intrinsic::nvvm_wmma_m16n16k16_load_b_s8_row:
4328 case Intrinsic::nvvm_wmma_m16n16k16_load_b_s8_row_stride:
4329 case Intrinsic::nvvm_wmma_m16n16k16_load_b_u8_row_stride:
4330 case Intrinsic::nvvm_wmma_m16n16k16_load_b_u8_row:
4331 case Intrinsic::nvvm_wmma_m32n8k16_load_b_bf16_col:
4332 case Intrinsic::nvvm_wmma_m32n8k16_load_b_bf16_col_stride:
4333 case Intrinsic::nvvm_wmma_m32n8k16_load_b_bf16_row:
4334 case Intrinsic::nvvm_wmma_m32n8k16_load_b_bf16_row_stride: {
4335 Info.opc = ISD::INTRINSIC_W_CHAIN;
4336 Info.memVT = MVT::v2i32;
4337 Info.ptrVal = I.getArgOperand(0);
4338 Info.offset = 0;
4339 Info.flags = MachineMemOperand::MOLoad;
4340 Info.align = Align(8);
4341 Infos.push_back(Info);
4342 return;
4343 }
4344
4345 case Intrinsic::nvvm_wmma_m32n8k16_load_a_s8_col:
4346 case Intrinsic::nvvm_wmma_m32n8k16_load_a_s8_col_stride:
4347 case Intrinsic::nvvm_wmma_m32n8k16_load_a_u8_col_stride:
4348 case Intrinsic::nvvm_wmma_m32n8k16_load_a_u8_col:
4349 case Intrinsic::nvvm_wmma_m32n8k16_load_a_s8_row:
4350 case Intrinsic::nvvm_wmma_m32n8k16_load_a_s8_row_stride:
4351 case Intrinsic::nvvm_wmma_m32n8k16_load_a_u8_row_stride:
4352 case Intrinsic::nvvm_wmma_m32n8k16_load_a_u8_row:
4353 case Intrinsic::nvvm_wmma_m16n16k16_load_a_bf16_col:
4354 case Intrinsic::nvvm_wmma_m16n16k16_load_a_bf16_col_stride:
4355 case Intrinsic::nvvm_wmma_m16n16k16_load_a_bf16_row:
4356 case Intrinsic::nvvm_wmma_m16n16k16_load_a_bf16_row_stride:
4357 case Intrinsic::nvvm_wmma_m16n16k8_load_a_tf32_col:
4358 case Intrinsic::nvvm_wmma_m16n16k8_load_a_tf32_col_stride:
4359 case Intrinsic::nvvm_wmma_m16n16k8_load_a_tf32_row:
4360 case Intrinsic::nvvm_wmma_m16n16k8_load_a_tf32_row_stride:
4361
4362 case Intrinsic::nvvm_wmma_m8n32k16_load_b_s8_col:
4363 case Intrinsic::nvvm_wmma_m8n32k16_load_b_s8_col_stride:
4364 case Intrinsic::nvvm_wmma_m8n32k16_load_b_u8_col_stride:
4365 case Intrinsic::nvvm_wmma_m8n32k16_load_b_u8_col:
4366 case Intrinsic::nvvm_wmma_m8n32k16_load_b_s8_row:
4367 case Intrinsic::nvvm_wmma_m8n32k16_load_b_s8_row_stride:
4368 case Intrinsic::nvvm_wmma_m8n32k16_load_b_u8_row_stride:
4369 case Intrinsic::nvvm_wmma_m8n32k16_load_b_u8_row:
4370 case Intrinsic::nvvm_wmma_m16n16k16_load_b_bf16_col:
4371 case Intrinsic::nvvm_wmma_m16n16k16_load_b_bf16_col_stride:
4372 case Intrinsic::nvvm_wmma_m16n16k16_load_b_bf16_row:
4373 case Intrinsic::nvvm_wmma_m16n16k16_load_b_bf16_row_stride:
4374 case Intrinsic::nvvm_wmma_m16n16k8_load_b_tf32_col:
4375 case Intrinsic::nvvm_wmma_m16n16k8_load_b_tf32_col_stride:
4376 case Intrinsic::nvvm_wmma_m16n16k8_load_b_tf32_row:
4377 case Intrinsic::nvvm_wmma_m16n16k8_load_b_tf32_row_stride:
4378 case Intrinsic::nvvm_ldmatrix_sync_aligned_m8n8_x4_b16:
4379 case Intrinsic::nvvm_ldmatrix_sync_aligned_m8n8_x4_trans_b16:
4380 case Intrinsic::nvvm_ldmatrix_sync_aligned_m16n16_x2_trans_b8:
4381 case Intrinsic::nvvm_ldmatrix_sync_aligned_m16n16_x2_trans_b8x16_b4x16_p64:
4382 case Intrinsic::nvvm_ldmatrix_sync_aligned_m16n16_x2_trans_b8x16_b6x16_p32:
4383 case Intrinsic::nvvm_ldmatrix_sync_aligned_m8n16_x4_b8x16_b4x16_p64:
4384 case Intrinsic::nvvm_ldmatrix_sync_aligned_m8n16_x4_b8x16_b6x16_p32: {
4385 Info.opc = ISD::INTRINSIC_W_CHAIN;
4386 Info.memVT = MVT::v4i32;
4387 Info.ptrVal = I.getArgOperand(0);
4388 Info.offset = 0;
4389 Info.flags = MachineMemOperand::MOLoad;
4390 Info.align = Align(16);
4391 Infos.push_back(Info);
4392 return;
4393 }
4394
4395 case Intrinsic::nvvm_wmma_m32n8k16_load_b_s8_col:
4396 case Intrinsic::nvvm_wmma_m32n8k16_load_b_s8_col_stride:
4397 case Intrinsic::nvvm_wmma_m32n8k16_load_b_u8_col_stride:
4398 case Intrinsic::nvvm_wmma_m32n8k16_load_b_u8_col:
4399 case Intrinsic::nvvm_wmma_m32n8k16_load_b_s8_row:
4400 case Intrinsic::nvvm_wmma_m32n8k16_load_b_s8_row_stride:
4401 case Intrinsic::nvvm_wmma_m32n8k16_load_b_u8_row_stride:
4402 case Intrinsic::nvvm_wmma_m32n8k16_load_b_u8_row:
4403
4404 case Intrinsic::nvvm_wmma_m8n32k16_load_a_s8_col:
4405 case Intrinsic::nvvm_wmma_m8n32k16_load_a_s8_col_stride:
4406 case Intrinsic::nvvm_wmma_m8n32k16_load_a_u8_col_stride:
4407 case Intrinsic::nvvm_wmma_m8n32k16_load_a_u8_col:
4408 case Intrinsic::nvvm_wmma_m8n32k16_load_a_s8_row:
4409 case Intrinsic::nvvm_wmma_m8n32k16_load_a_s8_row_stride:
4410 case Intrinsic::nvvm_wmma_m8n32k16_load_a_u8_row_stride:
4411 case Intrinsic::nvvm_wmma_m8n32k16_load_a_u8_row:
4412 case Intrinsic::nvvm_wmma_m8n8k128_load_a_b1_row:
4413 case Intrinsic::nvvm_wmma_m8n8k128_load_a_b1_row_stride:
4414 case Intrinsic::nvvm_wmma_m8n8k128_load_b_b1_col:
4415 case Intrinsic::nvvm_wmma_m8n8k128_load_b_b1_col_stride:
4416 case Intrinsic::nvvm_wmma_m8n8k32_load_a_s4_row:
4417 case Intrinsic::nvvm_wmma_m8n8k32_load_a_s4_row_stride:
4418 case Intrinsic::nvvm_wmma_m8n8k32_load_a_u4_row_stride:
4419 case Intrinsic::nvvm_wmma_m8n8k32_load_a_u4_row:
4420 case Intrinsic::nvvm_wmma_m8n8k32_load_b_s4_col:
4421 case Intrinsic::nvvm_wmma_m8n8k32_load_b_s4_col_stride:
4422 case Intrinsic::nvvm_wmma_m8n8k32_load_b_u4_col_stride:
4423 case Intrinsic::nvvm_wmma_m8n8k32_load_b_u4_col:
4424 case Intrinsic::nvvm_ldmatrix_sync_aligned_m8n8_x1_b16:
4425 case Intrinsic::nvvm_ldmatrix_sync_aligned_m8n8_x1_trans_b16:
4426 case Intrinsic::nvvm_ldmatrix_sync_aligned_m8n16_x1_b8x16_b4x16_p64:
4427 case Intrinsic::nvvm_ldmatrix_sync_aligned_m8n16_x1_b8x16_b6x16_p32: {
4428 Info.opc = ISD::INTRINSIC_W_CHAIN;
4429 Info.memVT = MVT::i32;
4430 Info.ptrVal = I.getArgOperand(0);
4431 Info.offset = 0;
4432 Info.flags = MachineMemOperand::MOLoad;
4433 Info.align = Align(4);
4434 Infos.push_back(Info);
4435 return;
4436 }
4437
4438 case Intrinsic::nvvm_wmma_m16n16k16_load_c_f16_col:
4439 case Intrinsic::nvvm_wmma_m16n16k16_load_c_f16_row:
4440 case Intrinsic::nvvm_wmma_m16n16k16_load_c_f16_col_stride:
4441 case Intrinsic::nvvm_wmma_m16n16k16_load_c_f16_row_stride:
4442 case Intrinsic::nvvm_wmma_m32n8k16_load_c_f16_col:
4443 case Intrinsic::nvvm_wmma_m32n8k16_load_c_f16_row:
4444 case Intrinsic::nvvm_wmma_m32n8k16_load_c_f16_col_stride:
4445 case Intrinsic::nvvm_wmma_m32n8k16_load_c_f16_row_stride:
4446 case Intrinsic::nvvm_wmma_m8n32k16_load_c_f16_col:
4447 case Intrinsic::nvvm_wmma_m8n32k16_load_c_f16_row:
4448 case Intrinsic::nvvm_wmma_m8n32k16_load_c_f16_col_stride:
4449 case Intrinsic::nvvm_wmma_m8n32k16_load_c_f16_row_stride: {
4450 Info.opc = ISD::INTRINSIC_W_CHAIN;
4451 Info.memVT = MVT::v4f16;
4452 Info.ptrVal = I.getArgOperand(0);
4453 Info.offset = 0;
4454 Info.flags = MachineMemOperand::MOLoad;
4455 Info.align = Align(16);
4456 Infos.push_back(Info);
4457 return;
4458 }
4459
4460 case Intrinsic::nvvm_wmma_m16n16k16_load_c_f32_col:
4461 case Intrinsic::nvvm_wmma_m16n16k16_load_c_f32_row:
4462 case Intrinsic::nvvm_wmma_m16n16k16_load_c_f32_col_stride:
4463 case Intrinsic::nvvm_wmma_m16n16k16_load_c_f32_row_stride:
4464 case Intrinsic::nvvm_wmma_m32n8k16_load_c_f32_col:
4465 case Intrinsic::nvvm_wmma_m32n8k16_load_c_f32_row:
4466 case Intrinsic::nvvm_wmma_m32n8k16_load_c_f32_col_stride:
4467 case Intrinsic::nvvm_wmma_m32n8k16_load_c_f32_row_stride:
4468 case Intrinsic::nvvm_wmma_m8n32k16_load_c_f32_col:
4469 case Intrinsic::nvvm_wmma_m8n32k16_load_c_f32_row:
4470 case Intrinsic::nvvm_wmma_m8n32k16_load_c_f32_col_stride:
4471 case Intrinsic::nvvm_wmma_m8n32k16_load_c_f32_row_stride:
4472 case Intrinsic::nvvm_wmma_m16n16k8_load_c_f32_col:
4473 case Intrinsic::nvvm_wmma_m16n16k8_load_c_f32_row:
4474 case Intrinsic::nvvm_wmma_m16n16k8_load_c_f32_col_stride:
4475 case Intrinsic::nvvm_wmma_m16n16k8_load_c_f32_row_stride: {
4476 Info.opc = ISD::INTRINSIC_W_CHAIN;
4477 Info.memVT = MVT::v8f32;
4478 Info.ptrVal = I.getArgOperand(0);
4479 Info.offset = 0;
4480 Info.flags = MachineMemOperand::MOLoad;
4481 Info.align = Align(16);
4482 Infos.push_back(Info);
4483 return;
4484 }
4485
4486 case Intrinsic::nvvm_wmma_m32n8k16_load_a_bf16_col:
4487 case Intrinsic::nvvm_wmma_m32n8k16_load_a_bf16_col_stride:
4488 case Intrinsic::nvvm_wmma_m32n8k16_load_a_bf16_row:
4489 case Intrinsic::nvvm_wmma_m32n8k16_load_a_bf16_row_stride:
4490
4491 case Intrinsic::nvvm_wmma_m8n32k16_load_b_bf16_col:
4492 case Intrinsic::nvvm_wmma_m8n32k16_load_b_bf16_col_stride:
4493 case Intrinsic::nvvm_wmma_m8n32k16_load_b_bf16_row:
4494 case Intrinsic::nvvm_wmma_m8n32k16_load_b_bf16_row_stride:
4495
4496 case Intrinsic::nvvm_wmma_m16n16k16_load_c_s32_col:
4497 case Intrinsic::nvvm_wmma_m16n16k16_load_c_s32_col_stride:
4498 case Intrinsic::nvvm_wmma_m16n16k16_load_c_s32_row:
4499 case Intrinsic::nvvm_wmma_m16n16k16_load_c_s32_row_stride:
4500 case Intrinsic::nvvm_wmma_m32n8k16_load_c_s32_col:
4501 case Intrinsic::nvvm_wmma_m32n8k16_load_c_s32_col_stride:
4502 case Intrinsic::nvvm_wmma_m32n8k16_load_c_s32_row:
4503 case Intrinsic::nvvm_wmma_m32n8k16_load_c_s32_row_stride:
4504 case Intrinsic::nvvm_wmma_m8n32k16_load_c_s32_col:
4505 case Intrinsic::nvvm_wmma_m8n32k16_load_c_s32_col_stride:
4506 case Intrinsic::nvvm_wmma_m8n32k16_load_c_s32_row:
4507 case Intrinsic::nvvm_wmma_m8n32k16_load_c_s32_row_stride: {
4508 Info.opc = ISD::INTRINSIC_W_CHAIN;
4509 Info.memVT = MVT::v8i32;
4510 Info.ptrVal = I.getArgOperand(0);
4511 Info.offset = 0;
4512 Info.flags = MachineMemOperand::MOLoad;
4513 Info.align = Align(16);
4514 Infos.push_back(Info);
4515 return;
4516 }
4517
4518 case Intrinsic::nvvm_wmma_m8n8k128_load_c_s32_col:
4519 case Intrinsic::nvvm_wmma_m8n8k128_load_c_s32_col_stride:
4520 case Intrinsic::nvvm_wmma_m8n8k128_load_c_s32_row:
4521 case Intrinsic::nvvm_wmma_m8n8k128_load_c_s32_row_stride:
4522 case Intrinsic::nvvm_wmma_m8n8k32_load_c_s32_col:
4523 case Intrinsic::nvvm_wmma_m8n8k32_load_c_s32_col_stride:
4524 case Intrinsic::nvvm_wmma_m8n8k32_load_c_s32_row:
4525 case Intrinsic::nvvm_wmma_m8n8k32_load_c_s32_row_stride:
4526 case Intrinsic::nvvm_ldmatrix_sync_aligned_m8n8_x2_b16:
4527 case Intrinsic::nvvm_ldmatrix_sync_aligned_m8n8_x2_trans_b16:
4528 case Intrinsic::nvvm_ldmatrix_sync_aligned_m16n16_x1_trans_b8:
4529 case Intrinsic::nvvm_ldmatrix_sync_aligned_m16n16_x1_trans_b8x16_b4x16_p64:
4530 case Intrinsic::nvvm_ldmatrix_sync_aligned_m16n16_x1_trans_b8x16_b6x16_p32:
4531 case Intrinsic::nvvm_ldmatrix_sync_aligned_m8n16_x2_b8x16_b4x16_p64:
4532 case Intrinsic::nvvm_ldmatrix_sync_aligned_m8n16_x2_b8x16_b6x16_p32: {
4533 Info.opc = ISD::INTRINSIC_W_CHAIN;
4534 Info.memVT = MVT::v2i32;
4535 Info.ptrVal = I.getArgOperand(0);
4536 Info.offset = 0;
4537 Info.flags = MachineMemOperand::MOLoad;
4538 Info.align = Align(8);
4539 Infos.push_back(Info);
4540 return;
4541 }
4542
4543 case Intrinsic::nvvm_wmma_m8n8k4_load_a_f64_col:
4544 case Intrinsic::nvvm_wmma_m8n8k4_load_a_f64_col_stride:
4545 case Intrinsic::nvvm_wmma_m8n8k4_load_a_f64_row:
4546 case Intrinsic::nvvm_wmma_m8n8k4_load_a_f64_row_stride:
4547
4548 case Intrinsic::nvvm_wmma_m8n8k4_load_b_f64_col:
4549 case Intrinsic::nvvm_wmma_m8n8k4_load_b_f64_col_stride:
4550 case Intrinsic::nvvm_wmma_m8n8k4_load_b_f64_row:
4551 case Intrinsic::nvvm_wmma_m8n8k4_load_b_f64_row_stride: {
4552 Info.opc = ISD::INTRINSIC_W_CHAIN;
4553 Info.memVT = MVT::f64;
4554 Info.ptrVal = I.getArgOperand(0);
4555 Info.offset = 0;
4556 Info.flags = MachineMemOperand::MOLoad;
4557 Info.align = Align(8);
4558 Infos.push_back(Info);
4559 return;
4560 }
4561
4562 case Intrinsic::nvvm_wmma_m8n8k4_load_c_f64_col:
4563 case Intrinsic::nvvm_wmma_m8n8k4_load_c_f64_col_stride:
4564 case Intrinsic::nvvm_wmma_m8n8k4_load_c_f64_row:
4565 case Intrinsic::nvvm_wmma_m8n8k4_load_c_f64_row_stride: {
4566 Info.opc = ISD::INTRINSIC_W_CHAIN;
4567 Info.memVT = MVT::v2f64;
4568 Info.ptrVal = I.getArgOperand(0);
4569 Info.offset = 0;
4570 Info.flags = MachineMemOperand::MOLoad;
4571 Info.align = Align(16);
4572 Infos.push_back(Info);
4573 return;
4574 }
4575
4576 case Intrinsic::nvvm_wmma_m16n16k16_store_d_f16_col:
4577 case Intrinsic::nvvm_wmma_m16n16k16_store_d_f16_row:
4578 case Intrinsic::nvvm_wmma_m16n16k16_store_d_f16_col_stride:
4579 case Intrinsic::nvvm_wmma_m16n16k16_store_d_f16_row_stride:
4580 case Intrinsic::nvvm_wmma_m32n8k16_store_d_f16_col:
4581 case Intrinsic::nvvm_wmma_m32n8k16_store_d_f16_row:
4582 case Intrinsic::nvvm_wmma_m32n8k16_store_d_f16_col_stride:
4583 case Intrinsic::nvvm_wmma_m32n8k16_store_d_f16_row_stride:
4584 case Intrinsic::nvvm_wmma_m8n32k16_store_d_f16_col:
4585 case Intrinsic::nvvm_wmma_m8n32k16_store_d_f16_row:
4586 case Intrinsic::nvvm_wmma_m8n32k16_store_d_f16_col_stride:
4587 case Intrinsic::nvvm_wmma_m8n32k16_store_d_f16_row_stride: {
4588 Info.opc = ISD::INTRINSIC_VOID;
4589 Info.memVT = MVT::v4f16;
4590 Info.ptrVal = I.getArgOperand(0);
4591 Info.offset = 0;
4592 Info.flags = MachineMemOperand::MOStore;
4593 Info.align = Align(16);
4594 Infos.push_back(Info);
4595 return;
4596 }
4597
4598 case Intrinsic::nvvm_wmma_m16n16k16_store_d_f32_col:
4599 case Intrinsic::nvvm_wmma_m16n16k16_store_d_f32_row:
4600 case Intrinsic::nvvm_wmma_m16n16k16_store_d_f32_col_stride:
4601 case Intrinsic::nvvm_wmma_m16n16k16_store_d_f32_row_stride:
4602 case Intrinsic::nvvm_wmma_m32n8k16_store_d_f32_col:
4603 case Intrinsic::nvvm_wmma_m32n8k16_store_d_f32_row:
4604 case Intrinsic::nvvm_wmma_m32n8k16_store_d_f32_col_stride:
4605 case Intrinsic::nvvm_wmma_m32n8k16_store_d_f32_row_stride:
4606 case Intrinsic::nvvm_wmma_m8n32k16_store_d_f32_col:
4607 case Intrinsic::nvvm_wmma_m8n32k16_store_d_f32_row:
4608 case Intrinsic::nvvm_wmma_m8n32k16_store_d_f32_col_stride:
4609 case Intrinsic::nvvm_wmma_m8n32k16_store_d_f32_row_stride:
4610 case Intrinsic::nvvm_wmma_m16n16k8_store_d_f32_col:
4611 case Intrinsic::nvvm_wmma_m16n16k8_store_d_f32_row:
4612 case Intrinsic::nvvm_wmma_m16n16k8_store_d_f32_col_stride:
4613 case Intrinsic::nvvm_wmma_m16n16k8_store_d_f32_row_stride: {
4614 Info.opc = ISD::INTRINSIC_VOID;
4615 Info.memVT = MVT::v8f32;
4616 Info.ptrVal = I.getArgOperand(0);
4617 Info.offset = 0;
4618 Info.flags = MachineMemOperand::MOStore;
4619 Info.align = Align(16);
4620 Infos.push_back(Info);
4621 return;
4622 }
4623
4624 case Intrinsic::nvvm_wmma_m16n16k16_store_d_s32_col:
4625 case Intrinsic::nvvm_wmma_m16n16k16_store_d_s32_col_stride:
4626 case Intrinsic::nvvm_wmma_m16n16k16_store_d_s32_row:
4627 case Intrinsic::nvvm_wmma_m16n16k16_store_d_s32_row_stride:
4628 case Intrinsic::nvvm_wmma_m32n8k16_store_d_s32_col:
4629 case Intrinsic::nvvm_wmma_m32n8k16_store_d_s32_col_stride:
4630 case Intrinsic::nvvm_wmma_m32n8k16_store_d_s32_row:
4631 case Intrinsic::nvvm_wmma_m32n8k16_store_d_s32_row_stride:
4632 case Intrinsic::nvvm_wmma_m8n32k16_store_d_s32_col:
4633 case Intrinsic::nvvm_wmma_m8n32k16_store_d_s32_col_stride:
4634 case Intrinsic::nvvm_wmma_m8n32k16_store_d_s32_row:
4635 case Intrinsic::nvvm_wmma_m8n32k16_store_d_s32_row_stride: {
4636 Info.opc = ISD::INTRINSIC_VOID;
4637 Info.memVT = MVT::v8i32;
4638 Info.ptrVal = I.getArgOperand(0);
4639 Info.offset = 0;
4640 Info.flags = MachineMemOperand::MOStore;
4641 Info.align = Align(16);
4642 Infos.push_back(Info);
4643 return;
4644 }
4645
4646 case Intrinsic::nvvm_wmma_m8n8k128_store_d_s32_col:
4647 case Intrinsic::nvvm_wmma_m8n8k128_store_d_s32_col_stride:
4648 case Intrinsic::nvvm_wmma_m8n8k128_store_d_s32_row:
4649 case Intrinsic::nvvm_wmma_m8n8k128_store_d_s32_row_stride:
4650 case Intrinsic::nvvm_wmma_m8n8k32_store_d_s32_col:
4651 case Intrinsic::nvvm_wmma_m8n8k32_store_d_s32_col_stride:
4652 case Intrinsic::nvvm_wmma_m8n8k32_store_d_s32_row:
4653 case Intrinsic::nvvm_wmma_m8n8k32_store_d_s32_row_stride:
4654 case Intrinsic::nvvm_stmatrix_sync_aligned_m8n8_x2_b16:
4655 case Intrinsic::nvvm_stmatrix_sync_aligned_m8n8_x2_trans_b16:
4656 case Intrinsic::nvvm_stmatrix_sync_aligned_m16n8_x2_trans_b8: {
4657 Info.opc = ISD::INTRINSIC_VOID;
4658 Info.memVT = MVT::v2i32;
4659 Info.ptrVal = I.getArgOperand(0);
4660 Info.offset = 0;
4661 Info.flags = MachineMemOperand::MOStore;
4662 Info.align = Align(8);
4663 Infos.push_back(Info);
4664 return;
4665 }
4666
4667 case Intrinsic::nvvm_wmma_m8n8k4_store_d_f64_col:
4668 case Intrinsic::nvvm_wmma_m8n8k4_store_d_f64_col_stride:
4669 case Intrinsic::nvvm_wmma_m8n8k4_store_d_f64_row:
4670 case Intrinsic::nvvm_wmma_m8n8k4_store_d_f64_row_stride: {
4671 Info.opc = ISD::INTRINSIC_VOID;
4672 Info.memVT = MVT::v2f64;
4673 Info.ptrVal = I.getArgOperand(0);
4674 Info.offset = 0;
4675 Info.flags = MachineMemOperand::MOStore;
4676 Info.align = Align(16);
4677 Infos.push_back(Info);
4678 return;
4679 }
4680
4681 case Intrinsic::nvvm_stmatrix_sync_aligned_m8n8_x1_b16:
4682 case Intrinsic::nvvm_stmatrix_sync_aligned_m8n8_x1_trans_b16:
4683 case Intrinsic::nvvm_stmatrix_sync_aligned_m16n8_x1_trans_b8: {
4684 Info.opc = ISD::INTRINSIC_VOID;
4685 Info.memVT = MVT::i32;
4686 Info.ptrVal = I.getArgOperand(0);
4687 Info.offset = 0;
4688 Info.flags = MachineMemOperand::MOStore;
4689 Info.align = Align(4);
4690 Infos.push_back(Info);
4691 return;
4692 }
4693
4694 case Intrinsic::nvvm_stmatrix_sync_aligned_m8n8_x4_b16:
4695 case Intrinsic::nvvm_stmatrix_sync_aligned_m8n8_x4_trans_b16:
4696 case Intrinsic::nvvm_stmatrix_sync_aligned_m16n8_x4_trans_b8: {
4697 Info.opc = ISD::INTRINSIC_VOID;
4698 Info.memVT = MVT::v4i32;
4699 Info.ptrVal = I.getArgOperand(0);
4700 Info.offset = 0;
4701 Info.flags = MachineMemOperand::MOStore;
4702 Info.align = Align(16);
4703 Infos.push_back(Info);
4704 return;
4705 }
4706
4707 case Intrinsic::nvvm_atomic_add_gen_f_cta:
4708 case Intrinsic::nvvm_atomic_add_gen_f_sys:
4709 case Intrinsic::nvvm_atomic_add_gen_i_cta:
4710 case Intrinsic::nvvm_atomic_add_gen_i_sys:
4711 case Intrinsic::nvvm_atomic_and_gen_i_cta:
4712 case Intrinsic::nvvm_atomic_and_gen_i_sys:
4713 case Intrinsic::nvvm_atomic_cas_gen_i_cta:
4714 case Intrinsic::nvvm_atomic_cas_gen_i_sys:
4715 case Intrinsic::nvvm_atomic_dec_gen_i_cta:
4716 case Intrinsic::nvvm_atomic_dec_gen_i_sys:
4717 case Intrinsic::nvvm_atomic_inc_gen_i_cta:
4718 case Intrinsic::nvvm_atomic_inc_gen_i_sys:
4719 case Intrinsic::nvvm_atomic_max_gen_i_cta:
4720 case Intrinsic::nvvm_atomic_max_gen_i_sys:
4721 case Intrinsic::nvvm_atomic_min_gen_i_cta:
4722 case Intrinsic::nvvm_atomic_min_gen_i_sys:
4723 case Intrinsic::nvvm_atomic_or_gen_i_cta:
4724 case Intrinsic::nvvm_atomic_or_gen_i_sys:
4725 case Intrinsic::nvvm_atomic_exch_gen_i_cta:
4726 case Intrinsic::nvvm_atomic_exch_gen_i_sys:
4727 case Intrinsic::nvvm_atomic_xor_gen_i_cta:
4728 case Intrinsic::nvvm_atomic_xor_gen_i_sys: {
4729 auto &DL = I.getDataLayout();
4730 Info.opc = ISD::INTRINSIC_W_CHAIN;
4731 Info.memVT = getValueType(DL, I.getType());
4732 Info.ptrVal = I.getArgOperand(0);
4733 Info.offset = 0;
4735 Info.align.reset();
4736 Infos.push_back(Info);
4737 return;
4738 }
4739
4740 case Intrinsic::nvvm_prefetch_tensormap: {
4741 auto &DL = I.getDataLayout();
4742 Info.opc = ISD::INTRINSIC_VOID;
4743 Info.memVT = getPointerTy(DL);
4744 Info.ptrVal = I.getArgOperand(0);
4745 Info.offset = 0;
4746 Info.flags =
4748 Info.align.reset();
4749 Infos.push_back(Info);
4750 return;
4751 }
4752
4753 case Intrinsic::nvvm_tensormap_replace_global_address:
4754 case Intrinsic::nvvm_tensormap_replace_global_stride: {
4755 Info.opc = ISD::INTRINSIC_VOID;
4756 Info.memVT = MVT::i64;
4757 Info.ptrVal = I.getArgOperand(0);
4758 Info.offset = 0;
4759 Info.flags = MachineMemOperand::MOStore;
4760 Info.align.reset();
4761 Infos.push_back(Info);
4762 return;
4763 }
4764
4765 case Intrinsic::nvvm_tensormap_replace_rank:
4766 case Intrinsic::nvvm_tensormap_replace_box_dim:
4767 case Intrinsic::nvvm_tensormap_replace_global_dim:
4768 case Intrinsic::nvvm_tensormap_replace_element_stride:
4769 case Intrinsic::nvvm_tensormap_replace_elemtype:
4770 case Intrinsic::nvvm_tensormap_replace_interleave_layout:
4771 case Intrinsic::nvvm_tensormap_replace_swizzle_mode:
4772 case Intrinsic::nvvm_tensormap_replace_swizzle_atomicity:
4773 case Intrinsic::nvvm_tensormap_replace_fill_mode: {
4774 Info.opc = ISD::INTRINSIC_VOID;
4775 Info.memVT = MVT::i32;
4776 Info.ptrVal = I.getArgOperand(0);
4777 Info.offset = 0;
4778 Info.flags = MachineMemOperand::MOStore;
4779 Info.align.reset();
4780 Infos.push_back(Info);
4781 return;
4782 }
4783
4784 case Intrinsic::nvvm_ldu_global_i:
4785 case Intrinsic::nvvm_ldu_global_f:
4786 case Intrinsic::nvvm_ldu_global_p: {
4787 Info.opc = ISD::INTRINSIC_W_CHAIN;
4788 Info.memVT = getValueType(I.getDataLayout(), I.getType());
4789 Info.ptrVal = I.getArgOperand(0);
4790 Info.offset = 0;
4791 Info.flags = MachineMemOperand::MOLoad;
4792 Info.align = cast<ConstantInt>(I.getArgOperand(1))->getMaybeAlignValue();
4793
4794 Infos.push_back(Info);
4795 return;
4796 }
4797 case Intrinsic::nvvm_tex_1d_v4f32_s32:
4798 case Intrinsic::nvvm_tex_1d_v4f32_f32:
4799 case Intrinsic::nvvm_tex_1d_level_v4f32_f32:
4800 case Intrinsic::nvvm_tex_1d_grad_v4f32_f32:
4801 case Intrinsic::nvvm_tex_1d_array_v4f32_s32:
4802 case Intrinsic::nvvm_tex_1d_array_v4f32_f32:
4803 case Intrinsic::nvvm_tex_1d_array_level_v4f32_f32:
4804 case Intrinsic::nvvm_tex_1d_array_grad_v4f32_f32:
4805 case Intrinsic::nvvm_tex_2d_v4f32_s32:
4806 case Intrinsic::nvvm_tex_2d_v4f32_f32:
4807 case Intrinsic::nvvm_tex_2d_level_v4f32_f32:
4808 case Intrinsic::nvvm_tex_2d_grad_v4f32_f32:
4809 case Intrinsic::nvvm_tex_2d_array_v4f32_s32:
4810 case Intrinsic::nvvm_tex_2d_array_v4f32_f32:
4811 case Intrinsic::nvvm_tex_2d_array_level_v4f32_f32:
4812 case Intrinsic::nvvm_tex_2d_array_grad_v4f32_f32:
4813 case Intrinsic::nvvm_tex_3d_v4f32_s32:
4814 case Intrinsic::nvvm_tex_3d_v4f32_f32:
4815 case Intrinsic::nvvm_tex_3d_level_v4f32_f32:
4816 case Intrinsic::nvvm_tex_3d_grad_v4f32_f32:
4817 case Intrinsic::nvvm_tex_cube_v4f32_f32:
4818 case Intrinsic::nvvm_tex_cube_level_v4f32_f32:
4819 case Intrinsic::nvvm_tex_cube_array_v4f32_f32:
4820 case Intrinsic::nvvm_tex_cube_array_level_v4f32_f32:
4821 case Intrinsic::nvvm_tld4_r_2d_v4f32_f32:
4822 case Intrinsic::nvvm_tld4_g_2d_v4f32_f32:
4823 case Intrinsic::nvvm_tld4_b_2d_v4f32_f32:
4824 case Intrinsic::nvvm_tld4_a_2d_v4f32_f32:
4825 case Intrinsic::nvvm_tex_unified_1d_v4f32_s32:
4826 case Intrinsic::nvvm_tex_unified_1d_v4f32_f32:
4827 case Intrinsic::nvvm_tex_unified_1d_level_v4f32_f32:
4828 case Intrinsic::nvvm_tex_unified_1d_grad_v4f32_f32:
4829 case Intrinsic::nvvm_tex_unified_1d_array_v4f32_s32:
4830 case Intrinsic::nvvm_tex_unified_1d_array_v4f32_f32:
4831 case Intrinsic::nvvm_tex_unified_1d_array_level_v4f32_f32:
4832 case Intrinsic::nvvm_tex_unified_1d_array_grad_v4f32_f32:
4833 case Intrinsic::nvvm_tex_unified_2d_v4f32_s32:
4834 case Intrinsic::nvvm_tex_unified_2d_v4f32_f32:
4835 case Intrinsic::nvvm_tex_unified_2d_level_v4f32_f32:
4836 case Intrinsic::nvvm_tex_unified_2d_grad_v4f32_f32:
4837 case Intrinsic::nvvm_tex_unified_2d_array_v4f32_s32:
4838 case Intrinsic::nvvm_tex_unified_2d_array_v4f32_f32:
4839 case Intrinsic::nvvm_tex_unified_2d_array_level_v4f32_f32:
4840 case Intrinsic::nvvm_tex_unified_2d_array_grad_v4f32_f32:
4841 case Intrinsic::nvvm_tex_unified_3d_v4f32_s32:
4842 case Intrinsic::nvvm_tex_unified_3d_v4f32_f32:
4843 case Intrinsic::nvvm_tex_unified_3d_level_v4f32_f32:
4844 case Intrinsic::nvvm_tex_unified_3d_grad_v4f32_f32:
4845 case Intrinsic::nvvm_tex_unified_cube_v4f32_f32:
4846 case Intrinsic::nvvm_tex_unified_cube_level_v4f32_f32:
4847 case Intrinsic::nvvm_tex_unified_cube_array_v4f32_f32:
4848 case Intrinsic::nvvm_tex_unified_cube_array_level_v4f32_f32:
4849 case Intrinsic::nvvm_tex_unified_cube_grad_v4f32_f32:
4850 case Intrinsic::nvvm_tex_unified_cube_array_grad_v4f32_f32:
4851 case Intrinsic::nvvm_tld4_unified_r_2d_v4f32_f32:
4852 case Intrinsic::nvvm_tld4_unified_g_2d_v4f32_f32:
4853 case Intrinsic::nvvm_tld4_unified_b_2d_v4f32_f32:
4854 case Intrinsic::nvvm_tld4_unified_a_2d_v4f32_f32:
4855 Info.opc = ISD::INTRINSIC_W_CHAIN;
4856 Info.memVT = MVT::v4f32;
4857 Info.ptrVal = nullptr;
4858 Info.offset = 0;
4859 Info.flags = MachineMemOperand::MOLoad;
4860 Info.align = Align(16);
4861 Infos.push_back(Info);
4862 return;
4863
4864 case Intrinsic::nvvm_tex_1d_v4s32_s32:
4865 case Intrinsic::nvvm_tex_1d_v4s32_f32:
4866 case Intrinsic::nvvm_tex_1d_level_v4s32_f32:
4867 case Intrinsic::nvvm_tex_1d_grad_v4s32_f32:
4868 case Intrinsic::nvvm_tex_1d_array_v4s32_s32:
4869 case Intrinsic::nvvm_tex_1d_array_v4s32_f32:
4870 case Intrinsic::nvvm_tex_1d_array_level_v4s32_f32:
4871 case Intrinsic::nvvm_tex_1d_array_grad_v4s32_f32:
4872 case Intrinsic::nvvm_tex_2d_v4s32_s32:
4873 case Intrinsic::nvvm_tex_2d_v4s32_f32:
4874 case Intrinsic::nvvm_tex_2d_level_v4s32_f32:
4875 case Intrinsic::nvvm_tex_2d_grad_v4s32_f32:
4876 case Intrinsic::nvvm_tex_2d_array_v4s32_s32:
4877 case Intrinsic::nvvm_tex_2d_array_v4s32_f32:
4878 case Intrinsic::nvvm_tex_2d_array_level_v4s32_f32:
4879 case Intrinsic::nvvm_tex_2d_array_grad_v4s32_f32:
4880 case Intrinsic::nvvm_tex_3d_v4s32_s32:
4881 case Intrinsic::nvvm_tex_3d_v4s32_f32:
4882 case Intrinsic::nvvm_tex_3d_level_v4s32_f32:
4883 case Intrinsic::nvvm_tex_3d_grad_v4s32_f32:
4884 case Intrinsic::nvvm_tex_cube_v4s32_f32:
4885 case Intrinsic::nvvm_tex_cube_level_v4s32_f32:
4886 case Intrinsic::nvvm_tex_cube_array_v4s32_f32:
4887 case Intrinsic::nvvm_tex_cube_array_level_v4s32_f32:
4888 case Intrinsic::nvvm_tex_cube_v4u32_f32:
4889 case Intrinsic::nvvm_tex_cube_level_v4u32_f32:
4890 case Intrinsic::nvvm_tex_cube_array_v4u32_f32:
4891 case Intrinsic::nvvm_tex_cube_array_level_v4u32_f32:
4892 case Intrinsic::nvvm_tex_1d_v4u32_s32:
4893 case Intrinsic::nvvm_tex_1d_v4u32_f32:
4894 case Intrinsic::nvvm_tex_1d_level_v4u32_f32:
4895 case Intrinsic::nvvm_tex_1d_grad_v4u32_f32:
4896 case Intrinsic::nvvm_tex_1d_array_v4u32_s32:
4897 case Intrinsic::nvvm_tex_1d_array_v4u32_f32:
4898 case Intrinsic::nvvm_tex_1d_array_level_v4u32_f32:
4899 case Intrinsic::nvvm_tex_1d_array_grad_v4u32_f32:
4900 case Intrinsic::nvvm_tex_2d_v4u32_s32:
4901 case Intrinsic::nvvm_tex_2d_v4u32_f32:
4902 case Intrinsic::nvvm_tex_2d_level_v4u32_f32:
4903 case Intrinsic::nvvm_tex_2d_grad_v4u32_f32:
4904 case Intrinsic::nvvm_tex_2d_array_v4u32_s32:
4905 case Intrinsic::nvvm_tex_2d_array_v4u32_f32:
4906 case Intrinsic::nvvm_tex_2d_array_level_v4u32_f32:
4907 case Intrinsic::nvvm_tex_2d_array_grad_v4u32_f32:
4908 case Intrinsic::nvvm_tex_3d_v4u32_s32:
4909 case Intrinsic::nvvm_tex_3d_v4u32_f32:
4910 case Intrinsic::nvvm_tex_3d_level_v4u32_f32:
4911 case Intrinsic::nvvm_tex_3d_grad_v4u32_f32:
4912 case Intrinsic::nvvm_tld4_r_2d_v4s32_f32:
4913 case Intrinsic::nvvm_tld4_g_2d_v4s32_f32:
4914 case Intrinsic::nvvm_tld4_b_2d_v4s32_f32:
4915 case Intrinsic::nvvm_tld4_a_2d_v4s32_f32:
4916 case Intrinsic::nvvm_tld4_r_2d_v4u32_f32:
4917 case Intrinsic::nvvm_tld4_g_2d_v4u32_f32:
4918 case Intrinsic::nvvm_tld4_b_2d_v4u32_f32:
4919 case Intrinsic::nvvm_tld4_a_2d_v4u32_f32:
4920 case Intrinsic::nvvm_tex_unified_1d_v4s32_s32:
4921 case Intrinsic::nvvm_tex_unified_1d_v4s32_f32:
4922 case Intrinsic::nvvm_tex_unified_1d_level_v4s32_f32:
4923 case Intrinsic::nvvm_tex_unified_1d_grad_v4s32_f32:
4924 case Intrinsic::nvvm_tex_unified_1d_array_v4s32_s32:
4925 case Intrinsic::nvvm_tex_unified_1d_array_v4s32_f32:
4926 case Intrinsic::nvvm_tex_unified_1d_array_level_v4s32_f32:
4927 case Intrinsic::nvvm_tex_unified_1d_array_grad_v4s32_f32:
4928 case Intrinsic::nvvm_tex_unified_2d_v4s32_s32:
4929 case Intrinsic::nvvm_tex_unified_2d_v4s32_f32:
4930 case Intrinsic::nvvm_tex_unified_2d_level_v4s32_f32:
4931 case Intrinsic::nvvm_tex_unified_2d_grad_v4s32_f32:
4932 case Intrinsic::nvvm_tex_unified_2d_array_v4s32_s32:
4933 case Intrinsic::nvvm_tex_unified_2d_array_v4s32_f32:
4934 case Intrinsic::nvvm_tex_unified_2d_array_level_v4s32_f32:
4935 case Intrinsic::nvvm_tex_unified_2d_array_grad_v4s32_f32:
4936 case Intrinsic::nvvm_tex_unified_3d_v4s32_s32:
4937 case Intrinsic::nvvm_tex_unified_3d_v4s32_f32:
4938 case Intrinsic::nvvm_tex_unified_3d_level_v4s32_f32:
4939 case Intrinsic::nvvm_tex_unified_3d_grad_v4s32_f32:
4940 case Intrinsic::nvvm_tex_unified_1d_v4u32_s32:
4941 case Intrinsic::nvvm_tex_unified_1d_v4u32_f32:
4942 case Intrinsic::nvvm_tex_unified_1d_level_v4u32_f32:
4943 case Intrinsic::nvvm_tex_unified_1d_grad_v4u32_f32:
4944 case Intrinsic::nvvm_tex_unified_1d_array_v4u32_s32:
4945 case Intrinsic::nvvm_tex_unified_1d_array_v4u32_f32:
4946 case Intrinsic::nvvm_tex_unified_1d_array_level_v4u32_f32:
4947 case Intrinsic::nvvm_tex_unified_1d_array_grad_v4u32_f32:
4948 case Intrinsic::nvvm_tex_unified_2d_v4u32_s32:
4949 case Intrinsic::nvvm_tex_unified_2d_v4u32_f32:
4950 case Intrinsic::nvvm_tex_unified_2d_level_v4u32_f32:
4951 case Intrinsic::nvvm_tex_unified_2d_grad_v4u32_f32:
4952 case Intrinsic::nvvm_tex_unified_2d_array_v4u32_s32:
4953 case Intrinsic::nvvm_tex_unified_2d_array_v4u32_f32:
4954 case Intrinsic::nvvm_tex_unified_2d_array_level_v4u32_f32:
4955 case Intrinsic::nvvm_tex_unified_2d_array_grad_v4u32_f32:
4956 case Intrinsic::nvvm_tex_unified_3d_v4u32_s32:
4957 case Intrinsic::nvvm_tex_unified_3d_v4u32_f32:
4958 case Intrinsic::nvvm_tex_unified_3d_level_v4u32_f32:
4959 case Intrinsic::nvvm_tex_unified_3d_grad_v4u32_f32:
4960 case Intrinsic::nvvm_tex_unified_cube_v4s32_f32:
4961 case Intrinsic::nvvm_tex_unified_cube_level_v4s32_f32:
4962 case Intrinsic::nvvm_tex_unified_cube_array_v4s32_f32:
4963 case Intrinsic::nvvm_tex_unified_cube_array_level_v4s32_f32:
4964 case Intrinsic::nvvm_tex_unified_cube_v4u32_f32:
4965 case Intrinsic::nvvm_tex_unified_cube_level_v4u32_f32:
4966 case Intrinsic::nvvm_tex_unified_cube_array_v4u32_f32:
4967 case Intrinsic::nvvm_tex_unified_cube_array_level_v4u32_f32:
4968 case Intrinsic::nvvm_tex_unified_cube_grad_v4s32_f32:
4969 case Intrinsic::nvvm_tex_unified_cube_grad_v4u32_f32:
4970 case Intrinsic::nvvm_tex_unified_cube_array_grad_v4s32_f32:
4971 case Intrinsic::nvvm_tex_unified_cube_array_grad_v4u32_f32:
4972 case Intrinsic::nvvm_tld4_unified_r_2d_v4s32_f32:
4973 case Intrinsic::nvvm_tld4_unified_g_2d_v4s32_f32:
4974 case Intrinsic::nvvm_tld4_unified_b_2d_v4s32_f32:
4975 case Intrinsic::nvvm_tld4_unified_a_2d_v4s32_f32:
4976 case Intrinsic::nvvm_tld4_unified_r_2d_v4u32_f32:
4977 case Intrinsic::nvvm_tld4_unified_g_2d_v4u32_f32:
4978 case Intrinsic::nvvm_tld4_unified_b_2d_v4u32_f32:
4979 case Intrinsic::nvvm_tld4_unified_a_2d_v4u32_f32:
4980 Info.opc = ISD::INTRINSIC_W_CHAIN;
4981 Info.memVT = MVT::v4i32;
4982 Info.ptrVal = nullptr;
4983 Info.offset = 0;
4984 Info.flags = MachineMemOperand::MOLoad;
4985 Info.align = Align(16);
4986 Infos.push_back(Info);
4987 return;
4988
4989 case Intrinsic::nvvm_suld_1d_i8_clamp:
4990 case Intrinsic::nvvm_suld_1d_v2i8_clamp:
4991 case Intrinsic::nvvm_suld_1d_v4i8_clamp:
4992 case Intrinsic::nvvm_suld_1d_array_i8_clamp:
4993 case Intrinsic::nvvm_suld_1d_array_v2i8_clamp:
4994 case Intrinsic::nvvm_suld_1d_array_v4i8_clamp:
4995 case Intrinsic::nvvm_suld_2d_i8_clamp:
4996 case Intrinsic::nvvm_suld_2d_v2i8_clamp:
4997 case Intrinsic::nvvm_suld_2d_v4i8_clamp:
4998 case Intrinsic::nvvm_suld_2d_array_i8_clamp:
4999 case Intrinsic::nvvm_suld_2d_array_v2i8_clamp:
5000 case Intrinsic::nvvm_suld_2d_array_v4i8_clamp:
5001 case Intrinsic::nvvm_suld_3d_i8_clamp:
5002 case Intrinsic::nvvm_suld_3d_v2i8_clamp:
5003 case Intrinsic::nvvm_suld_3d_v4i8_clamp:
5004 case Intrinsic::nvvm_suld_1d_i8_trap:
5005 case Intrinsic::nvvm_suld_1d_v2i8_trap:
5006 case Intrinsic::nvvm_suld_1d_v4i8_trap:
5007 case Intrinsic::nvvm_suld_1d_array_i8_trap:
5008 case Intrinsic::nvvm_suld_1d_array_v2i8_trap:
5009 case Intrinsic::nvvm_suld_1d_array_v4i8_trap:
5010 case Intrinsic::nvvm_suld_2d_i8_trap:
5011 case Intrinsic::nvvm_suld_2d_v2i8_trap:
5012 case Intrinsic::nvvm_suld_2d_v4i8_trap:
5013 case Intrinsic::nvvm_suld_2d_array_i8_trap:
5014 case Intrinsic::nvvm_suld_2d_array_v2i8_trap:
5015 case Intrinsic::nvvm_suld_2d_array_v4i8_trap:
5016 case Intrinsic::nvvm_suld_3d_i8_trap:
5017 case Intrinsic::nvvm_suld_3d_v2i8_trap:
5018 case Intrinsic::nvvm_suld_3d_v4i8_trap:
5019 case Intrinsic::nvvm_suld_1d_i8_zero:
5020 case Intrinsic::nvvm_suld_1d_v2i8_zero:
5021 case Intrinsic::nvvm_suld_1d_v4i8_zero:
5022 case Intrinsic::nvvm_suld_1d_array_i8_zero:
5023 case Intrinsic::nvvm_suld_1d_array_v2i8_zero:
5024 case Intrinsic::nvvm_suld_1d_array_v4i8_zero:
5025 case Intrinsic::nvvm_suld_2d_i8_zero:
5026 case Intrinsic::nvvm_suld_2d_v2i8_zero:
5027 case Intrinsic::nvvm_suld_2d_v4i8_zero:
5028 case Intrinsic::nvvm_suld_2d_array_i8_zero:
5029 case Intrinsic::nvvm_suld_2d_array_v2i8_zero:
5030 case Intrinsic::nvvm_suld_2d_array_v4i8_zero:
5031 case Intrinsic::nvvm_suld_3d_i8_zero:
5032 case Intrinsic::nvvm_suld_3d_v2i8_zero:
5033 case Intrinsic::nvvm_suld_3d_v4i8_zero:
5034 Info.opc = ISD::INTRINSIC_W_CHAIN;
5035 Info.memVT = MVT::i8;
5036 Info.ptrVal = nullptr;
5037 Info.offset = 0;
5038 Info.flags = MachineMemOperand::MOLoad;
5039 Info.align = Align(16);
5040 Infos.push_back(Info);
5041 return;
5042
5043 case Intrinsic::nvvm_suld_1d_i16_clamp:
5044 case Intrinsic::nvvm_suld_1d_v2i16_clamp:
5045 case Intrinsic::nvvm_suld_1d_v4i16_clamp:
5046 case Intrinsic::nvvm_suld_1d_array_i16_clamp:
5047 case Intrinsic::nvvm_suld_1d_array_v2i16_clamp:
5048 case Intrinsic::nvvm_suld_1d_array_v4i16_clamp:
5049 case Intrinsic::nvvm_suld_2d_i16_clamp:
5050 case Intrinsic::nvvm_suld_2d_v2i16_clamp:
5051 case Intrinsic::nvvm_suld_2d_v4i16_clamp:
5052 case Intrinsic::nvvm_suld_2d_array_i16_clamp:
5053 case Intrinsic::nvvm_suld_2d_array_v2i16_clamp:
5054 case Intrinsic::nvvm_suld_2d_array_v4i16_clamp:
5055 case Intrinsic::nvvm_suld_3d_i16_clamp:
5056 case Intrinsic::nvvm_suld_3d_v2i16_clamp:
5057 case Intrinsic::nvvm_suld_3d_v4i16_clamp:
5058 case Intrinsic::nvvm_suld_1d_i16_trap:
5059 case Intrinsic::nvvm_suld_1d_v2i16_trap:
5060 case Intrinsic::nvvm_suld_1d_v4i16_trap:
5061 case Intrinsic::nvvm_suld_1d_array_i16_trap:
5062 case Intrinsic::nvvm_suld_1d_array_v2i16_trap:
5063 case Intrinsic::nvvm_suld_1d_array_v4i16_trap:
5064 case Intrinsic::nvvm_suld_2d_i16_trap:
5065 case Intrinsic::nvvm_suld_2d_v2i16_trap:
5066 case Intrinsic::nvvm_suld_2d_v4i16_trap:
5067 case Intrinsic::nvvm_suld_2d_array_i16_trap:
5068 case Intrinsic::nvvm_suld_2d_array_v2i16_trap:
5069 case Intrinsic::nvvm_suld_2d_array_v4i16_trap:
5070 case Intrinsic::nvvm_suld_3d_i16_trap:
5071 case Intrinsic::nvvm_suld_3d_v2i16_trap:
5072 case Intrinsic::nvvm_suld_3d_v4i16_trap:
5073 case Intrinsic::nvvm_suld_1d_i16_zero:
5074 case Intrinsic::nvvm_suld_1d_v2i16_zero:
5075 case Intrinsic::nvvm_suld_1d_v4i16_zero:
5076 case Intrinsic::nvvm_suld_1d_array_i16_zero:
5077 case Intrinsic::nvvm_suld_1d_array_v2i16_zero:
5078 case Intrinsic::nvvm_suld_1d_array_v4i16_zero:
5079 case Intrinsic::nvvm_suld_2d_i16_zero:
5080 case Intrinsic::nvvm_suld_2d_v2i16_zero:
5081 case Intrinsic::nvvm_suld_2d_v4i16_zero:
5082 case Intrinsic::nvvm_suld_2d_array_i16_zero:
5083 case Intrinsic::nvvm_suld_2d_array_v2i16_zero:
5084 case Intrinsic::nvvm_suld_2d_array_v4i16_zero:
5085 case Intrinsic::nvvm_suld_3d_i16_zero:
5086 case Intrinsic::nvvm_suld_3d_v2i16_zero:
5087 case Intrinsic::nvvm_suld_3d_v4i16_zero:
5088 Info.opc = ISD::INTRINSIC_W_CHAIN;
5089 Info.memVT = MVT::i16;
5090 Info.ptrVal = nullptr;
5091 Info.offset = 0;
5092 Info.flags = MachineMemOperand::MOLoad;
5093 Info.align = Align(16);
5094 Infos.push_back(Info);
5095 return;
5096
5097 case Intrinsic::nvvm_suld_1d_i32_clamp:
5098 case Intrinsic::nvvm_suld_1d_v2i32_clamp:
5099 case Intrinsic::nvvm_suld_1d_v4i32_clamp:
5100 case Intrinsic::nvvm_suld_1d_array_i32_clamp:
5101 case Intrinsic::nvvm_suld_1d_array_v2i32_clamp:
5102 case Intrinsic::nvvm_suld_1d_array_v4i32_clamp:
5103 case Intrinsic::nvvm_suld_2d_i32_clamp:
5104 case Intrinsic::nvvm_suld_2d_v2i32_clamp:
5105 case Intrinsic::nvvm_suld_2d_v4i32_clamp:
5106 case Intrinsic::nvvm_suld_2d_array_i32_clamp:
5107 case Intrinsic::nvvm_suld_2d_array_v2i32_clamp:
5108 case Intrinsic::nvvm_suld_2d_array_v4i32_clamp:
5109 case Intrinsic::nvvm_suld_3d_i32_clamp:
5110 case Intrinsic::nvvm_suld_3d_v2i32_clamp:
5111 case Intrinsic::nvvm_suld_3d_v4i32_clamp:
5112 case Intrinsic::nvvm_suld_1d_i32_trap:
5113 case Intrinsic::nvvm_suld_1d_v2i32_trap:
5114 case Intrinsic::nvvm_suld_1d_v4i32_trap:
5115 case Intrinsic::nvvm_suld_1d_array_i32_trap:
5116 case Intrinsic::nvvm_suld_1d_array_v2i32_trap:
5117 case Intrinsic::nvvm_suld_1d_array_v4i32_trap:
5118 case Intrinsic::nvvm_suld_2d_i32_trap:
5119 case Intrinsic::nvvm_suld_2d_v2i32_trap:
5120 case Intrinsic::nvvm_suld_2d_v4i32_trap:
5121 case Intrinsic::nvvm_suld_2d_array_i32_trap:
5122 case Intrinsic::nvvm_suld_2d_array_v2i32_trap:
5123 case Intrinsic::nvvm_suld_2d_array_v4i32_trap:
5124 case Intrinsic::nvvm_suld_3d_i32_trap:
5125 case Intrinsic::nvvm_suld_3d_v2i32_trap:
5126 case Intrinsic::nvvm_suld_3d_v4i32_trap:
5127 case Intrinsic::nvvm_suld_1d_i32_zero:
5128 case Intrinsic::nvvm_suld_1d_v2i32_zero:
5129 case Intrinsic::nvvm_suld_1d_v4i32_zero:
5130 case Intrinsic::nvvm_suld_1d_array_i32_zero:
5131 case Intrinsic::nvvm_suld_1d_array_v2i32_zero:
5132 case Intrinsic::nvvm_suld_1d_array_v4i32_zero:
5133 case Intrinsic::nvvm_suld_2d_i32_zero:
5134 case Intrinsic::nvvm_suld_2d_v2i32_zero:
5135 case Intrinsic::nvvm_suld_2d_v4i32_zero:
5136 case Intrinsic::nvvm_suld_2d_array_i32_zero:
5137 case Intrinsic::nvvm_suld_2d_array_v2i32_zero:
5138 case Intrinsic::nvvm_suld_2d_array_v4i32_zero:
5139 case Intrinsic::nvvm_suld_3d_i32_zero:
5140 case Intrinsic::nvvm_suld_3d_v2i32_zero:
5141 case Intrinsic::nvvm_suld_3d_v4i32_zero:
5142 Info.opc = ISD::INTRINSIC_W_CHAIN;
5143 Info.memVT = MVT::i32;
5144 Info.ptrVal = nullptr;
5145 Info.offset = 0;
5146 Info.flags = MachineMemOperand::MOLoad;
5147 Info.align = Align(16);
5148 Infos.push_back(Info);
5149 return;
5150
5151 case Intrinsic::nvvm_suld_1d_i64_clamp:
5152 case Intrinsic::nvvm_suld_1d_v2i64_clamp:
5153 case Intrinsic::nvvm_suld_1d_array_i64_clamp:
5154 case Intrinsic::nvvm_suld_1d_array_v2i64_clamp:
5155 case Intrinsic::nvvm_suld_2d_i64_clamp:
5156 case Intrinsic::nvvm_suld_2d_v2i64_clamp:
5157 case Intrinsic::nvvm_suld_2d_array_i64_clamp:
5158 case Intrinsic::nvvm_suld_2d_array_v2i64_clamp:
5159 case Intrinsic::nvvm_suld_3d_i64_clamp:
5160 case Intrinsic::nvvm_suld_3d_v2i64_clamp:
5161 case Intrinsic::nvvm_suld_1d_i64_trap:
5162 case Intrinsic::nvvm_suld_1d_v2i64_trap:
5163 case Intrinsic::nvvm_suld_1d_array_i64_trap:
5164 case Intrinsic::nvvm_suld_1d_array_v2i64_trap:
5165 case Intrinsic::nvvm_suld_2d_i64_trap:
5166 case Intrinsic::nvvm_suld_2d_v2i64_trap:
5167 case Intrinsic::nvvm_suld_2d_array_i64_trap:
5168 case Intrinsic::nvvm_suld_2d_array_v2i64_trap:
5169 case Intrinsic::nvvm_suld_3d_i64_trap:
5170 case Intrinsic::nvvm_suld_3d_v2i64_trap:
5171 case Intrinsic::nvvm_suld_1d_i64_zero:
5172 case Intrinsic::nvvm_suld_1d_v2i64_zero:
5173 case Intrinsic::nvvm_suld_1d_array_i64_zero:
5174 case Intrinsic::nvvm_suld_1d_array_v2i64_zero:
5175 case Intrinsic::nvvm_suld_2d_i64_zero:
5176 case Intrinsic::nvvm_suld_2d_v2i64_zero:
5177 case Intrinsic::nvvm_suld_2d_array_i64_zero:
5178 case Intrinsic::nvvm_suld_2d_array_v2i64_zero:
5179 case Intrinsic::nvvm_suld_3d_i64_zero:
5180 case Intrinsic::nvvm_suld_3d_v2i64_zero:
5181 Info.opc = ISD::INTRINSIC_W_CHAIN;
5182 Info.memVT = MVT::i64;
5183 Info.ptrVal = nullptr;
5184 Info.offset = 0;
5185 Info.flags = MachineMemOperand::MOLoad;
5186 Info.align = Align(16);
5187 Infos.push_back(Info);
5188 return;
5189
5190 case Intrinsic::nvvm_tcgen05_ld_16x64b_x1:
5191 case Intrinsic::nvvm_tcgen05_ld_32x32b_x1:
5192 case Intrinsic::nvvm_tcgen05_ld_16x32bx2_x1: {
5193 Info.opc = ISD::INTRINSIC_W_CHAIN;
5194 Info.memVT = MVT::v1i32;
5195 Info.ptrVal = I.getArgOperand(0);
5196 Info.offset = 0;
5197 Info.flags = MachineMemOperand::MOLoad;
5198 Info.align.reset();
5199 Infos.push_back(Info);
5200 return;
5201 }
5202
5203 case Intrinsic::nvvm_tcgen05_ld_16x64b_x2:
5204 case Intrinsic::nvvm_tcgen05_ld_16x128b_x1:
5205 case Intrinsic::nvvm_tcgen05_ld_32x32b_x2:
5206 case Intrinsic::nvvm_tcgen05_ld_16x32bx2_x2:
5207 case Intrinsic::nvvm_tcgen05_ld_red_32x32b_x2_i32:
5208 case Intrinsic::nvvm_tcgen05_ld_red_16x32bx2_x2_i32: {
5209 Info.opc = ISD::INTRINSIC_W_CHAIN;
5210 Info.memVT = MVT::v2i32;
5211 Info.ptrVal = I.getArgOperand(0);
5212 Info.offset = 0;
5213 Info.flags = MachineMemOperand::MOLoad;
5214 Info.align.reset();
5215 Infos.push_back(Info);
5216 return;
5217 }
5218
5219 case Intrinsic::nvvm_tcgen05_ld_red_32x32b_x2_f32:
5220 case Intrinsic::nvvm_tcgen05_ld_red_16x32bx2_x2_f32: {
5221 Info.opc = ISD::INTRINSIC_W_CHAIN;
5222 Info.memVT = MVT::v2f32;
5223 Info.ptrVal = I.getArgOperand(0);
5224 Info.offset = 0;
5225 Info.flags = MachineMemOperand::MOLoad;
5226 Info.align.reset();
5227 Infos.push_back(Info);
5228 return;
5229 }
5230
5231 case Intrinsic::nvvm_tcgen05_ld_16x64b_x4:
5232 case Intrinsic::nvvm_tcgen05_ld_16x128b_x2:
5233 case Intrinsic::nvvm_tcgen05_ld_32x32b_x4:
5234 case Intrinsic::nvvm_tcgen05_ld_16x256b_x1:
5235 case Intrinsic::nvvm_tcgen05_ld_16x32bx2_x4:
5236 case Intrinsic::nvvm_tcgen05_ld_red_32x32b_x4_i32:
5237 case Intrinsic::nvvm_tcgen05_ld_red_16x32bx2_x4_i32: {
5238 Info.opc = ISD::INTRINSIC_W_CHAIN;
5239 Info.memVT = MVT::v4i32;
5240 Info.ptrVal = I.getArgOperand(0);
5241 Info.offset = 0;
5242 Info.flags = MachineMemOperand::MOLoad;
5243 Info.align.reset();
5244 Infos.push_back(Info);
5245 return;
5246 }
5247
5248 case Intrinsic::nvvm_tcgen05_ld_red_32x32b_x4_f32:
5249 case Intrinsic::nvvm_tcgen05_ld_red_16x32bx2_x4_f32: {
5250 Info.opc = ISD::INTRINSIC_W_CHAIN;
5251 Info.memVT = MVT::v4f32;
5252 Info.ptrVal = I.getArgOperand(0);
5253 Info.offset = 0;
5254 Info.flags = MachineMemOperand::MOLoad;
5255 Info.align.reset();
5256 Infos.push_back(Info);
5257 return;
5258 }
5259
5260 case Intrinsic::nvvm_tcgen05_ld_16x64b_x8:
5261 case Intrinsic::nvvm_tcgen05_ld_16x128b_x4:
5262 case Intrinsic::nvvm_tcgen05_ld_16x256b_x2:
5263 case Intrinsic::nvvm_tcgen05_ld_32x32b_x8:
5264 case Intrinsic::nvvm_tcgen05_ld_16x32bx2_x8:
5265 case Intrinsic::nvvm_tcgen05_ld_red_32x32b_x8_i32:
5266 case Intrinsic::nvvm_tcgen05_ld_red_16x32bx2_x8_i32: {
5267 Info.opc = ISD::INTRINSIC_W_CHAIN;
5268 Info.memVT = MVT::v8i32;
5269 Info.ptrVal = I.getArgOperand(0);
5270 Info.offset = 0;
5271 Info.flags = MachineMemOperand::MOLoad;
5272 Info.align.reset();
5273 Infos.push_back(Info);
5274 return;
5275 }
5276
5277 case Intrinsic::nvvm_tcgen05_ld_red_32x32b_x8_f32:
5278 case Intrinsic::nvvm_tcgen05_ld_red_16x32bx2_x8_f32: {
5279 Info.opc = ISD::INTRINSIC_W_CHAIN;
5280 Info.memVT = MVT::v8f32;
5281 Info.ptrVal = I.getArgOperand(0);
5282 Info.offset = 0;
5283 Info.flags = MachineMemOperand::MOLoad;
5284 Info.align.reset();
5285 Infos.push_back(Info);
5286 return;
5287 }
5288
5289 case Intrinsic::nvvm_tcgen05_ld_16x64b_x16:
5290 case Intrinsic::nvvm_tcgen05_ld_16x128b_x8:
5291 case Intrinsic::nvvm_tcgen05_ld_16x256b_x4:
5292 case Intrinsic::nvvm_tcgen05_ld_32x32b_x16:
5293 case Intrinsic::nvvm_tcgen05_ld_16x32bx2_x16:
5294 case Intrinsic::nvvm_tcgen05_ld_red_32x32b_x16_i32:
5295 case Intrinsic::nvvm_tcgen05_ld_red_16x32bx2_x16_i32: {
5296 Info.opc = ISD::INTRINSIC_W_CHAIN;
5297 Info.memVT = MVT::v16i32;
5298 Info.ptrVal = I.getArgOperand(0);
5299 Info.offset = 0;
5300 Info.flags = MachineMemOperand::MOLoad;
5301 Info.align.reset();
5302 Infos.push_back(Info);
5303 return;
5304 }
5305
5306 case Intrinsic::nvvm_tcgen05_ld_red_32x32b_x16_f32:
5307 case Intrinsic::nvvm_tcgen05_ld_red_16x32bx2_x16_f32: {
5308 Info.opc = ISD::INTRINSIC_W_CHAIN;
5309 Info.memVT = MVT::v16f32;
5310 Info.ptrVal = I.getArgOperand(0);
5311 Info.offset = 0;
5312 Info.flags = MachineMemOperand::MOLoad;
5313 Info.align.reset();
5314 Infos.push_back(Info);
5315 return;
5316 }
5317
5318 case Intrinsic::nvvm_tcgen05_ld_16x64b_x32:
5319 case Intrinsic::nvvm_tcgen05_ld_16x128b_x16:
5320 case Intrinsic::nvvm_tcgen05_ld_16x256b_x8:
5321 case Intrinsic::nvvm_tcgen05_ld_32x32b_x32:
5322 case Intrinsic::nvvm_tcgen05_ld_16x32bx2_x32:
5323 case Intrinsic::nvvm_tcgen05_ld_red_32x32b_x32_i32:
5324 case Intrinsic::nvvm_tcgen05_ld_red_16x32bx2_x32_i32: {
5325 Info.opc = ISD::INTRINSIC_W_CHAIN;
5326 Info.memVT = MVT::v32i32;
5327 Info.ptrVal = I.getArgOperand(0);
5328 Info.offset = 0;
5329 Info.flags = MachineMemOperand::MOLoad;
5330 Info.align.reset();
5331 Infos.push_back(Info);
5332 return;
5333 }
5334
5335 case Intrinsic::nvvm_tcgen05_ld_red_32x32b_x32_f32:
5336 case Intrinsic::nvvm_tcgen05_ld_red_16x32bx2_x32_f32: {
5337 Info.opc = ISD::INTRINSIC_W_CHAIN;
5338 Info.memVT = MVT::v32f32;
5339 Info.ptrVal = I.getArgOperand(0);
5340 Info.offset = 0;
5341 Info.flags = MachineMemOperand::MOLoad;
5342 Info.align.reset();
5343 Infos.push_back(Info);
5344 return;
5345 }
5346
5347 case Intrinsic::nvvm_tcgen05_ld_16x64b_x64:
5348 case Intrinsic::nvvm_tcgen05_ld_16x128b_x32:
5349 case Intrinsic::nvvm_tcgen05_ld_16x256b_x16:
5350 case Intrinsic::nvvm_tcgen05_ld_32x32b_x64:
5351 case Intrinsic::nvvm_tcgen05_ld_16x32bx2_x64:
5352 case Intrinsic::nvvm_tcgen05_ld_red_32x32b_x64_i32:
5353 case Intrinsic::nvvm_tcgen05_ld_red_16x32bx2_x64_i32: {
5354 Info.opc = ISD::INTRINSIC_W_CHAIN;
5355 Info.memVT = MVT::v64i32;
5356 Info.ptrVal = I.getArgOperand(0);
5357 Info.offset = 0;
5358 Info.flags = MachineMemOperand::MOLoad;
5359 Info.align.reset();
5360 Infos.push_back(Info);
5361 return;
5362 }
5363
5364 case Intrinsic::nvvm_tcgen05_ld_red_32x32b_x64_f32:
5365 case Intrinsic::nvvm_tcgen05_ld_red_16x32bx2_x64_f32: {
5366 Info.opc = ISD::INTRINSIC_W_CHAIN;
5367 Info.memVT = MVT::v64f32;
5368 Info.ptrVal = I.getArgOperand(0);
5369 Info.offset = 0;
5370 Info.flags = MachineMemOperand::MOLoad;
5371 Info.align.reset();
5372 Infos.push_back(Info);
5373 return;
5374 }
5375
5376 case Intrinsic::nvvm_tcgen05_ld_16x64b_x128:
5377 case Intrinsic::nvvm_tcgen05_ld_16x128b_x64:
5378 case Intrinsic::nvvm_tcgen05_ld_16x256b_x32:
5379 case Intrinsic::nvvm_tcgen05_ld_32x32b_x128:
5380 case Intrinsic::nvvm_tcgen05_ld_16x32bx2_x128:
5381 case Intrinsic::nvvm_tcgen05_ld_red_32x32b_x128_i32:
5382 case Intrinsic::nvvm_tcgen05_ld_red_16x32bx2_x128_i32: {
5383 Info.opc = ISD::INTRINSIC_W_CHAIN;
5384 Info.memVT = MVT::v128i32;
5385 Info.ptrVal = I.getArgOperand(0);
5386 Info.offset = 0;
5387 Info.flags = MachineMemOperand::MOLoad;
5388 Info.align.reset();
5389 Infos.push_back(Info);
5390 return;
5391 }
5392
5393 case Intrinsic::nvvm_tcgen05_ld_red_32x32b_x128_f32:
5394 case Intrinsic::nvvm_tcgen05_ld_red_16x32bx2_x128_f32: {
5395 Info.opc = ISD::INTRINSIC_W_CHAIN;
5396 Info.memVT = MVT::v128f32;
5397 Info.ptrVal = I.getArgOperand(0);
5398 Info.offset = 0;
5399 Info.flags = MachineMemOperand::MOLoad;
5400 Info.align.reset();
5401 Infos.push_back(Info);
5402 return;
5403 }
5404
5405 case Intrinsic::nvvm_tcgen05_st_16x64b_x1:
5406 case Intrinsic::nvvm_tcgen05_st_32x32b_x1:
5407 case Intrinsic::nvvm_tcgen05_st_16x32bx2_x1: {
5408 Info.opc = ISD::INTRINSIC_VOID;
5409 Info.memVT = MVT::i32;
5410 Info.ptrVal = I.getArgOperand(0);
5411 Info.offset = 0;
5412 Info.flags = MachineMemOperand::MOStore;
5413 Info.align.reset();
5414 Infos.push_back(Info);
5415 return;
5416 }
5417
5418 case Intrinsic::nvvm_tcgen05_st_16x64b_x2:
5419 case Intrinsic::nvvm_tcgen05_st_16x128b_x1:
5420 case Intrinsic::nvvm_tcgen05_st_32x32b_x2:
5421 case Intrinsic::nvvm_tcgen05_st_16x32bx2_x2: {
5422 Info.opc = ISD::INTRINSIC_VOID;
5423 Info.memVT = MVT::v2i32;
5424 Info.ptrVal = I.getArgOperand(0);
5425 Info.offset = 0;
5426 Info.flags = MachineMemOperand::MOStore;
5427 Info.align.reset();
5428 Infos.push_back(Info);
5429 return;
5430 }
5431
5432 case Intrinsic::nvvm_tcgen05_st_16x64b_x4:
5433 case Intrinsic::nvvm_tcgen05_st_16x128b_x2:
5434 case Intrinsic::nvvm_tcgen05_st_16x256b_x1:
5435 case Intrinsic::nvvm_tcgen05_st_32x32b_x4:
5436 case Intrinsic::nvvm_tcgen05_st_16x32bx2_x4: {
5437 Info.opc = ISD::INTRINSIC_VOID;
5438 Info.memVT = MVT::v4i32;
5439 Info.ptrVal = I.getArgOperand(0);
5440 Info.offset = 0;
5441 Info.flags = MachineMemOperand::MOStore;
5442 Info.align.reset();
5443 Infos.push_back(Info);
5444 return;
5445 }
5446
5447 case Intrinsic::nvvm_tcgen05_st_16x64b_x8:
5448 case Intrinsic::nvvm_tcgen05_st_16x128b_x4:
5449 case Intrinsic::nvvm_tcgen05_st_16x256b_x2:
5450 case Intrinsic::nvvm_tcgen05_st_32x32b_x8:
5451 case Intrinsic::nvvm_tcgen05_st_16x32bx2_x8: {
5452 Info.opc = ISD::INTRINSIC_VOID;
5453 Info.memVT = MVT::v8i32;
5454 Info.ptrVal = I.getArgOperand(0);
5455 Info.offset = 0;
5456 Info.flags = MachineMemOperand::MOStore;
5457 Info.align.reset();
5458 Infos.push_back(Info);
5459 return;
5460 }
5461
5462 case Intrinsic::nvvm_tcgen05_st_16x64b_x16:
5463 case Intrinsic::nvvm_tcgen05_st_16x128b_x8:
5464 case Intrinsic::nvvm_tcgen05_st_16x256b_x4:
5465 case Intrinsic::nvvm_tcgen05_st_32x32b_x16:
5466 case Intrinsic::nvvm_tcgen05_st_16x32bx2_x16: {
5467 Info.opc = ISD::INTRINSIC_VOID;
5468 Info.memVT = MVT::v16i32;
5469 Info.ptrVal = I.getArgOperand(0);
5470 Info.offset = 0;
5471 Info.flags = MachineMemOperand::MOStore;
5472 Info.align.reset();
5473 Infos.push_back(Info);
5474 return;
5475 }
5476
5477 case Intrinsic::nvvm_tcgen05_st_16x64b_x32:
5478 case Intrinsic::nvvm_tcgen05_st_16x128b_x16:
5479 case Intrinsic::nvvm_tcgen05_st_16x256b_x8:
5480 case Intrinsic::nvvm_tcgen05_st_32x32b_x32:
5481 case Intrinsic::nvvm_tcgen05_st_16x32bx2_x32: {
5482 Info.opc = ISD::INTRINSIC_VOID;
5483 Info.memVT = MVT::v32i32;
5484 Info.ptrVal = I.getArgOperand(0);
5485 Info.offset = 0;
5486 Info.flags = MachineMemOperand::MOStore;
5487 Info.align.reset();
5488 Infos.push_back(Info);
5489 return;
5490 }
5491
5492 case Intrinsic::nvvm_tcgen05_st_16x64b_x64:
5493 case Intrinsic::nvvm_tcgen05_st_16x128b_x32:
5494 case Intrinsic::nvvm_tcgen05_st_16x256b_x16:
5495 case Intrinsic::nvvm_tcgen05_st_32x32b_x64:
5496 case Intrinsic::nvvm_tcgen05_st_16x32bx2_x64: {
5497 Info.opc = ISD::INTRINSIC_VOID;
5498 Info.memVT = MVT::v64i32;
5499 Info.ptrVal = I.getArgOperand(0);
5500 Info.offset = 0;
5501 Info.flags = MachineMemOperand::MOStore;
5502 Info.align.reset();
5503 Infos.push_back(Info);
5504 return;
5505 }
5506
5507 case Intrinsic::nvvm_tcgen05_st_16x64b_x128:
5508 case Intrinsic::nvvm_tcgen05_st_16x128b_x64:
5509 case Intrinsic::nvvm_tcgen05_st_16x256b_x32:
5510 case Intrinsic::nvvm_tcgen05_st_32x32b_x128:
5511 case Intrinsic::nvvm_tcgen05_st_16x32bx2_x128: {
5512 Info.opc = ISD::INTRINSIC_VOID;
5513 Info.memVT = MVT::v128i32;
5514 Info.ptrVal = I.getArgOperand(0);
5515 Info.offset = 0;
5516 Info.flags = MachineMemOperand::MOStore;
5517 Info.align.reset();
5518 Infos.push_back(Info);
5519 return;
5520 }
5521 case Intrinsic::nvvm_tcgen05_mma_shared_disable_output_lane_cg1:
5522 case Intrinsic::nvvm_tcgen05_mma_shared_scale_d_disable_output_lane_cg1:
5523 case Intrinsic::nvvm_tcgen05_mma_sp_shared_disable_output_lane_cg1:
5524 case Intrinsic::nvvm_tcgen05_mma_sp_shared_scale_d_disable_output_lane_cg1:
5525 case Intrinsic::nvvm_tcgen05_mma_tensor_disable_output_lane_cg1:
5526 case Intrinsic::nvvm_tcgen05_mma_tensor_scale_d_disable_output_lane_cg1:
5527 case Intrinsic::nvvm_tcgen05_mma_tensor_disable_output_lane_cg1_ashift:
5528 case Intrinsic::
5529 nvvm_tcgen05_mma_tensor_scale_d_disable_output_lane_cg1_ashift:
5530 case Intrinsic::nvvm_tcgen05_mma_sp_tensor_disable_output_lane_cg1:
5531 case Intrinsic::nvvm_tcgen05_mma_sp_tensor_scale_d_disable_output_lane_cg1:
5532 case Intrinsic::nvvm_tcgen05_mma_sp_tensor_disable_output_lane_cg1_ashift:
5533 case Intrinsic::
5534 nvvm_tcgen05_mma_sp_tensor_scale_d_disable_output_lane_cg1_ashift: {
5535 // We are reading and writing back to TMem
5536 Info.opc = ISD::INTRINSIC_VOID;
5537 Info.memVT = MVT::v4i32;
5538 Info.ptrVal = I.getArgOperand(0);
5539 Info.offset = 0;
5541 Info.align = Align(16);
5542 Infos.push_back(Info);
5543 return;
5544 }
5545
5546 case Intrinsic::nvvm_tcgen05_mma_shared_disable_output_lane_cg2:
5547 case Intrinsic::nvvm_tcgen05_mma_shared_scale_d_disable_output_lane_cg2:
5548 case Intrinsic::nvvm_tcgen05_mma_sp_shared_disable_output_lane_cg2:
5549 case Intrinsic::nvvm_tcgen05_mma_sp_shared_scale_d_disable_output_lane_cg2:
5550 case Intrinsic::nvvm_tcgen05_mma_tensor_disable_output_lane_cg2:
5551 case Intrinsic::nvvm_tcgen05_mma_tensor_scale_d_disable_output_lane_cg2:
5552 case Intrinsic::nvvm_tcgen05_mma_sp_tensor_disable_output_lane_cg2:
5553 case Intrinsic::nvvm_tcgen05_mma_sp_tensor_scale_d_disable_output_lane_cg2:
5554 case Intrinsic::nvvm_tcgen05_mma_tensor_disable_output_lane_cg2_ashift:
5555 case Intrinsic::
5556 nvvm_tcgen05_mma_tensor_scale_d_disable_output_lane_cg2_ashift:
5557 case Intrinsic::nvvm_tcgen05_mma_sp_tensor_disable_output_lane_cg2_ashift:
5558 case Intrinsic::
5559 nvvm_tcgen05_mma_sp_tensor_scale_d_disable_output_lane_cg2_ashift: {
5560 // We are reading and writing back to TMem
5561 Info.opc = ISD::INTRINSIC_VOID;
5562 Info.memVT = MVT::v8i32;
5563 Info.ptrVal = I.getArgOperand(0);
5564 Info.offset = 0;
5566 Info.align = Align(16);
5567 Infos.push_back(Info);
5568 return;
5569 }
5570 }
5571}
5572
5573/// getFunctionParamOptimizedAlign - since function arguments are passed via
5574/// .param space, we may want to increase their alignment in a way that
5575/// ensures that we can effectively vectorize their loads & stores. We can
5576/// increase alignment only if the function has internal or has private
5577/// linkage as for other linkage types callers may already rely on default
5578/// alignment. To allow using 128-bit vectorized loads/stores, this function
5579/// ensures that alignment is 16 or greater.
5581 const Function *F, Type *ArgTy, const DataLayout &DL) const {
5582 // Capping the alignment to 128 bytes as that is the maximum alignment
5583 // supported by PTX.
5584 const Align ABITypeAlign = std::min(Align(128), DL.getABITypeAlign(ArgTy));
5585
5586 // If a function has linkage different from internal or private, we
5587 // must use default ABI alignment as external users rely on it. Same
5588 // for a function that may be called from a function pointer.
5589 if (!F || !F->hasLocalLinkage() ||
5590 F->hasAddressTaken(/*Users=*/nullptr,
5591 /*IgnoreCallbackUses=*/false,
5592 /*IgnoreAssumeLikeCalls=*/true,
5593 /*IgnoreLLVMUsed=*/true))
5594 return ABITypeAlign;
5595
5596 assert(!isKernelFunction(*F) && "Expect kernels to have non-local linkage");
5597 return std::max(Align(16), ABITypeAlign);
5598}
5599
5600/// Helper for computing alignment of a device function byval parameter.
5602 const Function *F, Type *ArgTy, Align InitialAlign,
5603 const DataLayout &DL) const {
5604 Align ArgAlign = InitialAlign;
5605 // Try to increase alignment to enhance vectorization options.
5606 if (F)
5607 ArgAlign = std::max(ArgAlign, getFunctionParamOptimizedAlign(F, ArgTy, DL));
5608
5609 // Old ptx versions have a bug. When PTX code takes address of
5610 // byval parameter with alignment < 4, ptxas generates code to
5611 // spill argument into memory. Alas on sm_50+ ptxas generates
5612 // SASS code that fails with misaligned access. To work around
5613 // the problem, make sure that we align byval parameters by at
5614 // least 4. This bug seems to be fixed at least starting from
5615 // ptxas > 9.0.
5616 // TODO: remove this after verifying the bug is not reproduced
5617 // on non-deprecated ptxas versions.
5619 ArgAlign = std::max(ArgAlign, Align(4));
5620
5621 return ArgAlign;
5622}
5623
5624// Helper for getting a function parameter name. Name is composed from
5625// its index and the function name. Negative index corresponds to special
5626// parameter (unsized array) used for passing variable arguments.
5628 int Idx) const {
5629 std::string ParamName;
5630 raw_string_ostream ParamStr(ParamName);
5631
5632 ParamStr << getTargetMachine().getSymbol(F)->getName();
5633 if (Idx < 0)
5634 ParamStr << "_vararg";
5635 else
5636 ParamStr << "_param_" << Idx;
5637
5638 return ParamName;
5639}
5640
5641/// isLegalAddressingMode - Return true if the addressing mode represented
5642/// by AM is legal for this target, for a load/store of the specified type.
5643/// Used to guide target specific optimizations, like loop strength reduction
5644/// (LoopStrengthReduce.cpp) and memory optimization for address mode
5645/// (CodeGenPrepare.cpp)
5647 const AddrMode &AM, Type *Ty,
5648 unsigned AS, Instruction *I) const {
5649 // AddrMode - This represents an addressing mode of:
5650 // BaseGV + BaseOffs + BaseReg + Scale*ScaleReg
5651 //
5652 // The legal address modes are
5653 // - [avar]
5654 // - [areg]
5655 // - [areg+immoff]
5656 // - [immAddr]
5657
5658 // immoff must fit in a signed 32-bit int
5659 if (!APInt(64, AM.BaseOffs).isSignedIntN(32))
5660 return false;
5661
5662 if (AM.BaseGV)
5663 return !AM.BaseOffs && !AM.HasBaseReg && !AM.Scale;
5664
5665 switch (AM.Scale) {
5666 case 0: // "r", "r+i" or "i" is allowed
5667 break;
5668 case 1:
5669 if (AM.HasBaseReg) // "r+r+i" or "r+r" is not allowed.
5670 return false;
5671 // Otherwise we have r+i.
5672 break;
5673 default:
5674 // No scale > 1 is allowed
5675 return false;
5676 }
5677 return true;
5678}
5679
5680//===----------------------------------------------------------------------===//
5681// NVPTX Inline Assembly Support
5682//===----------------------------------------------------------------------===//
5683
5684/// getConstraintType - Given a constraint letter, return the type of
5685/// constraint it is for this target.
5688 if (Constraint.size() == 1) {
5689 switch (Constraint[0]) {
5690 default:
5691 break;
5692 case 'b':
5693 case 'r':
5694 case 'h':
5695 case 'c':
5696 case 'l':
5697 case 'f':
5698 case 'd':
5699 case 'q':
5700 case '0':
5701 case 'N':
5702 return C_RegisterClass;
5703 }
5704 }
5705 return TargetLowering::getConstraintType(Constraint);
5706}
5707
5708std::pair<unsigned, const TargetRegisterClass *>
5710 StringRef Constraint,
5711 MVT VT) const {
5712 if (Constraint.size() == 1) {
5713 switch (Constraint[0]) {
5714 case 'b':
5715 return std::make_pair(0U, &NVPTX::B1RegClass);
5716 case 'c':
5717 case 'h':
5718 return std::make_pair(0U, &NVPTX::B16RegClass);
5719 case 'r':
5720 case 'f':
5721 return std::make_pair(0U, &NVPTX::B32RegClass);
5722 case 'l':
5723 case 'N':
5724 case 'd':
5725 return std::make_pair(0U, &NVPTX::B64RegClass);
5726 case 'q': {
5727 if (STI.getSmVersion() < 70)
5728 report_fatal_error("Inline asm with 128 bit operands is only "
5729 "supported for sm_70 and higher!");
5730 return std::make_pair(0U, &NVPTX::B128RegClass);
5731 }
5732 }
5733 }
5734 return TargetLowering::getRegForInlineAsmConstraint(TRI, Constraint, VT);
5735}
5736
5737//===----------------------------------------------------------------------===//
5738// NVPTX DAG Combining
5739//===----------------------------------------------------------------------===//
5740
5742 CodeGenOptLevel OptLevel) const {
5743 // Always honor command-line argument
5744 if (FMAContractLevelOpt.getNumOccurrences() > 0)
5745 return FMAContractLevelOpt > 0;
5746
5747 // Do not contract if we're not optimizing the code.
5748 if (OptLevel == CodeGenOptLevel::None)
5749 return false;
5750
5751 // Honor TargetOptions flags that explicitly say fusion is okay.
5753 return true;
5754
5755 return false;
5756}
5757
5758static bool isConstZero(const SDValue &Operand) {
5759 const auto *Const = dyn_cast<ConstantSDNode>(Operand);
5760 return Const && Const->getZExtValue() == 0;
5761}
5762
5763/// PerformADDCombineWithOperands - Try DAG combinations for an ADD with
5764/// operands N0 and N1. This is a helper for PerformADDCombine that is
5765/// called with the default operands, and if that fails, with commuted
5766/// operands.
5767static SDValue
5770 EVT VT = N0.getValueType();
5771
5772 // Since integer multiply-add costs the same as integer multiply
5773 // but is more costly than integer add, do the fusion only when
5774 // the mul is only used in the add.
5775 // TODO: this may not be true for later architectures, consider relaxing this
5776 if (!N0.getNode()->hasOneUse())
5777 return SDValue();
5778
5779 // fold (add (select cond, 0, (mul a, b)), c)
5780 // -> (select cond, c, (add (mul a, b), c))
5781 //
5782 if (N0.getOpcode() == ISD::SELECT) {
5783 unsigned ZeroOpNum;
5784 if (isConstZero(N0->getOperand(1)))
5785 ZeroOpNum = 1;
5786 else if (isConstZero(N0->getOperand(2)))
5787 ZeroOpNum = 2;
5788 else
5789 return SDValue();
5790
5791 SDValue M = N0->getOperand((ZeroOpNum == 1) ? 2 : 1);
5792 if (M->getOpcode() != ISD::MUL || !M.getNode()->hasOneUse())
5793 return SDValue();
5794
5795 SDLoc DL(N);
5796 SDValue Mul =
5797 DCI.DAG.getNode(ISD::MUL, DL, VT, M->getOperand(0), M->getOperand(1));
5798 SDValue MAD = DCI.DAG.getNode(ISD::ADD, DL, VT, Mul, N1);
5799 return DCI.DAG.getSelect(SDLoc(N), VT, N0->getOperand(0),
5800 ((ZeroOpNum == 1) ? N1 : MAD),
5801 ((ZeroOpNum == 1) ? MAD : N1));
5802 }
5803
5804 return SDValue();
5805}
5806
5807static SDValue
5810 CodeGenOptLevel OptLevel) {
5811 EVT VT = N0.getValueType();
5812 if (N0.getOpcode() == ISD::FMUL) {
5813 const auto *TLI = static_cast<const NVPTXTargetLowering *>(
5814 &DCI.DAG.getTargetLoweringInfo());
5815 if (!(TLI->allowFMA(DCI.DAG.getMachineFunction(), OptLevel) ||
5816 (N->getFlags().hasAllowContract() &&
5817 N0->getFlags().hasAllowContract())))
5818 return SDValue();
5819
5820 // For floating point:
5821 // Do the fusion only when the mul has less than 5 uses and all
5822 // are add.
5823 // The heuristic is that if a use is not an add, then that use
5824 // cannot be fused into fma, therefore mul is still needed anyway.
5825 // If there are more than 4 uses, even if they are all add, fusing
5826 // them will increase register pressue.
5827 //
5828 int numUses = 0;
5829 int nonAddCount = 0;
5830 for (const SDNode *User : N0.getNode()->users()) {
5831 numUses++;
5832 if (User->getOpcode() != ISD::FADD)
5833 ++nonAddCount;
5834 if (numUses >= 5)
5835 return SDValue();
5836 }
5837 if (nonAddCount) {
5838 int orderNo = N->getIROrder();
5839 int orderNo2 = N0.getNode()->getIROrder();
5840 // simple heuristics here for considering potential register
5841 // pressure, the logics here is that the differnce are used
5842 // to measure the distance between def and use, the longer distance
5843 // more likely cause register pressure.
5844 if (orderNo - orderNo2 < 500)
5845 return SDValue();
5846
5847 // Now, check if at least one of the FMUL's operands is live beyond the
5848 // node N, which guarantees that the FMA will not increase register
5849 // pressure at node N.
5850 bool opIsLive = false;
5851 const SDNode *left = N0.getOperand(0).getNode();
5852 const SDNode *right = N0.getOperand(1).getNode();
5853
5854 if (isa<ConstantSDNode>(left) || isa<ConstantSDNode>(right))
5855 opIsLive = true;
5856
5857 if (!opIsLive)
5858 for (const SDNode *User : left->users()) {
5859 int orderNo3 = User->getIROrder();
5860 if (orderNo3 > orderNo) {
5861 opIsLive = true;
5862 break;
5863 }
5864 }
5865
5866 if (!opIsLive)
5867 for (const SDNode *User : right->users()) {
5868 int orderNo3 = User->getIROrder();
5869 if (orderNo3 > orderNo) {
5870 opIsLive = true;
5871 break;
5872 }
5873 }
5874
5875 if (!opIsLive)
5876 return SDValue();
5877 }
5878
5879 return DCI.DAG.getNode(ISD::FMA, SDLoc(N), VT, N0.getOperand(0),
5880 N0.getOperand(1), N1);
5881 }
5882
5883 return SDValue();
5884}
5885
5886/// Fold unpacking movs into a load by increasing the number of return values.
5887///
5888/// ex:
5889/// L: v2f16,ch = load <p>
5890/// a: f16 = extractelt L:0, 0
5891/// b: f16 = extractelt L:0, 1
5892/// use(a, b)
5893///
5894/// ...is turned into...
5895///
5896/// L: f16,f16,ch = LoadV2 <p>
5897/// use(L:0, L:1)
5898static SDValue
5900 // Don't run this optimization before the legalizer
5901 if (!DCI.isAfterLegalizeDAG())
5902 return SDValue();
5903
5904 EVT ElementVT = N->getValueType(0);
5905 // Avoid non-packed types and v4i8
5906 if (!NVPTX::isPackedVectorTy(ElementVT) || ElementVT == MVT::v4i8)
5907 return SDValue();
5908
5909 // Check whether all outputs are either used by an extractelt or are
5910 // glue/chain nodes
5911 if (!all_of(N->uses(), [&](SDUse &U) {
5912 // Skip glue, chain nodes
5913 if (U.getValueType() == MVT::Glue || U.getValueType() == MVT::Other)
5914 return true;
5915 if (U.getUser()->getOpcode() == ISD::EXTRACT_VECTOR_ELT) {
5916 if (N->getOpcode() != ISD::LOAD)
5917 return true;
5918 // Since this is an ISD::LOAD, check all extractelts are used. If
5919 // any are not used, we don't want to defeat another optimization that
5920 // will narrow the load.
5921 //
5922 // For example:
5923 //
5924 // L: v2f16,ch = load <p>
5925 // e0: f16 = extractelt L:0, 0
5926 // e1: f16 = extractelt L:0, 1 <-- unused
5927 // store e0
5928 //
5929 // Can be optimized by DAGCombiner to:
5930 //
5931 // L: f16,ch = load <p>
5932 // store L:0
5933 return !U.getUser()->use_empty();
5934 }
5935
5936 // Otherwise, this use prevents us from splitting a value.
5937 return false;
5938 }))
5939 return SDValue();
5940
5941 auto *LD = cast<MemSDNode>(N);
5942 SDLoc DL(LD);
5943
5944 // the new opcode after we double the number of operands
5945 unsigned Opcode;
5946 SmallVector<SDValue> Operands(LD->ops());
5947 unsigned OldNumOutputs; // non-glue, non-chain outputs
5948 switch (LD->getOpcode()) {
5949 case ISD::LOAD:
5950 OldNumOutputs = 1;
5951 // Any packed type is legal, so the legalizer will not have lowered
5952 // ISD::LOAD -> NVPTXISD::Load (unless it's under-aligned). We have to do it
5953 // here.
5954 Opcode = NVPTXISD::LoadV2;
5955 // append a "full" used bytes mask operand right before the extension type
5956 // operand, signifying that all bytes are used.
5957 Operands.push_back(DCI.DAG.getConstant(UINT32_MAX, DL, MVT::i32));
5958 Operands.push_back(DCI.DAG.getIntPtrConstant(
5959 cast<LoadSDNode>(LD)->getExtensionType(), DL));
5960 break;
5961 case NVPTXISD::LoadV2:
5962 OldNumOutputs = 2;
5963 Opcode = NVPTXISD::LoadV4;
5964 break;
5965 case NVPTXISD::LoadV4:
5966 // V8 is only supported for f32/i32. Don't forget, we're not changing the
5967 // load size here. This is already a 256-bit load.
5968 if (ElementVT != MVT::v2f32 && ElementVT != MVT::v2i32)
5969 return SDValue();
5970 OldNumOutputs = 4;
5971 Opcode = NVPTXISD::LoadV8;
5972 break;
5973 case NVPTXISD::LoadV8:
5974 // PTX doesn't support the next doubling of outputs
5975 return SDValue();
5976 }
5977
5978 // the non-glue, non-chain outputs in the new load
5979 const unsigned NewNumOutputs = OldNumOutputs * 2;
5980 SmallVector<EVT> NewVTs(NewNumOutputs, ElementVT.getVectorElementType());
5981 // add remaining chain and glue values
5982 NewVTs.append(LD->value_begin() + OldNumOutputs, LD->value_end());
5983
5984 // Create the new load
5985 SDValue NewLoad = DCI.DAG.getMemIntrinsicNode(
5986 Opcode, DL, DCI.DAG.getVTList(NewVTs), Operands, LD->getMemoryVT(),
5987 LD->getMemOperand());
5988
5989 // Now we use a combination of BUILD_VECTORs and a MERGE_VALUES node to keep
5990 // the outputs the same. These nodes will be optimized away in later
5991 // DAGCombiner iterations.
5993 for (unsigned I : seq(OldNumOutputs))
5994 Results.push_back(DCI.DAG.getBuildVector(
5995 ElementVT, DL, {NewLoad.getValue(I * 2), NewLoad.getValue(I * 2 + 1)}));
5996 // Add remaining chain and glue nodes
5997 for (unsigned I : seq(NewLoad->getNumValues() - NewNumOutputs))
5998 Results.push_back(NewLoad.getValue(NewNumOutputs + I));
5999
6000 return DCI.DAG.getMergeValues(Results, DL);
6001}
6002
6003/// Fold packing movs into a store.
6004///
6005/// ex:
6006/// v1: v2f16 = BUILD_VECTOR a:f16, b:f16
6007/// v2: v2f16 = BUILD_VECTOR c:f16, d:f16
6008/// StoreV2 v1, v2
6009///
6010/// ...is turned into...
6011///
6012/// StoreV4 a, b, c, d
6015 unsigned Front, unsigned Back) {
6016 // We want to run this as late as possible since other optimizations may
6017 // eliminate the BUILD_VECTORs.
6018 if (!DCI.isAfterLegalizeDAG())
6019 return SDValue();
6020
6021 // Get the type of the operands being stored.
6022 EVT ElementVT = N->getOperand(Front).getValueType();
6023
6024 // Avoid non-packed types and v4i8
6025 if (!NVPTX::isPackedVectorTy(ElementVT) || ElementVT == MVT::v4i8)
6026 return SDValue();
6027
6028 auto *ST = cast<MemSDNode>(N);
6029
6030 // The new opcode after we double the number of operands.
6031 unsigned Opcode;
6032 switch (N->getOpcode()) {
6033 case ISD::STORE:
6034 // Any packed type is legal, so the legalizer will not have lowered
6035 // ISD::STORE -> NVPTXISD::Store (unless it's under-aligned). We have to do
6036 // it here.
6037 Opcode = NVPTXISD::StoreV2;
6038 break;
6039 case NVPTXISD::StoreV2:
6040 Opcode = NVPTXISD::StoreV4;
6041 break;
6042 case NVPTXISD::StoreV4:
6043 // V8 is only supported for f32/i32. Don't forget, we're not changing the
6044 // store size here. This is already a 256-bit store.
6045 if (ElementVT != MVT::v2f32 && ElementVT != MVT::v2i32)
6046 return SDValue();
6047 Opcode = NVPTXISD::StoreV8;
6048 break;
6049 case NVPTXISD::StoreV8:
6050 // PTX doesn't support the next doubling of operands
6051 return SDValue();
6052 default:
6053 llvm_unreachable("Unhandled store opcode");
6054 }
6055
6056 // Scan the operands and if they're all BUILD_VECTORs, we'll have gathered
6057 // their elements.
6058 SmallVector<SDValue, 4> Operands(N->ops().take_front(Front));
6059 for (SDValue BV : N->ops().drop_front(Front).drop_back(Back)) {
6060 if (BV.getOpcode() != ISD::BUILD_VECTOR)
6061 return SDValue();
6062
6063 // If the operand has multiple uses, this optimization can increase register
6064 // pressure.
6065 if (!BV.hasOneUse())
6066 return SDValue();
6067
6068 // DAGCombiner visits nodes bottom-up. Check the BUILD_VECTOR operands for
6069 // any signs they may be folded by some other pattern or rule.
6070 for (SDValue Op : BV->ops()) {
6071 // Peek through bitcasts
6072 if (Op.getOpcode() == ISD::BITCAST)
6073 Op = Op.getOperand(0);
6074
6075 // This may be folded into a PRMT.
6076 if (Op.getValueType() == MVT::i16 && Op.getOpcode() == ISD::TRUNCATE &&
6077 Op->getOperand(0).getValueType() == MVT::i32)
6078 return SDValue();
6079
6080 // This may be folded into cvt.bf16x2
6081 if (Op.getOpcode() == ISD::FP_ROUND)
6082 return SDValue();
6083 }
6084 Operands.append({BV.getOperand(0), BV.getOperand(1)});
6085 }
6086 Operands.append(N->op_end() - Back, N->op_end());
6087
6088 // Now we replace the store
6089 return DCI.DAG.getMemIntrinsicNode(Opcode, SDLoc(N), N->getVTList(), Operands,
6090 ST->getMemoryVT(), ST->getMemOperand());
6091}
6092
6094 const NVPTXSubtarget &STI) {
6095
6096 if (DCI.isBeforeLegalize() && N->getOpcode() == ISD::STORE) {
6097 // Here is our chance to custom lower a store with a non-simple type.
6098 // Unfortunately, we can't do this in the legalizer because there is no
6099 // way to setOperationAction for an non-simple type.
6101 if (!ST->getValue().getValueType().isSimple())
6102 return lowerSTOREVector(SDValue(ST, 0), DCI.DAG, STI);
6103 }
6104
6105 return combinePackingMovIntoStore(N, DCI, 1, 2);
6106}
6107
6109 const NVPTXSubtarget &STI) {
6110 if (DCI.isBeforeLegalize() && N->getOpcode() == ISD::LOAD) {
6111 // Here is our chance to custom lower a load with a non-simple type.
6112 // Unfortunately, we can't do this in the legalizer because there is no
6113 // way to setOperationAction for an non-simple type.
6114 if (!N->getValueType(0).isSimple())
6115 return lowerLoadVector(N, DCI.DAG, STI);
6116 }
6117
6118 return combineUnpackingMovIntoLoad(N, DCI);
6119}
6120
6121/// PerformADDCombine - Target-specific dag combine xforms for ISD::ADD.
6122///
6125 CodeGenOptLevel OptLevel) {
6126 if (OptLevel == CodeGenOptLevel::None)
6127 return SDValue();
6128
6129 SDValue N0 = N->getOperand(0);
6130 SDValue N1 = N->getOperand(1);
6131
6132 // Skip non-integer, non-scalar case
6133 EVT VT = N0.getValueType();
6134 if (VT.isVector() || VT != MVT::i32)
6135 return SDValue();
6136
6137 // First try with the default operand order.
6138 if (SDValue Result = PerformADDCombineWithOperands(N, N0, N1, DCI))
6139 return Result;
6140
6141 // If that didn't work, try again with the operands commuted.
6142 return PerformADDCombineWithOperands(N, N1, N0, DCI);
6143}
6144
6145/// Check if a v2f32 BUILD_VECTOR provably packs values from non-adjacent
6146/// register pairs (non-coalescable).
6147static bool isNonCoalescableBuildVector(const SDValue &BV) {
6148 if (BV.getOpcode() != ISD::BUILD_VECTOR || BV.getValueType() != MVT::v2f32)
6149 return false;
6150
6151 SDValue Elt0 = BV.getOperand(0);
6152 SDValue Elt1 = BV.getOperand(1);
6153
6154 bool IsExt0 = Elt0.getOpcode() == ISD::EXTRACT_VECTOR_ELT;
6155 bool IsExt1 = Elt1.getOpcode() == ISD::EXTRACT_VECTOR_ELT;
6156
6157 // If neither element is an EXTRACT_VECTOR_ELT they are free-standing
6158 // scalars and the register allocator can still place them side-by-side.
6159 if (!IsExt0 && !IsExt1)
6160 return false;
6161
6162 // If exactly one element is an EXTRACT_VECTOR_ELT, the other is a scalar
6163 // that cannot generally occupy the adjacent register slot.
6164 if (IsExt0 != IsExt1)
6165 return true;
6166
6167 // At this point both sources are extracting from vectors. If they are from
6168 // different vectors, then the BUILD_VECTOR is non-coalescable.
6169 SDValue Src0 = Elt0.getOperand(0);
6170 SDValue Src1 = Elt1.getOperand(0);
6171 if (Src0 != Src1)
6172 return true;
6173
6174 auto *Idx0 = dyn_cast<ConstantSDNode>(Elt0.getOperand(1));
6175 auto *Idx1 = dyn_cast<ConstantSDNode>(Elt1.getOperand(1));
6176 // If both indices are dynamic they will be lowered to
6177 // loads and the vector will be spilled to local memory. The register
6178 // allocator can easily place the results in adjacent registers.
6179 if (!Idx0 && !Idx1)
6180 return false;
6181
6182 // If one index is dynamic and the other is constant, the value from the
6183 // constant load will result in an additional register to pair with the result
6184 // from the dynamic load. We consider this non-coalescable.
6185 if ((Idx0 && !Idx1) || (!Idx0 && Idx1))
6186 return true;
6187
6188 // Both are constant, adjacent pairs are coalescable
6189 return std::abs(Idx0->getSExtValue() - Idx1->getSExtValue()) != 1;
6190}
6191
6192/// Scalarize a v2f32 arithmetic node (FADD, FMUL, FSUB, FMA) when at least
6193/// one operand is a BUILD_VECTOR that repacks values from non-adjacent register
6194/// pairs. Without this combine the BUILD_VECTOR forces allocation of a
6195/// temporary 64-bit register, increasing register pressure.
6196///
6197/// Example - before:
6198/// t0: v2f32,v2f32,ch = LoadV2 ...
6199/// t1: f32 = extract_vector_elt t0, 0
6200/// t2: f32 = extract_vector_elt t0:1, 0
6201/// t3: v2f32 = BUILD_VECTOR t1, t2 ;; non-coalescable repack
6202/// t4: v2f32 = fma t_a, t3, t_c
6203///
6204/// After:
6205/// t0: v2f32,v2f32,ch = LoadV2 ...
6206/// t1: f32 = extract_vector_elt t0, 0
6207/// t2: f32 = extract_vector_elt t0:1, 0
6208/// a0: f32 = extract_vector_elt t_a, 0
6209/// a1: f32 = extract_vector_elt t_a, 1
6210/// c0: f32 = extract_vector_elt t_c, 0
6211/// c1: f32 = extract_vector_elt t_c, 1
6212/// r0: f32 = fma a0, t1, c0
6213/// r1: f32 = fma a1, t2, c1
6214/// t4: v2f32 = BUILD_VECTOR r0, r1
6217 EVT VT = N->getValueType(0);
6218 if (VT != MVT::v2f32)
6219 return SDValue();
6220
6221 // Only scalarize when at least one operand is a BUILD_VECTOR whose elements
6222 // are guaranteed to reside in different register pairs.
6224 return SDValue();
6225
6226 SelectionDAG &DAG = DCI.DAG;
6227 SDLoc DL(N);
6228 EVT EltVT = VT.getVectorElementType();
6229 unsigned Opc = N->getOpcode();
6230
6231 // For each operand, get the scalar element at the given index: if the operand
6232 // is a BUILD_VECTOR, grab the element directly; otherwise, emit an
6233 // EXTRACT_VECTOR_ELT.
6234 auto GetElement = [&](SDValue Op, unsigned Index) -> SDValue {
6235 if (Op.getOpcode() == ISD::BUILD_VECTOR)
6236 return Op.getOperand(Index);
6237 return DAG.getNode(ISD::EXTRACT_VECTOR_ELT, DL, EltVT, Op,
6238 DAG.getVectorIdxConstant(Index, DL));
6239 };
6240
6241 // Build scalar operand lists for element 0 and element 1.
6242 SmallVector<SDValue, 3> Ops0, Ops1;
6243 for (const SDValue &Op : N->ops()) {
6244 Ops0.push_back(GetElement(Op, 0));
6245 Ops1.push_back(GetElement(Op, 1));
6246 }
6247
6248 SDValue Res0 = DAG.getNode(Opc, DL, EltVT, Ops0, N->getFlags());
6249 SDValue Res1 = DAG.getNode(Opc, DL, EltVT, Ops1, N->getFlags());
6250
6251 return DAG.getNode(ISD::BUILD_VECTOR, DL, VT, Res0, Res1);
6252}
6253
6254/// PerformFADDCombine - Target-specific dag combine xforms for ISD::FADD.
6255///
6258 CodeGenOptLevel OptLevel) {
6259 SDValue N0 = N->getOperand(0);
6260 SDValue N1 = N->getOperand(1);
6261
6262 if (SDValue Result = PerformScalarizeV2F32Op(N, DCI))
6263 return Result;
6264
6265 EVT VT = N0.getValueType();
6266 if (VT.isVector() || !(VT == MVT::f32 || VT == MVT::f64))
6267 return SDValue();
6268
6269 // First try with the default operand order.
6270 if (SDValue Result = PerformFADDCombineWithOperands(N, N0, N1, DCI, OptLevel))
6271 return Result;
6272
6273 // If that didn't work, try again with the operands commuted.
6274 return PerformFADDCombineWithOperands(N, N1, N0, DCI, OptLevel);
6275}
6276
6277/// Get 3-input version of a 2-input min/max opcode
6278static unsigned getMinMax3Opcode(unsigned MinMax2Opcode) {
6279 switch (MinMax2Opcode) {
6280 case ISD::FMAXNUM:
6281 case ISD::FMAXIMUMNUM:
6282 return NVPTXISD::FMAXNUM3;
6283 case ISD::FMINNUM:
6284 case ISD::FMINIMUMNUM:
6285 return NVPTXISD::FMINNUM3;
6286 case ISD::FMAXIMUM:
6287 return NVPTXISD::FMAXIMUM3;
6288 case ISD::FMINIMUM:
6289 return NVPTXISD::FMINIMUM3;
6290 default:
6291 llvm_unreachable("Invalid 2-input min/max opcode");
6292 }
6293}
6294
6295/// PerformFMinMaxCombine - Combine (fmaxnum (fmaxnum a, b), c) into
6296/// (fmaxnum3 a, b, c). Also covers other llvm min/max intrinsics.
6299 unsigned PTXVersion, unsigned SmVersion) {
6300
6301 // 3-input min/max requires PTX 8.8+ and SM_100+, and only supports f32s
6302 EVT VT = N->getValueType(0);
6303 if (VT != MVT::f32 || PTXVersion < 88 || SmVersion < 100)
6304 return SDValue();
6305
6306 SDValue Op0 = N->getOperand(0);
6307 SDValue Op1 = N->getOperand(1);
6308 unsigned MinMaxOp2 = N->getOpcode();
6309 unsigned MinMaxOp3 = getMinMax3Opcode(MinMaxOp2);
6310
6311 if (Op0.getOpcode() == MinMaxOp2 && Op0.hasOneUse()) {
6312 // (maxnum (maxnum a, b), c) -> (maxnum3 a, b, c)
6313 SDValue A = Op0.getOperand(0);
6314 SDValue B = Op0.getOperand(1);
6315 SDValue C = Op1;
6316 return DCI.DAG.getNode(MinMaxOp3, SDLoc(N), VT, A, B, C, N->getFlags());
6317 } else if (Op1.getOpcode() == MinMaxOp2 && Op1.hasOneUse()) {
6318 // (maxnum a, (maxnum b, c)) -> (maxnum3 a, b, c)
6319 SDValue A = Op0;
6320 SDValue B = Op1.getOperand(0);
6321 SDValue C = Op1.getOperand(1);
6322 return DCI.DAG.getNode(MinMaxOp3, SDLoc(N), VT, A, B, C, N->getFlags());
6323 }
6324 return SDValue();
6325}
6326
6329 CodeGenOptLevel OptLevel) {
6330 assert(N->getOpcode() == ISD::SREM || N->getOpcode() == ISD::UREM);
6331
6332 // Don't do anything at less than -O2.
6333 if (OptLevel < CodeGenOptLevel::Default)
6334 return SDValue();
6335
6336 SelectionDAG &DAG = DCI.DAG;
6337 SDLoc DL(N);
6338 EVT VT = N->getValueType(0);
6339 bool IsSigned = N->getOpcode() == ISD::SREM;
6340 unsigned DivOpc = IsSigned ? ISD::SDIV : ISD::UDIV;
6341
6342 const SDValue &Num = N->getOperand(0);
6343 const SDValue &Den = N->getOperand(1);
6344
6345 for (const SDNode *U : Num->users()) {
6346 if (U->getOpcode() == DivOpc && U->getOperand(0) == Num &&
6347 U->getOperand(1) == Den) {
6348 // Num % Den -> Num - (Num / Den) * Den
6349 return DAG.getNode(ISD::SUB, DL, VT, Num,
6350 DAG.getNode(ISD::MUL, DL, VT,
6351 DAG.getNode(DivOpc, DL, VT, Num, Den),
6352 Den));
6353 }
6354 }
6355 return SDValue();
6356}
6357
6358// (sign_extend|zero_extend (mul|shl) x, y) -> (mul.wide x, y)
6360 CodeGenOptLevel OptLevel) {
6361 if (OptLevel == CodeGenOptLevel::None)
6362 return SDValue();
6363
6364 SDValue Op = N->getOperand(0);
6365 if (!Op.hasOneUse())
6366 return SDValue();
6367 EVT ToVT = N->getValueType(0);
6368 EVT FromVT = Op.getValueType();
6369 if (!((ToVT == MVT::i32 && FromVT == MVT::i16) ||
6370 (ToVT == MVT::i64 && FromVT == MVT::i32)))
6371 return SDValue();
6372 if (!(Op.getOpcode() == ISD::MUL ||
6373 (Op.getOpcode() == ISD::SHL && isa<ConstantSDNode>(Op.getOperand(1)))))
6374 return SDValue();
6375
6376 SDLoc DL(N);
6377 unsigned ExtOpcode = N->getOpcode();
6378 unsigned Opcode = 0;
6379 if (ExtOpcode == ISD::SIGN_EXTEND && Op->getFlags().hasNoSignedWrap())
6380 Opcode = NVPTXISD::MUL_WIDE_SIGNED;
6381 else if (ExtOpcode == ISD::ZERO_EXTEND && Op->getFlags().hasNoUnsignedWrap())
6382 Opcode = NVPTXISD::MUL_WIDE_UNSIGNED;
6383 else
6384 return SDValue();
6385 SDValue RHS = Op.getOperand(1);
6386 if (Op.getOpcode() == ISD::SHL) {
6387 const auto ShiftAmt = Op.getConstantOperandVal(1);
6388 const auto MulVal = APInt(FromVT.getSizeInBits(), 1) << ShiftAmt;
6389 RHS = DCI.DAG.getConstant(MulVal, DL, FromVT);
6390 }
6391 return DCI.DAG.getNode(Opcode, DL, ToVT, Op.getOperand(0), RHS);
6392}
6393
6399
6400/// IsMulWideOperandDemotable - Checks if the provided DAG node is an operand
6401/// that can be demoted to \p OptSize bits without loss of information. The
6402/// signedness of the operand, if determinable, is placed in \p S.
6404 unsigned OptSize,
6405 OperandSignedness &S) {
6406 S = Unknown;
6407
6408 if (Op.getOpcode() == ISD::SIGN_EXTEND ||
6409 Op.getOpcode() == ISD::SIGN_EXTEND_INREG) {
6410 EVT OrigVT = Op.getOperand(0).getValueType();
6411 if (OrigVT.getFixedSizeInBits() <= OptSize) {
6412 S = Signed;
6413 return true;
6414 }
6415 } else if (Op.getOpcode() == ISD::ZERO_EXTEND) {
6416 EVT OrigVT = Op.getOperand(0).getValueType();
6417 if (OrigVT.getFixedSizeInBits() <= OptSize) {
6418 S = Unsigned;
6419 return true;
6420 }
6421 }
6422
6423 return false;
6424}
6425
6426/// AreMulWideOperandsDemotable - Checks if the given LHS and RHS operands can
6427/// be demoted to \p OptSize bits without loss of information. If the operands
6428/// contain a constant, it should appear as the RHS operand. The signedness of
6429/// the operands is placed in \p IsSigned.
6431 unsigned OptSize,
6432 bool &IsSigned) {
6433 OperandSignedness LHSSign;
6434
6435 // The LHS operand must be a demotable op
6436 if (!IsMulWideOperandDemotable(LHS, OptSize, LHSSign))
6437 return false;
6438
6439 // We should have been able to determine the signedness from the LHS
6440 if (LHSSign == Unknown)
6441 return false;
6442
6443 IsSigned = (LHSSign == Signed);
6444
6445 // The RHS can be a demotable op or a constant
6447 const APInt &Val = CI->getAPIntValue();
6448 if (LHSSign == Unsigned) {
6449 return Val.isIntN(OptSize);
6450 } else {
6451 return Val.isSignedIntN(OptSize);
6452 }
6453 } else {
6454 OperandSignedness RHSSign;
6455 if (!IsMulWideOperandDemotable(RHS, OptSize, RHSSign))
6456 return false;
6457
6458 return LHSSign == RHSSign;
6459 }
6460}
6461
6462/// TryMULWIDECombine - Attempt to replace a multiply of M bits with a multiply
6463/// of M/2 bits that produces an M-bit result (i.e. mul.wide). This transform
6464/// works on both multiply DAG nodes and SHL DAG nodes with a constant shift
6465/// amount.
6468 EVT MulType = N->getValueType(0);
6469 if (MulType != MVT::i32 && MulType != MVT::i64) {
6470 return SDValue();
6471 }
6472
6473 SDLoc DL(N);
6474 unsigned OptSize = MulType.getSizeInBits() >> 1;
6475 SDValue LHS = N->getOperand(0);
6476 SDValue RHS = N->getOperand(1);
6477
6478 // Canonicalize the multiply so the constant (if any) is on the right
6479 if (N->getOpcode() == ISD::MUL) {
6480 if (isa<ConstantSDNode>(LHS)) {
6481 std::swap(LHS, RHS);
6482 }
6483 }
6484
6485 // If we have a SHL, determine the actual multiply amount
6486 if (N->getOpcode() == ISD::SHL) {
6488 if (!ShlRHS) {
6489 return SDValue();
6490 }
6491
6492 APInt ShiftAmt = ShlRHS->getAPIntValue();
6493 unsigned BitWidth = MulType.getSizeInBits();
6494 if (ShiftAmt.sge(0) && ShiftAmt.slt(BitWidth)) {
6495 APInt MulVal = APInt(BitWidth, 1) << ShiftAmt;
6496 RHS = DCI.DAG.getConstant(MulVal, DL, MulType);
6497 } else {
6498 return SDValue();
6499 }
6500 }
6501
6502 bool Signed;
6503 // Verify that our operands are demotable
6504 if (!AreMulWideOperandsDemotable(LHS, RHS, OptSize, Signed)) {
6505 return SDValue();
6506 }
6507
6508 EVT DemotedVT;
6509 if (MulType == MVT::i32) {
6510 DemotedVT = MVT::i16;
6511 } else {
6512 DemotedVT = MVT::i32;
6513 }
6514
6515 // Truncate the operands to the correct size. Note that these are just for
6516 // type consistency and will (likely) be eliminated in later phases.
6517 SDValue TruncLHS =
6518 DCI.DAG.getNode(ISD::TRUNCATE, DL, DemotedVT, LHS);
6519 SDValue TruncRHS =
6520 DCI.DAG.getNode(ISD::TRUNCATE, DL, DemotedVT, RHS);
6521
6522 unsigned Opc;
6523 if (Signed) {
6524 Opc = NVPTXISD::MUL_WIDE_SIGNED;
6525 } else {
6526 Opc = NVPTXISD::MUL_WIDE_UNSIGNED;
6527 }
6528
6529 return DCI.DAG.getNode(Opc, DL, MulType, TruncLHS, TruncRHS);
6530}
6531
6532static bool isConstOne(const SDValue &Operand) {
6533 const auto *Const = dyn_cast<ConstantSDNode>(Operand);
6534 return Const && Const->getZExtValue() == 1;
6535}
6536
6538 if (Add->getOpcode() != ISD::ADD)
6539 return SDValue();
6540
6541 if (isConstOne(Add->getOperand(0)))
6542 return Add->getOperand(1);
6543
6544 if (isConstOne(Add->getOperand(1)))
6545 return Add->getOperand(0);
6546
6547 return SDValue();
6548}
6549
6552
6554 SDValue Mul = DCI.DAG.getNode(ISD::MUL, DL, VT, X, Y);
6555 return DCI.DAG.getNode(ISD::ADD, DL, VT, Mul, X);
6556 }
6557
6558 return SDValue();
6559}
6560
6562 SDLoc DL,
6564 if (Select->getOpcode() != ISD::SELECT)
6565 return SDValue();
6566
6567 SDValue Cond = Select->getOperand(0);
6568
6569 unsigned ConstOpNo;
6570 if (isConstOne(Select->getOperand(1)))
6571 ConstOpNo = 1;
6572 else if (isConstOne(Select->getOperand(2)))
6573 ConstOpNo = 2;
6574 else
6575 return SDValue();
6576
6577 SDValue Y = Select->getOperand((ConstOpNo == 1) ? 2 : 1);
6578
6579 // Do not combine if the resulting sequence is not obviously profitable.
6581 return SDValue();
6582
6583 SDValue NewMul = DCI.DAG.getNode(ISD::MUL, DL, VT, X, Y);
6584
6585 return DCI.DAG.getNode(ISD::SELECT, DL, VT, Cond,
6586 (ConstOpNo == 1) ? X : NewMul,
6587 (ConstOpNo == 1) ? NewMul : X);
6588}
6589
6590static SDValue
6593
6594 EVT VT = N0.getValueType();
6595 if (VT.isVector())
6596 return SDValue();
6597
6598 if (VT != MVT::i16 && VT != MVT::i32 && VT != MVT::i64)
6599 return SDValue();
6600
6601 SDLoc DL(N);
6602
6603 // (mul x, (add y, 1)) -> (add (mul x, y), x)
6604 if (SDValue Res = combineMADConstOne(N0, N1, VT, DL, DCI))
6605 return Res;
6606 if (SDValue Res = combineMADConstOne(N1, N0, VT, DL, DCI))
6607 return Res;
6608
6609 // (mul x, (select y, 1)) -> (select (mul x, y), x)
6610 if (SDValue Res = combineMulSelectConstOne(N0, N1, VT, DL, DCI))
6611 return Res;
6612 if (SDValue Res = combineMulSelectConstOne(N1, N0, VT, DL, DCI))
6613 return Res;
6614
6615 return SDValue();
6616}
6617
6618/// PerformMULCombine - Runs PTX-specific DAG combine patterns on MUL nodes.
6621 CodeGenOptLevel OptLevel) {
6622 if (OptLevel == CodeGenOptLevel::None)
6623 return SDValue();
6624
6625 if (SDValue Ret = TryMULWIDECombine(N, DCI))
6626 return Ret;
6627
6628 SDValue N0 = N->getOperand(0);
6629 SDValue N1 = N->getOperand(1);
6630 return PerformMULCombineWithOperands(N, N0, N1, DCI);
6631}
6632
6633/// PerformSHLCombine - Runs PTX-specific DAG combine patterns on SHL nodes.
6636 CodeGenOptLevel OptLevel) {
6637 if (OptLevel > CodeGenOptLevel::None) {
6638 // Try mul.wide combining at OptLevel > 0
6639 if (SDValue Ret = TryMULWIDECombine(N, DCI))
6640 return Ret;
6641 }
6642
6643 return SDValue();
6644}
6645
6648 unsigned int SmVersion) {
6649 EVT CCType = N->getValueType(0);
6650 SDValue A = N->getOperand(0);
6651 SDValue B = N->getOperand(1);
6652
6653 EVT AType = A.getValueType();
6654 if (!(CCType == MVT::v2i1 && (AType == MVT::v2f16 || AType == MVT::v2bf16)))
6655 return SDValue();
6656
6657 if (A.getValueType() == MVT::v2bf16 && SmVersion < 90)
6658 return SDValue();
6659
6660 SDLoc DL(N);
6661 // setp.f16x2 returns two scalar predicates, which we need to
6662 // convert back to v2i1. The returned result will be scalarized by
6663 // the legalizer, but the comparison will remain a single vector
6664 // instruction.
6665 SDValue CCNode = DCI.DAG.getNode(
6666 A.getValueType() == MVT::v2f16 ? NVPTXISD::SETP_F16X2
6668 DL, DCI.DAG.getVTList(MVT::i1, MVT::i1), {A, B, N->getOperand(2)});
6669 return DCI.DAG.getNode(ISD::BUILD_VECTOR, DL, CCType, CCNode.getValue(0),
6670 CCNode.getValue(1));
6671}
6672
6675 SDValue Vector = N->getOperand(0);
6676 if (Vector->getOpcode() == ISD::FREEZE)
6677 Vector = Vector->getOperand(0);
6678 SDLoc DL(N);
6679 EVT VectorVT = Vector.getValueType();
6680 if (Vector->getOpcode() == ISD::LOAD && VectorVT.isSimple() &&
6681 IsPTXVectorType(VectorVT.getSimpleVT()))
6682 return SDValue(); // Native vector loads already combine nicely w/
6683 // extract_vector_elt.
6684 // Don't mess with singletons or packed types (v2*32, v2*16, v4i8 and v8i8),
6685 // we already handle them OK.
6686 if (VectorVT.getVectorNumElements() == 1 ||
6687 NVPTX::isPackedVectorTy(VectorVT) || VectorVT == MVT::v8i8)
6688 return SDValue();
6689
6690 // Don't mess with undef values as sra may be simplified to 0, not undef.
6691 if (Vector->isUndef() || ISD::allOperandsUndef(Vector.getNode()))
6692 return SDValue();
6693
6694 uint64_t VectorBits = VectorVT.getSizeInBits();
6695 // We only handle the types we can extract in-register.
6696 if (!(VectorBits == 16 || VectorBits == 32 || VectorBits == 64))
6697 return SDValue();
6698
6699 ConstantSDNode *Index = dyn_cast<ConstantSDNode>(N->getOperand(1));
6700 // Index == 0 is handled by generic DAG combiner.
6701 if (!Index || Index->getZExtValue() == 0)
6702 return SDValue();
6703
6704 MVT IVT = MVT::getIntegerVT(VectorBits);
6705 EVT EltVT = VectorVT.getVectorElementType();
6706 EVT EltIVT = EltVT.changeTypeToInteger();
6707 uint64_t EltBits = EltVT.getScalarSizeInBits();
6708
6709 SDValue Result = DCI.DAG.getNode(
6710 ISD::TRUNCATE, DL, EltIVT,
6711 DCI.DAG.getNode(
6712 ISD::SRA, DL, IVT, DCI.DAG.getNode(ISD::BITCAST, DL, IVT, Vector),
6713 DCI.DAG.getConstant(Index->getZExtValue() * EltBits, DL, IVT)));
6714
6715 // If element has non-integer type, bitcast it back to the expected type.
6716 if (EltVT != EltIVT)
6717 Result = DCI.DAG.getNode(ISD::BITCAST, DL, EltVT, Result);
6718 // Past legalizer, we may need to extent i8 -> i16 to match the register type.
6719 if (EltVT != N->getValueType(0))
6720 Result = DCI.DAG.getNode(ISD::ANY_EXTEND, DL, N->getValueType(0), Result);
6721
6722 return Result;
6723}
6724
6725/// Transform patterns like:
6726/// (select (ugt shift_amt, BitWidth-1), 0, (srl/shl x, shift_amt))
6727/// (select (ult shift_amt, BitWidth), (srl/shl x, shift_amt), 0)
6728/// Into:
6729/// (NVPTXISD::SRL_CLAMP x, shift_amt) or (NVPTXISD::SHL_CLAMP x, shift_amt)
6730///
6731/// These patterns arise from C/C++ code like `shift >= 32 ? 0 : x >> shift`
6732/// which guards against undefined behavior. PTX shr/shl instructions clamp
6733/// shift amounts >= BitWidth to produce 0 for logical shifts, making the
6734/// guard redundant.
6735///
6736/// Note: We only handle SRL and SHL, not SRA, because arithmetic right
6737/// shifts could produce 0 or -1 when shift >= BitWidth.
6738/// Note: We don't handle uge or ule. These don't appear because of
6739/// canonicalization.
6742 if (!DCI.isAfterLegalizeDAG())
6743 return SDValue();
6744
6745 using namespace SDPatternMatch;
6746 unsigned BitWidth = N->getValueType(0).getSizeInBits();
6747 SDValue ShiftAmt, ShiftOp;
6748
6749 // Match logical shifts where the shift amount in the guard matches the shift
6750 // amount in the operation.
6751 auto LogicalShift =
6752 m_AllOf(m_Value(ShiftOp),
6753 m_AnyOf(m_Srl(m_Value(), m_TruncOrSelf(m_Deferred(ShiftAmt))),
6754 m_Shl(m_Value(), m_TruncOrSelf(m_Deferred(ShiftAmt)))));
6755
6756 // shift_amt > BitWidth-1 ? 0 : shift_op
6757 bool MatchedUGT =
6758 sd_match(N, m_Select(m_SetCC(m_Value(ShiftAmt),
6760 m_SpecificCondCode(ISD::SETUGT)),
6761 m_Zero(), LogicalShift));
6762 // shift_amt < BitWidth ? shift_op : 0
6763 bool MatchedULT =
6764 !MatchedUGT &&
6765 sd_match(N, m_Select(m_SetCC(m_Value(ShiftAmt),
6767 m_SpecificCondCode(ISD::SETULT)),
6768 LogicalShift, m_Zero()));
6769
6770 if (!MatchedUGT && !MatchedULT)
6771 return SDValue();
6772
6773 // Return a clamp shift operation, which has the same semantics as PTX shift.
6774 unsigned ClampOpc = ShiftOp.getOpcode() == ISD::SRL ? NVPTXISD::SRL_CLAMP
6775 : NVPTXISD::SHL_CLAMP;
6776 return DCI.DAG.getNode(ClampOpc, SDLoc(N), ShiftOp.getValueType(),
6777 ShiftOp.getOperand(0), ShiftOp.getOperand(1));
6778}
6779
6782 SDValue VA = N->getOperand(1);
6783 EVT VectorVT = VA.getValueType();
6784 if (VectorVT != MVT::v4i8)
6785 return SDValue();
6786
6787 // We need to split vselect into individual per-element operations Because we
6788 // use BFE/BFI instruction for byte extraction/insertion, we do end up with
6789 // 32-bit values, so we may as well do comparison as i32 to avoid conversions
6790 // to/from i16 normally used for i8 values.
6792 SDLoc DL(N);
6793 SDValue VCond = N->getOperand(0);
6794 SDValue VB = N->getOperand(2);
6795 for (int I = 0; I < 4; ++I) {
6796 SDValue C = DCI.DAG.getNode(ISD::EXTRACT_VECTOR_ELT, DL, MVT::i1, VCond,
6797 DCI.DAG.getConstant(I, DL, MVT::i32));
6798 SDValue EA = DCI.DAG.getAnyExtOrTrunc(
6799 DCI.DAG.getNode(ISD::EXTRACT_VECTOR_ELT, DL, MVT::i8, VA,
6800 DCI.DAG.getConstant(I, DL, MVT::i32)),
6801 DL, MVT::i32);
6802 SDValue EB = DCI.DAG.getAnyExtOrTrunc(
6803 DCI.DAG.getNode(ISD::EXTRACT_VECTOR_ELT, DL, MVT::i8, VB,
6804 DCI.DAG.getConstant(I, DL, MVT::i32)),
6805 DL, MVT::i32);
6806 E.push_back(DCI.DAG.getAnyExtOrTrunc(
6807 DCI.DAG.getNode(ISD::SELECT, DL, MVT::i32, C, EA, EB), DL, MVT::i8));
6808 }
6809 return DCI.DAG.getNode(ISD::BUILD_VECTOR, DL, MVT::v4i8, E);
6810}
6811
6812static SDValue
6814 auto VT = N->getValueType(0);
6815 if (!DCI.isAfterLegalizeDAG() ||
6816 // only process v2*16 types
6817 !(NVPTX::isPackedVectorTy(VT) && VT.is32BitVector() &&
6818 VT.getVectorNumElements() == 2))
6819 return SDValue();
6820
6821 auto Op0 = N->getOperand(0);
6822 auto Op1 = N->getOperand(1);
6823
6824 // Start out by assuming we want to take the lower 2 bytes of each i32
6825 // operand.
6826 uint64_t Op0Bytes = 0x10;
6827 uint64_t Op1Bytes = 0x54;
6828
6829 std::pair<SDValue *, uint64_t *> OpData[2] = {{&Op0, &Op0Bytes},
6830 {&Op1, &Op1Bytes}};
6831
6832 // Check that each operand is an i16, truncated from an i32 operand. We'll
6833 // select individual bytes from those original operands. Optionally, fold in a
6834 // shift right of that original operand.
6835 for (auto &[Op, OpBytes] : OpData) {
6836 // Eat up any bitcast
6837 if (Op->getOpcode() == ISD::BITCAST)
6838 *Op = Op->getOperand(0);
6839
6840 if (!(Op->getValueType() == MVT::i16 && Op->getOpcode() == ISD::TRUNCATE &&
6841 Op->getOperand(0).getValueType() == MVT::i32))
6842 return SDValue();
6843
6844 // If the truncate has multiple uses, this optimization can increase
6845 // register pressure
6846 if (!Op->hasOneUse())
6847 return SDValue();
6848
6849 *Op = Op->getOperand(0);
6850
6851 // Optionally, fold in a shift-right of the original operand and let permute
6852 // pick the two higher bytes of the original value directly.
6853 if (Op->getOpcode() == ISD::SRL && isa<ConstantSDNode>(Op->getOperand(1))) {
6854 if (cast<ConstantSDNode>(Op->getOperand(1))->getZExtValue() == 16) {
6855 // Shift the PRMT byte selector to pick upper bytes from each respective
6856 // value, instead of the lower ones: 0x10 -> 0x32, 0x54 -> 0x76
6857 assert((*OpBytes == 0x10 || *OpBytes == 0x54) &&
6858 "PRMT selector values out of range");
6859 *OpBytes += 0x22;
6860 *Op = Op->getOperand(0);
6861 }
6862 }
6863 }
6864
6865 SDLoc DL(N);
6866 auto &DAG = DCI.DAG;
6867
6868 auto PRMT =
6869 getPRMT(DAG.getBitcast(MVT::i32, Op0), DAG.getBitcast(MVT::i32, Op1),
6870 (Op1Bytes << 8) | Op0Bytes, DL, DAG);
6871 return DAG.getBitcast(VT, PRMT);
6872}
6873
6876 auto *ASCN1 = cast<AddrSpaceCastSDNode>(N);
6877
6878 if (auto *ASCN2 = dyn_cast<AddrSpaceCastSDNode>(ASCN1->getOperand(0))) {
6879 assert(ASCN2->getDestAddressSpace() == ASCN1->getSrcAddressSpace());
6880
6881 // Fold asc[B -> A](asc[A -> B](x)) -> x
6882 if (ASCN1->getDestAddressSpace() == ASCN2->getSrcAddressSpace())
6883 return ASCN2->getOperand(0);
6884 }
6885
6886 return SDValue();
6887}
6888
6889// Given a constant selector value and a prmt mode, return the selector value
6890// normalized to the generic prmt mode. See the PTX ISA documentation for more
6891// details:
6892// https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#data-movement-and-conversion-instructions-prmt
6893static APInt getPRMTSelector(const APInt &Selector, unsigned Mode) {
6894 assert(Selector.getBitWidth() == 32 && "PRMT must have i32 operands");
6895
6897 return Selector;
6898
6899 const unsigned V = Selector.trunc(2).getZExtValue();
6900
6901 const auto GetSelector = [](unsigned S0, unsigned S1, unsigned S2,
6902 unsigned S3) {
6903 return APInt(32, S0 | (S1 << 4) | (S2 << 8) | (S3 << 12));
6904 };
6905
6906 switch (Mode) {
6908 return GetSelector(V, V + 1, V + 2, V + 3);
6910 return GetSelector(V, (V - 1) & 7, (V - 2) & 7, (V - 3) & 7);
6912 return GetSelector(V, V, V, V);
6914 return GetSelector(V, std::max(V, 1U), std::max(V, 2U), 3U);
6916 return GetSelector(0, std::min(V, 1U), std::min(V, 2U), V);
6918 unsigned V1 = (V & 1) << 1;
6919 return GetSelector(V1, V1 + 1, V1, V1 + 1);
6920 }
6921 default:
6922 llvm_unreachable("Invalid PRMT mode");
6923 }
6924}
6925
6926static APInt computePRMT(APInt A, APInt B, APInt Selector, unsigned Mode) {
6927 assert(A.getBitWidth() == 32 && B.getBitWidth() == 32 &&
6928 Selector.getBitWidth() == 32 && "PRMT must have i32 operands");
6929 // {b, a} = {{b7, b6, b5, b4}, {b3, b2, b1, b0}}
6930 APInt BitField = B.concat(A);
6931 APInt SelectorVal = getPRMTSelector(Selector, Mode);
6932 APInt Result(32, 0);
6933 for (unsigned I : llvm::seq(4U)) {
6934 APInt Sel = SelectorVal.extractBits(4, I * 4);
6935 unsigned Idx = Sel.getLoBits(3).getZExtValue();
6936 unsigned Sign = Sel.getHiBits(1).getZExtValue();
6937 APInt Byte = BitField.extractBits(8, Idx * 8);
6938 if (Sign)
6939 Byte = Byte.ashr(8);
6940 Result.insertBits(Byte, I * 8);
6941 }
6942 return Result;
6943}
6944
6946 CodeGenOptLevel OptLevel) {
6947 if (OptLevel == CodeGenOptLevel::None)
6948 return SDValue();
6949
6950 // Constant fold PRMT
6951 if (isa<ConstantSDNode>(N->getOperand(0)) &&
6952 isa<ConstantSDNode>(N->getOperand(1)) &&
6953 isa<ConstantSDNode>(N->getOperand(2)))
6954 return DCI.DAG.getConstant(computePRMT(N->getConstantOperandAPInt(0),
6955 N->getConstantOperandAPInt(1),
6956 N->getConstantOperandAPInt(2),
6957 N->getConstantOperandVal(3)),
6958 SDLoc(N), N->getValueType(0));
6959 return SDValue();
6960}
6961
6962// During call lowering we wrap the return values in a ProxyReg node which
6963// depend on the chain value produced by the completed call. This ensures that
6964// the full call is emitted in cases where libcalls are used to legalize
6965// operations. To improve the functioning of other DAG combines we pull all
6966// operations we can through one of these nodes, ensuring that the ProxyReg
6967// directly wraps a load. That is:
6968//
6969// (ProxyReg (zext (load retval0))) => (zext (ProxyReg (load retval0)))
6970//
6973 switch (R.getOpcode()) {
6974 case ISD::TRUNCATE:
6975 case ISD::ANY_EXTEND:
6976 case ISD::SIGN_EXTEND:
6977 case ISD::ZERO_EXTEND:
6978 case ISD::BITCAST: {
6979 if (SDValue V = sinkProxyReg(R.getOperand(0), Chain, DCI))
6980 return DCI.DAG.getNode(R.getOpcode(), SDLoc(R), R.getValueType(), V);
6981 return SDValue();
6982 }
6983 case ISD::SHL:
6984 case ISD::SRL:
6985 case ISD::SRA:
6986 case ISD::OR: {
6987 if (SDValue A = sinkProxyReg(R.getOperand(0), Chain, DCI))
6988 if (SDValue B = sinkProxyReg(R.getOperand(1), Chain, DCI))
6989 return DCI.DAG.getNode(R.getOpcode(), SDLoc(R), R.getValueType(), A, B);
6990 return SDValue();
6991 }
6992 case ISD::Constant:
6993 return R;
6994 case ISD::LOAD:
6995 case NVPTXISD::LoadV2:
6996 case NVPTXISD::LoadV4: {
6997 return DCI.DAG.getNode(NVPTXISD::ProxyReg, SDLoc(R), R.getValueType(),
6998 {Chain, R});
6999 }
7000 case ISD::BUILD_VECTOR: {
7001 if (DCI.isBeforeLegalize())
7002 return SDValue();
7003
7005 for (auto &Op : R->ops()) {
7006 SDValue V = sinkProxyReg(Op, Chain, DCI);
7007 if (!V)
7008 return SDValue();
7009 Ops.push_back(V);
7010 }
7011 return DCI.DAG.getNode(ISD::BUILD_VECTOR, SDLoc(R), R.getValueType(), Ops);
7012 }
7014 if (DCI.isBeforeLegalize())
7015 return SDValue();
7016
7017 if (SDValue V = sinkProxyReg(R.getOperand(0), Chain, DCI))
7019 R.getValueType(), V, R.getOperand(1));
7020 return SDValue();
7021 }
7022 default:
7023 return SDValue();
7024 }
7025}
7026
7027static unsigned getF16SubOpc(Intrinsic::ID AddIntrinsicID) {
7028 switch (AddIntrinsicID) {
7029 default:
7030 break;
7031 case Intrinsic::nvvm_add_rn_sat_f16:
7032 case Intrinsic::nvvm_add_rn_sat_v2f16:
7033 return NVPTXISD::SUB_RN_SAT;
7034 case Intrinsic::nvvm_add_rn_ftz_sat_f16:
7035 case Intrinsic::nvvm_add_rn_ftz_sat_v2f16:
7036 return NVPTXISD::SUB_RN_FTZ_SAT;
7037 }
7038 llvm_unreachable("Invalid F16 add intrinsic");
7039}
7040
7042 Intrinsic::ID AddIntrinsicID) {
7043 SDValue Op1 = N->getOperand(1);
7044 SDValue Op2 = N->getOperand(2);
7045
7046 SDValue SubOp1, SubOp2;
7047
7048 if (Op1.getOpcode() == ISD::FNEG) {
7049 SubOp1 = Op2;
7050 SubOp2 = Op1.getOperand(0);
7051 } else if (Op2.getOpcode() == ISD::FNEG) {
7052 SubOp1 = Op1;
7053 SubOp2 = Op2.getOperand(0);
7054 } else {
7055 return SDValue();
7056 }
7057
7058 SDLoc DL(N);
7059 return DAG.getNode(getF16SubOpc(AddIntrinsicID), DL, N->getValueType(0),
7060 SubOp1, SubOp2);
7061}
7062
7065 const NVPTXSubtarget &STI) {
7066 unsigned IID = N->getConstantOperandVal(0);
7067
7068 switch (IID) {
7069 default:
7070 break;
7071 case Intrinsic::nvvm_add_rn_sat_f16:
7072 case Intrinsic::nvvm_add_rn_ftz_sat_f16:
7073 case Intrinsic::nvvm_add_rn_sat_v2f16:
7074 case Intrinsic::nvvm_add_rn_ftz_sat_v2f16:
7075 return combineF16AddWithNeg(N, DCI.DAG, IID);
7076 }
7077 return SDValue();
7078}
7079
7082
7083 SDValue Chain = N->getOperand(0);
7084 SDValue Reg = N->getOperand(1);
7085
7086 // If the ProxyReg is not wrapping a load, try to pull the operations through
7087 // the ProxyReg.
7088 if (Reg.getOpcode() != ISD::LOAD) {
7089 if (SDValue V = sinkProxyReg(Reg, Chain, DCI))
7090 return V;
7091 }
7092
7093 return SDValue();
7094}
7095
7096SDValue NVPTXTargetLowering::PerformDAGCombine(SDNode *N,
7097 DAGCombinerInfo &DCI) const {
7099 switch (N->getOpcode()) {
7100 default:
7101 break;
7102 case ISD::ADD:
7103 return PerformADDCombine(N, DCI, OptLevel);
7104 case ISD::ADDRSPACECAST:
7105 return combineADDRSPACECAST(N, DCI);
7106 case ISD::SIGN_EXTEND:
7107 case ISD::ZERO_EXTEND:
7108 return combineMulWide(N, DCI, OptLevel);
7109 case ISD::BUILD_VECTOR:
7110 return PerformBUILD_VECTORCombine(N, DCI);
7112 return PerformEXTRACTCombine(N, DCI);
7113 case ISD::FADD:
7114 return PerformFADDCombine(N, DCI, OptLevel);
7115 case ISD::FMA:
7116 case ISD::FMUL:
7117 case ISD::FSUB:
7118 return PerformScalarizeV2F32Op(N, DCI);
7119 case ISD::FMAXNUM:
7120 case ISD::FMINNUM:
7121 case ISD::FMAXIMUM:
7122 case ISD::FMINIMUM:
7123 case ISD::FMAXIMUMNUM:
7124 case ISD::FMINIMUMNUM:
7125 return PerformFMinMaxCombine(N, DCI, STI.getPTXVersion(),
7126 STI.getSmVersion());
7127 case ISD::LOAD:
7128 case NVPTXISD::LoadV2:
7129 case NVPTXISD::LoadV4:
7130 return combineLOAD(N, DCI, STI);
7131 case ISD::MUL:
7132 return PerformMULCombine(N, DCI, OptLevel);
7133 case NVPTXISD::PRMT:
7134 return combinePRMT(N, DCI, OptLevel);
7135 case NVPTXISD::ProxyReg:
7136 return combineProxyReg(N, DCI);
7137 case ISD::SETCC:
7138 return PerformSETCCCombine(N, DCI, STI.getSmVersion());
7139 case ISD::SHL:
7140 return PerformSHLCombine(N, DCI, OptLevel);
7141 case ISD::SREM:
7142 case ISD::UREM:
7143 return PerformREMCombine(N, DCI, OptLevel);
7144 case ISD::STORE:
7145 case NVPTXISD::StoreV2:
7146 case NVPTXISD::StoreV4:
7147 return combineSTORE(N, DCI, STI);
7148 case ISD::SELECT:
7149 return PerformSELECTShiftCombine(N, DCI);
7150 case ISD::VSELECT:
7151 return PerformVSELECTCombine(N, DCI);
7153 return combineIntrinsicWOChain(N, DCI, STI);
7154 }
7155 return SDValue();
7156}
7157
7160 // Handle bitcasting to v2i8 without hitting the default promotion
7161 // strategy which goes through stack memory.
7162 SDValue Op(Node, 0);
7163 EVT ToVT = Op->getValueType(0);
7164 if (ToVT != MVT::v2i8) {
7165 return;
7166 }
7167
7168 // Bitcast to i16 and unpack elements into a vector
7169 SDLoc DL(Node);
7170 SDValue AsInt = DAG.getBitcast(MVT::i16, Op->getOperand(0));
7171 SDValue Vec0 = DAG.getNode(ISD::TRUNCATE, DL, MVT::i8, AsInt);
7172 SDValue Const8 = DAG.getConstant(8, DL, MVT::i16);
7173 SDValue Vec1 =
7174 DAG.getNode(ISD::TRUNCATE, DL, MVT::i8,
7175 DAG.getNode(ISD::SRL, DL, MVT::i16, {AsInt, Const8}));
7176 Results.push_back(
7177 DAG.getNode(ISD::BUILD_VECTOR, DL, MVT::v2i8, {Vec0, Vec1}));
7178}
7179
7182 SDValue Chain = N->getOperand(0);
7183 SDValue Intrin = N->getOperand(1);
7184 SDLoc DL(N);
7185
7186 // Get the intrinsic ID
7187 unsigned IntrinNo = Intrin.getNode()->getAsZExtVal();
7188 switch (IntrinNo) {
7189 default:
7190 return;
7191 case Intrinsic::nvvm_ldu_global_i:
7192 case Intrinsic::nvvm_ldu_global_f:
7193 case Intrinsic::nvvm_ldu_global_p: {
7194 EVT ResVT = N->getValueType(0);
7195
7196 if (ResVT.isVector()) {
7197 // Vector LDG/LDU
7198
7199 unsigned NumElts = ResVT.getVectorNumElements();
7200 EVT EltVT = ResVT.getVectorElementType();
7201
7202 // Since LDU/LDG are target nodes, we cannot rely on DAG type
7203 // legalization.
7204 // Therefore, we must ensure the type is legal. For i1 and i8, we set the
7205 // loaded type to i16 and propagate the "real" type as the memory type.
7206 bool NeedTrunc = false;
7207 if (EltVT.getSizeInBits() < 16) {
7208 EltVT = MVT::i16;
7209 NeedTrunc = true;
7210 }
7211
7212 unsigned Opcode = 0;
7213 SDVTList LdResVTs;
7214
7215 switch (NumElts) {
7216 default:
7217 return;
7218 case 2:
7219 Opcode = NVPTXISD::LDUV2;
7220 LdResVTs = DAG.getVTList(EltVT, EltVT, MVT::Other);
7221 break;
7222 case 4: {
7223 Opcode = NVPTXISD::LDUV4;
7224 EVT ListVTs[] = { EltVT, EltVT, EltVT, EltVT, MVT::Other };
7225 LdResVTs = DAG.getVTList(ListVTs);
7226 break;
7227 }
7228 }
7229
7230 SmallVector<SDValue, 8> OtherOps;
7231
7232 // Copy regular operands
7233
7234 OtherOps.push_back(Chain); // Chain
7235 // Skip operand 1 (intrinsic ID)
7236 // Others
7237 OtherOps.append(N->op_begin() + 2, N->op_end());
7238
7240
7241 SDValue NewLD = DAG.getMemIntrinsicNode(Opcode, DL, LdResVTs, OtherOps,
7242 MemSD->getMemoryVT(),
7243 MemSD->getMemOperand());
7244
7245 SmallVector<SDValue, 4> ScalarRes;
7246
7247 for (unsigned i = 0; i < NumElts; ++i) {
7248 SDValue Res = NewLD.getValue(i);
7249 if (NeedTrunc)
7250 Res =
7251 DAG.getNode(ISD::TRUNCATE, DL, ResVT.getVectorElementType(), Res);
7252 ScalarRes.push_back(Res);
7253 }
7254
7255 SDValue LoadChain = NewLD.getValue(NumElts);
7256
7257 SDValue BuildVec =
7258 DAG.getBuildVector(ResVT, DL, ScalarRes);
7259
7260 Results.push_back(BuildVec);
7261 Results.push_back(LoadChain);
7262 } else {
7263 // i8 LDG/LDU
7264 assert(ResVT.isSimple() && ResVT.getSimpleVT().SimpleTy == MVT::i8 &&
7265 "Custom handling of non-i8 ldu/ldg?");
7266
7267 // Just copy all operands as-is
7269
7270 // Force output to i16
7271 SDVTList LdResVTs = DAG.getVTList(MVT::i16, MVT::Other);
7272
7274
7275 // We make sure the memory type is i8, which will be used during isel
7276 // to select the proper instruction.
7277 SDValue NewLD =
7279 MVT::i8, MemSD->getMemOperand());
7280
7281 Results.push_back(DAG.getNode(ISD::TRUNCATE, DL, MVT::i8,
7282 NewLD.getValue(0)));
7283 Results.push_back(NewLD.getValue(1));
7284 }
7285 return;
7286 }
7287
7288 case Intrinsic::nvvm_tcgen05_ld_16x64b_x4:
7289 case Intrinsic::nvvm_tcgen05_ld_16x64b_x8:
7290 case Intrinsic::nvvm_tcgen05_ld_16x64b_x16:
7291 case Intrinsic::nvvm_tcgen05_ld_16x64b_x32:
7292 case Intrinsic::nvvm_tcgen05_ld_16x64b_x64:
7293 case Intrinsic::nvvm_tcgen05_ld_16x64b_x128:
7294 case Intrinsic::nvvm_tcgen05_ld_32x32b_x4:
7295 case Intrinsic::nvvm_tcgen05_ld_32x32b_x8:
7296 case Intrinsic::nvvm_tcgen05_ld_32x32b_x16:
7297 case Intrinsic::nvvm_tcgen05_ld_32x32b_x32:
7298 case Intrinsic::nvvm_tcgen05_ld_32x32b_x64:
7299 case Intrinsic::nvvm_tcgen05_ld_32x32b_x128:
7300 case Intrinsic::nvvm_tcgen05_ld_16x128b_x2:
7301 case Intrinsic::nvvm_tcgen05_ld_16x128b_x4:
7302 case Intrinsic::nvvm_tcgen05_ld_16x128b_x8:
7303 case Intrinsic::nvvm_tcgen05_ld_16x128b_x16:
7304 case Intrinsic::nvvm_tcgen05_ld_16x128b_x32:
7305 case Intrinsic::nvvm_tcgen05_ld_16x128b_x64:
7306 case Intrinsic::nvvm_tcgen05_ld_16x256b_x1:
7307 case Intrinsic::nvvm_tcgen05_ld_16x256b_x2:
7308 case Intrinsic::nvvm_tcgen05_ld_16x256b_x4:
7309 case Intrinsic::nvvm_tcgen05_ld_16x256b_x8:
7310 case Intrinsic::nvvm_tcgen05_ld_16x256b_x16:
7311 case Intrinsic::nvvm_tcgen05_ld_16x256b_x32:
7312 if (auto Res = lowerTcgen05Ld(N, DAG)) {
7313 Results.push_back(Res->first);
7314 Results.push_back(Res->second);
7315 }
7316 return;
7317
7318 case Intrinsic::nvvm_tcgen05_ld_16x32bx2_x4:
7319 case Intrinsic::nvvm_tcgen05_ld_16x32bx2_x8:
7320 case Intrinsic::nvvm_tcgen05_ld_16x32bx2_x16:
7321 case Intrinsic::nvvm_tcgen05_ld_16x32bx2_x32:
7322 case Intrinsic::nvvm_tcgen05_ld_16x32bx2_x64:
7323 case Intrinsic::nvvm_tcgen05_ld_16x32bx2_x128:
7324 if (auto Res = lowerTcgen05Ld(N, DAG, /*HasOffset=*/true)) {
7325 Results.push_back(Res->first);
7326 Results.push_back(Res->second);
7327 }
7328 return;
7329
7330 case Intrinsic::nvvm_tcgen05_ld_red_32x32b_x8_i32:
7331 case Intrinsic::nvvm_tcgen05_ld_red_32x32b_x8_f32:
7332 case Intrinsic::nvvm_tcgen05_ld_red_32x32b_x64_i32:
7333 case Intrinsic::nvvm_tcgen05_ld_red_32x32b_x64_f32:
7334 case Intrinsic::nvvm_tcgen05_ld_red_32x32b_x4_i32:
7335 case Intrinsic::nvvm_tcgen05_ld_red_32x32b_x4_f32:
7336 case Intrinsic::nvvm_tcgen05_ld_red_32x32b_x32_i32:
7337 case Intrinsic::nvvm_tcgen05_ld_red_32x32b_x32_f32:
7338 case Intrinsic::nvvm_tcgen05_ld_red_32x32b_x16_i32:
7339 case Intrinsic::nvvm_tcgen05_ld_red_32x32b_x16_f32:
7340 case Intrinsic::nvvm_tcgen05_ld_red_32x32b_x128_i32:
7341 case Intrinsic::nvvm_tcgen05_ld_red_32x32b_x128_f32:
7342 case Intrinsic::nvvm_tcgen05_ld_red_16x32bx2_x8_i32:
7343 case Intrinsic::nvvm_tcgen05_ld_red_16x32bx2_x8_f32:
7344 case Intrinsic::nvvm_tcgen05_ld_red_16x32bx2_x64_i32:
7345 case Intrinsic::nvvm_tcgen05_ld_red_16x32bx2_x64_f32:
7346 case Intrinsic::nvvm_tcgen05_ld_red_16x32bx2_x4_i32:
7347 case Intrinsic::nvvm_tcgen05_ld_red_16x32bx2_x4_f32:
7348 case Intrinsic::nvvm_tcgen05_ld_red_16x32bx2_x32_i32:
7349 case Intrinsic::nvvm_tcgen05_ld_red_16x32bx2_x32_f32:
7350 case Intrinsic::nvvm_tcgen05_ld_red_16x32bx2_x16_i32:
7351 case Intrinsic::nvvm_tcgen05_ld_red_16x32bx2_x16_f32:
7352 case Intrinsic::nvvm_tcgen05_ld_red_16x32bx2_x128_i32:
7353 case Intrinsic::nvvm_tcgen05_ld_red_16x32bx2_x128_f32:
7354 if (auto Res = lowerTcgen05LdRed(N, DAG)) {
7355 Results.push_back(std::get<0>(*Res));
7356 Results.push_back(std::get<1>(*Res));
7357 Results.push_back(std::get<2>(*Res));
7358 }
7359 return;
7360 }
7361}
7362
7365 // Change the CopyFromReg to output 2 64-bit results instead of a 128-bit
7366 // result so that it can pass the legalization
7367 SDLoc DL(N);
7368 SDValue Chain = N->getOperand(0);
7369 SDValue Reg = N->getOperand(1);
7370 SDValue Glue = N->getOperand(2);
7371
7372 assert(Reg.getValueType() == MVT::i128 &&
7373 "Custom lowering for CopyFromReg with 128-bit reg only");
7374 SmallVector<EVT, 4> ResultsType = {MVT::i64, MVT::i64, N->getValueType(1),
7375 N->getValueType(2)};
7376 SmallVector<SDValue, 3> NewOps = {Chain, Reg, Glue};
7377
7378 SDValue NewValue = DAG.getNode(ISD::CopyFromReg, DL, ResultsType, NewOps);
7379 SDValue Pair = DAG.getNode(ISD::BUILD_PAIR, DL, MVT::i128,
7380 {NewValue.getValue(0), NewValue.getValue(1)});
7381
7382 Results.push_back(Pair);
7383 Results.push_back(NewValue.getValue(2));
7384 Results.push_back(NewValue.getValue(3));
7385}
7386
7388 const TargetLowering &TLI,
7390 SDValue Chain = N->getOperand(0);
7391 SDValue Reg = N->getOperand(1);
7392
7393 MVT VT = TLI.getRegisterType(*DAG.getContext(), Reg.getValueType());
7394
7395 SDValue NewReg = DAG.getAnyExtOrTrunc(Reg, SDLoc(N), VT);
7396 SDValue NewProxy =
7397 DAG.getNode(NVPTXISD::ProxyReg, SDLoc(N), VT, {Chain, NewReg});
7398 SDValue Res = DAG.getAnyExtOrTrunc(NewProxy, SDLoc(N), N->getValueType(0));
7399
7400 Results.push_back(Res);
7401}
7402
7404 const NVPTXSubtarget &STI,
7406 assert(N->getValueType(0) == MVT::i128 &&
7407 "Custom lowering for atomic128 only supports i128");
7408
7410 SDLoc dl(N);
7411
7412 if (!STI.hasAtomSwap128()) {
7415 "Support for b128 atomics introduced in PTX ISA version 8.3 and "
7416 "requires target sm_90.",
7417 dl.getDebugLoc()));
7418
7419 Results.push_back(DAG.getUNDEF(MVT::i128));
7420 Results.push_back(AN->getOperand(0)); // Chain
7421 return;
7422 }
7423
7425 Ops.push_back(AN->getOperand(0)); // Chain
7426 Ops.push_back(AN->getOperand(1)); // Ptr
7427 for (const auto &Op : AN->ops().drop_front(2)) {
7428 // Low part
7429 Ops.push_back(DAG.getNode(ISD::EXTRACT_ELEMENT, dl, MVT::i64, Op,
7430 DAG.getIntPtrConstant(0, dl)));
7431 // High part
7432 Ops.push_back(DAG.getNode(ISD::EXTRACT_ELEMENT, dl, MVT::i64, Op,
7433 DAG.getIntPtrConstant(1, dl)));
7434 }
7435 unsigned Opcode = N->getOpcode() == ISD::ATOMIC_SWAP
7438 SDVTList Tys = DAG.getVTList(MVT::i64, MVT::i64, MVT::Other);
7439 SDValue Result = DAG.getMemIntrinsicNode(Opcode, dl, Tys, Ops, MVT::i128,
7440 AN->getMemOperand());
7441 Results.push_back(DAG.getNode(ISD::BUILD_PAIR, dl, MVT::i128,
7442 {Result.getValue(0), Result.getValue(1)}));
7443 Results.push_back(Result.getValue(2));
7444}
7445
7446void NVPTXTargetLowering::ReplaceNodeResults(
7448 switch (N->getOpcode()) {
7449 default:
7450 report_fatal_error("Unhandled custom legalization");
7451 case ISD::BITCAST:
7452 ReplaceBITCAST(N, DAG, Results);
7453 return;
7454 case ISD::LOAD:
7455 case ISD::MLOAD:
7456 replaceLoadVector(N, DAG, Results, STI);
7457 return;
7460 return;
7461 case ISD::CopyFromReg:
7463 return;
7464 case NVPTXISD::ProxyReg:
7465 replaceProxyReg(N, DAG, *this, Results);
7466 return;
7468 case ISD::ATOMIC_SWAP:
7469 replaceAtomicSwap128(N, DAG, STI, Results);
7470 return;
7471 }
7472}
7473
7476 Type *Ty = AI->getValOperand()->getType();
7477
7478 if (AI->isFloatingPointOperation()) {
7480 if (Ty->isHalfTy() && STI.getSmVersion() >= 70 &&
7481 STI.getPTXVersion() >= 63)
7483 if (Ty->isBFloatTy() && STI.getSmVersion() >= 90 &&
7484 STI.getPTXVersion() >= 78)
7486 if (Ty->isFloatTy())
7488 if (Ty->isDoubleTy() && STI.hasAtomAddF64())
7490 }
7492 }
7493
7494 assert(Ty->isIntegerTy() && "Ty should be integer at this point");
7495 const unsigned BitWidth = cast<IntegerType>(Ty)->getBitWidth();
7496
7497 switch (AI->getOperation()) {
7498 default:
7501 if (BitWidth == 128)
7503 [[fallthrough]];
7507 switch (BitWidth) {
7508 case 8:
7509 case 16:
7511 case 32:
7513 case 64:
7514 if (STI.hasAtomBitwise64())
7517 case 128:
7519 default:
7520 llvm_unreachable("unsupported width encountered");
7521 }
7528 switch (BitWidth) {
7529 case 8:
7530 case 16:
7532 case 32:
7534 case 64:
7535 if (STI.hasAtomMinMax64())
7538 case 128:
7540 default:
7541 llvm_unreachable("unsupported width encountered");
7542 }
7545 switch (BitWidth) {
7546 case 32:
7548 case 8:
7549 case 16:
7550 case 64:
7551 case 128:
7553 default:
7554 llvm_unreachable("unsupported width encountered");
7555 }
7556 }
7557
7559}
7560
7562 const Instruction *I) const {
7563 // This function returns true iff the operation is emulated using a CAS-loop,
7564 // or if it has the memory order seq_cst (which is not natively supported in
7565 // the PTX `atom` instruction).
7566 //
7567 // atomicrmw and cmpxchg instructions not efficiently supported by PTX
7568 // are lowered to CAS emulation loops that preserve their memory order,
7569 // syncscope, and volatile semantics. For PTX, it is more efficient to use
7570 // atom.cas.relaxed.sco instructions within the loop, and fences before and
7571 // after the loop to restore order.
7572 //
7573 // Atomic instructions efficiently supported by PTX are lowered to
7574 // `atom.<op>.<sem>.<scope` instruction with their corresponding memory order
7575 // and scope. Since PTX does not support seq_cst, we emulate it by lowering to
7576 // a fence.sc followed by an atom according to the PTX atomics ABI
7577 // https://docs.nvidia.com/cuda/ptx-writers-guide-to-interoperability/atomic-abi.html
7578 if (auto *CI = dyn_cast<AtomicCmpXchgInst>(I))
7579 return (cast<IntegerType>(CI->getCompareOperand()->getType())
7580 ->getBitWidth() < STI.getMinCmpXchgSizeInBits()) ||
7581 CI->getMergedOrdering() == AtomicOrdering::SequentiallyConsistent;
7582 if (auto *RI = dyn_cast<AtomicRMWInst>(I))
7584 RI->getOrdering() == AtomicOrdering::SequentiallyConsistent;
7585 return false;
7586}
7587
7589 const Instruction *I) const {
7590 // If the operation is emulated by a CAS-loop, we lower the instruction to
7591 // atom.<op>.relaxed, since AtomicExpandPass will insert fences for enforcing
7592 // the correct memory ordering around the CAS loop.
7593 //
7594 // When the operation is not emulated, but the memory order is seq_cst,
7595 // we must lower to "fence.sc.<scope>; atom.<op>.acquire.<scope>;" to conform
7596 // to the PTX atomics ABI.
7597 // https://docs.nvidia.com/cuda/ptx-writers-guide-to-interoperability/atomic-abi.html
7598 // For such cases, emitLeadingFence() will separately insert the leading
7599 // "fence.sc.<scope>;". Here, we only set the memory order to acquire.
7600 //
7601 // Otherwise, the operation is not emulated, and the memory order is not
7602 // seq_cst. In this case, the LLVM memory order is natively supported by the
7603 // PTX `atom` instruction, and we just lower to the corresponding
7604 // `atom.<op>.relaxed|acquire|release|acq_rel". For such cases, this function
7605 // will NOT be called.
7606 // prerequisite: shouldInsertFencesForAtomic() should have returned `true` for
7607 // I before its memory order was modified.
7608 if (auto *CI = dyn_cast<AtomicCmpXchgInst>(I);
7609 CI && CI->getMergedOrdering() == AtomicOrdering::SequentiallyConsistent &&
7610 cast<IntegerType>(CI->getCompareOperand()->getType())->getBitWidth() >=
7611 STI.getMinCmpXchgSizeInBits())
7613 else if (auto *RI = dyn_cast<AtomicRMWInst>(I);
7614 RI && RI->getOrdering() == AtomicOrdering::SequentiallyConsistent &&
7617
7619}
7620
7622 Instruction *Inst,
7623 AtomicOrdering Ord) const {
7624 // prerequisite: shouldInsertFencesForAtomic() should have returned `true` for
7625 // `Inst` before its memory order was modified. We cannot enforce this with an
7626 // assert, because AtomicExpandPass will have modified the memory order
7627 // between the initial call to shouldInsertFencesForAtomic() and the call to
7628 // this function.
7629 if (!isa<AtomicCmpXchgInst>(Inst) && !isa<AtomicRMWInst>(Inst))
7630 return TargetLoweringBase::emitLeadingFence(Builder, Inst, Ord);
7631
7632 // Specialize for cmpxchg and atomicrmw
7633 auto SSID = getAtomicSyncScopeID(Inst);
7634 assert(SSID.has_value() && "Expected an atomic operation");
7635
7636 if (isReleaseOrStronger(Ord))
7637 return Builder.CreateFence(Ord == AtomicOrdering::SequentiallyConsistent
7640 SSID.value());
7641
7642 return nullptr;
7643}
7644
7646 Instruction *Inst,
7647 AtomicOrdering Ord) const {
7648 // prerequisite: shouldInsertFencesForAtomic() should have returned `true` for
7649 // `Inst` before its memory order was modified. See `emitLeadingFence` for why
7650 // this cannot be enforced with an assert. Specialize for cmpxchg and
7651 // atomicrmw
7652 auto *CI = dyn_cast<AtomicCmpXchgInst>(Inst);
7653 auto *RI = dyn_cast<AtomicRMWInst>(Inst);
7654 if (!CI && !RI)
7655 return TargetLoweringBase::emitTrailingFence(Builder, Inst, Ord);
7656
7657 auto SSID = getAtomicSyncScopeID(Inst);
7658 assert(SSID.has_value() && "Expected an atomic operation");
7659
7660 bool IsEmulated =
7661 CI ? cast<IntegerType>(CI->getCompareOperand()->getType())
7662 ->getBitWidth() < STI.getMinCmpXchgSizeInBits()
7664
7665 if (isAcquireOrStronger(Ord) && IsEmulated)
7666 return Builder.CreateFence(AtomicOrdering::Acquire, SSID.value());
7667
7668 return nullptr;
7669}
7670
7671// Rather than default to SINT when both UINT and SINT are custom, we only
7672// change the opcode when UINT is not legal and SINT is. UINT is preferred when
7673// both are custom since unsigned CVT instructions can lead to slightly better
7674// SASS code with fewer instructions.
7676 EVT ToVT) const {
7677 if (isOperationLegal(Op, ToVT))
7678 return Op;
7679 switch (Op) {
7680 case ISD::FP_TO_UINT:
7682 return ISD::FP_TO_SINT;
7683 break;
7687 break;
7688 case ISD::VP_FP_TO_UINT:
7689 if (isOperationLegal(ISD::VP_FP_TO_SINT, ToVT))
7690 return ISD::VP_FP_TO_SINT;
7691 break;
7692 default:
7693 break;
7694 }
7695 return Op;
7696}
7697
7698// Pin NVPTXTargetObjectFile's vtables to this file.
7700
7705
7707 const SelectionDAG &DAG, unsigned Depth) {
7708 SDValue A = Op.getOperand(0);
7709 SDValue B = Op.getOperand(1);
7710 ConstantSDNode *Selector = dyn_cast<ConstantSDNode>(Op.getOperand(2));
7711 unsigned Mode = Op.getConstantOperandVal(3);
7712
7713 if (!Selector)
7714 return;
7715
7716 KnownBits AKnown = DAG.computeKnownBits(A, Depth);
7717 KnownBits BKnown = DAG.computeKnownBits(B, Depth);
7718
7719 // {b, a} = {{b7, b6, b5, b4}, {b3, b2, b1, b0}}
7720 assert(AKnown.getBitWidth() == 32 && BKnown.getBitWidth() == 32 &&
7721 "PRMT must have i32 operands");
7722 assert(Known.getBitWidth() == 32 && "PRMT must have i32 result");
7723 KnownBits BitField = BKnown.concat(AKnown);
7724
7725 APInt SelectorVal = getPRMTSelector(Selector->getAPIntValue(), Mode);
7726 for (unsigned I : llvm::seq(4)) {
7727 APInt Sel = SelectorVal.extractBits(4, I * 4);
7728 unsigned Idx = Sel.getLoBits(3).getZExtValue();
7729 unsigned Sign = Sel.getHiBits(1).getZExtValue();
7730 KnownBits Byte = BitField.extractBits(8, Idx * 8);
7731 if (Sign)
7732 Byte = KnownBits::ashr(Byte, 8);
7733 Known.insertBits(Byte, I * 8);
7734 }
7735}
7736
7737static void computeKnownBitsForLoadV(const SDValue Op, KnownBits &Known) {
7739
7740 // We can't do anything without knowing the sign bit.
7741 auto ExtType = LD->getConstantOperandVal(LD->getNumOperands() - 1);
7742 if (ExtType == ISD::SEXTLOAD)
7743 return;
7744
7745 // ExtLoading to vector types is weird and may not work well with known bits.
7746 auto DestVT = LD->getValueType(0);
7747 if (DestVT.isVector())
7748 return;
7749
7750 assert(Known.getBitWidth() == DestVT.getSizeInBits());
7751 auto ElementBitWidth = NVPTXDAGToDAGISel::getFromTypeWidthForLoad(LD);
7752 Known.Zero.setHighBits(Known.getBitWidth() - ElementBitWidth);
7753}
7754
7756 const SDValue Op, KnownBits &Known, const APInt &DemandedElts,
7757 const SelectionDAG &DAG, unsigned Depth) const {
7758 Known.resetAll();
7759
7760 switch (Op.getOpcode()) {
7761 case NVPTXISD::PRMT:
7762 computeKnownBitsForPRMT(Op, Known, DAG, Depth);
7763 break;
7764 case NVPTXISD::LoadV2:
7765 case NVPTXISD::LoadV4:
7766 case NVPTXISD::LoadV8:
7768 break;
7769 default:
7770 break;
7771 }
7772}
7773
7774static std::pair<APInt, APInt> getPRMTDemandedBits(const APInt &SelectorVal,
7775 const APInt &DemandedBits) {
7776 APInt DemandedLHS = APInt(32, 0);
7777 APInt DemandedRHS = APInt(32, 0);
7778
7779 for (unsigned I : llvm::seq(4)) {
7780 if (DemandedBits.extractBits(8, I * 8).isZero())
7781 continue;
7782
7783 APInt Sel = SelectorVal.extractBits(4, I * 4);
7784 unsigned Idx = Sel.getLoBits(3).getZExtValue();
7785 unsigned Sign = Sel.getHiBits(1).getZExtValue();
7786
7787 APInt &Src = Idx < 4 ? DemandedLHS : DemandedRHS;
7788 unsigned ByteStart = (Idx % 4) * 8;
7789 if (Sign)
7790 Src.setBit(ByteStart + 7);
7791 else
7792 Src.setBits(ByteStart, ByteStart + 8);
7793 }
7794
7795 return {DemandedLHS, DemandedRHS};
7796}
7797
7798// Replace undef with 0 as this is easier for other optimizations such as
7799// known bits.
7801 if (!Op)
7802 return SDValue();
7803 if (Op.isUndef())
7804 return DAG.getConstant(0, SDLoc(), MVT::i32);
7805 return Op;
7806}
7807
7809 const APInt &DemandedBits,
7810 SelectionDAG &DAG,
7811 const TargetLowering &TLI,
7812 unsigned Depth) {
7813 assert(PRMT.getOpcode() == NVPTXISD::PRMT);
7814 SDValue Op0 = PRMT.getOperand(0);
7815 SDValue Op1 = PRMT.getOperand(1);
7816 auto *SelectorConst = dyn_cast<ConstantSDNode>(PRMT.getOperand(2));
7817 if (!SelectorConst)
7818 return SDValue();
7819
7820 unsigned Mode = PRMT.getConstantOperandVal(3);
7821 const APInt Selector = getPRMTSelector(SelectorConst->getAPIntValue(), Mode);
7822
7823 // Try to simplify the PRMT to one of the inputs if the used bytes are all
7824 // from the same input in the correct order.
7825 const unsigned LeadingBytes = DemandedBits.countLeadingZeros() / 8;
7826 const unsigned SelBits = (4 - LeadingBytes) * 4;
7827 if (Selector.getLoBits(SelBits) == APInt(32, 0x3210).getLoBits(SelBits))
7828 return Op0;
7829 if (Selector.getLoBits(SelBits) == APInt(32, 0x7654).getLoBits(SelBits))
7830 return Op1;
7831
7832 auto [DemandedLHS, DemandedRHS] = getPRMTDemandedBits(Selector, DemandedBits);
7833
7834 // Attempt to avoid multi-use ops if we don't need anything from them.
7835 SDValue DemandedOp0 =
7836 TLI.SimplifyMultipleUseDemandedBits(Op0, DemandedLHS, DAG, Depth + 1);
7837 SDValue DemandedOp1 =
7838 TLI.SimplifyMultipleUseDemandedBits(Op1, DemandedRHS, DAG, Depth + 1);
7839
7840 DemandedOp0 = canonicalizePRMTInput(DemandedOp0, DAG);
7841 DemandedOp1 = canonicalizePRMTInput(DemandedOp1, DAG);
7842 if ((DemandedOp0 && DemandedOp0 != Op0) ||
7843 (DemandedOp1 && DemandedOp1 != Op1)) {
7844 Op0 = DemandedOp0 ? DemandedOp0 : Op0;
7845 Op1 = DemandedOp1 ? DemandedOp1 : Op1;
7846 return getPRMT(Op0, Op1, Selector.getZExtValue(), SDLoc(PRMT), DAG);
7847 }
7848
7849 return SDValue();
7850}
7851
7853 SDValue Op, const APInt &DemandedBits, const APInt &DemandedElts,
7854 KnownBits &Known, TargetLoweringOpt &TLO, unsigned Depth) const {
7855 Known.resetAll();
7856
7857 switch (Op.getOpcode()) {
7858 case NVPTXISD::PRMT:
7860 *this, Depth)) {
7861 TLO.CombineTo(Op, Result);
7862 return true;
7863 }
7864 break;
7865 default:
7866 break;
7867 }
7868
7869 computeKnownBitsForTargetNode(Op, Known, DemandedElts, TLO.DAG, Depth);
7870 return false;
7871}
return SDValue()
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
constexpr LLT S1
constexpr LLT F32
AMDGPU Register Bank Select
This file declares a class to represent arbitrary precision floating point values and provide a varie...
This file implements a class to represent arbitrary precision integral constant values and operations...
static SDValue PerformADDCombineWithOperands(SDNode *N, SDValue N0, SDValue N1, TargetLowering::DAGCombinerInfo &DCI, const ARMSubtarget *Subtarget)
PerformADDCombineWithOperands - Try DAG combinations for an ADD with operands N0 and N1.
static SDValue PerformADDCombine(SDNode *N, TargetLowering::DAGCombinerInfo &DCI, const ARMSubtarget *Subtarget)
PerformADDCombine - Target-specific dag combine xforms for ISD::ADD.
static SDValue PerformVSELECTCombine(SDNode *N, TargetLowering::DAGCombinerInfo &DCI, const ARMSubtarget *Subtarget)
static SDValue PerformMULCombine(SDNode *N, TargetLowering::DAGCombinerInfo &DCI, const ARMSubtarget *Subtarget)
static SDValue PerformFADDCombine(SDNode *N, SelectionDAG &DAG, const ARMSubtarget *Subtarget)
static SDValue PerformBUILD_VECTORCombine(SDNode *N, TargetLowering::DAGCombinerInfo &DCI, const ARMSubtarget *Subtarget)
PerformBUILD_VECTORCombine - Target-specific dag combine xforms for ISD::BUILD_VECTOR.
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
Function Alias Analysis Results
Atomic ordering constants.
This file contains the simple types necessary to represent the attributes associated with functions a...
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
#define clEnumValN(ENUMVAL, FLAGNAME, DESC)
This file contains the declarations for the subclasses of Constant, which represent the different fla...
This file contains the declarations of entities that describe floating point environment and related ...
static bool IsIndirectCall(const MachineInstr *MI)
Module.h This file contains the declarations for the Module class.
const AbstractManglingParser< Derived, Alloc >::OperatorInfo AbstractManglingParser< Derived, Alloc >::Ops[]
#define F(x, y, z)
Definition MD5.cpp:54
#define I(x, y, z)
Definition MD5.cpp:57
static DebugLoc getDebugLoc(MachineBasicBlock::instr_iterator FirstMI, MachineBasicBlock::instr_iterator LastMI)
Return the first DebugLoc that has line number information, given a range of instructions.
Register Reg
Register const TargetRegisterInfo * TRI
#define T
NVPTX address space definition.
static SDValue reportInvalidTensormapReplaceUsage(SDValue Op, SelectionDAG &DAG, unsigned Val)
static bool shouldConvertToIndirectCall(const CallBase *CB, const GlobalAddressSDNode *Func)
static SDValue combineADDRSPACECAST(SDNode *N, TargetLowering::DAGCombinerInfo &DCI)
static cl::opt< bool > sched4reg("nvptx-sched4reg", cl::desc("NVPTX Specific: schedule for register pressue"), cl::init(false))
static SDValue lowerTcgen05St(SDValue Op, SelectionDAG &DAG, bool hasOffset=false)
static SDValue PerformEXTRACTCombine(SDNode *N, TargetLowering::DAGCombinerInfo &DCI)
static cl::opt< NVPTX::DivPrecisionLevel > UsePrecDivF32("nvptx-prec-divf32", cl::Hidden, cl::desc("NVPTX Specific: Override the precision of the lowering for f32 fdiv"), cl::values(clEnumValN(NVPTX::DivPrecisionLevel::Approx, "0", "Use div.approx"), clEnumValN(NVPTX::DivPrecisionLevel::Full, "1", "Use div.full"), clEnumValN(NVPTX::DivPrecisionLevel::IEEE754, "2", "Use IEEE Compliant F32 div.rnd if available (default)"), clEnumValN(NVPTX::DivPrecisionLevel::IEEE754_NoFTZ, "3", "Use IEEE Compliant F32 div.rnd if available, no FTZ")), cl::init(NVPTX::DivPrecisionLevel::IEEE754))
static bool isConstOne(const SDValue &Operand)
static cl::opt< unsigned > FMAContractLevelOpt("nvptx-fma-level", cl::Hidden, cl::desc("NVPTX Specific: FMA contraction (0: don't do it" " 1: do it 2: do it aggressively"), cl::init(2))
static bool IsPTXVectorType(MVT VT)
static SDValue PerformSELECTShiftCombine(SDNode *N, TargetLowering::DAGCombinerInfo &DCI)
Transform patterns like: (select (ugt shift_amt, BitWidth-1), 0, (srl/shl x, shift_amt)) (select (ult...
static SDValue lowerLOADi1(LoadSDNode *LD, SelectionDAG &DAG)
static SDValue lowerIntrinsicVoid(SDValue Op, SelectionDAG &DAG)
static MachinePointerInfo refinePtrAS(SDValue &Ptr, SelectionDAG &DAG, const DataLayout &DL, const TargetLowering &TL)
static SDValue lowerROT(SDValue Op, SelectionDAG &DAG)
static void ComputePTXValueVTs(const TargetLowering &TLI, const DataLayout &DL, LLVMContext &Ctx, CallingConv::ID CallConv, Type *Ty, SmallVectorImpl< EVT > &ValueVTs, SmallVectorImpl< uint64_t > &Offsets, uint64_t StartingOffset=0)
ComputePTXValueVTs - For the given Type Ty, returns the set of primitive legal-ish MVTs that compose ...
static void ReplaceBITCAST(SDNode *Node, SelectionDAG &DAG, SmallVectorImpl< SDValue > &Results)
static void replaceAtomicSwap128(SDNode *N, SelectionDAG &DAG, const NVPTXSubtarget &STI, SmallVectorImpl< SDValue > &Results)
static unsigned getMinMax3Opcode(unsigned MinMax2Opcode)
Get 3-input version of a 2-input min/max opcode.
static SDValue lowerSTOREVector(SDValue Op, SelectionDAG &DAG, const NVPTXSubtarget &STI)
static SDValue lowerLoadVector(SDNode *N, SelectionDAG &DAG, const NVPTXSubtarget &STI)
static void replaceProxyReg(SDNode *N, SelectionDAG &DAG, const TargetLowering &TLI, SmallVectorImpl< SDValue > &Results)
static void ReplaceCopyFromReg_128(SDNode *N, SelectionDAG &DAG, SmallVectorImpl< SDValue > &Results)
#define TCGEN05_LD_RED_INST(SHAPE, NUM, TYPE)
static SDValue lowerCTLZCTPOP(SDValue Op, SelectionDAG &DAG)
static SDValue combineMADConstOne(SDValue X, SDValue Add, EVT VT, SDLoc DL, TargetLowering::DAGCombinerInfo &DCI)
static unsigned getTcgen05LdRedID(Intrinsic::ID IID)
static SDValue combinePRMT(SDNode *N, TargetLowering::DAGCombinerInfo &DCI, CodeGenOptLevel OptLevel)
static SDValue combinePackingMovIntoStore(SDNode *N, TargetLowering::DAGCombinerInfo &DCI, unsigned Front, unsigned Back)
Fold packing movs into a store.
static void ReplaceINTRINSIC_W_CHAIN(SDNode *N, SelectionDAG &DAG, SmallVectorImpl< SDValue > &Results)
static SDValue getBuildVectorizedValue(unsigned N, const SDLoc &dl, SelectionDAG &DAG, T GetElement)
static SDValue getExtractVectorizedValue(SDValue V, unsigned I, EVT VT, const SDLoc &dl, SelectionDAG &DAG)
static unsigned canMergeParamLoadStoresStartingAt(unsigned Idx, uint32_t AccessSize, const SmallVectorImpl< EVT > &ValueVTs, const SmallVectorImpl< T > &Offsets, Align ParamAlignment)
static EVT getVectorizedVT(EVT VT, unsigned N, LLVMContext &C)
static SDValue lowerIntrinsicWOChain(SDValue Op, SelectionDAG &DAG)
static SDValue PerformFMinMaxCombine(SDNode *N, TargetLowering::DAGCombinerInfo &DCI, unsigned PTXVersion, unsigned SmVersion)
PerformFMinMaxCombine - Combine (fmaxnum (fmaxnum a, b), c) into (fmaxnum3 a, b, c).
static SDValue combineMulWide(SDNode *N, TargetLowering::DAGCombinerInfo &DCI, CodeGenOptLevel OptLevel)
static SDValue PerformFADDCombineWithOperands(SDNode *N, SDValue N0, SDValue N1, TargetLowering::DAGCombinerInfo &DCI, CodeGenOptLevel OptLevel)
static std::optional< unsigned > getScalar3OpcodeForReduction(unsigned ReductionOpcode)
Get 3-input scalar reduction opcode.
static SDValue lowerIntrinsicWChain(SDValue Op, SelectionDAG &DAG)
static bool isNonCoalescableBuildVector(const SDValue &BV)
Check if a v2f32 BUILD_VECTOR provably packs values from non-adjacent register pairs (non-coalescable...
static SDValue PerformScalarizeV2F32Op(SDNode *N, TargetLowering::DAGCombinerInfo &DCI)
Scalarize a v2f32 arithmetic node (FADD, FMUL, FSUB, FMA) when at least one operand is a BUILD_VECTOR...
static bool isConstZero(const SDValue &Operand)
static unsigned getF16SubOpc(Intrinsic::ID AddIntrinsicID)
static SDValue LowerVectorArith(SDValue Op, SelectionDAG &DAG)
static SDValue LowerTcgen05MMADisableOutputLane(SDValue Op, SelectionDAG &DAG)
static bool IsMulWideOperandDemotable(SDValue Op, unsigned OptSize, OperandSignedness &S)
IsMulWideOperandDemotable - Checks if the provided DAG node is an operand that can be demoted to OptS...
static unsigned getTcgen05MMADisableOutputLane(unsigned IID)
static std::pair< APInt, APInt > getPRMTDemandedBits(const APInt &SelectorVal, const APInt &DemandedBits)
static APInt computePRMT(APInt A, APInt B, APInt Selector, unsigned Mode)
static ISD::NodeType getScalarOpcodeForReduction(unsigned ReductionOpcode)
static SDValue PerformREMCombine(SDNode *N, TargetLowering::DAGCombinerInfo &DCI, CodeGenOptLevel OptLevel)
static SDValue lowerBSWAP(SDValue Op, SelectionDAG &DAG)
static SDValue lowerMSTORE(SDValue Op, SelectionDAG &DAG)
static SDValue PerformMULCombineWithOperands(SDNode *N, SDValue N0, SDValue N1, TargetLowering::DAGCombinerInfo &DCI)
static void computeKnownBitsForPRMT(const SDValue Op, KnownBits &Known, const SelectionDAG &DAG, unsigned Depth)
static SDValue combineUnpackingMovIntoLoad(SDNode *N, TargetLowering::DAGCombinerInfo &DCI)
Fold unpacking movs into a load by increasing the number of return values.
#define TCGEN05_LD_RED_INTR(SHAPE, NUM, TYPE)
static SDValue lowerTensormapReplaceElemtype(SDValue Op, SelectionDAG &DAG)
static SDValue LowerClusterLaunchControlQueryCancel(SDValue Op, SelectionDAG &DAG)
static std::optional< std::pair< SDValue, SDValue > > lowerTcgen05Ld(SDNode *N, SelectionDAG &DAG, bool HasOffset=false)
static SDValue lowerCvtRSIntrinsics(SDValue Op, SelectionDAG &DAG)
static std::optional< std::pair< SDValue, SDValue > > replaceLoadVector(SDNode *N, SelectionDAG &DAG, const NVPTXSubtarget &STI)
replaceLoadVector - Convert vector loads into multi-output scalar loads.
static SDValue expandFSH64(SDValue A, SDValue B, SDValue ShiftAmount, SDLoc DL, unsigned Opcode, SelectionDAG &DAG)
static bool AreMulWideOperandsDemotable(SDValue LHS, SDValue RHS, unsigned OptSize, bool &IsSigned)
AreMulWideOperandsDemotable - Checks if the given LHS and RHS operands can be demoted to OptSize bits...
static std::pair< MemSDNode *, uint32_t > convertMLOADToLoadWithUsedBytesMask(MemSDNode *N, SelectionDAG &DAG, const NVPTXSubtarget &STI)
static SDValue TryMULWIDECombine(SDNode *N, TargetLowering::DAGCombinerInfo &DCI)
TryMULWIDECombine - Attempt to replace a multiply of M bits with a multiply of M/2 bits that produces...
static SDValue lowerPrmtIntrinsic(SDValue Op, SelectionDAG &DAG)
static SDValue combineMulSelectConstOne(SDValue X, SDValue Select, EVT VT, SDLoc DL, TargetLowering::DAGCombinerInfo &DCI)
static SDValue buildTreeReduction(const SmallVector< SDValue > &Elements, EVT EltTy, ArrayRef< std::pair< unsigned, unsigned > > Ops, const SDLoc &DL, const SDNodeFlags Flags, SelectionDAG &DAG)
Reduces the elements using the scalar operations provided.
static SDValue combineProxyReg(SDNode *N, TargetLowering::DAGCombinerInfo &DCI)
static SmallVector< unsigned, 16 > VectorizePTXValueVTs(const SmallVectorImpl< EVT > &ValueVTs, const SmallVectorImpl< T > &Offsets, Align ParamAlignment, bool IsVAArg=false)
static SDValue getPRMT(SDValue A, SDValue B, SDValue Selector, SDLoc DL, SelectionDAG &DAG, unsigned Mode=NVPTX::PTXPrmtMode::NONE)
static SDValue matchMADConstOnePattern(SDValue Add)
static SDValue correctParamType(SDValue V, EVT ExpectedVT, ISD::ArgFlagsTy Flags, SelectionDAG &DAG, SDLoc dl)
static ISD::NodeType getExtOpcode(const ISD::ArgFlagsTy &Flags)
static cl::opt< bool > UsePrecSqrtF32("nvptx-prec-sqrtf32", cl::Hidden, cl::desc("NVPTX Specific: 0 use sqrt.approx, 1 use sqrt.rn."), cl::init(true))
static void computeKnownBitsForLoadV(const SDValue Op, KnownBits &Known)
static APInt getPRMTSelector(const APInt &Selector, unsigned Mode)
static EVT promoteScalarIntegerPTX(const EVT VT)
PromoteScalarIntegerPTX Used to make sure the arguments/returns are suitable for passing and promote ...
static std::optional< std::tuple< SDValue, SDValue, SDValue > > lowerTcgen05LdRed(SDNode *N, SelectionDAG &DAG)
static SDValue simplifyDemandedBitsForPRMT(SDValue PRMT, const APInt &DemandedBits, SelectionDAG &DAG, const TargetLowering &TLI, unsigned Depth)
static SDValue lowerFREM(SDValue Op, SelectionDAG &DAG)
static SDValue canonicalizePRMTInput(SDValue Op, SelectionDAG &DAG)
static SDValue sinkProxyReg(SDValue R, SDValue Chain, TargetLowering::DAGCombinerInfo &DCI)
static SDValue lowerFSH(SDValue Op, SelectionDAG &DAG)
static SDValue lowerTensormapReplaceSwizzleMode(SDValue Op, SelectionDAG &DAG)
static SDValue combineIntrinsicWOChain(SDNode *N, TargetLowering::DAGCombinerInfo &DCI, const NVPTXSubtarget &STI)
static SDValue PromoteBinOpToF32(SDNode *N, SelectionDAG &DAG)
static SDValue PerformSETCCCombine(SDNode *N, TargetLowering::DAGCombinerInfo &DCI, unsigned int SmVersion)
static std::optional< std::pair< unsigned int, MVT > > getVectorLoweringShape(EVT VectorEVT, const NVPTXSubtarget &STI, unsigned AddressSpace)
static cl::opt< bool > ForceMinByValParamAlign("nvptx-force-min-byval-param-align", cl::Hidden, cl::desc("NVPTX Specific: force 4-byte minimal alignment for byval" " params of device functions."), cl::init(false))
static SDValue combineF16AddWithNeg(SDNode *N, SelectionDAG &DAG, Intrinsic::ID AddIntrinsicID)
static cl::opt< bool > UseApproxLog2F32("nvptx-approx-log2f32", cl::desc("NVPTX Specific: whether to use lg2.approx for log2"), cl::init(false))
Whereas CUDA's implementation (see libdevice) uses ex2.approx for exp2(), it does NOT use lg2....
static SDValue lowerSELECT(SDValue Op, SelectionDAG &DAG)
static SDValue combineLOAD(SDNode *N, TargetLowering::DAGCombinerInfo &DCI, const NVPTXSubtarget &STI)
static SDValue combineSTORE(SDNode *N, TargetLowering::DAGCombinerInfo &DCI, const NVPTXSubtarget &STI)
static SDValue PerformSHLCombine(SDNode *N, TargetLowering::DAGCombinerInfo &DCI, CodeGenOptLevel OptLevel)
PerformSHLCombine - Runs PTX-specific DAG combine patterns on SHL nodes.
MachineInstr unsigned OpIdx
uint64_t High
#define P(N)
const SmallVectorImpl< MachineOperand > & Cond
static cl::opt< RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode > Mode("regalloc-enable-advisor", cl::Hidden, cl::init(RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode::Default), cl::desc("Enable regalloc advisor mode"), cl::values(clEnumValN(RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode::Default, "default", "Default"), clEnumValN(RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode::Release, "release", "precompiled"), clEnumValN(RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode::Development, "development", "for training")))
Contains matchers for matching SelectionDAG nodes and values.
This file contains some templates that are useful if you are working with the STL at all.
This file defines the SmallVector class.
static TableGen::Emitter::Opt Y("gen-skeleton-entry", EmitSkeleton, "Generate example skeleton entry")
static TableGen::Emitter::OptClass< SkeletonEmitter > X("gen-skeleton-class", "Generate example skeleton class")
This file describes how to lower LLVM code to machine code.
Value * RHS
Value * LHS
BinaryOperator * Mul
static const fltSemantics & IEEEsingle()
Definition APFloat.h:296
static APFloat getInf(const fltSemantics &Sem, bool Negative=false)
Factory for Positive and Negative Infinity.
Definition APFloat.h:1149
Class for arbitrary precision integers.
Definition APInt.h:78
LLVM_ABI APInt getLoBits(unsigned numBits) const
Compute an APInt containing numBits lowbits from this APInt.
Definition APInt.cpp:644
uint64_t getZExtValue() const
Get zero extended value.
Definition APInt.h:1555
void setHighBits(unsigned hiBits)
Set the top hiBits bits.
Definition APInt.h:1406
LLVM_ABI APInt getHiBits(unsigned numBits) const
Compute an APInt containing numBits highbits from this APInt.
Definition APInt.cpp:639
LLVM_ABI APInt trunc(unsigned width) const
Truncate to new width.
Definition APInt.cpp:936
void setBit(unsigned BitPosition)
Set the given bit to 1 whose position is given as "bitPosition".
Definition APInt.h:1345
unsigned getBitWidth() const
Return the number of bits in the APInt.
Definition APInt.h:1503
bool isSignedIntN(unsigned N) const
Check if this APInt has an N-bits signed integer value.
Definition APInt.h:436
bool slt(const APInt &RHS) const
Signed less than comparison.
Definition APInt.h:1137
LLVM_ABI APInt extractBits(unsigned numBits, unsigned bitPosition) const
Return an APInt with the extracted bits [bitPosition,bitPosition+numBits).
Definition APInt.cpp:482
bool isIntN(unsigned N) const
Check if this APInt has an N-bits unsigned integer value.
Definition APInt.h:433
bool sge(const APInt &RHS) const
Signed greater or equal comparison.
Definition APInt.h:1244
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:40
ArrayRef< T > slice(size_t N, size_t M) const
slice(n, m) - Chop off the first N elements of the array, and keep M elements in the array.
Definition ArrayRef.h:186
an instruction that atomically reads a memory location, combines it with another value,...
@ Add
*p = old + v
@ FAdd
*p = old + v
@ Min
*p = old <signed v ? old : v
@ Sub
*p = old - v
@ And
*p = old & v
@ Xor
*p = old ^ v
@ UIncWrap
Increment one up to a maximum value.
@ Max
*p = old >signed v ? old : v
@ UMin
*p = old <unsigned v ? old : v
@ UMax
*p = old >unsigned v ? old : v
@ UDecWrap
Decrement one until a minimum value or zero.
bool isFloatingPointOperation() const
BinOp getOperation() const
This is an SDNode representing atomic operations.
Base class for all callable instructions (InvokeInst and CallInst) Holds everything related to callin...
Function * getCalledFunction() const
Returns the function called, or null if this is an indirect function invocation or the function signa...
FunctionType * getFunctionType() const
const APInt & getAPIntValue() const
static LLVM_ABI Constant * getNullValue(Type *Ty)
Constructor to create a '0' constant of arbitrary type.
A parsed version of the target data layout string in and methods for querying it.
Definition DataLayout.h:64
LLVM_ABI TypeSize getTypeAllocSize(Type *Ty) const
Returns the offset in bytes between successive objects of the specified type, including alignment pad...
LLVM_ABI Align getPrefTypeAlign(Type *Ty) const
Returns the preferred stack/global alignment for the specified type.
Diagnostic information for unsupported feature in backend.
void addFnAttr(Attribute::AttrKind Kind)
Add function attributes to this function.
Definition Function.cpp:639
Module * getParent()
Get the module that this global value is contained inside of...
Common base class shared among various IRBuilders.
Definition IRBuilder.h:114
This is an important class for using LLVM in a threaded context.
Definition LLVMContext.h:68
LLVM_ABI void diagnose(const DiagnosticInfo &DI)
Report a message to the currently installed diagnostic handler.
This class is used to represent ISD::LOAD nodes.
MCSection * getDataSection() const
static constexpr unsigned NoRegister
Definition MCRegister.h:60
Instances of this class represent a uniqued identifier for a section in the current translation unit.
Definition MCSection.h:516
StringRef getName() const
getName - Get the symbol name.
Definition MCSymbol.h:188
Machine Value Type.
static auto integer_fixedlen_vector_valuetypes()
SimpleValueType SimpleTy
unsigned getVectorNumElements() const
bool isVector() const
Return true if this is a vector value type.
bool isScalableVector() const
Return true if this is a vector value type where the runtime length is machine dependent.
static auto integer_valuetypes()
TypeSize getSizeInBits() const
Returns the size of the specified MVT in bits.
static auto fixedlen_vector_valuetypes()
TypeSize getStoreSize() const
Return the number of bytes overwritten by a store of the specified value type.
static MVT getVectorVT(MVT VT, unsigned NumElements)
MVT getVectorElementType() const
static MVT getIntegerVT(unsigned BitWidth)
static auto fp_valuetypes()
MVT getScalarType() const
If this is a vector, return the element type, otherwise return this.
static auto fp_fixedlen_vector_valuetypes()
DenormalMode getDenormalMode(const fltSemantics &FPType) const
Returns the denormal handling type for the default rounding mode of the function.
Function & getFunction()
Return the LLVM function that this machine code represents.
const TargetMachine & getTarget() const
getTarget - Return the target machine this machine code is compiled with
@ EK_Inline
EK_Inline - Jump table entries are emitted inline at their point of use.
@ MODereferenceable
The memory access is dereferenceable (i.e., doesn't trap).
@ MOLoad
The memory access reads data.
@ MOInvariant
The memory access always returns the same value (or traps).
@ MOStore
The memory access writes data.
This SDNode is used for target intrinsics that touch memory and need an associated MachineMemOperand.
This is an abstract virtual class for memory operations.
Align getAlign() const
MachineMemOperand * getMemOperand() const
Return the unique MachineMemOperand object describing the memory reference performed by operation.
EVT getMemoryVT() const
Return the type of the in-memory value.
A Module instance is used to store all the information related to an LLVM module.
Definition Module.h:67
static unsigned getFromTypeWidthForLoad(const MemSDNode *Mem)
bool hasTensormapReplaceSwizzleModeSupport(unsigned value) const
bool hasUsedBytesMaskPragma() const
bool hasTensormapReplaceElemtypeSupport(unsigned value) const
bool hasAtomSwap128() const
bool hasF32x2Instructions() const
bool has256BitVectorLoadStore(unsigned AS) const
AtomicOrdering atomicOperationOrderAfterFenceSplit(const Instruction *I) const override
ConstraintType getConstraintType(StringRef Constraint) const override
getConstraintType - Given a constraint letter, return the type of constraint it is for this target.
SDValue LowerOperation(SDValue Op, SelectionDAG &DAG) const override
This callback is invoked for operations that are unsupported by the target, which are registered to u...
const NVPTXTargetMachine * nvTM
bool SimplifyDemandedBitsForTargetNode(SDValue Op, const APInt &DemandedBits, const APInt &DemandedElts, KnownBits &Known, TargetLoweringOpt &TLO, unsigned Depth=0) const override
Attempt to simplify any target nodes based on the demanded bits/elts, returning true on success.
AtomicExpansionKind shouldExpandAtomicRMWInIR(const AtomicRMWInst *AI) const override
Returns how the IR-level AtomicExpand pass should expand the given AtomicRMW, if at all.
NVPTXTargetLowering(const NVPTXTargetMachine &TM, const NVPTXSubtarget &STI)
std::string getPrototype(const DataLayout &DL, Type *, const ArgListTy &, const SmallVectorImpl< ISD::OutputArg > &, std::optional< unsigned > FirstVAArg, const CallBase &CB, unsigned UniqueCallSite) const
unsigned getPreferredFPToIntOpcode(unsigned Op, EVT FromVT, EVT ToVT) const override
bool useF32FTZ(const MachineFunction &MF) const
SDValue LowerSTACKSAVE(SDValue Op, SelectionDAG &DAG) const
Align getFunctionArgumentAlignment(const Function *F, Type *Ty, unsigned Idx, const DataLayout &DL) const
SDValue getSqrtEstimate(SDValue Operand, SelectionDAG &DAG, int Enabled, int &ExtraSteps, bool &UseOneConst, bool Reciprocal) const override
Hooks for building estimates in place of slower divisions and square roots.
SDValue LowerReturn(SDValue Chain, CallingConv::ID CallConv, bool isVarArg, const SmallVectorImpl< ISD::OutputArg > &Outs, const SmallVectorImpl< SDValue > &OutVals, const SDLoc &dl, SelectionDAG &DAG) const override
This hook must be implemented to lower outgoing return values, described by the Outs array,...
SDValue LowerFormalArguments(SDValue Chain, CallingConv::ID CallConv, bool isVarArg, const SmallVectorImpl< ISD::InputArg > &Ins, const SDLoc &dl, SelectionDAG &DAG, SmallVectorImpl< SDValue > &InVals) const override
This hook must be implemented to lower the incoming (formal) arguments, described by the Ins array,...
void LowerAsmOperandForConstraint(SDValue Op, StringRef Constraint, std::vector< SDValue > &Ops, SelectionDAG &DAG) const override
Lower the specified operand into the Ops vector.
SDValue LowerSTACKRESTORE(SDValue Op, SelectionDAG &DAG) const
Instruction * emitTrailingFence(IRBuilderBase &Builder, Instruction *Inst, AtomicOrdering Ord) const override
std::string getParamName(const Function *F, int Idx) const
TargetLoweringBase::LegalizeTypeAction getPreferredVectorAction(MVT VT) const override
Return the preferred vector type legalization action.
NVPTX::DivPrecisionLevel getDivF32Level(const MachineFunction &MF, const SDNode &N) const
bool shouldInsertFencesForAtomic(const Instruction *) const override
Whether AtomicExpandPass should automatically insert fences and reduce ordering for this atomic.
Align getFunctionParamOptimizedAlign(const Function *F, Type *ArgTy, const DataLayout &DL) const
getFunctionParamOptimizedAlign - since function arguments are passed via .param space,...
SDValue LowerDYNAMIC_STACKALLOC(SDValue Op, SelectionDAG &DAG) const
EVT getSetCCResultType(const DataLayout &DL, LLVMContext &Ctx, EVT VT) const override
Return the ValueType of the result of SETCC operations.
std::pair< unsigned, const TargetRegisterClass * > getRegForInlineAsmConstraint(const TargetRegisterInfo *TRI, StringRef Constraint, MVT VT) const override
Given a physical register constraint (e.g.
bool isLegalAddressingMode(const DataLayout &DL, const AddrMode &AM, Type *Ty, unsigned AS, Instruction *I=nullptr) const override
isLegalAddressingMode - Return true if the addressing mode represented by AM is legal for this target...
Instruction * emitLeadingFence(IRBuilderBase &Builder, Instruction *Inst, AtomicOrdering Ord) const override
Inserts in the IR a target-specific intrinsic specifying a fence.
Align getFunctionByValParamAlign(const Function *F, Type *ArgTy, Align InitialAlign, const DataLayout &DL) const
Helper for computing alignment of a device function byval parameter.
void getTgtMemIntrinsic(SmallVectorImpl< IntrinsicInfo > &Infos, const CallBase &I, MachineFunction &MF, unsigned Intrinsic) const override
Given an intrinsic, checks if on the target the intrinsic will need to map to a MemIntrinsicNode (tou...
bool allowFMA(MachineFunction &MF, CodeGenOptLevel OptLevel) const
bool usePrecSqrtF32(const SDNode *N=nullptr) const
unsigned getJumpTableEncoding() const override
Return the entry encoding for a jump table in the current function.
SDValue LowerCall(CallLoweringInfo &CLI, SmallVectorImpl< SDValue > &InVals) const override
This hook must be implemented to lower calls into the specified DAG.
void computeKnownBitsForTargetNode(const SDValue Op, KnownBits &Known, const APInt &DemandedElts, const SelectionDAG &DAG, unsigned Depth=0) const override
Determine which of the bits specified in Mask are known to be either zero or one and return them in t...
MCSection * SelectSectionForGlobal(const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const override
static LLVM_ABI PointerType * get(Type *ElementType, unsigned AddressSpace)
This constructs a pointer to an object of the specified type in a numbered address space.
Wrapper class for IR location info (IR ordering and DebugLoc) to be passed into SDNode creation funct...
const DebugLoc & getDebugLoc() const
Represents one node in the SelectionDAG.
ArrayRef< SDUse > ops() const
const APInt & getAsAPIntVal() const
Helper method returns the APInt value of a ConstantSDNode.
unsigned getOpcode() const
Return the SelectionDAG opcode value for this node.
bool hasOneUse() const
Return true if there is exactly one use of this node.
unsigned getIROrder() const
Return the node ordering.
SDNodeFlags getFlags() const
uint64_t getAsZExtVal() const
Helper method returns the zero-extended integer value of a ConstantSDNode.
unsigned getNumValues() const
Return the number of values defined/returned by this operator.
SDVTList getVTList() const
const SDValue & getOperand(unsigned Num) const
bool isUndef() const
Returns true if the node type is UNDEF or POISON.
iterator_range< user_iterator > users()
void setFlags(SDNodeFlags NewFlags)
Represents a use of a SDNode.
Unlike LLVM values, Selection DAG nodes may return multiple values as the result of a computation.
SDNode * getNode() const
get the SDNode which holds the desired result
bool hasOneUse() const
Return true if there is exactly one node using value ResNo of Node.
SDValue getValue(unsigned R) const
EVT getValueType() const
Return the ValueType of the referenced return value.
const SDValue & getOperand(unsigned i) const
uint64_t getScalarValueSizeInBits() const
uint64_t getConstantOperandVal(unsigned i) const
unsigned getOpcode() const
SectionKind - This is a simple POD value that classifies the properties of a section.
Definition SectionKind.h:22
This is used to represent a portion of an LLVM function in a low-level Data Dependence DAG representa...
LLVM_ABI SDValue getExtLoad(ISD::LoadExtType ExtType, const SDLoc &dl, EVT VT, SDValue Chain, SDValue Ptr, MachinePointerInfo PtrInfo, EVT MemVT, MaybeAlign Alignment=MaybeAlign(), MachineMemOperand::Flags MMOFlags=MachineMemOperand::MONone, const AAMDNodes &AAInfo=AAMDNodes())
const SDValue & getRoot() const
Return the root tag of the SelectionDAG.
LLVM_ABI SDValue getAddrSpaceCast(const SDLoc &dl, EVT VT, SDValue Ptr, unsigned SrcAS, unsigned DestAS)
Return an AddrSpaceCastSDNode.
const TargetSubtargetInfo & getSubtarget() const
LLVM_ABI SDValue getMergeValues(ArrayRef< SDValue > Ops, const SDLoc &dl)
Create a MERGE_VALUES node from the given operands.
LLVM_ABI SDVTList getVTList(EVT VT)
Return an SDVTList that represents the list of values specified.
LLVM_ABI void ExtractVectorElements(SDValue Op, SmallVectorImpl< SDValue > &Args, unsigned Start=0, unsigned Count=0, EVT EltVT=EVT())
Append the extracted elements from Start to Count out of the vector Op in Args.
LLVM_ABI SDValue getFreeze(SDValue V)
Return a freeze using the SDLoc of the value operand.
LLVM_ABI SDValue getSymbolFunctionGlobalAddress(SDValue Op, Function **TargetFunction=nullptr)
Return a GlobalAddress of the function from the current module with name matching the given ExternalS...
LLVM_ABI SDValue getConstantFP(double Val, const SDLoc &DL, EVT VT, bool isTarget=false)
Create a ConstantFPSDNode wrapping a constant value.
LLVM_ABI SDValue getRegister(Register Reg, EVT VT)
LLVM_ABI SDValue getLoad(EVT VT, const SDLoc &dl, SDValue Chain, SDValue Ptr, MachinePointerInfo PtrInfo, MaybeAlign Alignment=MaybeAlign(), MachineMemOperand::Flags MMOFlags=MachineMemOperand::MONone, const AAMDNodes &AAInfo=AAMDNodes(), const MDNode *Ranges=nullptr)
Loads are not normal binary operators: their result type is not determined by their operands,...
LLVM_ABI SDValue getMemIntrinsicNode(unsigned Opcode, const SDLoc &dl, SDVTList VTList, ArrayRef< SDValue > Ops, EVT MemVT, MachinePointerInfo PtrInfo, Align Alignment, MachineMemOperand::Flags Flags=MachineMemOperand::MOLoad|MachineMemOperand::MOStore, LocationSize Size=LocationSize::precise(0), const AAMDNodes &AAInfo=AAMDNodes())
Creates a MemIntrinsicNode that may produce a result and takes a list of operands.
SDValue getSetCC(const SDLoc &DL, EVT VT, SDValue LHS, SDValue RHS, ISD::CondCode Cond, SDValue Chain=SDValue(), bool IsSignaling=false, SDNodeFlags Flags={})
Helper function to make it easier to build SetCC's if you just have an ISD::CondCode instead of an SD...
LLVM_ABI Align getEVTAlign(EVT MemoryVT) const
Compute the default alignment value for the given type.
LLVM_ABI SDValue getNOT(const SDLoc &DL, SDValue Val, EVT VT)
Create a bitwise NOT operation as (XOR Val, -1).
const TargetLowering & getTargetLoweringInfo() const
LLVM_ABI SDNode * MorphNodeTo(SDNode *N, unsigned Opc, SDVTList VTs, ArrayRef< SDValue > Ops)
This mutates the specified node to have the specified return type, opcode, and operands.
SDValue getUNDEF(EVT VT)
Return an UNDEF node. UNDEF does not have a useful SDLoc.
SDValue getCALLSEQ_END(SDValue Chain, SDValue Op1, SDValue Op2, SDValue InGlue, const SDLoc &DL)
Return a new CALLSEQ_END node, which always must have a glue result (to ensure it's not CSE'd).
SDValue getBuildVector(EVT VT, const SDLoc &DL, ArrayRef< SDValue > Ops)
Return an ISD::BUILD_VECTOR node.
LLVM_ABI SDValue getBitcast(EVT VT, SDValue V)
Return a bitcast using the SDLoc of the value operand, and casting to the provided type.
SDValue getSelect(const SDLoc &DL, EVT VT, SDValue Cond, SDValue LHS, SDValue RHS, SDNodeFlags Flags=SDNodeFlags())
Helper function to make it easier to build Select's if you just have operands and don't want to check...
const DataLayout & getDataLayout() const
LLVM_ABI SDValue getTokenFactor(const SDLoc &DL, SmallVectorImpl< SDValue > &Vals)
Creates a new TokenFactor containing Vals.
LLVM_ABI SDValue getConstant(uint64_t Val, const SDLoc &DL, EVT VT, bool isTarget=false, bool isOpaque=false)
Create a ConstantSDNode wrapping a constant value.
LLVM_ABI SDValue getTruncStore(SDValue Chain, const SDLoc &dl, SDValue Val, SDValue Ptr, MachinePointerInfo PtrInfo, EVT SVT, Align Alignment, MachineMemOperand::Flags MMOFlags=MachineMemOperand::MONone, const AAMDNodes &AAInfo=AAMDNodes())
LLVM_ABI SDValue getStore(SDValue Chain, const SDLoc &dl, SDValue Val, SDValue Ptr, MachinePointerInfo PtrInfo, Align Alignment, MachineMemOperand::Flags MMOFlags=MachineMemOperand::MONone, const AAMDNodes &AAInfo=AAMDNodes())
Helper function to build ISD::STORE nodes.
LLVM_ABI SDValue getSignedConstant(int64_t Val, const SDLoc &DL, EVT VT, bool isTarget=false, bool isOpaque=false)
SDValue getCALLSEQ_START(SDValue Chain, uint64_t InSize, uint64_t OutSize, const SDLoc &DL)
Return a new CALLSEQ_START node, that starts new call frame, in which InSize bytes are set up inside ...
SDValue getSelectCC(const SDLoc &DL, SDValue LHS, SDValue RHS, SDValue True, SDValue False, ISD::CondCode Cond, SDNodeFlags Flags=SDNodeFlags())
Helper function to make it easier to build SelectCC's if you just have an ISD::CondCode instead of an...
LLVM_ABI SDValue getExternalSymbol(const char *Sym, EVT VT)
LLVM_ABI SDValue getAnyExtOrTrunc(SDValue Op, const SDLoc &DL, EVT VT)
Convert Op, which must be of integer type, to the integer type VT, by either any-extending or truncat...
LLVM_ABI SDValue getIntPtrConstant(uint64_t Val, const SDLoc &DL, bool isTarget=false)
LLVM_ABI SDValue getNode(unsigned Opcode, const SDLoc &DL, EVT VT, ArrayRef< SDUse > Ops)
Gets or creates the specified node.
LLVM_ABI SDValue getFPExtendOrRound(SDValue Op, const SDLoc &DL, EVT VT)
Convert Op, which must be of float type, to the float type VT, by either extending or rounding (by tr...
SDValue getTargetConstant(uint64_t Val, const SDLoc &DL, EVT VT, bool isOpaque=false)
LLVM_ABI SDValue getVectorIdxConstant(uint64_t Val, const SDLoc &DL, bool isTarget=false)
MachineFunction & getMachineFunction() const
LLVM_ABI KnownBits computeKnownBits(SDValue Op, unsigned Depth=0) const
Determine which bits of Op are known to be either zero or one and return them in Known.
LLVM_ABI SDValue getZExtOrTrunc(SDValue Op, const SDLoc &DL, EVT VT)
Convert Op, which must be of integer type, to the integer type VT, by either zero-extending or trunca...
SDValue getObjectPtrOffset(const SDLoc &SL, SDValue Ptr, TypeSize Offset)
Create an add instruction with appropriate flags when used for addressing some offset of an object.
LLVMContext * getContext() const
const SDValue & setRoot(SDValue N)
Set the current root tag of the SelectionDAG.
LLVM_ABI SDValue getTargetExternalSymbol(const char *Sym, EVT VT, unsigned TargetFlags=0)
ArrayRef< int > getMask() const
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
void append(ItTy in_start, ItTy in_end)
Add the specified range to the end of the SmallVector.
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
This class is used to represent ISD::STORE nodes.
StringRef - Represent a constant reference to a string, i.e.
Definition StringRef.h:55
constexpr size_t size() const
size - Get the string size.
Definition StringRef.h:143
constexpr const char * data() const
data - Get a pointer to the start of the string (which may not be null terminated).
Definition StringRef.h:137
Align getStackAlign() const
getStackAlignment - This method returns the number of bytes to which the stack pointer must be aligne...
void setBooleanVectorContents(BooleanContent Ty)
Specify how the target extends the result of a vector boolean value from a vector of i1 to a wider ty...
void setOperationAction(unsigned Op, MVT VT, LegalizeAction Action)
Indicate that the specified operation does not work with the specified type and indicate what to do a...
void setMaxDivRemBitWidthSupported(unsigned SizeInBits)
Set the size in bits of the maximum div/rem the backend supports.
EVT getValueType(const DataLayout &DL, Type *Ty, bool AllowUnknown=false) const
Return the EVT corresponding to this LLVM type.
unsigned MaxStoresPerMemcpyOptSize
Likewise for functions with the OptSize attribute.
const TargetMachine & getTargetMachine() const
virtual unsigned getNumRegistersForCallingConv(LLVMContext &Context, CallingConv::ID CC, EVT VT) const
Certain targets require unusual breakdowns of certain types.
virtual MVT getRegisterTypeForCallingConv(LLVMContext &Context, CallingConv::ID CC, EVT VT) const
Certain combinations of ABIs, Targets and features require that types are legal for some operations a...
void setOperationPromotedToType(unsigned Opc, MVT OrigVT, MVT DestVT)
Convenience method to set an operation to Promote and specify the type in a single call.
LegalizeTypeAction
This enum indicates whether a types are legal for a target, and if not, what action should be used to...
void addBypassSlowDiv(unsigned int SlowBitWidth, unsigned int FastBitWidth)
Tells the code generator which bitwidths to bypass.
virtual unsigned getNumRegisters(LLVMContext &Context, EVT VT, std::optional< MVT > RegisterVT=std::nullopt) const
Return the number of registers that this ValueType will eventually require.
void setMaxAtomicSizeInBitsSupported(unsigned SizeInBits)
Set the maximum atomic operation size supported by the backend.
virtual TargetLoweringBase::LegalizeTypeAction getPreferredVectorAction(MVT VT) const
Return the preferred vector type legalization action.
unsigned MaxStoresPerMemsetOptSize
Likewise for functions with the OptSize attribute.
void setBooleanContents(BooleanContent Ty)
Specify how the target extends the result of integer and floating point boolean values from i1 to a w...
unsigned MaxStoresPerMemmove
Specify maximum number of store instructions per memmove call.
void computeRegisterProperties(const TargetRegisterInfo *TRI)
Once all of the register classes are added, this allows us to compute derived properties we expose.
unsigned MaxStoresPerMemmoveOptSize
Likewise for functions with the OptSize attribute.
void addRegisterClass(MVT VT, const TargetRegisterClass *RC)
Add the specified register class as an available regclass for the specified value type.
bool isTypeLegal(EVT VT) const
Return true if the target has native support for the specified value type.
virtual MVT getPointerTy(const DataLayout &DL, uint32_t AS=0) const
Return the pointer type for the given address space, defaults to the pointer type from the data layou...
bool isOperationLegal(unsigned Op, EVT VT) const
Return true if the specified operation is legal on this target.
unsigned MaxStoresPerMemset
Specify maximum number of store instructions per memset call.
void setTruncStoreAction(MVT ValVT, MVT MemVT, LegalizeAction Action)
Indicate that the specified truncating store does not work with the specified type and indicate what ...
void setMinCmpXchgSizeInBits(unsigned SizeInBits)
Sets the minimum cmpxchg or ll/sc size supported by the backend.
void AddPromotedToType(unsigned Opc, MVT OrigVT, MVT DestVT)
If Opc/OrigVT is specified as being promoted, the promotion code defaults to trying a larger integer/...
AtomicExpansionKind
Enum that specifies what an atomic load/AtomicRMWInst is expanded to, if at all.
void setCondCodeAction(ArrayRef< ISD::CondCode > CCs, MVT VT, LegalizeAction Action)
Indicate that the specified condition code is or isn't supported on the target and indicate what to d...
void setTargetDAGCombine(ArrayRef< ISD::NodeType > NTs)
Targets should invoke this method for each target independent node that they want to provide a custom...
Align getMinStackArgumentAlignment() const
Return the minimum stack alignment of an argument.
void setLoadExtAction(unsigned ExtType, MVT ValVT, MVT MemVT, LegalizeAction Action)
Indicate that the specified load with extension does not work with the specified type and indicate wh...
std::vector< ArgListEntry > ArgListTy
virtual Instruction * emitTrailingFence(IRBuilderBase &Builder, Instruction *Inst, AtomicOrdering Ord) const
virtual Instruction * emitLeadingFence(IRBuilderBase &Builder, Instruction *Inst, AtomicOrdering Ord) const
Inserts in the IR a target-specific intrinsic specifying a fence.
unsigned MaxStoresPerMemcpy
Specify maximum number of store instructions per memcpy call.
void setSchedulingPreference(Sched::Preference Pref)
Specify the target scheduling preference.
MVT getRegisterType(MVT VT) const
Return the type of registers that this ValueType will eventually require.
void setJumpIsExpensive(bool isExpensive=true)
Tells the code generator not to expand logic operations on comparison predicates into separate sequen...
LegalizeAction getOperationAction(unsigned Op, EVT VT) const
Return how this operation should be treated: either it is legal, needs to be promoted to a larger siz...
This class defines information used to lower LLVM code to legal SelectionDAG operators that the targe...
SDValue SimplifyMultipleUseDemandedBits(SDValue Op, const APInt &DemandedBits, const APInt &DemandedElts, SelectionDAG &DAG, unsigned Depth=0) const
More limited version of SimplifyDemandedBits that can be used to "lookthrough" ops that don't contrib...
virtual ConstraintType getConstraintType(StringRef Constraint) const
Given a constraint, return the type of constraint it is for this target.
virtual std::pair< unsigned, const TargetRegisterClass * > getRegForInlineAsmConstraint(const TargetRegisterInfo *TRI, StringRef Constraint, MVT VT) const
Given a physical register constraint (e.g.
TargetLowering(const TargetLowering &)=delete
SDValue expandRoundInexactToOdd(EVT ResultVT, SDValue Op, const SDLoc &DL, SelectionDAG &DAG) const
Truncate Op to ResultVT.
SDValue expandFP_ROUND(SDNode *Node, SelectionDAG &DAG) const
Expand round(fp) to fp conversion.
virtual void LowerAsmOperandForConstraint(SDValue Op, StringRef Constraint, std::vector< SDValue > &Ops, SelectionDAG &DAG) const
Lower the specified operand into the Ops vector.
Primary interface to the complete machine description for the target machine.
CodeGenOptLevel getOptLevel() const
Returns the optimization level: None, Less, Default, or Aggressive.
TargetOptions Options
MCSymbol * getSymbol(const GlobalValue *GV) const
FPOpFusion::FPOpFusionMode AllowFPOpFusion
AllowFPOpFusion - This flag is set by the -fp-contract=xxx option.
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
virtual const TargetFrameLowering * getFrameLowering() const
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition Twine.h:82
static constexpr TypeSize getFixed(ScalarTy ExactSize)
Definition TypeSize.h:343
The instances of the Type class are immutable: once they are created, they are never changed.
Definition Type.h:45
LLVM_ABI TypeSize getPrimitiveSizeInBits() const LLVM_READONLY
Return the basic size of this type if it is a primitive type.
Definition Type.cpp:197
bool isFloatingPointTy() const
Return true if this is one of the floating-point types.
Definition Type.h:184
bool isIntegerTy() const
True if this is an instance of IntegerType.
Definition Type.h:240
bool isVoidTy() const
Return true if this is 'void'.
Definition Type.h:139
Type * getType() const
All values are typed, get the type of this value.
Definition Value.h:256
A raw_ostream that writes to an std::string.
CallInst * Call
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
LLVM_ABI APInt pow(const APInt &X, int64_t N)
Compute X^N for N>=0.
Definition APInt.cpp:3166
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
Definition CallingConv.h:24
@ C
The default llvm calling convention, compatible with C.
Definition CallingConv.h:34
NodeType
ISD::NodeType enum - This enum defines the target-independent operators for a SelectionDAG.
Definition ISDOpcodes.h:41
@ SETCC
SetCC operator - This evaluates to a true value iff the condition is true.
Definition ISDOpcodes.h:819
@ STACKRESTORE
STACKRESTORE has two operands, an input chain and a pointer to restore to it returns an output chain.
@ STACKSAVE
STACKSAVE - STACKSAVE has one operand, an input chain.
@ CTLZ_ZERO_UNDEF
Definition ISDOpcodes.h:788
@ POISON
POISON - A poison node.
Definition ISDOpcodes.h:236
@ MLOAD
Masked load and store - consecutive vector load and store operations with additional mask operand tha...
@ SMUL_LOHI
SMUL_LOHI/UMUL_LOHI - Multiply two integers of type iN, producing a signed/unsigned value of type i[2...
Definition ISDOpcodes.h:275
@ BSWAP
Byte Swap and Counting operators.
Definition ISDOpcodes.h:779
@ VAEND
VAEND, VASTART - VAEND and VASTART have three operands: an input chain, pointer, and a SRCVALUE.
@ ADDC
Carry-setting nodes for multiple precision addition and subtraction.
Definition ISDOpcodes.h:294
@ ADD
Simple integer binary arithmetic operators.
Definition ISDOpcodes.h:264
@ LOAD
LOAD and STORE have token chains as their first operand, then the same operands as an LLVM load/store...
@ ANY_EXTEND
ANY_EXTEND - Used for integer types. The high bits are undefined.
Definition ISDOpcodes.h:853
@ FMA
FMA - Perform a * b + c with no intermediate rounding step.
Definition ISDOpcodes.h:518
@ INTRINSIC_VOID
OUTCHAIN = INTRINSIC_VOID(INCHAIN, INTRINSICID, arg1, arg2, ...) This node represents a target intrin...
Definition ISDOpcodes.h:220
@ SINT_TO_FP
[SU]INT_TO_FP - These operators convert integers (whose interpreted sign depends on the first letter)...
Definition ISDOpcodes.h:880
@ CONCAT_VECTORS
CONCAT_VECTORS(VECTOR0, VECTOR1, ...) - Given a number of values of vector type with the same length ...
Definition ISDOpcodes.h:584
@ VECREDUCE_FMAX
FMIN/FMAX nodes can have flags, for NaN/NoNaN variants.
@ FADD
Simple binary floating point operators.
Definition ISDOpcodes.h:417
@ VECREDUCE_FMAXIMUM
FMINIMUM/FMAXIMUM nodes propatate NaNs and signed zeroes using the llvm.minimum and llvm....
@ ABS
ABS - Determine the unsigned absolute value of a signed integer value of the same bitwidth.
Definition ISDOpcodes.h:747
@ SDIVREM
SDIVREM/UDIVREM - Divide two integers and produce both a quotient and remainder result.
Definition ISDOpcodes.h:280
@ BITCAST
BITCAST - This operator converts between integer, vector and FP values, as if the value was stored to...
Definition ISDOpcodes.h:993
@ BUILD_PAIR
BUILD_PAIR - This is the opposite of EXTRACT_ELEMENT in some ways.
Definition ISDOpcodes.h:254
@ SIGN_EXTEND
Conversion operators.
Definition ISDOpcodes.h:844
@ READSTEADYCOUNTER
READSTEADYCOUNTER - This corresponds to the readfixedcounter intrinsic.
@ FNEG
Perform various unary floating-point operations inspired by libm.
@ BR_CC
BR_CC - Conditional branch.
@ SSUBO
Same for subtraction.
Definition ISDOpcodes.h:352
@ BRIND
BRIND - Indirect branch.
@ BR_JT
BR_JT - Jumptable branch.
@ SSUBSAT
RESULT = [US]SUBSAT(LHS, RHS) - Perform saturation subtraction on 2 integers with the same bit width ...
Definition ISDOpcodes.h:374
@ SELECT
Select(COND, TRUEVAL, FALSEVAL).
Definition ISDOpcodes.h:796
@ UNDEF
UNDEF - An undefined node.
Definition ISDOpcodes.h:233
@ EXTRACT_ELEMENT
EXTRACT_ELEMENT - This is used to get the lower or upper (determined by a Constant,...
Definition ISDOpcodes.h:247
@ VACOPY
VACOPY - VACOPY has 5 operands: an input chain, a destination pointer, a source pointer,...
@ CopyFromReg
CopyFromReg - This node indicates that the input value is a virtual or physical register that is defi...
Definition ISDOpcodes.h:230
@ SADDO
RESULT, BOOL = [SU]ADDO(LHS, RHS) - Overflow-aware nodes for addition.
Definition ISDOpcodes.h:348
@ MULHU
MULHU/MULHS - Multiply high - Multiply two integers of type iN, producing an unsigned/signed value of...
Definition ISDOpcodes.h:704
@ SHL
Shift and rotation operations.
Definition ISDOpcodes.h:765
@ VECTOR_SHUFFLE
VECTOR_SHUFFLE(VEC1, VEC2) - Returns a vector, of the same type as VEC1/VEC2.
Definition ISDOpcodes.h:649
@ EXTRACT_SUBVECTOR
EXTRACT_SUBVECTOR(VECTOR, IDX) - Returns a subvector from VECTOR.
Definition ISDOpcodes.h:614
@ FMINNUM_IEEE
FMINNUM_IEEE/FMAXNUM_IEEE - Perform floating-point minimumNumber or maximumNumber on two values,...
@ EXTRACT_VECTOR_ELT
EXTRACT_VECTOR_ELT(VECTOR, IDX) - Returns a single element from VECTOR identified by the (potentially...
Definition ISDOpcodes.h:576
@ CopyToReg
CopyToReg - This node has three operands: a chain, a register number to set to this value,...
Definition ISDOpcodes.h:224
@ ZERO_EXTEND
ZERO_EXTEND - Used for integer types, zeroing the new bits.
Definition ISDOpcodes.h:850
@ DEBUGTRAP
DEBUGTRAP - Trap intended to get the attention of a debugger.
@ SELECT_CC
Select with condition operator - This selects between a true value and a false value (ops #2 and #3) ...
Definition ISDOpcodes.h:811
@ ATOMIC_CMP_SWAP
Val, OUTCHAIN = ATOMIC_CMP_SWAP(INCHAIN, ptr, cmp, swap) For double-word atomic operations: ValLo,...
@ FMINNUM
FMINNUM/FMAXNUM - Perform floating-point minimum maximum on two values, following IEEE-754 definition...
@ SSHLSAT
RESULT = [US]SHLSAT(LHS, RHS) - Perform saturation left shift.
Definition ISDOpcodes.h:386
@ SMULO
Same for multiplication.
Definition ISDOpcodes.h:356
@ DYNAMIC_STACKALLOC
DYNAMIC_STACKALLOC - Allocate some number of bytes on the stack aligned to a specified boundary.
@ SIGN_EXTEND_INREG
SIGN_EXTEND_INREG - This operator atomically performs a SHL/SRA pair to sign extend a small value in ...
Definition ISDOpcodes.h:888
@ SMIN
[US]{MIN/MAX} - Binary minimum or maximum of signed or unsigned integers.
Definition ISDOpcodes.h:727
@ FP_EXTEND
X = FP_EXTEND(Y) - Extend a smaller FP type into a larger FP type.
Definition ISDOpcodes.h:978
@ VSELECT
Select with a vector condition (op #0) and two vector operands (ops #1 and #2), returning a vector re...
Definition ISDOpcodes.h:805
@ UADDO_CARRY
Carry-using nodes for multiple precision addition and subtraction.
Definition ISDOpcodes.h:328
@ BF16_TO_FP
BF16_TO_FP, FP_TO_BF16 - These operators are used to perform promotions and truncation for bfloat16.
@ FRAMEADDR
FRAMEADDR, RETURNADDR - These nodes represent llvm.frameaddress and llvm.returnaddress on the DAG.
Definition ISDOpcodes.h:110
@ STRICT_FP_TO_UINT
Definition ISDOpcodes.h:478
@ STRICT_FP_TO_SINT
STRICT_FP_TO_[US]INT - Convert a floating point value to a signed or unsigned integer.
Definition ISDOpcodes.h:477
@ FMINIMUM
FMINIMUM/FMAXIMUM - NaN-propagating minimum/maximum that also treat -0.0 as less than 0....
@ FP_TO_SINT
FP_TO_[US]INT - Convert a floating point value to a signed or unsigned integer.
Definition ISDOpcodes.h:926
@ READCYCLECOUNTER
READCYCLECOUNTER - This corresponds to the readcyclecounter intrinsic.
@ AND
Bitwise operators - logical and, logical or, logical xor.
Definition ISDOpcodes.h:739
@ TRAP
TRAP - Trapping instruction.
@ INTRINSIC_WO_CHAIN
RESULT = INTRINSIC_WO_CHAIN(INTRINSICID, arg1, arg2, ...) This node represents a target intrinsic fun...
Definition ISDOpcodes.h:205
@ ADDE
Carry-using nodes for multiple precision addition and subtraction.
Definition ISDOpcodes.h:304
@ FREEZE
FREEZE - FREEZE(VAL) returns an arbitrary value if VAL is UNDEF (or is evaluated to UNDEF),...
Definition ISDOpcodes.h:241
@ INSERT_VECTOR_ELT
INSERT_VECTOR_ELT(VECTOR, VAL, IDX) - Returns VECTOR with the element at IDX replaced with VAL.
Definition ISDOpcodes.h:565
@ ATOMIC_SWAP
Val, OUTCHAIN = ATOMIC_SWAP(INCHAIN, ptr, amt) Val, OUTCHAIN = ATOMIC_LOAD_[OpName](INCHAIN,...
@ FP_ROUND
X = FP_ROUND(Y, TRUNC) - Rounding 'Y' from a larger floating point type down to the precision of the ...
Definition ISDOpcodes.h:959
@ ADDRSPACECAST
ADDRSPACECAST - This operator converts between pointers of different address spaces.
Definition ISDOpcodes.h:997
@ VECREDUCE_FMINIMUM
@ TRUNCATE
TRUNCATE - Completely drop the high bits.
Definition ISDOpcodes.h:856
@ VAARG
VAARG - VAARG has four operands: an input chain, a pointer, a SRCVALUE, and the alignment.
@ SHL_PARTS
SHL_PARTS/SRA_PARTS/SRL_PARTS - These operators are used for expanded integer shift operations.
Definition ISDOpcodes.h:833
@ FCOPYSIGN
FCOPYSIGN(X, Y) - Return the value of X with the sign of Y.
Definition ISDOpcodes.h:534
@ SADDSAT
RESULT = [US]ADDSAT(LHS, RHS) - Perform saturation addition on 2 integers with the same bit width (W)...
Definition ISDOpcodes.h:365
@ FMINIMUMNUM
FMINIMUMNUM/FMAXIMUMNUM - minimumnum/maximumnum that is same with FMINNUM_IEEE and FMAXNUM_IEEE besid...
@ SADDO_CARRY
Carry-using overflow-aware nodes for multiple precision addition and subtraction.
Definition ISDOpcodes.h:338
@ INTRINSIC_W_CHAIN
RESULT,OUTCHAIN = INTRINSIC_W_CHAIN(INCHAIN, INTRINSICID, arg1, ...) This node represents a target in...
Definition ISDOpcodes.h:213
@ BUILD_VECTOR
BUILD_VECTOR(ELT0, ELT1, ELT2, ELT3,...) - Return a fixed-width vector with the specified,...
Definition ISDOpcodes.h:556
LLVM_ABI bool allOperandsUndef(const SDNode *N)
Return true if the node has at least one operand and all operands of the specified node are ISD::UNDE...
This namespace contains an enum with a value for every intrinsic/builtin function known by LLVM.
LLVM_ABI StringRef getName(ID id)
Return the LLVM name for an intrinsic, such as "llvm.ppc.altivec.lvx".
@ Bitcast
Perform the operation on a different, but equivalently sized type.
@ ATOMIC_CMP_SWAP_B128
These nodes are used to lower atomic instructions with i128 type.
bool isPackedVectorTy(EVT VT)
DivPrecisionLevel
Definition NVPTX.h:257
match_combine_or< CastInst_match< OpTy, TruncInst >, OpTy > m_TruncOrSelf(const OpTy &Op)
specific_intval< false > m_SpecificInt(const APInt &V)
Match a specific integer value or vector with all elements equal to the value.
ThreeOps_match< Cond, LHS, RHS, Instruction::Select > m_Select(const Cond &C, const LHS &L, const RHS &R)
Matches SelectInst.
deferredval_ty< Value > m_Deferred(Value *const &V)
Like m_Specific(), but works if the specific value to match is determined as part of the same match()...
class_match< Value > m_Value()
Match an arbitrary value and ignore it.
BinaryOp_match< LHS, RHS, Instruction::Shl > m_Shl(const LHS &L, const RHS &R)
is_zero m_Zero()
Match any null constant or a vector with all elements equal to 0.
ValuesClass values(OptsTy... Options)
Helper to build a ValuesClass by forwarding a variable number of arguments as an initializer list to ...
initializer< Ty > init(const Ty &Val)
NodeAddr< NodeBase * > Node
Definition RDFGraph.h:381
This is an optimization pass for GlobalISel generic memory operations.
Definition Types.h:26
@ Low
Lower the current thread's priority such that it does not affect foreground tasks significantly.
Definition Threading.h:280
@ Offset
Definition DWP.cpp:532
detail::zippy< detail::zip_shortest, T, U, Args... > zip(T &&t, U &&u, Args &&...args)
zip iterator for two or more iteratable types.
Definition STLExtras.h:831
FunctionAddr VTableAddr Value
Definition InstrProf.h:137
bool shouldEmitPTXNoReturn(const Value *V, const TargetMachine &TM)
bool all_of(R &&range, UnaryPredicate P)
Provide wrappers to std::all_of which take ranges instead of having to pass begin/end explicitly.
Definition STLExtras.h:1739
MaybeAlign getAlign(const CallInst &I, unsigned Index)
auto size(R &&Range, std::enable_if_t< std::is_base_of< std::random_access_iterator_tag, typename std::iterator_traits< decltype(Range.begin())>::iterator_category >::value, void > *=nullptr)
Get the size of a range.
Definition STLExtras.h:1669
void ComputeValueVTs(const TargetLowering &TLI, const DataLayout &DL, Type *Ty, SmallVectorImpl< EVT > &ValueVTs, SmallVectorImpl< EVT > *MemVTs=nullptr, SmallVectorImpl< TypeSize > *Offsets=nullptr, TypeSize StartingOffset=TypeSize::getZero())
ComputeValueVTs - Given an LLVM IR type, compute a sequence of EVTs that represent all the individual...
Definition Analysis.cpp:119
auto enumerate(FirstRange &&First, RestRanges &&...Rest)
Given two or more input ranges, returns a new range whose values are tuples (A, B,...
Definition STLExtras.h:2554
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:643
uint64_t PowerOf2Ceil(uint64_t A)
Returns the power of two which is greater than or equal to the given value.
Definition MathExtras.h:385
bool isReleaseOrStronger(AtomicOrdering AO)
OutputIt transform(R &&Range, OutputIt d_first, UnaryFunction F)
Wrapper function around std::transform to apply a function to a range and store the result elsewhere.
Definition STLExtras.h:2026
auto reverse(ContainerTy &&C)
Definition STLExtras.h:408
std::optional< SyncScope::ID > getAtomicSyncScopeID(const Instruction *I)
A helper function that returns an atomic operation's sync scope; returns std::nullopt if it is not an...
unsigned promoteScalarArgumentSize(unsigned size)
bool none_of(R &&Range, UnaryPredicate P)
Provide wrappers to std::none_of which take ranges instead of having to pass begin/end explicitly.
Definition STLExtras.h:1753
LLVM_ABI void report_fatal_error(Error Err, bool gen_crash_diag=true)
Definition Error.cpp:163
bool shouldPassAsArray(Type *Ty)
CodeGenOptLevel
Code generation optimization level.
Definition CodeGen.h:82
@ Default
-O2, -Os, -Oz
Definition CodeGen.h:85
class LLVM_GSL_OWNER SmallVector
Forward declaration of SmallVector so that calculateSmallVectorDefaultInlinedElements can reference s...
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
Definition Casting.h:547
AtomicOrdering
Atomic ordering for LLVM's memory model.
@ Sub
Subtraction of integers.
@ Add
Sum of integers.
uint64_t alignTo(uint64_t Size, Align A)
Returns a multiple of A needed to store Size bytes.
Definition Alignment.h:144
DWARFExpression::Operation Op
ArrayRef(const T &OneElt) -> ArrayRef< T >
bool isParamGridConstant(const Argument &Arg)
bool isAcquireOrStronger(AtomicOrdering AO)
constexpr unsigned BitWidth
bool isKernelFunction(const Function &F)
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:559
Function * getMaybeBitcastedCallee(const CallBase *CB)
Align commonAlignment(Align A, uint64_t Offset)
Returns the alignment that satisfies both alignments.
Definition Alignment.h:201
auto seq(T Begin, T End)
Iterate over an integral type from Begin up to - but not including - End.
Definition Sequence.h:305
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
Definition BitVector.h:872
#define N
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition Alignment.h:39
constexpr uint64_t value() const
This is a hole in the type system and should not be abused.
Definition Alignment.h:77
@ PreserveSign
The sign of a flushed-to-zero number is preserved in the sign of 0.
DenormalModeKind Output
Denormal flushing mode for floating point instruction results in the default floating point environme...
Extended Value Type.
Definition ValueTypes.h:35
TypeSize getStoreSize() const
Return the number of bytes overwritten by a store of the specified value type.
Definition ValueTypes.h:395
bool isSimple() const
Test if the given EVT is simple (as opposed to being extended).
Definition ValueTypes.h:137
static EVT getVectorVT(LLVMContext &Context, EVT VT, unsigned NumElements, bool IsScalable=false)
Returns the EVT that represents a vector NumElements in length, where each element is of type VT.
Definition ValueTypes.h:74
EVT changeTypeToInteger() const
Return the type converted to an equivalently sized integer or vector with integer element type.
Definition ValueTypes.h:121
bool bitsGT(EVT VT) const
Return true if this has more bits than VT.
Definition ValueTypes.h:284
bool bitsLT(EVT VT) const
Return true if this has less bits than VT.
Definition ValueTypes.h:300
bool isFloatingPoint() const
Return true if this is a FP or a vector FP type.
Definition ValueTypes.h:147
ElementCount getVectorElementCount() const
Definition ValueTypes.h:350
bool is32BitVector() const
Return true if this is a 32-bit vector type.
Definition ValueTypes.h:197
TypeSize getSizeInBits() const
Return the size of the specified value type in bits.
Definition ValueTypes.h:373
uint64_t getScalarSizeInBits() const
Definition ValueTypes.h:385
MVT getSimpleVT() const
Return the SimpleValueType held in the specified simple EVT.
Definition ValueTypes.h:316
uint64_t getFixedSizeInBits() const
Return the size of the specified fixed width value type in bits.
Definition ValueTypes.h:381
bool isVector() const
Return true if this is a vector value type.
Definition ValueTypes.h:168
EVT getScalarType() const
If this is a vector type, return the element type, otherwise return this.
Definition ValueTypes.h:323
bool bitsEq(EVT VT) const
Return true if this has the same number of bits as VT.
Definition ValueTypes.h:256
LLVM_ABI Type * getTypeForEVT(LLVMContext &Context) const
This method returns an LLVM type corresponding to the specified EVT.
EVT getVectorElementType() const
Given a vector type, return the type of each element.
Definition ValueTypes.h:328
EVT changeElementType(LLVMContext &Context, EVT EltVT) const
Return a VT for a type whose attributes match ourselves with the exception of the element type that i...
Definition ValueTypes.h:113
bool isScalarInteger() const
Return true if this is an integer, but not a vector.
Definition ValueTypes.h:157
unsigned getVectorNumElements() const
Given a vector type, return the number of elements it contains.
Definition ValueTypes.h:336
bool isInteger() const
Return true if this is an integer or a vector integer type.
Definition ValueTypes.h:152
static LLVM_ABI KnownBits ashr(const KnownBits &LHS, const KnownBits &RHS, bool ShAmtNonZero=false, bool Exact=false)
Compute known bits for ashr(LHS, RHS).
KnownBits concat(const KnownBits &Lo) const
Concatenate the bits from Lo onto the bottom of *this.
Definition KnownBits.h:249
unsigned getBitWidth() const
Get the bit width of this value.
Definition KnownBits.h:44
void resetAll()
Resets the known state of all bits.
Definition KnownBits.h:74
void insertBits(const KnownBits &SubBits, unsigned BitPosition)
Insert the bits from a smaller known bits starting at bitPosition.
Definition KnownBits.h:235
This class contains a discriminated union of information about pointers in memory operands,...
This struct is a compact representation of a valid (power of two) or undefined (0) alignment.
Definition Alignment.h:106
These are IR-level optimization flags that may be propagated to SDNodes.
bool hasAllowContract() const
This represents a list of ValueType's that has been intern'd by a SelectionDAG.
This represents an addressing mode of: BaseGV + BaseOffs + BaseReg + Scale*ScaleReg + ScalableOffset*...
This structure contains all information that is necessary for lowering calls.
SmallVector< ISD::InputArg, 32 > Ins
SmallVector< ISD::OutputArg, 32 > Outs
Type * RetTy
Same as OrigRetTy, or partially legalized for soft float libcalls.
A convenience struct that encapsulates a DAG, and two SDValues for returning information from TargetL...