Re-commit AMDGPU/GlobalISel: Add support for simple shaders
Fix build when global-isel is disabled and fix a warning.
Summary: We can select constant/global G_LOAD, global G_STORE, and G_GEP.
Reviewers: qcolombet, MatzeB, t.p.northover, ab, arsenm
Subscribers: mehdi_amini, vkalintiris, kzhuravl, wdng, nhaehnle, mgorny, yaxunl, tony-tye, modocache, llvm-commits, dberris
Differential Revision: https://reviews.llvm.org/D26730
llvm-svn: 293551
2017-01-31 05:56:46 +08:00
|
|
|
//===- AMDGPULegalizerInfo.cpp -----------------------------------*- C++ -*-==//
|
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
Re-commit AMDGPU/GlobalISel: Add support for simple shaders
Fix build when global-isel is disabled and fix a warning.
Summary: We can select constant/global G_LOAD, global G_STORE, and G_GEP.
Reviewers: qcolombet, MatzeB, t.p.northover, ab, arsenm
Subscribers: mehdi_amini, vkalintiris, kzhuravl, wdng, nhaehnle, mgorny, yaxunl, tony-tye, modocache, llvm-commits, dberris
Differential Revision: https://reviews.llvm.org/D26730
llvm-svn: 293551
2017-01-31 05:56:46 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
/// \file
|
|
|
|
/// This file implements the targeting of the Machinelegalizer class for
|
|
|
|
/// AMDGPU.
|
|
|
|
/// \todo This should be generated by TableGen.
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2018-03-30 01:21:10 +08:00
|
|
|
#include "AMDGPULegalizerInfo.h"
|
2019-09-19 12:29:20 +08:00
|
|
|
|
|
|
|
#include "AMDGPU.h"
|
|
|
|
#include "AMDGPUGlobalISelUtils.h"
|
2020-12-25 23:52:14 +08:00
|
|
|
#include "AMDGPUInstrInfo.h"
|
2018-03-17 23:17:41 +08:00
|
|
|
#include "AMDGPUTargetMachine.h"
|
2019-02-08 10:40:47 +08:00
|
|
|
#include "SIMachineFunctionInfo.h"
|
2021-03-24 23:52:10 +08:00
|
|
|
#include "Utils/AMDGPUBaseInfo.h"
|
2020-01-27 09:02:51 +08:00
|
|
|
#include "llvm/ADT/ScopeExit.h"
|
2021-03-24 23:52:10 +08:00
|
|
|
#include "llvm/BinaryFormat/ELF.h"
|
2019-07-11 00:31:19 +08:00
|
|
|
#include "llvm/CodeGen/GlobalISel/LegalizerHelper.h"
|
2019-09-19 12:29:20 +08:00
|
|
|
#include "llvm/CodeGen/GlobalISel/MIPatternMatch.h"
|
2020-08-10 17:47:50 +08:00
|
|
|
#include "llvm/CodeGen/GlobalISel/MachineIRBuilder.h"
|
2019-09-10 01:13:44 +08:00
|
|
|
#include "llvm/IR/DiagnosticInfo.h"
|
2020-12-25 23:52:14 +08:00
|
|
|
#include "llvm/IR/IntrinsicsAMDGPU.h"
|
Re-commit AMDGPU/GlobalISel: Add support for simple shaders
Fix build when global-isel is disabled and fix a warning.
Summary: We can select constant/global G_LOAD, global G_STORE, and G_GEP.
Reviewers: qcolombet, MatzeB, t.p.northover, ab, arsenm
Subscribers: mehdi_amini, vkalintiris, kzhuravl, wdng, nhaehnle, mgorny, yaxunl, tony-tye, modocache, llvm-commits, dberris
Differential Revision: https://reviews.llvm.org/D26730
llvm-svn: 293551
2017-01-31 05:56:46 +08:00
|
|
|
|
2019-07-02 02:45:36 +08:00
|
|
|
#define DEBUG_TYPE "amdgpu-legalinfo"
|
|
|
|
|
Re-commit AMDGPU/GlobalISel: Add support for simple shaders
Fix build when global-isel is disabled and fix a warning.
Summary: We can select constant/global G_LOAD, global G_STORE, and G_GEP.
Reviewers: qcolombet, MatzeB, t.p.northover, ab, arsenm
Subscribers: mehdi_amini, vkalintiris, kzhuravl, wdng, nhaehnle, mgorny, yaxunl, tony-tye, modocache, llvm-commits, dberris
Differential Revision: https://reviews.llvm.org/D26730
llvm-svn: 293551
2017-01-31 05:56:46 +08:00
|
|
|
using namespace llvm;
|
2018-01-30 01:37:29 +08:00
|
|
|
using namespace LegalizeActions;
|
2019-01-25 08:51:00 +08:00
|
|
|
using namespace LegalizeMutations;
|
2019-01-21 03:45:18 +08:00
|
|
|
using namespace LegalityPredicates;
|
2019-09-19 12:29:20 +08:00
|
|
|
using namespace MIPatternMatch;
|
2019-02-08 03:10:15 +08:00
|
|
|
|
2020-06-10 08:05:05 +08:00
|
|
|
// Hack until load/store selection patterns support any tuple of legal types.
|
|
|
|
static cl::opt<bool> EnableNewLegality(
|
|
|
|
"amdgpu-global-isel-new-legality",
|
|
|
|
cl::desc("Use GlobalISel desired legality, rather than try to use"
|
|
|
|
"rules compatible with selection patterns"),
|
|
|
|
cl::init(false),
|
|
|
|
cl::ReallyHidden);
|
|
|
|
|
2020-06-14 06:32:30 +08:00
|
|
|
static constexpr unsigned MaxRegisterSize = 1024;
|
2020-06-10 08:05:05 +08:00
|
|
|
|
2020-01-31 06:34:33 +08:00
|
|
|
// Round the number of elements to the next power of two elements
|
|
|
|
static LLT getPow2VectorType(LLT Ty) {
|
|
|
|
unsigned NElts = Ty.getNumElements();
|
|
|
|
unsigned Pow2NElts = 1 << Log2_32_Ceil(NElts);
|
2021-06-25 18:27:41 +08:00
|
|
|
return Ty.changeElementCount(ElementCount::getFixed(Pow2NElts));
|
2020-01-31 06:34:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Round the number of bits to the next power of two bits
|
|
|
|
static LLT getPow2ScalarType(LLT Ty) {
|
|
|
|
unsigned Bits = Ty.getSizeInBits();
|
|
|
|
unsigned Pow2Bits = 1 << Log2_32_Ceil(Bits);
|
|
|
|
return LLT::scalar(Pow2Bits);
|
|
|
|
}
|
|
|
|
|
2021-09-21 05:28:10 +08:00
|
|
|
/// \returns true if this is an odd sized vector which should widen by adding an
|
2020-07-19 00:35:28 +08:00
|
|
|
/// additional element. This is mostly to handle <3 x s16> -> <4 x s16>. This
|
|
|
|
/// excludes s1 vectors, which should always be scalarized.
|
2019-02-12 06:00:39 +08:00
|
|
|
static LegalityPredicate isSmallOddVector(unsigned TypeIdx) {
|
|
|
|
return [=](const LegalityQuery &Query) {
|
|
|
|
const LLT Ty = Query.Types[TypeIdx];
|
2020-07-19 00:35:28 +08:00
|
|
|
if (!Ty.isVector())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
const LLT EltTy = Ty.getElementType();
|
|
|
|
const unsigned EltSize = EltTy.getSizeInBits();
|
|
|
|
return Ty.getNumElements() % 2 != 0 &&
|
|
|
|
EltSize > 1 && EltSize < 32 &&
|
2019-10-04 01:50:29 +08:00
|
|
|
Ty.getSizeInBits() % 32 != 0;
|
2019-02-12 06:00:39 +08:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2020-06-15 23:54:49 +08:00
|
|
|
static LegalityPredicate sizeIsMultipleOf32(unsigned TypeIdx) {
|
|
|
|
return [=](const LegalityQuery &Query) {
|
|
|
|
const LLT Ty = Query.Types[TypeIdx];
|
|
|
|
return Ty.getSizeInBits() % 32 == 0;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2019-10-10 06:44:43 +08:00
|
|
|
static LegalityPredicate isWideVec16(unsigned TypeIdx) {
|
|
|
|
return [=](const LegalityQuery &Query) {
|
|
|
|
const LLT Ty = Query.Types[TypeIdx];
|
|
|
|
const LLT EltTy = Ty.getScalarType();
|
|
|
|
return EltTy.getSizeInBits() == 16 && Ty.getNumElements() > 2;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2019-02-12 06:00:39 +08:00
|
|
|
static LegalizeMutation oneMoreElement(unsigned TypeIdx) {
|
|
|
|
return [=](const LegalityQuery &Query) {
|
|
|
|
const LLT Ty = Query.Types[TypeIdx];
|
|
|
|
const LLT EltTy = Ty.getElementType();
|
2021-06-24 16:58:21 +08:00
|
|
|
return std::make_pair(TypeIdx,
|
|
|
|
LLT::fixed_vector(Ty.getNumElements() + 1, EltTy));
|
2019-02-12 06:00:39 +08:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2019-02-20 00:30:19 +08:00
|
|
|
static LegalizeMutation fewerEltsToSize64Vector(unsigned TypeIdx) {
|
|
|
|
return [=](const LegalityQuery &Query) {
|
|
|
|
const LLT Ty = Query.Types[TypeIdx];
|
|
|
|
const LLT EltTy = Ty.getElementType();
|
|
|
|
unsigned Size = Ty.getSizeInBits();
|
|
|
|
unsigned Pieces = (Size + 63) / 64;
|
|
|
|
unsigned NewNumElts = (Ty.getNumElements() + 1) / Pieces;
|
2021-06-25 15:25:41 +08:00
|
|
|
return std::make_pair(
|
|
|
|
TypeIdx,
|
|
|
|
LLT::scalarOrVector(ElementCount::getFixed(NewNumElts), EltTy));
|
2019-02-20 00:30:19 +08:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2019-09-11 00:20:14 +08:00
|
|
|
// Increase the number of vector elements to reach the next multiple of 32-bit
|
|
|
|
// type.
|
|
|
|
static LegalizeMutation moreEltsToNext32Bit(unsigned TypeIdx) {
|
|
|
|
return [=](const LegalityQuery &Query) {
|
|
|
|
const LLT Ty = Query.Types[TypeIdx];
|
|
|
|
|
|
|
|
const LLT EltTy = Ty.getElementType();
|
|
|
|
const int Size = Ty.getSizeInBits();
|
|
|
|
const int EltSize = EltTy.getSizeInBits();
|
|
|
|
const int NextMul32 = (Size + 31) / 32;
|
|
|
|
|
|
|
|
assert(EltSize < 32);
|
|
|
|
|
|
|
|
const int NewNumElts = (32 * NextMul32 + EltSize - 1) / EltSize;
|
2021-06-24 16:58:21 +08:00
|
|
|
return std::make_pair(TypeIdx, LLT::fixed_vector(NewNumElts, EltTy));
|
2019-09-11 00:20:14 +08:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2020-06-17 02:52:14 +08:00
|
|
|
static LLT getBitcastRegisterType(const LLT Ty) {
|
|
|
|
const unsigned Size = Ty.getSizeInBits();
|
|
|
|
|
|
|
|
LLT CoercedTy;
|
|
|
|
if (Size <= 32) {
|
|
|
|
// <2 x s8> -> s16
|
|
|
|
// <4 x s8> -> s32
|
|
|
|
return LLT::scalar(Size);
|
|
|
|
}
|
|
|
|
|
2021-06-25 15:25:41 +08:00
|
|
|
return LLT::scalarOrVector(ElementCount::getFixed(Size / 32), 32);
|
2020-06-17 02:52:14 +08:00
|
|
|
}
|
|
|
|
|
AMDGPU/GlobalISel: Start rewriting load/store legality rules
The current set is an incomprehensible mess riddled with ordering
hacks for various limitations in the legalizer at the time of writing,
many of which have been fixed. This takes a very small step in
correcting this.
The core first change is to start checking for fully legal cases
first, rather than trying to figure out all of the actions that could
need to be performed. It's recommended to check the legal cases first
for faster legality checks in the common case. This still has a table
listing some common cases, but it needs measuring whether this really
helps or not.
More significantly, stop trying to allow any arbitrary type with a
legal bitwidth as a legal memory type, and start using the bitcast
legalize action for them. Allowing loads of these weird vector types
produced new burdens we don't need for handling all of the
legalization artifacts. Unlike the SelectionDAG handling, this is
still not casting 64 or 16-bit element vectors to 32-bit
vectors. These cases should still be handled by increasing/decreasing
the number of 16-bit elements. This is primarily to fix 8-bit element
vectors.
Another change is to stop trying to handle the load-widening based on
a higher alignment. We should still do this, but the way it was
handled wasn't really correct. We really need to modify the MMO's size
at the same time, and not just increase the result type. The
LegalizerHelper does not do this, and I think this would really
require a separate WidenMemory action (or to add a memory action
payload to the LegalizeMutation). These will now fail to legalize.
The structure of the legalizer rules makes writing concise rules here
difficult. It would be easier if the same function could answer the
query the query, and report the action to perform at the same
time. Instead these two are split into distinct predicate and action
functions. This is mostly tolerable for other cases, but the
load/store rules get pretty complicated so it's difficult to keep two
versions of these functions in sync.
2020-05-24 23:12:11 +08:00
|
|
|
static LegalizeMutation bitcastToRegisterType(unsigned TypeIdx) {
|
|
|
|
return [=](const LegalityQuery &Query) {
|
|
|
|
const LLT Ty = Query.Types[TypeIdx];
|
2020-06-17 02:52:14 +08:00
|
|
|
return std::make_pair(TypeIdx, getBitcastRegisterType(Ty));
|
AMDGPU/GlobalISel: Start rewriting load/store legality rules
The current set is an incomprehensible mess riddled with ordering
hacks for various limitations in the legalizer at the time of writing,
many of which have been fixed. This takes a very small step in
correcting this.
The core first change is to start checking for fully legal cases
first, rather than trying to figure out all of the actions that could
need to be performed. It's recommended to check the legal cases first
for faster legality checks in the common case. This still has a table
listing some common cases, but it needs measuring whether this really
helps or not.
More significantly, stop trying to allow any arbitrary type with a
legal bitwidth as a legal memory type, and start using the bitcast
legalize action for them. Allowing loads of these weird vector types
produced new burdens we don't need for handling all of the
legalization artifacts. Unlike the SelectionDAG handling, this is
still not casting 64 or 16-bit element vectors to 32-bit
vectors. These cases should still be handled by increasing/decreasing
the number of 16-bit elements. This is primarily to fix 8-bit element
vectors.
Another change is to stop trying to handle the load-widening based on
a higher alignment. We should still do this, but the way it was
handled wasn't really correct. We really need to modify the MMO's size
at the same time, and not just increase the result type. The
LegalizerHelper does not do this, and I think this would really
require a separate WidenMemory action (or to add a memory action
payload to the LegalizeMutation). These will now fail to legalize.
The structure of the legalizer rules makes writing concise rules here
difficult. It would be easier if the same function could answer the
query the query, and report the action to perform at the same
time. Instead these two are split into distinct predicate and action
functions. This is mostly tolerable for other cases, but the
load/store rules get pretty complicated so it's difficult to keep two
versions of these functions in sync.
2020-05-24 23:12:11 +08:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2020-06-15 23:54:49 +08:00
|
|
|
static LegalizeMutation bitcastToVectorElement32(unsigned TypeIdx) {
|
|
|
|
return [=](const LegalityQuery &Query) {
|
|
|
|
const LLT Ty = Query.Types[TypeIdx];
|
|
|
|
unsigned Size = Ty.getSizeInBits();
|
|
|
|
assert(Size % 32 == 0);
|
2021-06-25 15:25:41 +08:00
|
|
|
return std::make_pair(
|
|
|
|
TypeIdx, LLT::scalarOrVector(ElementCount::getFixed(Size / 32), 32));
|
2020-06-15 23:54:49 +08:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2019-09-11 00:20:14 +08:00
|
|
|
static LegalityPredicate vectorSmallerThan(unsigned TypeIdx, unsigned Size) {
|
|
|
|
return [=](const LegalityQuery &Query) {
|
|
|
|
const LLT QueryTy = Query.Types[TypeIdx];
|
|
|
|
return QueryTy.isVector() && QueryTy.getSizeInBits() < Size;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2019-02-20 00:30:19 +08:00
|
|
|
static LegalityPredicate vectorWiderThan(unsigned TypeIdx, unsigned Size) {
|
|
|
|
return [=](const LegalityQuery &Query) {
|
|
|
|
const LLT QueryTy = Query.Types[TypeIdx];
|
|
|
|
return QueryTy.isVector() && QueryTy.getSizeInBits() > Size;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2019-02-20 01:03:09 +08:00
|
|
|
static LegalityPredicate numElementsNotEven(unsigned TypeIdx) {
|
|
|
|
return [=](const LegalityQuery &Query) {
|
|
|
|
const LLT QueryTy = Query.Types[TypeIdx];
|
|
|
|
return QueryTy.isVector() && QueryTy.getNumElements() % 2 != 0;
|
|
|
|
};
|
|
|
|
}
|
2019-02-12 06:00:39 +08:00
|
|
|
|
AMDGPU/GlobalISel: Start rewriting load/store legality rules
The current set is an incomprehensible mess riddled with ordering
hacks for various limitations in the legalizer at the time of writing,
many of which have been fixed. This takes a very small step in
correcting this.
The core first change is to start checking for fully legal cases
first, rather than trying to figure out all of the actions that could
need to be performed. It's recommended to check the legal cases first
for faster legality checks in the common case. This still has a table
listing some common cases, but it needs measuring whether this really
helps or not.
More significantly, stop trying to allow any arbitrary type with a
legal bitwidth as a legal memory type, and start using the bitcast
legalize action for them. Allowing loads of these weird vector types
produced new burdens we don't need for handling all of the
legalization artifacts. Unlike the SelectionDAG handling, this is
still not casting 64 or 16-bit element vectors to 32-bit
vectors. These cases should still be handled by increasing/decreasing
the number of 16-bit elements. This is primarily to fix 8-bit element
vectors.
Another change is to stop trying to handle the load-widening based on
a higher alignment. We should still do this, but the way it was
handled wasn't really correct. We really need to modify the MMO's size
at the same time, and not just increase the result type. The
LegalizerHelper does not do this, and I think this would really
require a separate WidenMemory action (or to add a memory action
payload to the LegalizeMutation). These will now fail to legalize.
The structure of the legalizer rules makes writing concise rules here
difficult. It would be easier if the same function could answer the
query the query, and report the action to perform at the same
time. Instead these two are split into distinct predicate and action
functions. This is mostly tolerable for other cases, but the
load/store rules get pretty complicated so it's difficult to keep two
versions of these functions in sync.
2020-05-24 23:12:11 +08:00
|
|
|
static bool isRegisterSize(unsigned Size) {
|
2020-06-14 06:32:30 +08:00
|
|
|
return Size % 32 == 0 && Size <= MaxRegisterSize;
|
AMDGPU/GlobalISel: Start rewriting load/store legality rules
The current set is an incomprehensible mess riddled with ordering
hacks for various limitations in the legalizer at the time of writing,
many of which have been fixed. This takes a very small step in
correcting this.
The core first change is to start checking for fully legal cases
first, rather than trying to figure out all of the actions that could
need to be performed. It's recommended to check the legal cases first
for faster legality checks in the common case. This still has a table
listing some common cases, but it needs measuring whether this really
helps or not.
More significantly, stop trying to allow any arbitrary type with a
legal bitwidth as a legal memory type, and start using the bitcast
legalize action for them. Allowing loads of these weird vector types
produced new burdens we don't need for handling all of the
legalization artifacts. Unlike the SelectionDAG handling, this is
still not casting 64 or 16-bit element vectors to 32-bit
vectors. These cases should still be handled by increasing/decreasing
the number of 16-bit elements. This is primarily to fix 8-bit element
vectors.
Another change is to stop trying to handle the load-widening based on
a higher alignment. We should still do this, but the way it was
handled wasn't really correct. We really need to modify the MMO's size
at the same time, and not just increase the result type. The
LegalizerHelper does not do this, and I think this would really
require a separate WidenMemory action (or to add a memory action
payload to the LegalizeMutation). These will now fail to legalize.
The structure of the legalizer rules makes writing concise rules here
difficult. It would be easier if the same function could answer the
query the query, and report the action to perform at the same
time. Instead these two are split into distinct predicate and action
functions. This is mostly tolerable for other cases, but the
load/store rules get pretty complicated so it's difficult to keep two
versions of these functions in sync.
2020-05-24 23:12:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static bool isRegisterVectorElementType(LLT EltTy) {
|
|
|
|
const int EltSize = EltTy.getSizeInBits();
|
|
|
|
return EltSize == 16 || EltSize % 32 == 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool isRegisterVectorType(LLT Ty) {
|
|
|
|
const int EltSize = Ty.getElementType().getSizeInBits();
|
|
|
|
return EltSize == 32 || EltSize == 64 ||
|
|
|
|
(EltSize == 16 && Ty.getNumElements() % 2 == 0) ||
|
|
|
|
EltSize == 128 || EltSize == 256;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool isRegisterType(LLT Ty) {
|
|
|
|
if (!isRegisterSize(Ty.getSizeInBits()))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (Ty.isVector())
|
|
|
|
return isRegisterVectorType(Ty);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-06-14 06:32:30 +08:00
|
|
|
// Any combination of 32 or 64-bit elements up the maximum register size, and
|
|
|
|
// multiples of v2s16.
|
2019-07-09 22:17:31 +08:00
|
|
|
static LegalityPredicate isRegisterType(unsigned TypeIdx) {
|
|
|
|
return [=](const LegalityQuery &Query) {
|
AMDGPU/GlobalISel: Start rewriting load/store legality rules
The current set is an incomprehensible mess riddled with ordering
hacks for various limitations in the legalizer at the time of writing,
many of which have been fixed. This takes a very small step in
correcting this.
The core first change is to start checking for fully legal cases
first, rather than trying to figure out all of the actions that could
need to be performed. It's recommended to check the legal cases first
for faster legality checks in the common case. This still has a table
listing some common cases, but it needs measuring whether this really
helps or not.
More significantly, stop trying to allow any arbitrary type with a
legal bitwidth as a legal memory type, and start using the bitcast
legalize action for them. Allowing loads of these weird vector types
produced new burdens we don't need for handling all of the
legalization artifacts. Unlike the SelectionDAG handling, this is
still not casting 64 or 16-bit element vectors to 32-bit
vectors. These cases should still be handled by increasing/decreasing
the number of 16-bit elements. This is primarily to fix 8-bit element
vectors.
Another change is to stop trying to handle the load-widening based on
a higher alignment. We should still do this, but the way it was
handled wasn't really correct. We really need to modify the MMO's size
at the same time, and not just increase the result type. The
LegalizerHelper does not do this, and I think this would really
require a separate WidenMemory action (or to add a memory action
payload to the LegalizeMutation). These will now fail to legalize.
The structure of the legalizer rules makes writing concise rules here
difficult. It would be easier if the same function could answer the
query the query, and report the action to perform at the same
time. Instead these two are split into distinct predicate and action
functions. This is mostly tolerable for other cases, but the
load/store rules get pretty complicated so it's difficult to keep two
versions of these functions in sync.
2020-05-24 23:12:11 +08:00
|
|
|
return isRegisterType(Query.Types[TypeIdx]);
|
2019-07-09 22:17:31 +08:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2020-02-16 10:59:30 +08:00
|
|
|
static LegalityPredicate elementTypeIsLegal(unsigned TypeIdx) {
|
|
|
|
return [=](const LegalityQuery &Query) {
|
|
|
|
const LLT QueryTy = Query.Types[TypeIdx];
|
|
|
|
if (!QueryTy.isVector())
|
|
|
|
return false;
|
|
|
|
const LLT EltTy = QueryTy.getElementType();
|
|
|
|
return EltTy == LLT::scalar(16) || EltTy.getSizeInBits() >= 32;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2021-05-19 05:05:49 +08:00
|
|
|
// If we have a truncating store or an extending load with a data size larger
|
|
|
|
// than 32-bits, we need to reduce to a 32-bit type.
|
|
|
|
static LegalityPredicate isWideScalarExtLoadTruncStore(unsigned TypeIdx) {
|
2019-09-11 00:20:14 +08:00
|
|
|
return [=](const LegalityQuery &Query) {
|
|
|
|
const LLT Ty = Query.Types[TypeIdx];
|
|
|
|
return !Ty.isVector() && Ty.getSizeInBits() > 32 &&
|
2021-06-09 08:22:45 +08:00
|
|
|
Query.MMODescrs[0].MemoryTy.getSizeInBits() < Ty.getSizeInBits();
|
2019-09-11 00:20:14 +08:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
AMDGPU/GlobalISel: Start rewriting load/store legality rules
The current set is an incomprehensible mess riddled with ordering
hacks for various limitations in the legalizer at the time of writing,
many of which have been fixed. This takes a very small step in
correcting this.
The core first change is to start checking for fully legal cases
first, rather than trying to figure out all of the actions that could
need to be performed. It's recommended to check the legal cases first
for faster legality checks in the common case. This still has a table
listing some common cases, but it needs measuring whether this really
helps or not.
More significantly, stop trying to allow any arbitrary type with a
legal bitwidth as a legal memory type, and start using the bitcast
legalize action for them. Allowing loads of these weird vector types
produced new burdens we don't need for handling all of the
legalization artifacts. Unlike the SelectionDAG handling, this is
still not casting 64 or 16-bit element vectors to 32-bit
vectors. These cases should still be handled by increasing/decreasing
the number of 16-bit elements. This is primarily to fix 8-bit element
vectors.
Another change is to stop trying to handle the load-widening based on
a higher alignment. We should still do this, but the way it was
handled wasn't really correct. We really need to modify the MMO's size
at the same time, and not just increase the result type. The
LegalizerHelper does not do this, and I think this would really
require a separate WidenMemory action (or to add a memory action
payload to the LegalizeMutation). These will now fail to legalize.
The structure of the legalizer rules makes writing concise rules here
difficult. It would be easier if the same function could answer the
query the query, and report the action to perform at the same
time. Instead these two are split into distinct predicate and action
functions. This is mostly tolerable for other cases, but the
load/store rules get pretty complicated so it's difficult to keep two
versions of these functions in sync.
2020-05-24 23:12:11 +08:00
|
|
|
// TODO: Should load to s16 be legal? Most loads extend to 32-bits, but we
|
|
|
|
// handle some operations by just promoting the register during
|
|
|
|
// selection. There are also d16 loads on GFX9+ which preserve the high bits.
|
|
|
|
static unsigned maxSizeForAddrSpace(const GCNSubtarget &ST, unsigned AS,
|
|
|
|
bool IsLoad) {
|
|
|
|
switch (AS) {
|
|
|
|
case AMDGPUAS::PRIVATE_ADDRESS:
|
|
|
|
// FIXME: Private element size.
|
2020-12-22 04:31:06 +08:00
|
|
|
return ST.enableFlatScratch() ? 128 : 32;
|
AMDGPU/GlobalISel: Start rewriting load/store legality rules
The current set is an incomprehensible mess riddled with ordering
hacks for various limitations in the legalizer at the time of writing,
many of which have been fixed. This takes a very small step in
correcting this.
The core first change is to start checking for fully legal cases
first, rather than trying to figure out all of the actions that could
need to be performed. It's recommended to check the legal cases first
for faster legality checks in the common case. This still has a table
listing some common cases, but it needs measuring whether this really
helps or not.
More significantly, stop trying to allow any arbitrary type with a
legal bitwidth as a legal memory type, and start using the bitcast
legalize action for them. Allowing loads of these weird vector types
produced new burdens we don't need for handling all of the
legalization artifacts. Unlike the SelectionDAG handling, this is
still not casting 64 or 16-bit element vectors to 32-bit
vectors. These cases should still be handled by increasing/decreasing
the number of 16-bit elements. This is primarily to fix 8-bit element
vectors.
Another change is to stop trying to handle the load-widening based on
a higher alignment. We should still do this, but the way it was
handled wasn't really correct. We really need to modify the MMO's size
at the same time, and not just increase the result type. The
LegalizerHelper does not do this, and I think this would really
require a separate WidenMemory action (or to add a memory action
payload to the LegalizeMutation). These will now fail to legalize.
The structure of the legalizer rules makes writing concise rules here
difficult. It would be easier if the same function could answer the
query the query, and report the action to perform at the same
time. Instead these two are split into distinct predicate and action
functions. This is mostly tolerable for other cases, but the
load/store rules get pretty complicated so it's difficult to keep two
versions of these functions in sync.
2020-05-24 23:12:11 +08:00
|
|
|
case AMDGPUAS::LOCAL_ADDRESS:
|
|
|
|
return ST.useDS128() ? 128 : 64;
|
|
|
|
case AMDGPUAS::GLOBAL_ADDRESS:
|
|
|
|
case AMDGPUAS::CONSTANT_ADDRESS:
|
|
|
|
case AMDGPUAS::CONSTANT_ADDRESS_32BIT:
|
|
|
|
// Treat constant and global as identical. SMRD loads are sometimes usable for
|
|
|
|
// global loads (ideally constant address space should be eliminated)
|
|
|
|
// depending on the context. Legality cannot be context dependent, but
|
|
|
|
// RegBankSelect can split the load as necessary depending on the pointer
|
|
|
|
// register bank/uniformity and if the memory is invariant or not written in a
|
|
|
|
// kernel.
|
|
|
|
return IsLoad ? 512 : 128;
|
|
|
|
default:
|
|
|
|
// Flat addresses may contextually need to be split to 32-bit parts if they
|
|
|
|
// may alias scratch depending on the subtarget.
|
|
|
|
return 128;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool isLoadStoreSizeLegal(const GCNSubtarget &ST,
|
2021-05-19 05:02:25 +08:00
|
|
|
const LegalityQuery &Query) {
|
AMDGPU/GlobalISel: Start rewriting load/store legality rules
The current set is an incomprehensible mess riddled with ordering
hacks for various limitations in the legalizer at the time of writing,
many of which have been fixed. This takes a very small step in
correcting this.
The core first change is to start checking for fully legal cases
first, rather than trying to figure out all of the actions that could
need to be performed. It's recommended to check the legal cases first
for faster legality checks in the common case. This still has a table
listing some common cases, but it needs measuring whether this really
helps or not.
More significantly, stop trying to allow any arbitrary type with a
legal bitwidth as a legal memory type, and start using the bitcast
legalize action for them. Allowing loads of these weird vector types
produced new burdens we don't need for handling all of the
legalization artifacts. Unlike the SelectionDAG handling, this is
still not casting 64 or 16-bit element vectors to 32-bit
vectors. These cases should still be handled by increasing/decreasing
the number of 16-bit elements. This is primarily to fix 8-bit element
vectors.
Another change is to stop trying to handle the load-widening based on
a higher alignment. We should still do this, but the way it was
handled wasn't really correct. We really need to modify the MMO's size
at the same time, and not just increase the result type. The
LegalizerHelper does not do this, and I think this would really
require a separate WidenMemory action (or to add a memory action
payload to the LegalizeMutation). These will now fail to legalize.
The structure of the legalizer rules makes writing concise rules here
difficult. It would be easier if the same function could answer the
query the query, and report the action to perform at the same
time. Instead these two are split into distinct predicate and action
functions. This is mostly tolerable for other cases, but the
load/store rules get pretty complicated so it's difficult to keep two
versions of these functions in sync.
2020-05-24 23:12:11 +08:00
|
|
|
const LLT Ty = Query.Types[0];
|
|
|
|
|
|
|
|
// Handle G_LOAD, G_ZEXTLOAD, G_SEXTLOAD
|
2021-05-19 05:02:25 +08:00
|
|
|
const bool IsLoad = Query.Opcode != AMDGPU::G_STORE;
|
AMDGPU/GlobalISel: Start rewriting load/store legality rules
The current set is an incomprehensible mess riddled with ordering
hacks for various limitations in the legalizer at the time of writing,
many of which have been fixed. This takes a very small step in
correcting this.
The core first change is to start checking for fully legal cases
first, rather than trying to figure out all of the actions that could
need to be performed. It's recommended to check the legal cases first
for faster legality checks in the common case. This still has a table
listing some common cases, but it needs measuring whether this really
helps or not.
More significantly, stop trying to allow any arbitrary type with a
legal bitwidth as a legal memory type, and start using the bitcast
legalize action for them. Allowing loads of these weird vector types
produced new burdens we don't need for handling all of the
legalization artifacts. Unlike the SelectionDAG handling, this is
still not casting 64 or 16-bit element vectors to 32-bit
vectors. These cases should still be handled by increasing/decreasing
the number of 16-bit elements. This is primarily to fix 8-bit element
vectors.
Another change is to stop trying to handle the load-widening based on
a higher alignment. We should still do this, but the way it was
handled wasn't really correct. We really need to modify the MMO's size
at the same time, and not just increase the result type. The
LegalizerHelper does not do this, and I think this would really
require a separate WidenMemory action (or to add a memory action
payload to the LegalizeMutation). These will now fail to legalize.
The structure of the legalizer rules makes writing concise rules here
difficult. It would be easier if the same function could answer the
query the query, and report the action to perform at the same
time. Instead these two are split into distinct predicate and action
functions. This is mostly tolerable for other cases, but the
load/store rules get pretty complicated so it's difficult to keep two
versions of these functions in sync.
2020-05-24 23:12:11 +08:00
|
|
|
|
|
|
|
unsigned RegSize = Ty.getSizeInBits();
|
2022-01-13 04:01:27 +08:00
|
|
|
uint64_t MemSize = Query.MMODescrs[0].MemoryTy.getSizeInBits();
|
|
|
|
uint64_t AlignBits = Query.MMODescrs[0].AlignInBits;
|
AMDGPU/GlobalISel: Start rewriting load/store legality rules
The current set is an incomprehensible mess riddled with ordering
hacks for various limitations in the legalizer at the time of writing,
many of which have been fixed. This takes a very small step in
correcting this.
The core first change is to start checking for fully legal cases
first, rather than trying to figure out all of the actions that could
need to be performed. It's recommended to check the legal cases first
for faster legality checks in the common case. This still has a table
listing some common cases, but it needs measuring whether this really
helps or not.
More significantly, stop trying to allow any arbitrary type with a
legal bitwidth as a legal memory type, and start using the bitcast
legalize action for them. Allowing loads of these weird vector types
produced new burdens we don't need for handling all of the
legalization artifacts. Unlike the SelectionDAG handling, this is
still not casting 64 or 16-bit element vectors to 32-bit
vectors. These cases should still be handled by increasing/decreasing
the number of 16-bit elements. This is primarily to fix 8-bit element
vectors.
Another change is to stop trying to handle the load-widening based on
a higher alignment. We should still do this, but the way it was
handled wasn't really correct. We really need to modify the MMO's size
at the same time, and not just increase the result type. The
LegalizerHelper does not do this, and I think this would really
require a separate WidenMemory action (or to add a memory action
payload to the LegalizeMutation). These will now fail to legalize.
The structure of the legalizer rules makes writing concise rules here
difficult. It would be easier if the same function could answer the
query the query, and report the action to perform at the same
time. Instead these two are split into distinct predicate and action
functions. This is mostly tolerable for other cases, but the
load/store rules get pretty complicated so it's difficult to keep two
versions of these functions in sync.
2020-05-24 23:12:11 +08:00
|
|
|
unsigned AS = Query.Types[1].getAddressSpace();
|
|
|
|
|
|
|
|
// All of these need to be custom lowered to cast the pointer operand.
|
|
|
|
if (AS == AMDGPUAS::CONSTANT_ADDRESS_32BIT)
|
|
|
|
return false;
|
|
|
|
|
2021-05-19 05:05:49 +08:00
|
|
|
// Do not handle extending vector loads.
|
|
|
|
if (Ty.isVector() && MemSize != RegSize)
|
|
|
|
return false;
|
|
|
|
|
AMDGPU/GlobalISel: Start rewriting load/store legality rules
The current set is an incomprehensible mess riddled with ordering
hacks for various limitations in the legalizer at the time of writing,
many of which have been fixed. This takes a very small step in
correcting this.
The core first change is to start checking for fully legal cases
first, rather than trying to figure out all of the actions that could
need to be performed. It's recommended to check the legal cases first
for faster legality checks in the common case. This still has a table
listing some common cases, but it needs measuring whether this really
helps or not.
More significantly, stop trying to allow any arbitrary type with a
legal bitwidth as a legal memory type, and start using the bitcast
legalize action for them. Allowing loads of these weird vector types
produced new burdens we don't need for handling all of the
legalization artifacts. Unlike the SelectionDAG handling, this is
still not casting 64 or 16-bit element vectors to 32-bit
vectors. These cases should still be handled by increasing/decreasing
the number of 16-bit elements. This is primarily to fix 8-bit element
vectors.
Another change is to stop trying to handle the load-widening based on
a higher alignment. We should still do this, but the way it was
handled wasn't really correct. We really need to modify the MMO's size
at the same time, and not just increase the result type. The
LegalizerHelper does not do this, and I think this would really
require a separate WidenMemory action (or to add a memory action
payload to the LegalizeMutation). These will now fail to legalize.
The structure of the legalizer rules makes writing concise rules here
difficult. It would be easier if the same function could answer the
query the query, and report the action to perform at the same
time. Instead these two are split into distinct predicate and action
functions. This is mostly tolerable for other cases, but the
load/store rules get pretty complicated so it's difficult to keep two
versions of these functions in sync.
2020-05-24 23:12:11 +08:00
|
|
|
// TODO: We should be able to widen loads if the alignment is high enough, but
|
|
|
|
// we also need to modify the memory access size.
|
|
|
|
#if 0
|
|
|
|
// Accept widening loads based on alignment.
|
|
|
|
if (IsLoad && MemSize < Size)
|
|
|
|
MemSize = std::max(MemSize, Align);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// Only 1-byte and 2-byte to 32-bit extloads are valid.
|
|
|
|
if (MemSize != RegSize && RegSize != 32)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (MemSize > maxSizeForAddrSpace(ST, AS, IsLoad))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
switch (MemSize) {
|
|
|
|
case 8:
|
|
|
|
case 16:
|
|
|
|
case 32:
|
|
|
|
case 64:
|
|
|
|
case 128:
|
|
|
|
break;
|
|
|
|
case 96:
|
|
|
|
if (!ST.hasDwordx3LoadStores())
|
|
|
|
return false;
|
|
|
|
break;
|
|
|
|
case 256:
|
|
|
|
case 512:
|
|
|
|
// These may contextually need to be broken down.
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
assert(RegSize >= MemSize);
|
|
|
|
|
2020-07-31 23:04:13 +08:00
|
|
|
if (AlignBits < MemSize) {
|
AMDGPU/GlobalISel: Start rewriting load/store legality rules
The current set is an incomprehensible mess riddled with ordering
hacks for various limitations in the legalizer at the time of writing,
many of which have been fixed. This takes a very small step in
correcting this.
The core first change is to start checking for fully legal cases
first, rather than trying to figure out all of the actions that could
need to be performed. It's recommended to check the legal cases first
for faster legality checks in the common case. This still has a table
listing some common cases, but it needs measuring whether this really
helps or not.
More significantly, stop trying to allow any arbitrary type with a
legal bitwidth as a legal memory type, and start using the bitcast
legalize action for them. Allowing loads of these weird vector types
produced new burdens we don't need for handling all of the
legalization artifacts. Unlike the SelectionDAG handling, this is
still not casting 64 or 16-bit element vectors to 32-bit
vectors. These cases should still be handled by increasing/decreasing
the number of 16-bit elements. This is primarily to fix 8-bit element
vectors.
Another change is to stop trying to handle the load-widening based on
a higher alignment. We should still do this, but the way it was
handled wasn't really correct. We really need to modify the MMO's size
at the same time, and not just increase the result type. The
LegalizerHelper does not do this, and I think this would really
require a separate WidenMemory action (or to add a memory action
payload to the LegalizeMutation). These will now fail to legalize.
The structure of the legalizer rules makes writing concise rules here
difficult. It would be easier if the same function could answer the
query the query, and report the action to perform at the same
time. Instead these two are split into distinct predicate and action
functions. This is mostly tolerable for other cases, but the
load/store rules get pretty complicated so it's difficult to keep two
versions of these functions in sync.
2020-05-24 23:12:11 +08:00
|
|
|
const SITargetLowering *TLI = ST.getTargetLowering();
|
2020-07-31 23:04:13 +08:00
|
|
|
if (!TLI->allowsMisalignedMemoryAccessesImpl(MemSize, AS,
|
|
|
|
Align(AlignBits / 8)))
|
AMDGPU/GlobalISel: Start rewriting load/store legality rules
The current set is an incomprehensible mess riddled with ordering
hacks for various limitations in the legalizer at the time of writing,
many of which have been fixed. This takes a very small step in
correcting this.
The core first change is to start checking for fully legal cases
first, rather than trying to figure out all of the actions that could
need to be performed. It's recommended to check the legal cases first
for faster legality checks in the common case. This still has a table
listing some common cases, but it needs measuring whether this really
helps or not.
More significantly, stop trying to allow any arbitrary type with a
legal bitwidth as a legal memory type, and start using the bitcast
legalize action for them. Allowing loads of these weird vector types
produced new burdens we don't need for handling all of the
legalization artifacts. Unlike the SelectionDAG handling, this is
still not casting 64 or 16-bit element vectors to 32-bit
vectors. These cases should still be handled by increasing/decreasing
the number of 16-bit elements. This is primarily to fix 8-bit element
vectors.
Another change is to stop trying to handle the load-widening based on
a higher alignment. We should still do this, but the way it was
handled wasn't really correct. We really need to modify the MMO's size
at the same time, and not just increase the result type. The
LegalizerHelper does not do this, and I think this would really
require a separate WidenMemory action (or to add a memory action
payload to the LegalizeMutation). These will now fail to legalize.
The structure of the legalizer rules makes writing concise rules here
difficult. It would be easier if the same function could answer the
query the query, and report the action to perform at the same
time. Instead these two are split into distinct predicate and action
functions. This is mostly tolerable for other cases, but the
load/store rules get pretty complicated so it's difficult to keep two
versions of these functions in sync.
2020-05-24 23:12:11 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-06-10 08:05:05 +08:00
|
|
|
// The current selector can't handle <6 x s16>, <8 x s16>, s96, s128 etc, so
|
|
|
|
// workaround this. Eventually it should ignore the type for loads and only care
|
|
|
|
// about the size. Return true in cases where we will workaround this for now by
|
|
|
|
// bitcasting.
|
|
|
|
static bool loadStoreBitcastWorkaround(const LLT Ty) {
|
|
|
|
if (EnableNewLegality)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
const unsigned Size = Ty.getSizeInBits();
|
|
|
|
if (Size <= 64)
|
|
|
|
return false;
|
|
|
|
if (!Ty.isVector())
|
|
|
|
return true;
|
2020-08-17 00:51:31 +08:00
|
|
|
|
|
|
|
LLT EltTy = Ty.getElementType();
|
|
|
|
if (EltTy.isPointer())
|
|
|
|
return true;
|
|
|
|
|
|
|
|
unsigned EltSize = EltTy.getSizeInBits();
|
2020-06-16 01:42:47 +08:00
|
|
|
return EltSize != 32 && EltSize != 64;
|
2020-06-10 08:05:05 +08:00
|
|
|
}
|
|
|
|
|
2021-05-19 05:02:25 +08:00
|
|
|
static bool isLoadStoreLegal(const GCNSubtarget &ST, const LegalityQuery &Query) {
|
AMDGPU/GlobalISel: Start rewriting load/store legality rules
The current set is an incomprehensible mess riddled with ordering
hacks for various limitations in the legalizer at the time of writing,
many of which have been fixed. This takes a very small step in
correcting this.
The core first change is to start checking for fully legal cases
first, rather than trying to figure out all of the actions that could
need to be performed. It's recommended to check the legal cases first
for faster legality checks in the common case. This still has a table
listing some common cases, but it needs measuring whether this really
helps or not.
More significantly, stop trying to allow any arbitrary type with a
legal bitwidth as a legal memory type, and start using the bitcast
legalize action for them. Allowing loads of these weird vector types
produced new burdens we don't need for handling all of the
legalization artifacts. Unlike the SelectionDAG handling, this is
still not casting 64 or 16-bit element vectors to 32-bit
vectors. These cases should still be handled by increasing/decreasing
the number of 16-bit elements. This is primarily to fix 8-bit element
vectors.
Another change is to stop trying to handle the load-widening based on
a higher alignment. We should still do this, but the way it was
handled wasn't really correct. We really need to modify the MMO's size
at the same time, and not just increase the result type. The
LegalizerHelper does not do this, and I think this would really
require a separate WidenMemory action (or to add a memory action
payload to the LegalizeMutation). These will now fail to legalize.
The structure of the legalizer rules makes writing concise rules here
difficult. It would be easier if the same function could answer the
query the query, and report the action to perform at the same
time. Instead these two are split into distinct predicate and action
functions. This is mostly tolerable for other cases, but the
load/store rules get pretty complicated so it's difficult to keep two
versions of these functions in sync.
2020-05-24 23:12:11 +08:00
|
|
|
const LLT Ty = Query.Types[0];
|
2021-05-19 05:02:25 +08:00
|
|
|
return isRegisterType(Ty) && isLoadStoreSizeLegal(ST, Query) &&
|
2020-06-10 08:05:05 +08:00
|
|
|
!loadStoreBitcastWorkaround(Ty);
|
AMDGPU/GlobalISel: Start rewriting load/store legality rules
The current set is an incomprehensible mess riddled with ordering
hacks for various limitations in the legalizer at the time of writing,
many of which have been fixed. This takes a very small step in
correcting this.
The core first change is to start checking for fully legal cases
first, rather than trying to figure out all of the actions that could
need to be performed. It's recommended to check the legal cases first
for faster legality checks in the common case. This still has a table
listing some common cases, but it needs measuring whether this really
helps or not.
More significantly, stop trying to allow any arbitrary type with a
legal bitwidth as a legal memory type, and start using the bitcast
legalize action for them. Allowing loads of these weird vector types
produced new burdens we don't need for handling all of the
legalization artifacts. Unlike the SelectionDAG handling, this is
still not casting 64 or 16-bit element vectors to 32-bit
vectors. These cases should still be handled by increasing/decreasing
the number of 16-bit elements. This is primarily to fix 8-bit element
vectors.
Another change is to stop trying to handle the load-widening based on
a higher alignment. We should still do this, but the way it was
handled wasn't really correct. We really need to modify the MMO's size
at the same time, and not just increase the result type. The
LegalizerHelper does not do this, and I think this would really
require a separate WidenMemory action (or to add a memory action
payload to the LegalizeMutation). These will now fail to legalize.
The structure of the legalizer rules makes writing concise rules here
difficult. It would be easier if the same function could answer the
query the query, and report the action to perform at the same
time. Instead these two are split into distinct predicate and action
functions. This is mostly tolerable for other cases, but the
load/store rules get pretty complicated so it's difficult to keep two
versions of these functions in sync.
2020-05-24 23:12:11 +08:00
|
|
|
}
|
|
|
|
|
2020-06-17 02:52:14 +08:00
|
|
|
/// Return true if a load or store of the type should be lowered with a bitcast
|
|
|
|
/// to a different type.
|
|
|
|
static bool shouldBitcastLoadStoreType(const GCNSubtarget &ST, const LLT Ty,
|
2021-06-09 08:22:45 +08:00
|
|
|
const LLT MemTy) {
|
|
|
|
const unsigned MemSizeInBits = MemTy.getSizeInBits();
|
2020-06-17 02:52:14 +08:00
|
|
|
const unsigned Size = Ty.getSizeInBits();
|
2021-06-11 00:00:36 +08:00
|
|
|
if (Size != MemSizeInBits)
|
|
|
|
return Size <= 32 && Ty.isVector();
|
2020-06-17 02:52:14 +08:00
|
|
|
|
|
|
|
if (loadStoreBitcastWorkaround(Ty) && isRegisterType(Ty))
|
|
|
|
return true;
|
2021-06-09 08:22:45 +08:00
|
|
|
|
|
|
|
// Don't try to handle bitcasting vector ext loads for now.
|
|
|
|
return Ty.isVector() && (!MemTy.isVector() || MemTy == Ty) &&
|
|
|
|
(Size <= 32 || isRegisterSize(Size)) &&
|
2020-06-17 02:52:14 +08:00
|
|
|
!isRegisterVectorElementType(Ty.getElementType());
|
|
|
|
}
|
|
|
|
|
2020-06-27 07:02:46 +08:00
|
|
|
/// Return true if we should legalize a load by widening an odd sized memory
|
|
|
|
/// access up to the alignment. Note this case when the memory access itself
|
|
|
|
/// changes, not the size of the result register.
|
2021-06-09 08:22:45 +08:00
|
|
|
static bool shouldWidenLoad(const GCNSubtarget &ST, LLT MemoryTy,
|
2022-01-13 04:01:27 +08:00
|
|
|
uint64_t AlignInBits, unsigned AddrSpace,
|
2020-06-27 07:02:46 +08:00
|
|
|
unsigned Opcode) {
|
2021-06-09 08:22:45 +08:00
|
|
|
unsigned SizeInBits = MemoryTy.getSizeInBits();
|
2020-06-27 07:02:46 +08:00
|
|
|
// We don't want to widen cases that are naturally legal.
|
|
|
|
if (isPowerOf2_32(SizeInBits))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// If we have 96-bit memory operations, we shouldn't touch them. Note we may
|
|
|
|
// end up widening these for a scalar load during RegBankSelect, since there
|
|
|
|
// aren't 96-bit scalar loads.
|
|
|
|
if (SizeInBits == 96 && ST.hasDwordx3LoadStores())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (SizeInBits >= maxSizeForAddrSpace(ST, AddrSpace, Opcode))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// A load is known dereferenceable up to the alignment, so it's legal to widen
|
|
|
|
// to it.
|
|
|
|
//
|
|
|
|
// TODO: Could check dereferenceable for less aligned cases.
|
|
|
|
unsigned RoundedSize = NextPowerOf2(SizeInBits);
|
|
|
|
if (AlignInBits < RoundedSize)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// Do not widen if it would introduce a slow unaligned load.
|
|
|
|
const SITargetLowering *TLI = ST.getTargetLowering();
|
|
|
|
bool Fast = false;
|
|
|
|
return TLI->allowsMisalignedMemoryAccessesImpl(
|
|
|
|
RoundedSize, AddrSpace, Align(AlignInBits / 8),
|
|
|
|
MachineMemOperand::MOLoad, &Fast) &&
|
|
|
|
Fast;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool shouldWidenLoad(const GCNSubtarget &ST, const LegalityQuery &Query,
|
|
|
|
unsigned Opcode) {
|
|
|
|
if (Query.MMODescrs[0].Ordering != AtomicOrdering::NotAtomic)
|
|
|
|
return false;
|
|
|
|
|
2021-06-09 08:22:45 +08:00
|
|
|
return shouldWidenLoad(ST, Query.MMODescrs[0].MemoryTy,
|
2020-06-27 07:02:46 +08:00
|
|
|
Query.MMODescrs[0].AlignInBits,
|
|
|
|
Query.Types[1].getAddressSpace(), Opcode);
|
|
|
|
}
|
|
|
|
|
2019-07-02 02:49:01 +08:00
|
|
|
AMDGPULegalizerInfo::AMDGPULegalizerInfo(const GCNSubtarget &ST_,
|
|
|
|
const GCNTargetMachine &TM)
|
|
|
|
: ST(ST_) {
|
Re-commit AMDGPU/GlobalISel: Add support for simple shaders
Fix build when global-isel is disabled and fix a warning.
Summary: We can select constant/global G_LOAD, global G_STORE, and G_GEP.
Reviewers: qcolombet, MatzeB, t.p.northover, ab, arsenm
Subscribers: mehdi_amini, vkalintiris, kzhuravl, wdng, nhaehnle, mgorny, yaxunl, tony-tye, modocache, llvm-commits, dberris
Differential Revision: https://reviews.llvm.org/D26730
llvm-svn: 293551
2017-01-31 05:56:46 +08:00
|
|
|
using namespace TargetOpcode;
|
|
|
|
|
2018-03-17 23:17:41 +08:00
|
|
|
auto GetAddrSpacePtr = [&TM](unsigned AS) {
|
|
|
|
return LLT::pointer(AS, TM.getPointerSizeInBits(AS));
|
|
|
|
};
|
|
|
|
|
|
|
|
const LLT S1 = LLT::scalar(1);
|
2020-08-10 17:47:50 +08:00
|
|
|
const LLT S8 = LLT::scalar(8);
|
2019-01-19 05:33:50 +08:00
|
|
|
const LLT S16 = LLT::scalar(16);
|
Re-commit AMDGPU/GlobalISel: Add support for simple shaders
Fix build when global-isel is disabled and fix a warning.
Summary: We can select constant/global G_LOAD, global G_STORE, and G_GEP.
Reviewers: qcolombet, MatzeB, t.p.northover, ab, arsenm
Subscribers: mehdi_amini, vkalintiris, kzhuravl, wdng, nhaehnle, mgorny, yaxunl, tony-tye, modocache, llvm-commits, dberris
Differential Revision: https://reviews.llvm.org/D26730
llvm-svn: 293551
2017-01-31 05:56:46 +08:00
|
|
|
const LLT S32 = LLT::scalar(32);
|
|
|
|
const LLT S64 = LLT::scalar(64);
|
2019-01-25 10:36:32 +08:00
|
|
|
const LLT S128 = LLT::scalar(128);
|
2019-01-21 02:40:36 +08:00
|
|
|
const LLT S256 = LLT::scalar(256);
|
2020-03-16 22:42:15 +08:00
|
|
|
const LLT S512 = LLT::scalar(512);
|
2020-06-14 06:32:30 +08:00
|
|
|
const LLT MaxScalar = LLT::scalar(MaxRegisterSize);
|
2018-03-17 23:17:41 +08:00
|
|
|
|
2021-06-24 16:58:21 +08:00
|
|
|
const LLT V2S8 = LLT::fixed_vector(2, 8);
|
|
|
|
const LLT V2S16 = LLT::fixed_vector(2, 16);
|
|
|
|
const LLT V4S16 = LLT::fixed_vector(4, 16);
|
|
|
|
|
|
|
|
const LLT V2S32 = LLT::fixed_vector(2, 32);
|
|
|
|
const LLT V3S32 = LLT::fixed_vector(3, 32);
|
|
|
|
const LLT V4S32 = LLT::fixed_vector(4, 32);
|
|
|
|
const LLT V5S32 = LLT::fixed_vector(5, 32);
|
|
|
|
const LLT V6S32 = LLT::fixed_vector(6, 32);
|
|
|
|
const LLT V7S32 = LLT::fixed_vector(7, 32);
|
|
|
|
const LLT V8S32 = LLT::fixed_vector(8, 32);
|
|
|
|
const LLT V9S32 = LLT::fixed_vector(9, 32);
|
|
|
|
const LLT V10S32 = LLT::fixed_vector(10, 32);
|
|
|
|
const LLT V11S32 = LLT::fixed_vector(11, 32);
|
|
|
|
const LLT V12S32 = LLT::fixed_vector(12, 32);
|
|
|
|
const LLT V13S32 = LLT::fixed_vector(13, 32);
|
|
|
|
const LLT V14S32 = LLT::fixed_vector(14, 32);
|
|
|
|
const LLT V15S32 = LLT::fixed_vector(15, 32);
|
|
|
|
const LLT V16S32 = LLT::fixed_vector(16, 32);
|
|
|
|
const LLT V32S32 = LLT::fixed_vector(32, 32);
|
|
|
|
|
|
|
|
const LLT V2S64 = LLT::fixed_vector(2, 64);
|
|
|
|
const LLT V3S64 = LLT::fixed_vector(3, 64);
|
|
|
|
const LLT V4S64 = LLT::fixed_vector(4, 64);
|
|
|
|
const LLT V5S64 = LLT::fixed_vector(5, 64);
|
|
|
|
const LLT V6S64 = LLT::fixed_vector(6, 64);
|
|
|
|
const LLT V7S64 = LLT::fixed_vector(7, 64);
|
|
|
|
const LLT V8S64 = LLT::fixed_vector(8, 64);
|
|
|
|
const LLT V16S64 = LLT::fixed_vector(16, 64);
|
2018-12-21 11:03:11 +08:00
|
|
|
|
|
|
|
std::initializer_list<LLT> AllS32Vectors =
|
|
|
|
{V2S32, V3S32, V4S32, V5S32, V6S32, V7S32, V8S32,
|
2019-10-02 09:02:18 +08:00
|
|
|
V9S32, V10S32, V11S32, V12S32, V13S32, V14S32, V15S32, V16S32, V32S32};
|
2018-12-21 11:03:11 +08:00
|
|
|
std::initializer_list<LLT> AllS64Vectors =
|
2019-10-02 09:02:18 +08:00
|
|
|
{V2S64, V3S64, V4S64, V5S64, V6S64, V7S64, V8S64, V16S64};
|
2018-12-21 11:03:11 +08:00
|
|
|
|
2018-03-17 23:17:41 +08:00
|
|
|
const LLT GlobalPtr = GetAddrSpacePtr(AMDGPUAS::GLOBAL_ADDRESS);
|
|
|
|
const LLT ConstantPtr = GetAddrSpacePtr(AMDGPUAS::CONSTANT_ADDRESS);
|
2019-07-20 06:28:44 +08:00
|
|
|
const LLT Constant32Ptr = GetAddrSpacePtr(AMDGPUAS::CONSTANT_ADDRESS_32BIT);
|
2018-03-17 23:17:45 +08:00
|
|
|
const LLT LocalPtr = GetAddrSpacePtr(AMDGPUAS::LOCAL_ADDRESS);
|
2019-07-20 06:28:44 +08:00
|
|
|
const LLT RegionPtr = GetAddrSpacePtr(AMDGPUAS::REGION_ADDRESS);
|
2018-08-31 13:49:54 +08:00
|
|
|
const LLT FlatPtr = GetAddrSpacePtr(AMDGPUAS::FLAT_ADDRESS);
|
|
|
|
const LLT PrivatePtr = GetAddrSpacePtr(AMDGPUAS::PRIVATE_ADDRESS);
|
2018-03-17 23:17:45 +08:00
|
|
|
|
2018-12-14 04:34:15 +08:00
|
|
|
const LLT CodePtr = FlatPtr;
|
|
|
|
|
2019-02-15 06:24:28 +08:00
|
|
|
const std::initializer_list<LLT> AddrSpaces64 = {
|
|
|
|
GlobalPtr, ConstantPtr, FlatPtr
|
|
|
|
};
|
|
|
|
|
|
|
|
const std::initializer_list<LLT> AddrSpaces32 = {
|
2019-07-20 06:28:44 +08:00
|
|
|
LocalPtr, PrivatePtr, Constant32Ptr, RegionPtr
|
2018-03-17 23:17:45 +08:00
|
|
|
};
|
Re-commit AMDGPU/GlobalISel: Add support for simple shaders
Fix build when global-isel is disabled and fix a warning.
Summary: We can select constant/global G_LOAD, global G_STORE, and G_GEP.
Reviewers: qcolombet, MatzeB, t.p.northover, ab, arsenm
Subscribers: mehdi_amini, vkalintiris, kzhuravl, wdng, nhaehnle, mgorny, yaxunl, tony-tye, modocache, llvm-commits, dberris
Differential Revision: https://reviews.llvm.org/D26730
llvm-svn: 293551
2017-01-31 05:56:46 +08:00
|
|
|
|
2019-07-02 01:35:53 +08:00
|
|
|
const std::initializer_list<LLT> FPTypesBase = {
|
|
|
|
S32, S64
|
|
|
|
};
|
|
|
|
|
|
|
|
const std::initializer_list<LLT> FPTypes16 = {
|
|
|
|
S32, S64, S16
|
|
|
|
};
|
|
|
|
|
2019-07-11 00:31:19 +08:00
|
|
|
const std::initializer_list<LLT> FPTypesPK16 = {
|
|
|
|
S32, S64, S16, V2S16
|
|
|
|
};
|
|
|
|
|
2020-01-25 10:21:03 +08:00
|
|
|
const LLT MinScalarFPTy = ST.has16BitInsts() ? S16 : S32;
|
2020-01-12 07:03:18 +08:00
|
|
|
|
2021-06-04 17:15:38 +08:00
|
|
|
// s1 for VCC branches, s32 for SCC branches.
|
|
|
|
getActionDefinitionsBuilder(G_BRCOND).legalFor({S1, S32});
|
2019-01-08 09:22:47 +08:00
|
|
|
|
2019-02-21 23:48:13 +08:00
|
|
|
// TODO: All multiples of 32, vectors of pointers, all v2s16 pairs, more
|
|
|
|
// elements for v3s16
|
|
|
|
getActionDefinitionsBuilder(G_PHI)
|
2020-07-30 10:34:11 +08:00
|
|
|
.legalFor({S32, S64, V2S16, S16, V4S16, S1, S128, S256})
|
2019-02-21 23:48:13 +08:00
|
|
|
.legalFor(AllS32Vectors)
|
|
|
|
.legalFor(AllS64Vectors)
|
|
|
|
.legalFor(AddrSpaces64)
|
|
|
|
.legalFor(AddrSpaces32)
|
2020-07-26 05:22:22 +08:00
|
|
|
.legalIf(isPointer(0))
|
2020-07-30 10:34:11 +08:00
|
|
|
.clampScalar(0, S16, S256)
|
2019-02-21 23:48:13 +08:00
|
|
|
.widenScalarToNextPow2(0, 32)
|
2019-02-28 08:16:32 +08:00
|
|
|
.clampMaxNumElements(0, S32, 16)
|
2019-02-28 08:01:05 +08:00
|
|
|
.moreElementsIf(isSmallOddVector(0), oneMoreElement(0))
|
2020-07-26 05:22:22 +08:00
|
|
|
.scalarize(0);
|
2019-02-21 23:48:13 +08:00
|
|
|
|
2020-07-13 02:16:36 +08:00
|
|
|
if (ST.hasVOP3PInsts() && ST.hasAddNoCarry() && ST.hasIntClamp()) {
|
|
|
|
// Full set of gfx9 features.
|
2020-02-18 11:10:27 +08:00
|
|
|
getActionDefinitionsBuilder({G_ADD, G_SUB, G_MUL})
|
|
|
|
.legalFor({S32, S16, V2S16})
|
2021-09-07 22:25:04 +08:00
|
|
|
.minScalar(0, S16)
|
2021-12-23 21:09:51 +08:00
|
|
|
.clampMaxNumElementsStrict(0, S16, 2)
|
2021-09-07 22:25:04 +08:00
|
|
|
.widenScalarToNextMultipleOf(0, 32)
|
|
|
|
.maxScalar(0, S32)
|
|
|
|
.scalarize(0);
|
2020-07-13 02:18:45 +08:00
|
|
|
|
|
|
|
getActionDefinitionsBuilder({G_UADDSAT, G_USUBSAT, G_SADDSAT, G_SSUBSAT})
|
2020-07-13 02:16:36 +08:00
|
|
|
.legalFor({S32, S16, V2S16}) // Clamp modifier
|
2020-07-16 01:49:03 +08:00
|
|
|
.minScalarOrElt(0, S16)
|
2021-12-23 21:09:51 +08:00
|
|
|
.clampMaxNumElementsStrict(0, S16, 2)
|
2020-07-13 02:18:45 +08:00
|
|
|
.scalarize(0)
|
|
|
|
.widenScalarToNextPow2(0, 32)
|
|
|
|
.lower();
|
2020-02-18 11:10:27 +08:00
|
|
|
} else if (ST.has16BitInsts()) {
|
2019-07-02 02:18:55 +08:00
|
|
|
getActionDefinitionsBuilder({G_ADD, G_SUB, G_MUL})
|
|
|
|
.legalFor({S32, S16})
|
2021-09-07 22:25:04 +08:00
|
|
|
.minScalar(0, S16)
|
|
|
|
.widenScalarToNextMultipleOf(0, 32)
|
|
|
|
.maxScalar(0, S32)
|
|
|
|
.scalarize(0);
|
2020-07-13 02:18:45 +08:00
|
|
|
|
|
|
|
// Technically the saturating operations require clamp bit support, but this
|
|
|
|
// was introduced at the same time as 16-bit operations.
|
|
|
|
getActionDefinitionsBuilder({G_UADDSAT, G_USUBSAT})
|
2020-07-13 02:16:36 +08:00
|
|
|
.legalFor({S32, S16}) // Clamp modifier
|
2020-07-13 02:18:45 +08:00
|
|
|
.minScalar(0, S16)
|
|
|
|
.scalarize(0)
|
|
|
|
.widenScalarToNextPow2(0, 16)
|
|
|
|
.lower();
|
|
|
|
|
|
|
|
// We're just lowering this, but it helps get a better result to try to
|
|
|
|
// coerce to the desired type first.
|
|
|
|
getActionDefinitionsBuilder({G_SADDSAT, G_SSUBSAT})
|
|
|
|
.minScalar(0, S16)
|
|
|
|
.scalarize(0)
|
|
|
|
.lower();
|
2019-07-02 02:18:55 +08:00
|
|
|
} else {
|
|
|
|
getActionDefinitionsBuilder({G_ADD, G_SUB, G_MUL})
|
|
|
|
.legalFor({S32})
|
2021-09-07 22:25:04 +08:00
|
|
|
.widenScalarToNextMultipleOf(0, 32)
|
2019-07-02 02:18:55 +08:00
|
|
|
.clampScalar(0, S32, S32)
|
|
|
|
.scalarize(0);
|
2020-07-13 02:18:45 +08:00
|
|
|
|
|
|
|
if (ST.hasIntClamp()) {
|
|
|
|
getActionDefinitionsBuilder({G_UADDSAT, G_USUBSAT})
|
2020-07-13 02:16:36 +08:00
|
|
|
.legalFor({S32}) // Clamp modifier.
|
2020-07-13 02:18:45 +08:00
|
|
|
.scalarize(0)
|
|
|
|
.minScalarOrElt(0, S32)
|
|
|
|
.lower();
|
|
|
|
} else {
|
|
|
|
// Clamp bit support was added in VI, along with 16-bit operations.
|
|
|
|
getActionDefinitionsBuilder({G_UADDSAT, G_USUBSAT})
|
|
|
|
.minScalar(0, S32)
|
|
|
|
.scalarize(0)
|
|
|
|
.lower();
|
|
|
|
}
|
|
|
|
|
2020-07-13 02:16:36 +08:00
|
|
|
// FIXME: DAG expansion gets better results. The widening uses the smaller
|
|
|
|
// range values and goes for the min/max lowering directly.
|
2020-07-13 02:18:45 +08:00
|
|
|
getActionDefinitionsBuilder({G_SADDSAT, G_SSUBSAT})
|
|
|
|
.minScalar(0, S32)
|
|
|
|
.scalarize(0)
|
|
|
|
.lower();
|
2019-07-02 02:18:55 +08:00
|
|
|
}
|
|
|
|
|
2021-04-12 18:19:47 +08:00
|
|
|
getActionDefinitionsBuilder(
|
|
|
|
{G_SDIV, G_UDIV, G_SREM, G_UREM, G_SDIVREM, G_UDIVREM})
|
|
|
|
.customFor({S32, S64})
|
|
|
|
.clampScalar(0, S32, S64)
|
|
|
|
.widenScalarToNextPow2(0, 32)
|
|
|
|
.scalarize(0);
|
2020-01-05 02:24:09 +08:00
|
|
|
|
2020-08-10 17:47:50 +08:00
|
|
|
auto &Mulh = getActionDefinitionsBuilder({G_UMULH, G_SMULH})
|
|
|
|
.legalFor({S32})
|
2021-10-01 20:30:42 +08:00
|
|
|
.maxScalar(0, S32);
|
2020-08-10 17:47:50 +08:00
|
|
|
|
|
|
|
if (ST.hasVOP3PInsts()) {
|
|
|
|
Mulh
|
|
|
|
.clampMaxNumElements(0, S8, 2)
|
|
|
|
.lowerFor({V2S8});
|
|
|
|
}
|
|
|
|
|
|
|
|
Mulh
|
|
|
|
.scalarize(0)
|
|
|
|
.lower();
|
2018-12-20 09:35:49 +08:00
|
|
|
|
2019-01-27 07:47:07 +08:00
|
|
|
// Report legal for any types we can handle anywhere. For the cases only legal
|
|
|
|
// on the SALU, RegBankSelect will be able to re-legalize.
|
2018-12-20 09:35:49 +08:00
|
|
|
getActionDefinitionsBuilder({G_AND, G_OR, G_XOR})
|
2019-07-16 22:28:30 +08:00
|
|
|
.legalFor({S32, S1, S64, V2S32, S16, V2S16, V4S16})
|
2019-01-27 07:47:07 +08:00
|
|
|
.clampScalar(0, S32, S64)
|
2019-02-20 00:30:19 +08:00
|
|
|
.moreElementsIf(isSmallOddVector(0), oneMoreElement(0))
|
2019-10-04 01:50:29 +08:00
|
|
|
.fewerElementsIf(vectorWiderThan(0, 64), fewerEltsToSize64Vector(0))
|
2019-02-26 05:32:48 +08:00
|
|
|
.widenScalarToNextPow2(0)
|
2019-01-27 07:47:07 +08:00
|
|
|
.scalarize(0);
|
AMDGPU/GlobalISel: Mark 32-bit G_ADD as legal
Reviewers: arsenm
Reviewed By: arsenm
Subscribers: kzhuravl, wdng, nhaehnle, yaxunl, rovka, kristof.beyls, igorb, dstuttard, tpr, llvm-commits, t-tye
Differential Revision: https://reviews.llvm.org/D33992
llvm-svn: 305232
2017-06-13 04:54:56 +08:00
|
|
|
|
2019-10-17 04:46:32 +08:00
|
|
|
getActionDefinitionsBuilder({G_UADDO, G_USUBO,
|
2019-01-08 09:09:09 +08:00
|
|
|
G_UADDE, G_SADDE, G_USUBE, G_SSUBE})
|
AMDGPU/GlobalISel: Replace handling of boolean values
This solves selection failures with generated selection patterns,
which would fail due to inferring the SGPR reg bank for virtual
registers with a set register class instead of VCC bank. Use
instruction selection would constrain the virtual register to a
specific class, so when the def was selected later the bank no longer
was set to VCC.
Remove the SCC reg bank. SCC isn't directly addressable, so it
requires copying from SCC to an allocatable 32-bit register during
selection, so these might as well be treated as 32-bit SGPR values.
Now any scalar boolean value that will produce an outupt in SCC should
be widened during RegBankSelect to s32. Any s1 value should be a
vector boolean during selection. This makes the vcc register bank
unambiguous with a normal SGPR during selection.
Summary of how this should now work:
- G_TRUNC is always a no-op, and never should use a vcc bank result.
- SALU boolean operations should be promoted to s32 in RegBankSelect
apply mapping
- An s1 value means vcc bank at selection. The exception is for
legalization artifacts that use s1, which are never VCC. All other
contexts should infer the VCC register classes for s1 typed
registers. The LLT for the register is now needed to infer the
correct register class. Extensions with vcc sources should be
legalized to a select of constants during RegBankSelect.
- Copy from non-vcc to vcc ensures high bits of the input value are
cleared during selection.
- SALU boolean inputs should ensure the inputs are 0/1. This includes
select, conditional branches, and carry-ins.
There are a few somewhat dirty details. One is that G_TRUNC/G_*EXT
selection ignores the usual register-bank from register class
functions, and can't handle truncates with VCC result banks. I think
this is OK, since the artifacts are specially treated anyway. This
does require some care to avoid producing cases with vcc. There will
also be no 100% reliable way to verify this rule is followed in
selection in case of register classes, and violations manifests
themselves as invalid copy instructions much later.
Standard phi handling also only considers the bank of the result
register, and doesn't insert copies to make the source banks
match. This doesn't work for vcc, so we have to manually correct phi
inputs in this case. We should add a verifier check to make sure there
are no phis with mixed vcc and non-vcc register bank inputs.
There's also some duplication with the LegalizerHelper, and some code
which should live in the helper. I don't see a good way to share
special knowledge about what types to use for intermediate operations
depending on the bank for example. Using the helper to replace
extensions with selects also seems somewhat awkward to me.
Another issue is there are some contexts calling
getRegBankFromRegClass that apparently don't have the LLT type for the
register, but I haven't yet run into a real issue from this.
This also introduces new unnecessary instructions in most cases, since
we don't yet try to optimize out the zext when the source is known to
come from a compare.
2019-11-03 00:30:59 +08:00
|
|
|
.legalFor({{S32, S1}, {S32, S32}})
|
AMDGPU/GlobalISel: Lower 64-bit uaddo/usubo
Summary: Add more test cases for signed and unsigned add/sub with overflow.
Reviewers: arsenm, rampitec, kerbowa
Subscribers: kzhuravl, jvesely, wdng, nhaehnle, yaxunl, rovka, dstuttard, tpr, t-tye, hiraditya, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D75051
2020-01-24 17:02:47 +08:00
|
|
|
.minScalar(0, S32)
|
|
|
|
// TODO: .scalarize(0)
|
|
|
|
.lower();
|
2019-01-08 09:03:58 +08:00
|
|
|
|
2019-01-21 03:45:18 +08:00
|
|
|
getActionDefinitionsBuilder(G_BITCAST)
|
|
|
|
// Don't worry about the size constraint.
|
2019-10-03 13:46:08 +08:00
|
|
|
.legalIf(all(isRegisterType(0), isRegisterType(1)))
|
2020-01-10 10:53:28 +08:00
|
|
|
.lower();
|
|
|
|
|
AMDGPU/GlobalISel: Mark G_BITCAST s32 <--> <2 x s16> legal
Reviewers: arsenm
Reviewed By: arsenm
Subscribers: kzhuravl, wdng, nhaehnle, yaxunl, rovka, kristof.beyls, igorb, dstuttard, tpr, t-tye, llvm-commits
Differential Revision: https://reviews.llvm.org/D34129
llvm-svn: 305692
2017-06-19 21:15:45 +08:00
|
|
|
|
2020-01-22 06:12:26 +08:00
|
|
|
getActionDefinitionsBuilder(G_CONSTANT)
|
|
|
|
.legalFor({S1, S32, S64, S16, GlobalPtr,
|
|
|
|
LocalPtr, ConstantPtr, PrivatePtr, FlatPtr })
|
2020-07-25 23:14:27 +08:00
|
|
|
.legalIf(isPointer(0))
|
2020-01-22 06:12:26 +08:00
|
|
|
.clampScalar(0, S32, S64)
|
2020-07-25 23:14:27 +08:00
|
|
|
.widenScalarToNextPow2(0);
|
2020-01-22 06:12:26 +08:00
|
|
|
|
2019-09-05 00:19:45 +08:00
|
|
|
getActionDefinitionsBuilder(G_FCONSTANT)
|
|
|
|
.legalFor({S32, S64, S16})
|
|
|
|
.clampScalar(0, S16, S64);
|
AMDGPU/GlobalISel: Make IMPLICIT_DEF of all sizes < 512 legal.
Summary:
We could split sizes that are not power of two into smaller sized
G_IMPLICIT_DEF instructions, but this ends up generating
G_MERGE_VALUES instructions which we then have to handle in the instruction
selector. Since G_IMPLICIT_DEF is really a no-op it's easier just to
keep everything that can fit into a register legal.
Reviewers: arsenm
Reviewed By: arsenm
Subscribers: kzhuravl, wdng, nhaehnle, yaxunl, rovka, kristof.beyls, dstuttard, tpr, t-tye, llvm-commits
Differential Revision: https://reviews.llvm.org/D48777
llvm-svn: 336041
2018-06-30 12:09:44 +08:00
|
|
|
|
[GlobalISel][AMDGPU] add legalization for G_FREEZE
Summary:
Copy the legalization rules from SelectionDAG:
-widenScalar using anyext
-narrowScalar using intermediate merges
-scalarize/fewerElements using unmerge
-moreElements using G_IMPLICIT_DEF and insert
Add G_FREEZE legalization actions to AMDGPULegalizerInfo.
Use the same legalization actions as G_IMPLICIT_DEF.
Depends on D77795.
Reviewers: dsanders, arsenm, aqjune, aditya_nandakumar, t.p.northover, lebedev.ri, paquette, aemerson
Reviewed By: arsenm
Subscribers: kzhuravl, yaxunl, dstuttard, tpr, t-tye, jvesely, nhaehnle, kerbowa, wdng, rovka, hiraditya, volkan, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D78092
2020-04-14 17:25:05 +08:00
|
|
|
getActionDefinitionsBuilder({G_IMPLICIT_DEF, G_FREEZE})
|
2020-05-31 12:14:56 +08:00
|
|
|
.legalIf(isRegisterType(0))
|
|
|
|
// s1 and s16 are special cases because they have legal operations on
|
|
|
|
// them, but don't really occupy registers in the normal way.
|
|
|
|
.legalFor({S1, S16})
|
[GlobalISel][AMDGPU] add legalization for G_FREEZE
Summary:
Copy the legalization rules from SelectionDAG:
-widenScalar using anyext
-narrowScalar using intermediate merges
-scalarize/fewerElements using unmerge
-moreElements using G_IMPLICIT_DEF and insert
Add G_FREEZE legalization actions to AMDGPULegalizerInfo.
Use the same legalization actions as G_IMPLICIT_DEF.
Depends on D77795.
Reviewers: dsanders, arsenm, aqjune, aditya_nandakumar, t.p.northover, lebedev.ri, paquette, aemerson
Reviewed By: arsenm
Subscribers: kzhuravl, yaxunl, dstuttard, tpr, t-tye, jvesely, nhaehnle, kerbowa, wdng, rovka, hiraditya, volkan, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D78092
2020-04-14 17:25:05 +08:00
|
|
|
.moreElementsIf(isSmallOddVector(0), oneMoreElement(0))
|
2020-06-14 06:32:30 +08:00
|
|
|
.clampScalarOrElt(0, S32, MaxScalar)
|
[GlobalISel][AMDGPU] add legalization for G_FREEZE
Summary:
Copy the legalization rules from SelectionDAG:
-widenScalar using anyext
-narrowScalar using intermediate merges
-scalarize/fewerElements using unmerge
-moreElements using G_IMPLICIT_DEF and insert
Add G_FREEZE legalization actions to AMDGPULegalizerInfo.
Use the same legalization actions as G_IMPLICIT_DEF.
Depends on D77795.
Reviewers: dsanders, arsenm, aqjune, aditya_nandakumar, t.p.northover, lebedev.ri, paquette, aemerson
Reviewed By: arsenm
Subscribers: kzhuravl, yaxunl, dstuttard, tpr, t-tye, jvesely, nhaehnle, kerbowa, wdng, rovka, hiraditya, volkan, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D78092
2020-04-14 17:25:05 +08:00
|
|
|
.widenScalarToNextPow2(0, 32)
|
|
|
|
.clampMaxNumElements(0, S32, 16);
|
2018-06-25 23:42:12 +08:00
|
|
|
|
2021-06-04 17:15:38 +08:00
|
|
|
getActionDefinitionsBuilder(G_FRAME_INDEX).legalFor({PrivatePtr});
|
2020-05-30 23:04:15 +08:00
|
|
|
|
|
|
|
// If the amount is divergent, we have to do a wave reduction to get the
|
|
|
|
// maximum value, so this is expanded during RegBankSelect.
|
|
|
|
getActionDefinitionsBuilder(G_DYN_STACKALLOC)
|
|
|
|
.legalFor({{PrivatePtr, S32}});
|
|
|
|
|
2019-10-01 09:06:43 +08:00
|
|
|
getActionDefinitionsBuilder(G_GLOBAL_VALUE)
|
2020-07-25 23:12:29 +08:00
|
|
|
.customIf(typeIsNot(0, PrivatePtr));
|
|
|
|
|
2021-06-04 17:15:38 +08:00
|
|
|
getActionDefinitionsBuilder(G_BLOCK_ADDR).legalFor({CodePtr});
|
2018-12-18 17:46:13 +08:00
|
|
|
|
2019-02-08 02:03:11 +08:00
|
|
|
auto &FPOpActions = getActionDefinitionsBuilder(
|
2019-09-11 01:19:46 +08:00
|
|
|
{ G_FADD, G_FMUL, G_FMA, G_FCANONICALIZE})
|
2019-02-08 02:03:11 +08:00
|
|
|
.legalFor({S32, S64});
|
2019-08-30 04:06:48 +08:00
|
|
|
auto &TrigActions = getActionDefinitionsBuilder({G_FSIN, G_FCOS})
|
|
|
|
.customFor({S32, S64});
|
AMDGPU/GlobalISel: Legalize fast unsafe FDIV
Reviewers: arsenm
Reviewed By: arsenm
Subscribers: kzhuravl, jvesely, wdng, nhaehnle, yaxunl, rovka, dstuttard, tpr, t-tye, hiraditya, Petar.Avramovic, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D69231
llvm-svn: 375460
2019-10-22 06:18:26 +08:00
|
|
|
auto &FDIVActions = getActionDefinitionsBuilder(G_FDIV)
|
|
|
|
.customFor({S32, S64});
|
2019-02-08 02:03:11 +08:00
|
|
|
|
|
|
|
if (ST.has16BitInsts()) {
|
|
|
|
if (ST.hasVOP3PInsts())
|
|
|
|
FPOpActions.legalFor({S16, V2S16});
|
|
|
|
else
|
|
|
|
FPOpActions.legalFor({S16});
|
2019-08-30 04:06:48 +08:00
|
|
|
|
|
|
|
TrigActions.customFor({S16});
|
AMDGPU/GlobalISel: Legalize fast unsafe FDIV
Reviewers: arsenm
Reviewed By: arsenm
Subscribers: kzhuravl, jvesely, wdng, nhaehnle, yaxunl, rovka, dstuttard, tpr, t-tye, hiraditya, Petar.Avramovic, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D69231
llvm-svn: 375460
2019-10-22 06:18:26 +08:00
|
|
|
FDIVActions.customFor({S16});
|
2019-02-08 02:03:11 +08:00
|
|
|
}
|
|
|
|
|
2019-07-11 00:31:19 +08:00
|
|
|
auto &MinNumMaxNum = getActionDefinitionsBuilder({
|
|
|
|
G_FMINNUM, G_FMAXNUM, G_FMINNUM_IEEE, G_FMAXNUM_IEEE});
|
|
|
|
|
|
|
|
if (ST.hasVOP3PInsts()) {
|
|
|
|
MinNumMaxNum.customFor(FPTypesPK16)
|
2019-07-28 05:47:08 +08:00
|
|
|
.moreElementsIf(isSmallOddVector(0), oneMoreElement(0))
|
2019-07-11 00:31:19 +08:00
|
|
|
.clampMaxNumElements(0, S16, 2)
|
|
|
|
.clampScalar(0, S16, S64)
|
|
|
|
.scalarize(0);
|
|
|
|
} else if (ST.has16BitInsts()) {
|
|
|
|
MinNumMaxNum.customFor(FPTypes16)
|
|
|
|
.clampScalar(0, S16, S64)
|
|
|
|
.scalarize(0);
|
|
|
|
} else {
|
|
|
|
MinNumMaxNum.customFor(FPTypesBase)
|
|
|
|
.clampScalar(0, S32, S64)
|
|
|
|
.scalarize(0);
|
|
|
|
}
|
|
|
|
|
2019-02-08 02:03:11 +08:00
|
|
|
if (ST.hasVOP3PInsts())
|
2021-12-23 21:09:51 +08:00
|
|
|
FPOpActions.clampMaxNumElementsStrict(0, S16, 2);
|
2019-08-30 04:06:48 +08:00
|
|
|
|
2019-02-08 02:03:11 +08:00
|
|
|
FPOpActions
|
|
|
|
.scalarize(0)
|
|
|
|
.clampScalar(0, ST.has16BitInsts() ? S16 : S32, S64);
|
AMDGPU/GlobalISel: Mark 32-bit G_FADD as legal
Reviewers: arsenm
Reviewed By: arsenm
Subscribers: kzhuravl, wdng, nhaehnle, yaxunl, rovka, kristof.beyls, igorb, dstuttard, tpr, t-tye, llvm-commits
Differential Revision: https://reviews.llvm.org/D38439
llvm-svn: 316815
2017-10-28 07:57:41 +08:00
|
|
|
|
2019-08-30 04:06:48 +08:00
|
|
|
TrigActions
|
|
|
|
.scalarize(0)
|
|
|
|
.clampScalar(0, ST.has16BitInsts() ? S16 : S32, S64);
|
|
|
|
|
AMDGPU/GlobalISel: Legalize fast unsafe FDIV
Reviewers: arsenm
Reviewed By: arsenm
Subscribers: kzhuravl, jvesely, wdng, nhaehnle, yaxunl, rovka, dstuttard, tpr, t-tye, hiraditya, Petar.Avramovic, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D69231
llvm-svn: 375460
2019-10-22 06:18:26 +08:00
|
|
|
FDIVActions
|
|
|
|
.scalarize(0)
|
|
|
|
.clampScalar(0, ST.has16BitInsts() ? S16 : S32, S64);
|
|
|
|
|
2019-09-11 01:19:46 +08:00
|
|
|
getActionDefinitionsBuilder({G_FNEG, G_FABS})
|
|
|
|
.legalFor(FPTypesPK16)
|
2021-12-23 21:09:51 +08:00
|
|
|
.clampMaxNumElementsStrict(0, S16, 2)
|
2019-09-11 01:19:46 +08:00
|
|
|
.scalarize(0)
|
|
|
|
.clampScalar(0, S16, S64);
|
|
|
|
|
2019-02-08 02:14:39 +08:00
|
|
|
if (ST.has16BitInsts()) {
|
2019-09-13 09:48:15 +08:00
|
|
|
getActionDefinitionsBuilder({G_FSQRT, G_FFLOOR})
|
2019-02-08 02:14:39 +08:00
|
|
|
.legalFor({S32, S64, S16})
|
|
|
|
.scalarize(0)
|
|
|
|
.clampScalar(0, S16, S64);
|
|
|
|
} else {
|
2020-01-24 23:01:15 +08:00
|
|
|
getActionDefinitionsBuilder(G_FSQRT)
|
2019-02-08 02:14:39 +08:00
|
|
|
.legalFor({S32, S64})
|
|
|
|
.scalarize(0)
|
|
|
|
.clampScalar(0, S32, S64);
|
2020-01-24 23:01:15 +08:00
|
|
|
|
|
|
|
if (ST.hasFractBug()) {
|
|
|
|
getActionDefinitionsBuilder(G_FFLOOR)
|
|
|
|
.customFor({S64})
|
|
|
|
.legalFor({S32, S64})
|
|
|
|
.scalarize(0)
|
|
|
|
.clampScalar(0, S32, S64);
|
|
|
|
} else {
|
|
|
|
getActionDefinitionsBuilder(G_FFLOOR)
|
|
|
|
.legalFor({S32, S64})
|
|
|
|
.scalarize(0)
|
|
|
|
.clampScalar(0, S32, S64);
|
|
|
|
}
|
2019-02-08 02:14:39 +08:00
|
|
|
}
|
|
|
|
|
2018-12-20 08:37:02 +08:00
|
|
|
getActionDefinitionsBuilder(G_FPTRUNC)
|
2019-01-25 12:37:33 +08:00
|
|
|
.legalFor({{S32, S64}, {S16, S32}})
|
2020-01-18 23:08:11 +08:00
|
|
|
.scalarize(0)
|
|
|
|
.lower();
|
2018-12-20 08:37:02 +08:00
|
|
|
|
2019-01-21 02:34:24 +08:00
|
|
|
getActionDefinitionsBuilder(G_FPEXT)
|
|
|
|
.legalFor({{S64, S32}, {S32, S16}})
|
2020-07-20 22:12:19 +08:00
|
|
|
.narrowScalarFor({{S64, S16}}, changeTo(0, S32))
|
2019-01-25 10:36:32 +08:00
|
|
|
.scalarize(0);
|
2019-01-21 02:34:24 +08:00
|
|
|
|
2019-01-21 03:10:31 +08:00
|
|
|
getActionDefinitionsBuilder(G_FSUB)
|
2019-01-23 04:14:29 +08:00
|
|
|
// Use actual fsub instruction
|
|
|
|
.legalFor({S32})
|
|
|
|
// Must use fadd + fneg
|
|
|
|
.lowerFor({S64, S16, V2S16})
|
2019-01-25 08:51:00 +08:00
|
|
|
.scalarize(0)
|
2019-01-23 04:14:29 +08:00
|
|
|
.clampScalar(0, S32, S64);
|
2018-12-18 17:19:03 +08:00
|
|
|
|
2019-09-13 08:44:35 +08:00
|
|
|
// Whether this is legal depends on the floating point mode for the function.
|
|
|
|
auto &FMad = getActionDefinitionsBuilder(G_FMAD);
|
2020-06-19 09:29:47 +08:00
|
|
|
if (ST.hasMadF16() && ST.hasMadMacF32Insts())
|
2019-09-13 08:44:35 +08:00
|
|
|
FMad.customFor({S32, S16});
|
2020-06-19 09:29:47 +08:00
|
|
|
else if (ST.hasMadMacF32Insts())
|
2019-09-13 08:44:35 +08:00
|
|
|
FMad.customFor({S32});
|
2020-06-19 09:29:47 +08:00
|
|
|
else if (ST.hasMadF16())
|
|
|
|
FMad.customFor({S16});
|
2019-09-13 08:44:35 +08:00
|
|
|
FMad.scalarize(0)
|
|
|
|
.lower();
|
|
|
|
|
2020-08-10 16:10:46 +08:00
|
|
|
auto &FRem = getActionDefinitionsBuilder(G_FREM);
|
|
|
|
if (ST.has16BitInsts()) {
|
|
|
|
FRem.customFor({S16, S32, S64});
|
|
|
|
} else {
|
|
|
|
FRem.minScalar(0, S32)
|
|
|
|
.customFor({S32, S64});
|
|
|
|
}
|
|
|
|
FRem.scalarize(0);
|
|
|
|
|
2020-02-16 10:59:30 +08:00
|
|
|
// TODO: Do we need to clamp maximum bitwidth?
|
2020-01-22 09:22:57 +08:00
|
|
|
getActionDefinitionsBuilder(G_TRUNC)
|
2020-02-16 10:59:30 +08:00
|
|
|
.legalIf(isScalar(0))
|
|
|
|
.legalFor({{V2S16, V2S32}})
|
2020-02-16 09:24:36 +08:00
|
|
|
.clampMaxNumElements(0, S16, 2)
|
2020-02-16 10:59:30 +08:00
|
|
|
// Avoid scalarizing in cases that should be truly illegal. In unresolvable
|
|
|
|
// situations (like an invalid implicit use), we don't want to infinite loop
|
|
|
|
// in the legalizer.
|
|
|
|
.fewerElementsIf(elementTypeIsLegal(0), LegalizeMutations::scalarize(0))
|
2020-01-22 09:22:57 +08:00
|
|
|
.alwaysLegal();
|
|
|
|
|
2019-01-21 02:34:24 +08:00
|
|
|
getActionDefinitionsBuilder({G_SEXT, G_ZEXT, G_ANYEXT})
|
2019-01-21 03:28:20 +08:00
|
|
|
.legalFor({{S64, S32}, {S32, S16}, {S64, S16},
|
2020-01-22 05:47:27 +08:00
|
|
|
{S32, S1}, {S64, S1}, {S16, S1}})
|
2020-01-10 22:06:47 +08:00
|
|
|
.scalarize(0)
|
2020-02-07 10:11:52 +08:00
|
|
|
.clampScalar(0, S32, S64)
|
|
|
|
.widenScalarToNextPow2(1, 32);
|
2018-12-13 16:23:51 +08:00
|
|
|
|
2019-10-01 10:23:20 +08:00
|
|
|
// TODO: Split s1->s64 during regbankselect for VALU.
|
2019-10-08 07:33:08 +08:00
|
|
|
auto &IToFP = getActionDefinitionsBuilder({G_SITOFP, G_UITOFP})
|
2021-07-25 11:42:26 +08:00
|
|
|
.legalFor({{S32, S32}, {S64, S32}, {S16, S32}})
|
|
|
|
.lowerIf(typeIs(1, S1))
|
|
|
|
.customFor({{S32, S64}, {S64, S64}});
|
2019-10-08 07:33:08 +08:00
|
|
|
if (ST.has16BitInsts())
|
|
|
|
IToFP.legalFor({{S16, S16}});
|
|
|
|
IToFP.clampScalar(1, S32, S64)
|
2020-07-16 22:31:57 +08:00
|
|
|
.minScalar(0, S32)
|
2020-02-16 11:09:23 +08:00
|
|
|
.scalarize(0)
|
|
|
|
.widenScalarToNextPow2(1);
|
2018-03-02 03:04:25 +08:00
|
|
|
|
2019-10-01 09:06:48 +08:00
|
|
|
auto &FPToI = getActionDefinitionsBuilder({G_FPTOSI, G_FPTOUI})
|
2020-01-05 05:40:45 +08:00
|
|
|
.legalFor({{S32, S32}, {S32, S64}, {S32, S16}})
|
2021-06-12 05:21:09 +08:00
|
|
|
.customFor({{S64, S32}, {S64, S64}})
|
2020-07-20 17:04:30 +08:00
|
|
|
.narrowScalarFor({{S64, S16}}, changeTo(0, S32));
|
2019-10-01 09:06:48 +08:00
|
|
|
if (ST.has16BitInsts())
|
|
|
|
FPToI.legalFor({{S16, S16}});
|
|
|
|
else
|
|
|
|
FPToI.minScalar(1, S32);
|
|
|
|
|
|
|
|
FPToI.minScalar(0, S32)
|
2021-03-27 23:14:15 +08:00
|
|
|
.widenScalarToNextPow2(0, 32)
|
2020-01-05 06:09:48 +08:00
|
|
|
.scalarize(0)
|
|
|
|
.lower();
|
2018-02-07 12:47:59 +08:00
|
|
|
|
2020-07-19 21:56:15 +08:00
|
|
|
// Lower roundeven into G_FRINT
|
|
|
|
getActionDefinitionsBuilder({G_INTRINSIC_ROUND, G_INTRINSIC_ROUNDEVEN})
|
2019-12-25 03:49:31 +08:00
|
|
|
.scalarize(0)
|
|
|
|
.lower();
|
2018-12-21 11:14:45 +08:00
|
|
|
|
2019-12-24 08:42:53 +08:00
|
|
|
if (ST.has16BitInsts()) {
|
|
|
|
getActionDefinitionsBuilder({G_INTRINSIC_TRUNC, G_FCEIL, G_FRINT})
|
|
|
|
.legalFor({S16, S32, S64})
|
|
|
|
.clampScalar(0, S16, S64)
|
|
|
|
.scalarize(0);
|
|
|
|
} else if (ST.getGeneration() >= AMDGPUSubtarget::SEA_ISLANDS) {
|
2019-05-17 20:20:05 +08:00
|
|
|
getActionDefinitionsBuilder({G_INTRINSIC_TRUNC, G_FCEIL, G_FRINT})
|
2019-05-17 20:19:57 +08:00
|
|
|
.legalFor({S32, S64})
|
|
|
|
.clampScalar(0, S32, S64)
|
|
|
|
.scalarize(0);
|
|
|
|
} else {
|
2019-05-17 20:20:05 +08:00
|
|
|
getActionDefinitionsBuilder({G_INTRINSIC_TRUNC, G_FCEIL, G_FRINT})
|
2019-05-17 20:19:57 +08:00
|
|
|
.legalFor({S32})
|
|
|
|
.customFor({S64})
|
|
|
|
.clampScalar(0, S32, S64)
|
|
|
|
.scalarize(0);
|
|
|
|
}
|
Re-commit AMDGPU/GlobalISel: Add support for simple shaders
Fix build when global-isel is disabled and fix a warning.
Summary: We can select constant/global G_LOAD, global G_STORE, and G_GEP.
Reviewers: qcolombet, MatzeB, t.p.northover, ab, arsenm
Subscribers: mehdi_amini, vkalintiris, kzhuravl, wdng, nhaehnle, mgorny, yaxunl, tony-tye, modocache, llvm-commits, dberris
Differential Revision: https://reviews.llvm.org/D26730
llvm-svn: 293551
2017-01-31 05:56:46 +08:00
|
|
|
|
2020-05-16 06:33:01 +08:00
|
|
|
getActionDefinitionsBuilder(G_PTR_ADD)
|
2020-07-25 23:00:35 +08:00
|
|
|
.legalIf(all(isPointer(0), sameSize(0, 1)))
|
|
|
|
.scalarize(0)
|
|
|
|
.scalarSameSizeAs(1, 0);
|
2020-05-16 06:33:01 +08:00
|
|
|
|
|
|
|
getActionDefinitionsBuilder(G_PTRMASK)
|
2020-07-22 21:22:45 +08:00
|
|
|
.legalIf(all(sameSize(0, 1), typeInSet(1, {S64, S32})))
|
|
|
|
.scalarSameSizeAs(1, 0)
|
2020-05-24 06:10:34 +08:00
|
|
|
.scalarize(0);
|
2019-09-09 23:46:13 +08:00
|
|
|
|
2019-07-09 22:10:43 +08:00
|
|
|
auto &CmpBuilder =
|
|
|
|
getActionDefinitionsBuilder(G_ICMP)
|
AMDGPU/GlobalISel: Replace handling of boolean values
This solves selection failures with generated selection patterns,
which would fail due to inferring the SGPR reg bank for virtual
registers with a set register class instead of VCC bank. Use
instruction selection would constrain the virtual register to a
specific class, so when the def was selected later the bank no longer
was set to VCC.
Remove the SCC reg bank. SCC isn't directly addressable, so it
requires copying from SCC to an allocatable 32-bit register during
selection, so these might as well be treated as 32-bit SGPR values.
Now any scalar boolean value that will produce an outupt in SCC should
be widened during RegBankSelect to s32. Any s1 value should be a
vector boolean during selection. This makes the vcc register bank
unambiguous with a normal SGPR during selection.
Summary of how this should now work:
- G_TRUNC is always a no-op, and never should use a vcc bank result.
- SALU boolean operations should be promoted to s32 in RegBankSelect
apply mapping
- An s1 value means vcc bank at selection. The exception is for
legalization artifacts that use s1, which are never VCC. All other
contexts should infer the VCC register classes for s1 typed
registers. The LLT for the register is now needed to infer the
correct register class. Extensions with vcc sources should be
legalized to a select of constants during RegBankSelect.
- Copy from non-vcc to vcc ensures high bits of the input value are
cleared during selection.
- SALU boolean inputs should ensure the inputs are 0/1. This includes
select, conditional branches, and carry-ins.
There are a few somewhat dirty details. One is that G_TRUNC/G_*EXT
selection ignores the usual register-bank from register class
functions, and can't handle truncates with VCC result banks. I think
this is OK, since the artifacts are specially treated anyway. This
does require some care to avoid producing cases with vcc. There will
also be no 100% reliable way to verify this rule is followed in
selection in case of register classes, and violations manifests
themselves as invalid copy instructions much later.
Standard phi handling also only considers the bank of the result
register, and doesn't insert copies to make the source banks
match. This doesn't work for vcc, so we have to manually correct phi
inputs in this case. We should add a verifier check to make sure there
are no phis with mixed vcc and non-vcc register bank inputs.
There's also some duplication with the LegalizerHelper, and some code
which should live in the helper. I don't see a good way to share
special knowledge about what types to use for intermediate operations
depending on the bank for example. Using the helper to replace
extensions with selects also seems somewhat awkward to me.
Another issue is there are some contexts calling
getRegBankFromRegClass that apparently don't have the LLT type for the
register, but I haven't yet run into a real issue from this.
This also introduces new unnecessary instructions in most cases, since
we don't yet try to optimize out the zext when the source is known to
come from a compare.
2019-11-03 00:30:59 +08:00
|
|
|
// The compare output type differs based on the register bank of the output,
|
|
|
|
// so make both s1 and s32 legal.
|
|
|
|
//
|
|
|
|
// Scalar compares producing output in scc will be promoted to s32, as that
|
|
|
|
// is the allocatable register type that will be needed for the copy from
|
|
|
|
// scc. This will be promoted during RegBankSelect, and we assume something
|
|
|
|
// before that won't try to use s32 result types.
|
|
|
|
//
|
|
|
|
// Vector compares producing an output in vcc/SGPR will use s1 in VCC reg
|
|
|
|
// bank.
|
2019-02-03 07:35:15 +08:00
|
|
|
.legalForCartesianProduct(
|
|
|
|
{S1}, {S32, S64, GlobalPtr, LocalPtr, ConstantPtr, PrivatePtr, FlatPtr})
|
AMDGPU/GlobalISel: Replace handling of boolean values
This solves selection failures with generated selection patterns,
which would fail due to inferring the SGPR reg bank for virtual
registers with a set register class instead of VCC bank. Use
instruction selection would constrain the virtual register to a
specific class, so when the def was selected later the bank no longer
was set to VCC.
Remove the SCC reg bank. SCC isn't directly addressable, so it
requires copying from SCC to an allocatable 32-bit register during
selection, so these might as well be treated as 32-bit SGPR values.
Now any scalar boolean value that will produce an outupt in SCC should
be widened during RegBankSelect to s32. Any s1 value should be a
vector boolean during selection. This makes the vcc register bank
unambiguous with a normal SGPR during selection.
Summary of how this should now work:
- G_TRUNC is always a no-op, and never should use a vcc bank result.
- SALU boolean operations should be promoted to s32 in RegBankSelect
apply mapping
- An s1 value means vcc bank at selection. The exception is for
legalization artifacts that use s1, which are never VCC. All other
contexts should infer the VCC register classes for s1 typed
registers. The LLT for the register is now needed to infer the
correct register class. Extensions with vcc sources should be
legalized to a select of constants during RegBankSelect.
- Copy from non-vcc to vcc ensures high bits of the input value are
cleared during selection.
- SALU boolean inputs should ensure the inputs are 0/1. This includes
select, conditional branches, and carry-ins.
There are a few somewhat dirty details. One is that G_TRUNC/G_*EXT
selection ignores the usual register-bank from register class
functions, and can't handle truncates with VCC result banks. I think
this is OK, since the artifacts are specially treated anyway. This
does require some care to avoid producing cases with vcc. There will
also be no 100% reliable way to verify this rule is followed in
selection in case of register classes, and violations manifests
themselves as invalid copy instructions much later.
Standard phi handling also only considers the bank of the result
register, and doesn't insert copies to make the source banks
match. This doesn't work for vcc, so we have to manually correct phi
inputs in this case. We should add a verifier check to make sure there
are no phis with mixed vcc and non-vcc register bank inputs.
There's also some duplication with the LegalizerHelper, and some code
which should live in the helper. I don't see a good way to share
special knowledge about what types to use for intermediate operations
depending on the bank for example. Using the helper to replace
extensions with selects also seems somewhat awkward to me.
Another issue is there are some contexts calling
getRegBankFromRegClass that apparently don't have the LLT type for the
register, but I haven't yet run into a real issue from this.
This also introduces new unnecessary instructions in most cases, since
we don't yet try to optimize out the zext when the source is known to
come from a compare.
2019-11-03 00:30:59 +08:00
|
|
|
.legalForCartesianProduct(
|
|
|
|
{S32}, {S32, S64, GlobalPtr, LocalPtr, ConstantPtr, PrivatePtr, FlatPtr});
|
2019-07-09 22:10:43 +08:00
|
|
|
if (ST.has16BitInsts()) {
|
|
|
|
CmpBuilder.legalFor({{S1, S16}});
|
|
|
|
}
|
|
|
|
|
|
|
|
CmpBuilder
|
2019-02-03 07:35:15 +08:00
|
|
|
.widenScalarToNextPow2(1)
|
|
|
|
.clampScalar(1, S32, S64)
|
|
|
|
.scalarize(0)
|
AMDGPU/GlobalISel: Replace handling of boolean values
This solves selection failures with generated selection patterns,
which would fail due to inferring the SGPR reg bank for virtual
registers with a set register class instead of VCC bank. Use
instruction selection would constrain the virtual register to a
specific class, so when the def was selected later the bank no longer
was set to VCC.
Remove the SCC reg bank. SCC isn't directly addressable, so it
requires copying from SCC to an allocatable 32-bit register during
selection, so these might as well be treated as 32-bit SGPR values.
Now any scalar boolean value that will produce an outupt in SCC should
be widened during RegBankSelect to s32. Any s1 value should be a
vector boolean during selection. This makes the vcc register bank
unambiguous with a normal SGPR during selection.
Summary of how this should now work:
- G_TRUNC is always a no-op, and never should use a vcc bank result.
- SALU boolean operations should be promoted to s32 in RegBankSelect
apply mapping
- An s1 value means vcc bank at selection. The exception is for
legalization artifacts that use s1, which are never VCC. All other
contexts should infer the VCC register classes for s1 typed
registers. The LLT for the register is now needed to infer the
correct register class. Extensions with vcc sources should be
legalized to a select of constants during RegBankSelect.
- Copy from non-vcc to vcc ensures high bits of the input value are
cleared during selection.
- SALU boolean inputs should ensure the inputs are 0/1. This includes
select, conditional branches, and carry-ins.
There are a few somewhat dirty details. One is that G_TRUNC/G_*EXT
selection ignores the usual register-bank from register class
functions, and can't handle truncates with VCC result banks. I think
this is OK, since the artifacts are specially treated anyway. This
does require some care to avoid producing cases with vcc. There will
also be no 100% reliable way to verify this rule is followed in
selection in case of register classes, and violations manifests
themselves as invalid copy instructions much later.
Standard phi handling also only considers the bank of the result
register, and doesn't insert copies to make the source banks
match. This doesn't work for vcc, so we have to manually correct phi
inputs in this case. We should add a verifier check to make sure there
are no phis with mixed vcc and non-vcc register bank inputs.
There's also some duplication with the LegalizerHelper, and some code
which should live in the helper. I don't see a good way to share
special knowledge about what types to use for intermediate operations
depending on the bank for example. Using the helper to replace
extensions with selects also seems somewhat awkward to me.
Another issue is there are some contexts calling
getRegBankFromRegClass that apparently don't have the LLT type for the
register, but I haven't yet run into a real issue from this.
This also introduces new unnecessary instructions in most cases, since
we don't yet try to optimize out the zext when the source is known to
come from a compare.
2019-11-03 00:30:59 +08:00
|
|
|
.legalIf(all(typeInSet(0, {S1, S32}), isPointer(1)));
|
2019-02-03 07:35:15 +08:00
|
|
|
|
|
|
|
getActionDefinitionsBuilder(G_FCMP)
|
2019-07-02 01:35:53 +08:00
|
|
|
.legalForCartesianProduct({S1}, ST.has16BitInsts() ? FPTypes16 : FPTypesBase)
|
2019-01-25 10:59:34 +08:00
|
|
|
.widenScalarToNextPow2(1)
|
|
|
|
.clampScalar(1, S32, S64)
|
2019-01-27 07:54:53 +08:00
|
|
|
.scalarize(0);
|
2019-01-25 10:59:34 +08:00
|
|
|
|
2020-01-25 09:53:26 +08:00
|
|
|
// FIXME: fpow has a selection pattern that should move to custom lowering.
|
2020-02-21 07:59:08 +08:00
|
|
|
auto &Exp2Ops = getActionDefinitionsBuilder({G_FEXP2, G_FLOG2});
|
2020-01-25 10:21:03 +08:00
|
|
|
if (ST.has16BitInsts())
|
2020-01-25 09:53:26 +08:00
|
|
|
Exp2Ops.legalFor({S32, S16});
|
2020-01-25 10:21:03 +08:00
|
|
|
else
|
2020-01-25 09:53:26 +08:00
|
|
|
Exp2Ops.legalFor({S32});
|
|
|
|
Exp2Ops.clampScalar(0, MinScalarFPTy, S32);
|
|
|
|
Exp2Ops.scalarize(0);
|
AMDGPU/GlobalISel: Mark 32-bit G_ICMP as legal
Reviewers: arsenm
Reviewed By: arsenm
Subscribers: kzhuravl, wdng, nhaehnle, yaxunl, rovka, kristof.beyls, igorb, dstuttard, tpr, t-tye, llvm-commits
Differential Revision: https://reviews.llvm.org/D33890
llvm-svn: 304797
2017-06-06 22:16:50 +08:00
|
|
|
|
2020-02-21 07:59:08 +08:00
|
|
|
auto &ExpOps = getActionDefinitionsBuilder({G_FEXP, G_FLOG, G_FLOG10, G_FPOW});
|
2020-01-25 09:53:26 +08:00
|
|
|
if (ST.has16BitInsts())
|
|
|
|
ExpOps.customFor({{S32}, {S16}});
|
|
|
|
else
|
|
|
|
ExpOps.customFor({S32});
|
|
|
|
ExpOps.clampScalar(0, MinScalarFPTy, S32)
|
|
|
|
.scalarize(0);
|
2020-01-22 11:29:30 +08:00
|
|
|
|
2020-07-17 23:01:15 +08:00
|
|
|
getActionDefinitionsBuilder(G_FPOWI)
|
|
|
|
.clampScalar(0, MinScalarFPTy, S32)
|
|
|
|
.lower();
|
|
|
|
|
2019-01-31 10:09:57 +08:00
|
|
|
// The 64-bit versions produce 32-bit results, but only on the SALU.
|
2020-02-07 10:11:52 +08:00
|
|
|
getActionDefinitionsBuilder(G_CTPOP)
|
|
|
|
.legalFor({{S32, S32}, {S32, S64}})
|
|
|
|
.clampScalar(0, S32, S32)
|
|
|
|
.clampScalar(1, S32, S64)
|
|
|
|
.scalarize(0)
|
|
|
|
.widenScalarToNextPow2(0, 32)
|
|
|
|
.widenScalarToNextPow2(1, 32);
|
|
|
|
|
|
|
|
// The hardware instructions return a different result on 0 than the generic
|
|
|
|
// instructions expect. The hardware produces -1, but these produce the
|
|
|
|
// bitwidth.
|
|
|
|
getActionDefinitionsBuilder({G_CTLZ, G_CTTZ})
|
|
|
|
.scalarize(0)
|
|
|
|
.clampScalar(0, S32, S32)
|
|
|
|
.clampScalar(1, S32, S64)
|
|
|
|
.widenScalarToNextPow2(0, 32)
|
|
|
|
.widenScalarToNextPow2(1, 32)
|
2021-08-04 00:11:08 +08:00
|
|
|
.custom();
|
2020-02-07 10:11:52 +08:00
|
|
|
|
|
|
|
// The 64-bit versions produce 32-bit results, but only on the SALU.
|
|
|
|
getActionDefinitionsBuilder({G_CTLZ_ZERO_UNDEF, G_CTTZ_ZERO_UNDEF})
|
2019-01-31 10:09:57 +08:00
|
|
|
.legalFor({{S32, S32}, {S32, S64}})
|
|
|
|
.clampScalar(0, S32, S32)
|
2019-02-21 00:42:52 +08:00
|
|
|
.clampScalar(1, S32, S64)
|
2019-02-21 23:22:20 +08:00
|
|
|
.scalarize(0)
|
|
|
|
.widenScalarToNextPow2(0, 32)
|
|
|
|
.widenScalarToNextPow2(1, 32);
|
2019-01-31 10:09:57 +08:00
|
|
|
|
2021-02-26 21:40:03 +08:00
|
|
|
// S64 is only legal on SALU, and needs to be broken into 32-bit elements in
|
|
|
|
// RegBankSelect.
|
2020-02-14 23:56:46 +08:00
|
|
|
getActionDefinitionsBuilder(G_BITREVERSE)
|
2021-02-26 21:40:03 +08:00
|
|
|
.legalFor({S32, S64})
|
|
|
|
.clampScalar(0, S32, S64)
|
|
|
|
.scalarize(0)
|
|
|
|
.widenScalarToNextPow2(0);
|
2019-01-31 10:09:57 +08:00
|
|
|
|
2019-05-24 01:58:48 +08:00
|
|
|
if (ST.has16BitInsts()) {
|
2020-02-14 23:56:46 +08:00
|
|
|
getActionDefinitionsBuilder(G_BSWAP)
|
|
|
|
.legalFor({S16, S32, V2S16})
|
2021-12-23 21:09:51 +08:00
|
|
|
.clampMaxNumElementsStrict(0, S16, 2)
|
2020-02-14 23:56:46 +08:00
|
|
|
// FIXME: Fixing non-power-of-2 before clamp is workaround for
|
|
|
|
// narrowScalar limitation.
|
|
|
|
.widenScalarToNextPow2(0)
|
|
|
|
.clampScalar(0, S16, S32)
|
|
|
|
.scalarize(0);
|
|
|
|
|
2019-05-24 01:58:48 +08:00
|
|
|
if (ST.hasVOP3PInsts()) {
|
2021-06-04 00:09:45 +08:00
|
|
|
getActionDefinitionsBuilder({G_SMIN, G_SMAX, G_UMIN, G_UMAX, G_ABS})
|
2019-05-24 01:58:48 +08:00
|
|
|
.legalFor({S32, S16, V2S16})
|
|
|
|
.moreElementsIf(isSmallOddVector(0), oneMoreElement(0))
|
|
|
|
.clampMaxNumElements(0, S16, 2)
|
AMDGPU/GlobalISel: Legalize s64 min/max by lowering
Reviewers: arsenm, rampitec
Subscribers: kzhuravl, jvesely, wdng, nhaehnle, yaxunl, rovka, dstuttard, tpr, t-tye, hiraditya, kerbowa, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D75108
2020-02-25 18:31:37 +08:00
|
|
|
.minScalar(0, S16)
|
2019-05-24 01:58:48 +08:00
|
|
|
.widenScalarToNextPow2(0)
|
AMDGPU/GlobalISel: Legalize s64 min/max by lowering
Reviewers: arsenm, rampitec
Subscribers: kzhuravl, jvesely, wdng, nhaehnle, yaxunl, rovka, dstuttard, tpr, t-tye, hiraditya, kerbowa, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D75108
2020-02-25 18:31:37 +08:00
|
|
|
.scalarize(0)
|
|
|
|
.lower();
|
2019-05-24 01:58:48 +08:00
|
|
|
} else {
|
2021-06-04 00:09:45 +08:00
|
|
|
getActionDefinitionsBuilder({G_SMIN, G_SMAX, G_UMIN, G_UMAX, G_ABS})
|
2019-05-24 01:58:48 +08:00
|
|
|
.legalFor({S32, S16})
|
|
|
|
.widenScalarToNextPow2(0)
|
AMDGPU/GlobalISel: Legalize s64 min/max by lowering
Reviewers: arsenm, rampitec
Subscribers: kzhuravl, jvesely, wdng, nhaehnle, yaxunl, rovka, dstuttard, tpr, t-tye, hiraditya, kerbowa, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D75108
2020-02-25 18:31:37 +08:00
|
|
|
.minScalar(0, S16)
|
|
|
|
.scalarize(0)
|
|
|
|
.lower();
|
2019-05-24 01:58:48 +08:00
|
|
|
}
|
|
|
|
} else {
|
2020-02-14 23:56:46 +08:00
|
|
|
// TODO: Should have same legality without v_perm_b32
|
|
|
|
getActionDefinitionsBuilder(G_BSWAP)
|
|
|
|
.legalFor({S32})
|
2020-05-24 06:28:12 +08:00
|
|
|
.lowerIf(scalarNarrowerThan(0, 32))
|
2020-02-14 23:56:46 +08:00
|
|
|
// FIXME: Fixing non-power-of-2 before clamp is workaround for
|
|
|
|
// narrowScalar limitation.
|
|
|
|
.widenScalarToNextPow2(0)
|
|
|
|
.maxScalar(0, S32)
|
|
|
|
.scalarize(0)
|
|
|
|
.lower();
|
|
|
|
|
2021-06-04 00:09:45 +08:00
|
|
|
getActionDefinitionsBuilder({G_SMIN, G_SMAX, G_UMIN, G_UMAX, G_ABS})
|
2019-05-24 01:58:48 +08:00
|
|
|
.legalFor({S32})
|
AMDGPU/GlobalISel: Legalize s64 min/max by lowering
Reviewers: arsenm, rampitec
Subscribers: kzhuravl, jvesely, wdng, nhaehnle, yaxunl, rovka, dstuttard, tpr, t-tye, hiraditya, kerbowa, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D75108
2020-02-25 18:31:37 +08:00
|
|
|
.minScalar(0, S32)
|
2019-05-24 01:58:48 +08:00
|
|
|
.widenScalarToNextPow2(0)
|
AMDGPU/GlobalISel: Legalize s64 min/max by lowering
Reviewers: arsenm, rampitec
Subscribers: kzhuravl, jvesely, wdng, nhaehnle, yaxunl, rovka, dstuttard, tpr, t-tye, hiraditya, kerbowa, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D75108
2020-02-25 18:31:37 +08:00
|
|
|
.scalarize(0)
|
|
|
|
.lower();
|
2019-05-24 01:58:48 +08:00
|
|
|
}
|
2018-12-13 16:23:51 +08:00
|
|
|
|
AMDGPU/GlobalISel: Add support for G_INTTOPTR
Summary: This is a no-op.
Reviewers: arsenm
Reviewed By: arsenm
Subscribers: kzhuravl, jvesely, wdng, nhaehnle, yaxunl, rovka, kristof.beyls, dstuttard, tpr, t-tye, llvm-commits
Differential Revision: https://reviews.llvm.org/D52916
llvm-svn: 343839
2018-10-05 12:34:09 +08:00
|
|
|
getActionDefinitionsBuilder(G_INTTOPTR)
|
2019-02-03 07:29:55 +08:00
|
|
|
// List the common cases
|
2019-02-15 06:24:28 +08:00
|
|
|
.legalForCartesianProduct(AddrSpaces64, {S64})
|
|
|
|
.legalForCartesianProduct(AddrSpaces32, {S32})
|
2019-02-03 07:29:55 +08:00
|
|
|
.scalarize(0)
|
|
|
|
// Accept any address space as long as the size matches
|
|
|
|
.legalIf(sameSize(0, 1))
|
|
|
|
.widenScalarIf(smallerThan(1, 0),
|
|
|
|
[](const LegalityQuery &Query) {
|
|
|
|
return std::make_pair(1, LLT::scalar(Query.Types[0].getSizeInBits()));
|
|
|
|
})
|
2020-05-24 06:28:12 +08:00
|
|
|
.narrowScalarIf(largerThan(1, 0),
|
2019-02-03 07:29:55 +08:00
|
|
|
[](const LegalityQuery &Query) {
|
|
|
|
return std::make_pair(1, LLT::scalar(Query.Types[0].getSizeInBits()));
|
|
|
|
});
|
2018-03-17 23:17:41 +08:00
|
|
|
|
2018-12-13 16:23:51 +08:00
|
|
|
getActionDefinitionsBuilder(G_PTRTOINT)
|
2019-02-03 07:29:55 +08:00
|
|
|
// List the common cases
|
2019-02-15 06:24:28 +08:00
|
|
|
.legalForCartesianProduct(AddrSpaces64, {S64})
|
|
|
|
.legalForCartesianProduct(AddrSpaces32, {S32})
|
2019-02-03 07:29:55 +08:00
|
|
|
.scalarize(0)
|
|
|
|
// Accept any address space as long as the size matches
|
|
|
|
.legalIf(sameSize(0, 1))
|
|
|
|
.widenScalarIf(smallerThan(0, 1),
|
|
|
|
[](const LegalityQuery &Query) {
|
|
|
|
return std::make_pair(0, LLT::scalar(Query.Types[1].getSizeInBits()));
|
|
|
|
})
|
|
|
|
.narrowScalarIf(
|
2020-05-24 06:28:12 +08:00
|
|
|
largerThan(0, 1),
|
2019-02-03 07:29:55 +08:00
|
|
|
[](const LegalityQuery &Query) {
|
|
|
|
return std::make_pair(0, LLT::scalar(Query.Types[1].getSizeInBits()));
|
|
|
|
});
|
2018-12-13 16:23:51 +08:00
|
|
|
|
2019-08-28 08:58:24 +08:00
|
|
|
getActionDefinitionsBuilder(G_ADDRSPACE_CAST)
|
|
|
|
.scalarize(0)
|
|
|
|
.custom();
|
2019-02-08 10:40:47 +08:00
|
|
|
|
2020-01-22 02:23:45 +08:00
|
|
|
const auto needToSplitMemOp = [=](const LegalityQuery &Query,
|
|
|
|
bool IsLoad) -> bool {
|
2019-09-11 00:20:14 +08:00
|
|
|
const LLT DstTy = Query.Types[0];
|
|
|
|
|
|
|
|
// Split vector extloads.
|
2021-06-09 08:22:45 +08:00
|
|
|
unsigned MemSize = Query.MMODescrs[0].MemoryTy.getSizeInBits();
|
2020-01-03 03:45:11 +08:00
|
|
|
|
2019-09-11 00:20:14 +08:00
|
|
|
if (DstTy.isVector() && DstTy.getSizeInBits() > MemSize)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
const LLT PtrTy = Query.Types[1];
|
|
|
|
unsigned AS = PtrTy.getAddressSpace();
|
AMDGPU/GlobalISel: Start rewriting load/store legality rules
The current set is an incomprehensible mess riddled with ordering
hacks for various limitations in the legalizer at the time of writing,
many of which have been fixed. This takes a very small step in
correcting this.
The core first change is to start checking for fully legal cases
first, rather than trying to figure out all of the actions that could
need to be performed. It's recommended to check the legal cases first
for faster legality checks in the common case. This still has a table
listing some common cases, but it needs measuring whether this really
helps or not.
More significantly, stop trying to allow any arbitrary type with a
legal bitwidth as a legal memory type, and start using the bitcast
legalize action for them. Allowing loads of these weird vector types
produced new burdens we don't need for handling all of the
legalization artifacts. Unlike the SelectionDAG handling, this is
still not casting 64 or 16-bit element vectors to 32-bit
vectors. These cases should still be handled by increasing/decreasing
the number of 16-bit elements. This is primarily to fix 8-bit element
vectors.
Another change is to stop trying to handle the load-widening based on
a higher alignment. We should still do this, but the way it was
handled wasn't really correct. We really need to modify the MMO's size
at the same time, and not just increase the result type. The
LegalizerHelper does not do this, and I think this would really
require a separate WidenMemory action (or to add a memory action
payload to the LegalizeMutation). These will now fail to legalize.
The structure of the legalizer rules makes writing concise rules here
difficult. It would be easier if the same function could answer the
query the query, and report the action to perform at the same
time. Instead these two are split into distinct predicate and action
functions. This is mostly tolerable for other cases, but the
load/store rules get pretty complicated so it's difficult to keep two
versions of these functions in sync.
2020-05-24 23:12:11 +08:00
|
|
|
if (MemSize > maxSizeForAddrSpace(ST, AS, IsLoad))
|
2019-09-11 00:20:14 +08:00
|
|
|
return true;
|
|
|
|
|
|
|
|
// Catch weird sized loads that don't evenly divide into the access sizes
|
|
|
|
// TODO: May be able to widen depending on alignment etc.
|
2020-01-22 02:23:45 +08:00
|
|
|
unsigned NumRegs = (MemSize + 31) / 32;
|
|
|
|
if (NumRegs == 3) {
|
|
|
|
if (!ST.hasDwordx3LoadStores())
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
// If the alignment allows, these should have been widened.
|
|
|
|
if (!isPowerOf2_32(NumRegs))
|
|
|
|
return true;
|
|
|
|
}
|
2019-09-11 00:20:14 +08:00
|
|
|
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
|
2020-11-11 22:33:55 +08:00
|
|
|
unsigned GlobalAlign32 = ST.hasUnalignedBufferAccessEnabled() ? 0 : 32;
|
|
|
|
unsigned GlobalAlign16 = ST.hasUnalignedBufferAccessEnabled() ? 0 : 16;
|
|
|
|
unsigned GlobalAlign8 = ST.hasUnalignedBufferAccessEnabled() ? 0 : 8;
|
2019-09-11 00:20:14 +08:00
|
|
|
|
|
|
|
// TODO: Refine based on subtargets which support unaligned access or 128-bit
|
|
|
|
// LDS
|
|
|
|
// TODO: Unsupported flat for SI.
|
|
|
|
|
|
|
|
for (unsigned Op : {G_LOAD, G_STORE}) {
|
|
|
|
const bool IsStore = Op == G_STORE;
|
|
|
|
|
|
|
|
auto &Actions = getActionDefinitionsBuilder(Op);
|
2020-06-20 15:05:32 +08:00
|
|
|
// Explicitly list some common cases.
|
AMDGPU/GlobalISel: Start rewriting load/store legality rules
The current set is an incomprehensible mess riddled with ordering
hacks for various limitations in the legalizer at the time of writing,
many of which have been fixed. This takes a very small step in
correcting this.
The core first change is to start checking for fully legal cases
first, rather than trying to figure out all of the actions that could
need to be performed. It's recommended to check the legal cases first
for faster legality checks in the common case. This still has a table
listing some common cases, but it needs measuring whether this really
helps or not.
More significantly, stop trying to allow any arbitrary type with a
legal bitwidth as a legal memory type, and start using the bitcast
legalize action for them. Allowing loads of these weird vector types
produced new burdens we don't need for handling all of the
legalization artifacts. Unlike the SelectionDAG handling, this is
still not casting 64 or 16-bit element vectors to 32-bit
vectors. These cases should still be handled by increasing/decreasing
the number of 16-bit elements. This is primarily to fix 8-bit element
vectors.
Another change is to stop trying to handle the load-widening based on
a higher alignment. We should still do this, but the way it was
handled wasn't really correct. We really need to modify the MMO's size
at the same time, and not just increase the result type. The
LegalizerHelper does not do this, and I think this would really
require a separate WidenMemory action (or to add a memory action
payload to the LegalizeMutation). These will now fail to legalize.
The structure of the legalizer rules makes writing concise rules here
difficult. It would be easier if the same function could answer the
query the query, and report the action to perform at the same
time. Instead these two are split into distinct predicate and action
functions. This is mostly tolerable for other cases, but the
load/store rules get pretty complicated so it's difficult to keep two
versions of these functions in sync.
2020-05-24 23:12:11 +08:00
|
|
|
// TODO: Does this help compile time at all?
|
2021-06-09 08:22:45 +08:00
|
|
|
Actions.legalForTypesWithMemDesc({{S32, GlobalPtr, S32, GlobalAlign32},
|
|
|
|
{V2S32, GlobalPtr, V2S32, GlobalAlign32},
|
|
|
|
{V4S32, GlobalPtr, V4S32, GlobalAlign32},
|
|
|
|
{S64, GlobalPtr, S64, GlobalAlign32},
|
|
|
|
{V2S64, GlobalPtr, V2S64, GlobalAlign32},
|
|
|
|
{V2S16, GlobalPtr, V2S16, GlobalAlign32},
|
|
|
|
{S32, GlobalPtr, S8, GlobalAlign8},
|
|
|
|
{S32, GlobalPtr, S16, GlobalAlign16},
|
|
|
|
|
|
|
|
{S32, LocalPtr, S32, 32},
|
|
|
|
{S64, LocalPtr, S64, 32},
|
|
|
|
{V2S32, LocalPtr, V2S32, 32},
|
|
|
|
{S32, LocalPtr, S8, 8},
|
|
|
|
{S32, LocalPtr, S16, 16},
|
|
|
|
{V2S16, LocalPtr, S32, 32},
|
|
|
|
|
|
|
|
{S32, PrivatePtr, S32, 32},
|
|
|
|
{S32, PrivatePtr, S8, 8},
|
|
|
|
{S32, PrivatePtr, S16, 16},
|
|
|
|
{V2S16, PrivatePtr, S32, 32},
|
|
|
|
|
|
|
|
{S32, ConstantPtr, S32, GlobalAlign32},
|
|
|
|
{V2S32, ConstantPtr, V2S32, GlobalAlign32},
|
|
|
|
{V4S32, ConstantPtr, V4S32, GlobalAlign32},
|
|
|
|
{S64, ConstantPtr, S64, GlobalAlign32},
|
|
|
|
{V2S32, ConstantPtr, V2S32, GlobalAlign32}});
|
AMDGPU/GlobalISel: Start rewriting load/store legality rules
The current set is an incomprehensible mess riddled with ordering
hacks for various limitations in the legalizer at the time of writing,
many of which have been fixed. This takes a very small step in
correcting this.
The core first change is to start checking for fully legal cases
first, rather than trying to figure out all of the actions that could
need to be performed. It's recommended to check the legal cases first
for faster legality checks in the common case. This still has a table
listing some common cases, but it needs measuring whether this really
helps or not.
More significantly, stop trying to allow any arbitrary type with a
legal bitwidth as a legal memory type, and start using the bitcast
legalize action for them. Allowing loads of these weird vector types
produced new burdens we don't need for handling all of the
legalization artifacts. Unlike the SelectionDAG handling, this is
still not casting 64 or 16-bit element vectors to 32-bit
vectors. These cases should still be handled by increasing/decreasing
the number of 16-bit elements. This is primarily to fix 8-bit element
vectors.
Another change is to stop trying to handle the load-widening based on
a higher alignment. We should still do this, but the way it was
handled wasn't really correct. We really need to modify the MMO's size
at the same time, and not just increase the result type. The
LegalizerHelper does not do this, and I think this would really
require a separate WidenMemory action (or to add a memory action
payload to the LegalizeMutation). These will now fail to legalize.
The structure of the legalizer rules makes writing concise rules here
difficult. It would be easier if the same function could answer the
query the query, and report the action to perform at the same
time. Instead these two are split into distinct predicate and action
functions. This is mostly tolerable for other cases, but the
load/store rules get pretty complicated so it's difficult to keep two
versions of these functions in sync.
2020-05-24 23:12:11 +08:00
|
|
|
Actions.legalIf(
|
|
|
|
[=](const LegalityQuery &Query) -> bool {
|
2021-05-19 05:02:25 +08:00
|
|
|
return isLoadStoreLegal(ST, Query);
|
AMDGPU/GlobalISel: Start rewriting load/store legality rules
The current set is an incomprehensible mess riddled with ordering
hacks for various limitations in the legalizer at the time of writing,
many of which have been fixed. This takes a very small step in
correcting this.
The core first change is to start checking for fully legal cases
first, rather than trying to figure out all of the actions that could
need to be performed. It's recommended to check the legal cases first
for faster legality checks in the common case. This still has a table
listing some common cases, but it needs measuring whether this really
helps or not.
More significantly, stop trying to allow any arbitrary type with a
legal bitwidth as a legal memory type, and start using the bitcast
legalize action for them. Allowing loads of these weird vector types
produced new burdens we don't need for handling all of the
legalization artifacts. Unlike the SelectionDAG handling, this is
still not casting 64 or 16-bit element vectors to 32-bit
vectors. These cases should still be handled by increasing/decreasing
the number of 16-bit elements. This is primarily to fix 8-bit element
vectors.
Another change is to stop trying to handle the load-widening based on
a higher alignment. We should still do this, but the way it was
handled wasn't really correct. We really need to modify the MMO's size
at the same time, and not just increase the result type. The
LegalizerHelper does not do this, and I think this would really
require a separate WidenMemory action (or to add a memory action
payload to the LegalizeMutation). These will now fail to legalize.
The structure of the legalizer rules makes writing concise rules here
difficult. It would be easier if the same function could answer the
query the query, and report the action to perform at the same
time. Instead these two are split into distinct predicate and action
functions. This is mostly tolerable for other cases, but the
load/store rules get pretty complicated so it's difficult to keep two
versions of these functions in sync.
2020-05-24 23:12:11 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
// Constant 32-bit is handled by addrspacecasting the 32-bit pointer to
|
|
|
|
// 64-bits.
|
|
|
|
//
|
|
|
|
// TODO: Should generalize bitcast action into coerce, which will also cover
|
|
|
|
// inserting addrspacecasts.
|
|
|
|
Actions.customIf(typeIs(1, Constant32Ptr));
|
|
|
|
|
|
|
|
// Turn any illegal element vectors into something easier to deal
|
|
|
|
// with. These will ultimately produce 32-bit scalar shifts to extract the
|
|
|
|
// parts anyway.
|
|
|
|
//
|
|
|
|
// For odd 16-bit element vectors, prefer to split those into pieces with
|
|
|
|
// 16-bit vector parts.
|
|
|
|
Actions.bitcastIf(
|
|
|
|
[=](const LegalityQuery &Query) -> bool {
|
2020-06-17 02:52:14 +08:00
|
|
|
return shouldBitcastLoadStoreType(ST, Query.Types[0],
|
2021-06-09 08:22:45 +08:00
|
|
|
Query.MMODescrs[0].MemoryTy);
|
AMDGPU/GlobalISel: Start rewriting load/store legality rules
The current set is an incomprehensible mess riddled with ordering
hacks for various limitations in the legalizer at the time of writing,
many of which have been fixed. This takes a very small step in
correcting this.
The core first change is to start checking for fully legal cases
first, rather than trying to figure out all of the actions that could
need to be performed. It's recommended to check the legal cases first
for faster legality checks in the common case. This still has a table
listing some common cases, but it needs measuring whether this really
helps or not.
More significantly, stop trying to allow any arbitrary type with a
legal bitwidth as a legal memory type, and start using the bitcast
legalize action for them. Allowing loads of these weird vector types
produced new burdens we don't need for handling all of the
legalization artifacts. Unlike the SelectionDAG handling, this is
still not casting 64 or 16-bit element vectors to 32-bit
vectors. These cases should still be handled by increasing/decreasing
the number of 16-bit elements. This is primarily to fix 8-bit element
vectors.
Another change is to stop trying to handle the load-widening based on
a higher alignment. We should still do this, but the way it was
handled wasn't really correct. We really need to modify the MMO's size
at the same time, and not just increase the result type. The
LegalizerHelper does not do this, and I think this would really
require a separate WidenMemory action (or to add a memory action
payload to the LegalizeMutation). These will now fail to legalize.
The structure of the legalizer rules makes writing concise rules here
difficult. It would be easier if the same function could answer the
query the query, and report the action to perform at the same
time. Instead these two are split into distinct predicate and action
functions. This is mostly tolerable for other cases, but the
load/store rules get pretty complicated so it's difficult to keep two
versions of these functions in sync.
2020-05-24 23:12:11 +08:00
|
|
|
}, bitcastToRegisterType(0));
|
|
|
|
|
2020-06-27 07:02:46 +08:00
|
|
|
if (!IsStore) {
|
|
|
|
// Widen suitably aligned loads by loading extra bytes. The standard
|
|
|
|
// legalization actions can't properly express widening memory operands.
|
|
|
|
Actions.customIf([=](const LegalityQuery &Query) -> bool {
|
|
|
|
return shouldWidenLoad(ST, Query, G_LOAD);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
// FIXME: load/store narrowing should be moved to lower action
|
2019-09-11 00:20:14 +08:00
|
|
|
Actions
|
|
|
|
.narrowScalarIf(
|
|
|
|
[=](const LegalityQuery &Query) -> bool {
|
2020-01-20 08:48:27 +08:00
|
|
|
return !Query.Types[0].isVector() &&
|
|
|
|
needToSplitMemOp(Query, Op == G_LOAD);
|
2019-09-11 00:20:14 +08:00
|
|
|
},
|
|
|
|
[=](const LegalityQuery &Query) -> std::pair<unsigned, LLT> {
|
|
|
|
const LLT DstTy = Query.Types[0];
|
|
|
|
const LLT PtrTy = Query.Types[1];
|
|
|
|
|
|
|
|
const unsigned DstSize = DstTy.getSizeInBits();
|
2021-06-09 08:22:45 +08:00
|
|
|
unsigned MemSize = Query.MMODescrs[0].MemoryTy.getSizeInBits();
|
2019-09-11 00:20:14 +08:00
|
|
|
|
|
|
|
// Split extloads.
|
|
|
|
if (DstSize > MemSize)
|
|
|
|
return std::make_pair(0, LLT::scalar(MemSize));
|
|
|
|
|
AMDGPU/GlobalISel: Start rewriting load/store legality rules
The current set is an incomprehensible mess riddled with ordering
hacks for various limitations in the legalizer at the time of writing,
many of which have been fixed. This takes a very small step in
correcting this.
The core first change is to start checking for fully legal cases
first, rather than trying to figure out all of the actions that could
need to be performed. It's recommended to check the legal cases first
for faster legality checks in the common case. This still has a table
listing some common cases, but it needs measuring whether this really
helps or not.
More significantly, stop trying to allow any arbitrary type with a
legal bitwidth as a legal memory type, and start using the bitcast
legalize action for them. Allowing loads of these weird vector types
produced new burdens we don't need for handling all of the
legalization artifacts. Unlike the SelectionDAG handling, this is
still not casting 64 or 16-bit element vectors to 32-bit
vectors. These cases should still be handled by increasing/decreasing
the number of 16-bit elements. This is primarily to fix 8-bit element
vectors.
Another change is to stop trying to handle the load-widening based on
a higher alignment. We should still do this, but the way it was
handled wasn't really correct. We really need to modify the MMO's size
at the same time, and not just increase the result type. The
LegalizerHelper does not do this, and I think this would really
require a separate WidenMemory action (or to add a memory action
payload to the LegalizeMutation). These will now fail to legalize.
The structure of the legalizer rules makes writing concise rules here
difficult. It would be easier if the same function could answer the
query the query, and report the action to perform at the same
time. Instead these two are split into distinct predicate and action
functions. This is mostly tolerable for other cases, but the
load/store rules get pretty complicated so it's difficult to keep two
versions of these functions in sync.
2020-05-24 23:12:11 +08:00
|
|
|
unsigned MaxSize = maxSizeForAddrSpace(ST,
|
|
|
|
PtrTy.getAddressSpace(),
|
2020-01-20 08:48:27 +08:00
|
|
|
Op == G_LOAD);
|
2019-09-11 00:20:14 +08:00
|
|
|
if (MemSize > MaxSize)
|
|
|
|
return std::make_pair(0, LLT::scalar(MaxSize));
|
|
|
|
|
2022-01-13 04:01:27 +08:00
|
|
|
uint64_t Align = Query.MMODescrs[0].AlignInBits;
|
2019-09-11 00:20:14 +08:00
|
|
|
return std::make_pair(0, LLT::scalar(Align));
|
|
|
|
})
|
|
|
|
.fewerElementsIf(
|
|
|
|
[=](const LegalityQuery &Query) -> bool {
|
2020-01-20 08:48:27 +08:00
|
|
|
return Query.Types[0].isVector() &&
|
|
|
|
needToSplitMemOp(Query, Op == G_LOAD);
|
2019-09-11 00:20:14 +08:00
|
|
|
},
|
|
|
|
[=](const LegalityQuery &Query) -> std::pair<unsigned, LLT> {
|
|
|
|
const LLT DstTy = Query.Types[0];
|
|
|
|
const LLT PtrTy = Query.Types[1];
|
|
|
|
|
|
|
|
LLT EltTy = DstTy.getElementType();
|
AMDGPU/GlobalISel: Start rewriting load/store legality rules
The current set is an incomprehensible mess riddled with ordering
hacks for various limitations in the legalizer at the time of writing,
many of which have been fixed. This takes a very small step in
correcting this.
The core first change is to start checking for fully legal cases
first, rather than trying to figure out all of the actions that could
need to be performed. It's recommended to check the legal cases first
for faster legality checks in the common case. This still has a table
listing some common cases, but it needs measuring whether this really
helps or not.
More significantly, stop trying to allow any arbitrary type with a
legal bitwidth as a legal memory type, and start using the bitcast
legalize action for them. Allowing loads of these weird vector types
produced new burdens we don't need for handling all of the
legalization artifacts. Unlike the SelectionDAG handling, this is
still not casting 64 or 16-bit element vectors to 32-bit
vectors. These cases should still be handled by increasing/decreasing
the number of 16-bit elements. This is primarily to fix 8-bit element
vectors.
Another change is to stop trying to handle the load-widening based on
a higher alignment. We should still do this, but the way it was
handled wasn't really correct. We really need to modify the MMO's size
at the same time, and not just increase the result type. The
LegalizerHelper does not do this, and I think this would really
require a separate WidenMemory action (or to add a memory action
payload to the LegalizeMutation). These will now fail to legalize.
The structure of the legalizer rules makes writing concise rules here
difficult. It would be easier if the same function could answer the
query the query, and report the action to perform at the same
time. Instead these two are split into distinct predicate and action
functions. This is mostly tolerable for other cases, but the
load/store rules get pretty complicated so it's difficult to keep two
versions of these functions in sync.
2020-05-24 23:12:11 +08:00
|
|
|
unsigned MaxSize = maxSizeForAddrSpace(ST,
|
|
|
|
PtrTy.getAddressSpace(),
|
2020-01-20 08:48:27 +08:00
|
|
|
Op == G_LOAD);
|
2019-09-11 00:20:14 +08:00
|
|
|
|
2020-01-22 02:23:45 +08:00
|
|
|
// FIXME: Handle widened to power of 2 results better. This ends
|
|
|
|
// up scalarizing.
|
|
|
|
// FIXME: 3 element stores scalarized on SI
|
|
|
|
|
2019-09-11 00:20:14 +08:00
|
|
|
// Split if it's too large for the address space.
|
2021-06-09 08:22:45 +08:00
|
|
|
unsigned MemSize = Query.MMODescrs[0].MemoryTy.getSizeInBits();
|
|
|
|
if (MemSize > MaxSize) {
|
2019-09-11 00:20:14 +08:00
|
|
|
unsigned NumElts = DstTy.getNumElements();
|
2020-01-22 01:20:02 +08:00
|
|
|
unsigned EltSize = EltTy.getSizeInBits();
|
|
|
|
|
|
|
|
if (MaxSize % EltSize == 0) {
|
|
|
|
return std::make_pair(
|
2021-06-25 15:25:41 +08:00
|
|
|
0, LLT::scalarOrVector(
|
|
|
|
ElementCount::getFixed(MaxSize / EltSize), EltTy));
|
2020-01-22 01:20:02 +08:00
|
|
|
}
|
|
|
|
|
2021-06-09 08:22:45 +08:00
|
|
|
unsigned NumPieces = MemSize / MaxSize;
|
2019-09-11 00:20:14 +08:00
|
|
|
|
|
|
|
// FIXME: Refine when odd breakdowns handled
|
|
|
|
// The scalars will need to be re-legalized.
|
|
|
|
if (NumPieces == 1 || NumPieces >= NumElts ||
|
|
|
|
NumElts % NumPieces != 0)
|
|
|
|
return std::make_pair(0, EltTy);
|
|
|
|
|
2021-06-24 16:58:21 +08:00
|
|
|
return std::make_pair(
|
|
|
|
0, LLT::fixed_vector(NumElts / NumPieces, EltTy));
|
2019-09-11 00:20:14 +08:00
|
|
|
}
|
|
|
|
|
2020-01-22 02:23:45 +08:00
|
|
|
// FIXME: We could probably handle weird extending loads better.
|
|
|
|
if (DstTy.getSizeInBits() > MemSize)
|
|
|
|
return std::make_pair(0, EltTy);
|
|
|
|
|
|
|
|
unsigned EltSize = EltTy.getSizeInBits();
|
|
|
|
unsigned DstSize = DstTy.getSizeInBits();
|
|
|
|
if (!isPowerOf2_32(DstSize)) {
|
|
|
|
// We're probably decomposing an odd sized store. Try to split
|
|
|
|
// to the widest type. TODO: Account for alignment. As-is it
|
|
|
|
// should be OK, since the new parts will be further legalized.
|
|
|
|
unsigned FloorSize = PowerOf2Floor(DstSize);
|
|
|
|
return std::make_pair(
|
2021-06-25 15:25:41 +08:00
|
|
|
0, LLT::scalarOrVector(
|
|
|
|
ElementCount::getFixed(FloorSize / EltSize), EltTy));
|
2019-09-11 00:20:14 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// May need relegalization for the scalars.
|
|
|
|
return std::make_pair(0, EltTy);
|
|
|
|
})
|
2021-05-19 05:05:49 +08:00
|
|
|
.minScalar(0, S32)
|
|
|
|
.narrowScalarIf(isWideScalarExtLoadTruncStore(0), changeTo(0, S32))
|
|
|
|
.widenScalarToNextPow2(0)
|
|
|
|
.moreElementsIf(vectorSmallerThan(0, 32), moreEltsToNext32Bit(0))
|
|
|
|
.lower();
|
2019-09-11 00:20:14 +08:00
|
|
|
}
|
2018-03-17 23:17:41 +08:00
|
|
|
|
2021-06-10 21:28:20 +08:00
|
|
|
// FIXME: Unaligned accesses not lowered.
|
2019-01-23 03:02:10 +08:00
|
|
|
auto &ExtLoads = getActionDefinitionsBuilder({G_SEXTLOAD, G_ZEXTLOAD})
|
2021-06-09 08:22:45 +08:00
|
|
|
.legalForTypesWithMemDesc({{S32, GlobalPtr, S8, 8},
|
|
|
|
{S32, GlobalPtr, S16, 2 * 8},
|
|
|
|
{S32, LocalPtr, S8, 8},
|
|
|
|
{S32, LocalPtr, S16, 16},
|
|
|
|
{S32, PrivatePtr, S8, 8},
|
|
|
|
{S32, PrivatePtr, S16, 16},
|
|
|
|
{S32, ConstantPtr, S8, 8},
|
|
|
|
{S32, ConstantPtr, S16, 2 * 8}})
|
2021-05-19 05:05:49 +08:00
|
|
|
.legalIf(
|
|
|
|
[=](const LegalityQuery &Query) -> bool {
|
|
|
|
return isLoadStoreLegal(ST, Query);
|
|
|
|
});
|
|
|
|
|
2019-01-23 03:02:10 +08:00
|
|
|
if (ST.hasFlatAddressSpace()) {
|
2019-09-11 00:20:14 +08:00
|
|
|
ExtLoads.legalForTypesWithMemDesc(
|
2021-06-09 08:22:45 +08:00
|
|
|
{{S32, FlatPtr, S8, 8}, {S32, FlatPtr, S16, 16}});
|
2019-01-23 03:02:10 +08:00
|
|
|
}
|
|
|
|
|
2021-05-19 06:22:09 +08:00
|
|
|
// Constant 32-bit is handled by addrspacecasting the 32-bit pointer to
|
|
|
|
// 64-bits.
|
|
|
|
//
|
|
|
|
// TODO: Should generalize bitcast action into coerce, which will also cover
|
|
|
|
// inserting addrspacecasts.
|
|
|
|
ExtLoads.customIf(typeIs(1, Constant32Ptr));
|
|
|
|
|
2019-01-23 03:02:10 +08:00
|
|
|
ExtLoads.clampScalar(0, S32, S32)
|
|
|
|
.widenScalarToNextPow2(0)
|
|
|
|
.lower();
|
|
|
|
|
2018-12-20 08:33:49 +08:00
|
|
|
auto &Atomics = getActionDefinitionsBuilder(
|
|
|
|
{G_ATOMICRMW_XCHG, G_ATOMICRMW_ADD, G_ATOMICRMW_SUB,
|
|
|
|
G_ATOMICRMW_AND, G_ATOMICRMW_OR, G_ATOMICRMW_XOR,
|
|
|
|
G_ATOMICRMW_MAX, G_ATOMICRMW_MIN, G_ATOMICRMW_UMAX,
|
2019-10-09 01:04:41 +08:00
|
|
|
G_ATOMICRMW_UMIN})
|
2018-12-20 08:33:49 +08:00
|
|
|
.legalFor({{S32, GlobalPtr}, {S32, LocalPtr},
|
2020-07-26 03:41:58 +08:00
|
|
|
{S64, GlobalPtr}, {S64, LocalPtr},
|
|
|
|
{S32, RegionPtr}, {S64, RegionPtr}});
|
2018-12-20 08:33:49 +08:00
|
|
|
if (ST.hasFlatAddressSpace()) {
|
|
|
|
Atomics.legalFor({{S32, FlatPtr}, {S64, FlatPtr}});
|
|
|
|
}
|
Re-commit AMDGPU/GlobalISel: Add support for simple shaders
Fix build when global-isel is disabled and fix a warning.
Summary: We can select constant/global G_LOAD, global G_STORE, and G_GEP.
Reviewers: qcolombet, MatzeB, t.p.northover, ab, arsenm
Subscribers: mehdi_amini, vkalintiris, kzhuravl, wdng, nhaehnle, mgorny, yaxunl, tony-tye, modocache, llvm-commits, dberris
Differential Revision: https://reviews.llvm.org/D26730
llvm-svn: 293551
2017-01-31 05:56:46 +08:00
|
|
|
|
2021-03-02 01:24:57 +08:00
|
|
|
auto &Atomic = getActionDefinitionsBuilder(G_ATOMICRMW_FADD);
|
2021-08-31 21:03:12 +08:00
|
|
|
if (ST.hasLDSFPAtomicAdd()) {
|
2021-03-02 01:24:57 +08:00
|
|
|
Atomic.legalFor({{S32, LocalPtr}, {S32, RegionPtr}});
|
2021-02-18 05:37:46 +08:00
|
|
|
if (ST.hasGFX90AInsts())
|
|
|
|
Atomic.legalFor({{S64, LocalPtr}});
|
2020-06-05 03:21:20 +08:00
|
|
|
}
|
2021-03-02 01:24:57 +08:00
|
|
|
if (ST.hasAtomicFaddInsts())
|
|
|
|
Atomic.legalFor({{S32, GlobalPtr}});
|
2019-08-01 11:33:15 +08:00
|
|
|
|
2019-10-09 01:04:41 +08:00
|
|
|
// BUFFER/FLAT_ATOMIC_CMP_SWAP on GCN GPUs needs input marshalling, and output
|
|
|
|
// demarshalling
|
|
|
|
getActionDefinitionsBuilder(G_ATOMIC_CMPXCHG)
|
|
|
|
.customFor({{S32, GlobalPtr}, {S64, GlobalPtr},
|
|
|
|
{S32, FlatPtr}, {S64, FlatPtr}})
|
|
|
|
.legalFor({{S32, LocalPtr}, {S64, LocalPtr},
|
|
|
|
{S32, RegionPtr}, {S64, RegionPtr}});
|
2019-01-19 05:42:55 +08:00
|
|
|
// TODO: Pointer types, any 32-bit or 64-bit vector
|
AMDGPU/GlobalISel: Replace handling of boolean values
This solves selection failures with generated selection patterns,
which would fail due to inferring the SGPR reg bank for virtual
registers with a set register class instead of VCC bank. Use
instruction selection would constrain the virtual register to a
specific class, so when the def was selected later the bank no longer
was set to VCC.
Remove the SCC reg bank. SCC isn't directly addressable, so it
requires copying from SCC to an allocatable 32-bit register during
selection, so these might as well be treated as 32-bit SGPR values.
Now any scalar boolean value that will produce an outupt in SCC should
be widened during RegBankSelect to s32. Any s1 value should be a
vector boolean during selection. This makes the vcc register bank
unambiguous with a normal SGPR during selection.
Summary of how this should now work:
- G_TRUNC is always a no-op, and never should use a vcc bank result.
- SALU boolean operations should be promoted to s32 in RegBankSelect
apply mapping
- An s1 value means vcc bank at selection. The exception is for
legalization artifacts that use s1, which are never VCC. All other
contexts should infer the VCC register classes for s1 typed
registers. The LLT for the register is now needed to infer the
correct register class. Extensions with vcc sources should be
legalized to a select of constants during RegBankSelect.
- Copy from non-vcc to vcc ensures high bits of the input value are
cleared during selection.
- SALU boolean inputs should ensure the inputs are 0/1. This includes
select, conditional branches, and carry-ins.
There are a few somewhat dirty details. One is that G_TRUNC/G_*EXT
selection ignores the usual register-bank from register class
functions, and can't handle truncates with VCC result banks. I think
this is OK, since the artifacts are specially treated anyway. This
does require some care to avoid producing cases with vcc. There will
also be no 100% reliable way to verify this rule is followed in
selection in case of register classes, and violations manifests
themselves as invalid copy instructions much later.
Standard phi handling also only considers the bank of the result
register, and doesn't insert copies to make the source banks
match. This doesn't work for vcc, so we have to manually correct phi
inputs in this case. We should add a verifier check to make sure there
are no phis with mixed vcc and non-vcc register bank inputs.
There's also some duplication with the LegalizerHelper, and some code
which should live in the helper. I don't see a good way to share
special knowledge about what types to use for intermediate operations
depending on the bank for example. Using the helper to replace
extensions with selects also seems somewhat awkward to me.
Another issue is there are some contexts calling
getRegBankFromRegClass that apparently don't have the LLT type for the
register, but I haven't yet run into a real issue from this.
This also introduces new unnecessary instructions in most cases, since
we don't yet try to optimize out the zext when the source is known to
come from a compare.
2019-11-03 00:30:59 +08:00
|
|
|
|
|
|
|
// Condition should be s32 for scalar, s1 for vector.
|
2019-01-19 05:42:55 +08:00
|
|
|
getActionDefinitionsBuilder(G_SELECT)
|
2021-06-24 16:58:21 +08:00
|
|
|
.legalForCartesianProduct({S32, S64, S16, V2S32, V2S16, V4S16, GlobalPtr,
|
|
|
|
LocalPtr, FlatPtr, PrivatePtr,
|
|
|
|
LLT::fixed_vector(2, LocalPtr),
|
|
|
|
LLT::fixed_vector(2, PrivatePtr)},
|
|
|
|
{S1, S32})
|
|
|
|
.clampScalar(0, S16, S64)
|
|
|
|
.scalarize(1)
|
|
|
|
.moreElementsIf(isSmallOddVector(0), oneMoreElement(0))
|
|
|
|
.fewerElementsIf(numElementsNotEven(0), scalarize(0))
|
|
|
|
.clampMaxNumElements(0, S32, 2)
|
|
|
|
.clampMaxNumElements(0, LocalPtr, 2)
|
|
|
|
.clampMaxNumElements(0, PrivatePtr, 2)
|
|
|
|
.scalarize(0)
|
|
|
|
.widenScalarToNextPow2(0)
|
|
|
|
.legalIf(all(isPointer(0), typeInSet(1, {S1, S32})));
|
AMDGPU/GlobalISel: Mark 32-bit G_SELECT as legal
Reviewers: arsenm
Reviewed By: arsenm
Subscribers: kzhuravl, wdng, nhaehnle, yaxunl, rovka, kristof.beyls, igorb, dstuttard, tpr, t-tye, llvm-commits
Differential Revision: https://reviews.llvm.org/D33949
llvm-svn: 304910
2017-06-07 21:54:51 +08:00
|
|
|
|
2019-01-23 06:00:19 +08:00
|
|
|
// TODO: Only the low 4/5/6 bits of the shift amount are observed, so we can
|
|
|
|
// be more flexible with the shift amount type.
|
|
|
|
auto &Shifts = getActionDefinitionsBuilder({G_SHL, G_LSHR, G_ASHR})
|
|
|
|
.legalFor({{S32, S32}, {S64, S32}});
|
2019-01-30 11:36:25 +08:00
|
|
|
if (ST.has16BitInsts()) {
|
2019-02-08 01:38:00 +08:00
|
|
|
if (ST.hasVOP3PInsts()) {
|
2020-04-12 05:04:48 +08:00
|
|
|
Shifts.legalFor({{S16, S16}, {V2S16, V2S16}})
|
2019-02-08 01:38:00 +08:00
|
|
|
.clampMaxNumElements(0, S16, 2);
|
|
|
|
} else
|
2020-04-12 05:04:48 +08:00
|
|
|
Shifts.legalFor({{S16, S16}});
|
|
|
|
|
|
|
|
// TODO: Support 16-bit shift amounts for all types
|
|
|
|
Shifts.widenScalarIf(
|
|
|
|
[=](const LegalityQuery &Query) {
|
|
|
|
// Use 16-bit shift amounts for any 16-bit shift. Otherwise we want a
|
|
|
|
// 32-bit amount.
|
|
|
|
const LLT ValTy = Query.Types[0];
|
|
|
|
const LLT AmountTy = Query.Types[1];
|
|
|
|
return ValTy.getSizeInBits() <= 16 &&
|
|
|
|
AmountTy.getSizeInBits() < 16;
|
|
|
|
}, changeTo(1, S16));
|
|
|
|
Shifts.maxScalarIf(typeIs(0, S16), 1, S16);
|
2020-01-10 03:34:43 +08:00
|
|
|
Shifts.clampScalar(1, S32, S32);
|
2019-02-08 23:06:24 +08:00
|
|
|
Shifts.widenScalarToNextPow2(0, 16);
|
2022-01-16 23:45:38 +08:00
|
|
|
Shifts.clampScalar(0, S16, S64);
|
[Intrinsic] Add sshl.sat/ushl.sat, saturated shift intrinsics.
Summary:
This patch adds two intrinsics, llvm.sshl.sat and llvm.ushl.sat,
which perform signed and unsigned saturating left shift,
respectively.
These are useful for implementing the Embedded-C fixed point
support in Clang, originally discussed in
http://lists.llvm.org/pipermail/llvm-dev/2018-August/125433.html
and
http://lists.llvm.org/pipermail/cfe-dev/2018-May/058019.html
Reviewers: leonardchan, craig.topper, bjope, jdoerfert
Subscribers: hiraditya, jdoerfert, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D83216
2020-07-16 23:02:04 +08:00
|
|
|
|
|
|
|
getActionDefinitionsBuilder({G_SSHLSAT, G_USHLSAT})
|
|
|
|
.minScalar(0, S16)
|
|
|
|
.scalarize(0)
|
|
|
|
.lower();
|
2019-02-08 03:37:44 +08:00
|
|
|
} else {
|
|
|
|
// Make sure we legalize the shift amount type first, as the general
|
|
|
|
// expansion for the shifted type will produce much worse code if it hasn't
|
|
|
|
// been truncated already.
|
|
|
|
Shifts.clampScalar(1, S32, S32);
|
2019-02-08 23:06:24 +08:00
|
|
|
Shifts.widenScalarToNextPow2(0, 32);
|
2022-01-16 23:45:38 +08:00
|
|
|
Shifts.clampScalar(0, S32, S64);
|
[Intrinsic] Add sshl.sat/ushl.sat, saturated shift intrinsics.
Summary:
This patch adds two intrinsics, llvm.sshl.sat and llvm.ushl.sat,
which perform signed and unsigned saturating left shift,
respectively.
These are useful for implementing the Embedded-C fixed point
support in Clang, originally discussed in
http://lists.llvm.org/pipermail/llvm-dev/2018-August/125433.html
and
http://lists.llvm.org/pipermail/cfe-dev/2018-May/058019.html
Reviewers: leonardchan, craig.topper, bjope, jdoerfert
Subscribers: hiraditya, jdoerfert, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D83216
2020-07-16 23:02:04 +08:00
|
|
|
|
|
|
|
getActionDefinitionsBuilder({G_SSHLSAT, G_USHLSAT})
|
|
|
|
.minScalar(0, S32)
|
|
|
|
.scalarize(0)
|
|
|
|
.lower();
|
2019-02-08 03:37:44 +08:00
|
|
|
}
|
|
|
|
Shifts.scalarize(0);
|
Re-commit AMDGPU/GlobalISel: Add support for simple shaders
Fix build when global-isel is disabled and fix a warning.
Summary: We can select constant/global G_LOAD, global G_STORE, and G_GEP.
Reviewers: qcolombet, MatzeB, t.p.northover, ab, arsenm
Subscribers: mehdi_amini, vkalintiris, kzhuravl, wdng, nhaehnle, mgorny, yaxunl, tony-tye, modocache, llvm-commits, dberris
Differential Revision: https://reviews.llvm.org/D26730
llvm-svn: 293551
2017-01-31 05:56:46 +08:00
|
|
|
|
2018-03-12 21:35:53 +08:00
|
|
|
for (unsigned Op : {G_EXTRACT_VECTOR_ELT, G_INSERT_VECTOR_ELT}) {
|
2019-01-23 04:38:15 +08:00
|
|
|
unsigned VecTypeIdx = Op == G_EXTRACT_VECTOR_ELT ? 1 : 0;
|
|
|
|
unsigned EltTypeIdx = Op == G_EXTRACT_VECTOR_ELT ? 0 : 1;
|
|
|
|
unsigned IdxTypeIdx = 2;
|
|
|
|
|
2018-03-12 21:35:53 +08:00
|
|
|
getActionDefinitionsBuilder(Op)
|
2019-07-16 03:40:59 +08:00
|
|
|
.customIf([=](const LegalityQuery &Query) {
|
2019-07-16 02:31:10 +08:00
|
|
|
const LLT EltTy = Query.Types[EltTypeIdx];
|
|
|
|
const LLT VecTy = Query.Types[VecTypeIdx];
|
|
|
|
const LLT IdxTy = Query.Types[IdxTypeIdx];
|
2020-06-15 23:54:49 +08:00
|
|
|
const unsigned EltSize = EltTy.getSizeInBits();
|
|
|
|
return (EltSize == 32 || EltSize == 64) &&
|
|
|
|
VecTy.getSizeInBits() % 32 == 0 &&
|
|
|
|
VecTy.getSizeInBits() <= MaxRegisterSize &&
|
|
|
|
IdxTy.getSizeInBits() == 32;
|
|
|
|
})
|
2020-06-16 09:35:15 +08:00
|
|
|
.bitcastIf(all(sizeIsMultipleOf32(VecTypeIdx), scalarOrEltNarrowerThan(VecTypeIdx, 32)),
|
|
|
|
bitcastToVectorElement32(VecTypeIdx))
|
2020-06-15 23:54:49 +08:00
|
|
|
//.bitcastIf(vectorSmallerThan(1, 32), bitcastToScalar(1))
|
|
|
|
.bitcastIf(
|
2020-06-16 09:35:15 +08:00
|
|
|
all(sizeIsMultipleOf32(VecTypeIdx), scalarOrEltWiderThan(VecTypeIdx, 64)),
|
2020-06-15 23:54:49 +08:00
|
|
|
[=](const LegalityQuery &Query) {
|
|
|
|
// For > 64-bit element types, try to turn this into a 64-bit
|
|
|
|
// element vector since we may be able to do better indexing
|
|
|
|
// if this is scalar. If not, fall back to 32.
|
|
|
|
const LLT EltTy = Query.Types[EltTypeIdx];
|
|
|
|
const LLT VecTy = Query.Types[VecTypeIdx];
|
|
|
|
const unsigned DstEltSize = EltTy.getSizeInBits();
|
|
|
|
const unsigned VecSize = VecTy.getSizeInBits();
|
|
|
|
|
|
|
|
const unsigned TargetEltSize = DstEltSize % 64 == 0 ? 64 : 32;
|
|
|
|
return std::make_pair(
|
2021-06-24 16:58:21 +08:00
|
|
|
VecTypeIdx,
|
|
|
|
LLT::fixed_vector(VecSize / TargetEltSize, TargetEltSize));
|
2019-01-23 04:38:15 +08:00
|
|
|
})
|
|
|
|
.clampScalar(EltTypeIdx, S32, S64)
|
|
|
|
.clampScalar(VecTypeIdx, S32, S64)
|
2020-07-27 09:25:10 +08:00
|
|
|
.clampScalar(IdxTypeIdx, S32, S32)
|
2020-07-28 10:00:50 +08:00
|
|
|
.clampMaxNumElements(VecTypeIdx, S32, 32)
|
2020-07-27 21:58:17 +08:00
|
|
|
// TODO: Clamp elements for 64-bit vectors?
|
2020-07-27 09:25:10 +08:00
|
|
|
// It should only be necessary with variable indexes.
|
|
|
|
// As a last resort, lower to the stack
|
|
|
|
.lower();
|
2018-03-12 21:35:53 +08:00
|
|
|
}
|
|
|
|
|
2019-01-23 04:38:15 +08:00
|
|
|
getActionDefinitionsBuilder(G_EXTRACT_VECTOR_ELT)
|
|
|
|
.unsupportedIf([=](const LegalityQuery &Query) {
|
|
|
|
const LLT &EltTy = Query.Types[1].getElementType();
|
|
|
|
return Query.Types[0] != EltTy;
|
|
|
|
});
|
|
|
|
|
2019-02-21 00:11:22 +08:00
|
|
|
for (unsigned Op : {G_EXTRACT, G_INSERT}) {
|
|
|
|
unsigned BigTyIdx = Op == G_EXTRACT ? 1 : 0;
|
|
|
|
unsigned LitTyIdx = Op == G_EXTRACT ? 0 : 1;
|
|
|
|
|
|
|
|
// FIXME: Doesn't handle extract of illegal sizes.
|
2019-10-08 03:13:27 +08:00
|
|
|
getActionDefinitionsBuilder(Op)
|
|
|
|
.lowerIf(all(typeIs(LitTyIdx, S16), sizeIs(BigTyIdx, 32)))
|
2021-12-23 21:09:51 +08:00
|
|
|
.lowerIf([=](const LegalityQuery &Query) {
|
|
|
|
// Sub-vector(or single element) insert and extract.
|
|
|
|
// TODO: verify immediate offset here since lower only works with
|
|
|
|
// whole elements.
|
|
|
|
const LLT BigTy = Query.Types[BigTyIdx];
|
|
|
|
return BigTy.isVector();
|
|
|
|
})
|
2019-10-08 03:13:27 +08:00
|
|
|
// FIXME: Multiples of 16 should not be legal.
|
2019-02-08 01:25:51 +08:00
|
|
|
.legalIf([=](const LegalityQuery &Query) {
|
2019-02-21 00:11:22 +08:00
|
|
|
const LLT BigTy = Query.Types[BigTyIdx];
|
|
|
|
const LLT LitTy = Query.Types[LitTyIdx];
|
|
|
|
return (BigTy.getSizeInBits() % 32 == 0) &&
|
|
|
|
(LitTy.getSizeInBits() % 16 == 0);
|
|
|
|
})
|
|
|
|
.widenScalarIf(
|
|
|
|
[=](const LegalityQuery &Query) {
|
|
|
|
const LLT BigTy = Query.Types[BigTyIdx];
|
|
|
|
return (BigTy.getScalarSizeInBits() < 16);
|
|
|
|
},
|
|
|
|
LegalizeMutations::widenScalarOrEltToNextPow2(BigTyIdx, 16))
|
2019-02-08 01:25:51 +08:00
|
|
|
.widenScalarIf(
|
2019-02-21 00:11:22 +08:00
|
|
|
[=](const LegalityQuery &Query) {
|
|
|
|
const LLT LitTy = Query.Types[LitTyIdx];
|
|
|
|
return (LitTy.getScalarSizeInBits() < 16);
|
|
|
|
},
|
|
|
|
LegalizeMutations::widenScalarOrEltToNextPow2(LitTyIdx, 16))
|
2019-04-22 23:22:46 +08:00
|
|
|
.moreElementsIf(isSmallOddVector(BigTyIdx), oneMoreElement(BigTyIdx))
|
|
|
|
.widenScalarToNextPow2(BigTyIdx, 32);
|
|
|
|
|
2019-02-21 00:11:22 +08:00
|
|
|
}
|
2018-03-06 00:25:15 +08:00
|
|
|
|
2019-09-10 02:57:51 +08:00
|
|
|
auto &BuildVector = getActionDefinitionsBuilder(G_BUILD_VECTOR)
|
|
|
|
.legalForCartesianProduct(AllS32Vectors, {S32})
|
|
|
|
.legalForCartesianProduct(AllS64Vectors, {S64})
|
2019-10-02 09:02:18 +08:00
|
|
|
.clampNumElements(0, V16S32, V32S32)
|
2019-10-10 06:44:43 +08:00
|
|
|
.clampNumElements(0, V2S64, V16S64)
|
|
|
|
.fewerElementsIf(isWideVec16(0), changeTo(0, V2S16));
|
2019-09-10 02:57:51 +08:00
|
|
|
|
2019-09-10 01:04:18 +08:00
|
|
|
if (ST.hasScalarPackInsts()) {
|
2020-01-05 04:35:26 +08:00
|
|
|
BuildVector
|
|
|
|
// FIXME: Should probably widen s1 vectors straight to s32
|
|
|
|
.minScalarOrElt(0, S16)
|
|
|
|
// Widen source elements and produce a G_BUILD_VECTOR_TRUNC
|
|
|
|
.minScalar(1, S32);
|
|
|
|
|
2019-09-10 01:04:18 +08:00
|
|
|
getActionDefinitionsBuilder(G_BUILD_VECTOR_TRUNC)
|
|
|
|
.legalFor({V2S16, S32})
|
|
|
|
.lower();
|
2020-01-05 04:35:26 +08:00
|
|
|
BuildVector.minScalarOrElt(0, S32);
|
2019-09-10 01:04:18 +08:00
|
|
|
} else {
|
2020-01-05 04:35:26 +08:00
|
|
|
BuildVector.customFor({V2S16, S16});
|
|
|
|
BuildVector.minScalarOrElt(0, S32);
|
|
|
|
|
2019-09-10 01:04:18 +08:00
|
|
|
getActionDefinitionsBuilder(G_BUILD_VECTOR_TRUNC)
|
2020-01-05 04:35:26 +08:00
|
|
|
.customFor({V2S16, S32})
|
2019-09-10 01:04:18 +08:00
|
|
|
.lower();
|
|
|
|
}
|
|
|
|
|
2020-01-05 04:35:26 +08:00
|
|
|
BuildVector.legalIf(isRegisterType(0));
|
|
|
|
|
|
|
|
// FIXME: Clamp maximum size
|
2019-01-08 09:30:02 +08:00
|
|
|
getActionDefinitionsBuilder(G_CONCAT_VECTORS)
|
2020-08-04 02:13:38 +08:00
|
|
|
.legalIf(all(isRegisterType(0), isRegisterType(1)))
|
|
|
|
.clampMaxNumElements(0, S32, 32)
|
|
|
|
.clampMaxNumElements(1, S16, 2) // TODO: Make 4?
|
|
|
|
.clampMaxNumElements(0, S16, 64);
|
2019-01-08 09:30:02 +08:00
|
|
|
|
2020-01-02 04:51:46 +08:00
|
|
|
// TODO: Don't fully scalarize v2s16 pieces? Or combine out thosse
|
|
|
|
// pre-legalize.
|
|
|
|
if (ST.hasVOP3PInsts()) {
|
|
|
|
getActionDefinitionsBuilder(G_SHUFFLE_VECTOR)
|
|
|
|
.customFor({V2S16, V2S16})
|
|
|
|
.lower();
|
|
|
|
} else
|
|
|
|
getActionDefinitionsBuilder(G_SHUFFLE_VECTOR).lower();
|
2019-08-14 00:09:07 +08:00
|
|
|
|
2018-03-12 21:35:43 +08:00
|
|
|
// Merge/Unmerge
|
|
|
|
for (unsigned Op : {G_MERGE_VALUES, G_UNMERGE_VALUES}) {
|
|
|
|
unsigned BigTyIdx = Op == G_MERGE_VALUES ? 0 : 1;
|
|
|
|
unsigned LitTyIdx = Op == G_MERGE_VALUES ? 1 : 0;
|
|
|
|
|
2019-01-21 02:40:36 +08:00
|
|
|
auto notValidElt = [=](const LegalityQuery &Query, unsigned TypeIdx) {
|
2020-03-16 22:42:15 +08:00
|
|
|
const LLT Ty = Query.Types[TypeIdx];
|
2019-01-21 02:40:36 +08:00
|
|
|
if (Ty.isVector()) {
|
|
|
|
const LLT &EltTy = Ty.getElementType();
|
2020-03-16 22:42:15 +08:00
|
|
|
if (EltTy.getSizeInBits() < 8 || EltTy.getSizeInBits() > 512)
|
2019-01-21 02:40:36 +08:00
|
|
|
return true;
|
|
|
|
if (!isPowerOf2_32(EltTy.getSizeInBits()))
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
|
2019-10-08 03:05:58 +08:00
|
|
|
auto &Builder = getActionDefinitionsBuilder(Op)
|
2020-08-23 06:00:08 +08:00
|
|
|
.legalIf(all(isRegisterType(0), isRegisterType(1)))
|
2020-03-30 06:04:53 +08:00
|
|
|
.lowerFor({{S16, V2S16}})
|
|
|
|
.lowerIf([=](const LegalityQuery &Query) {
|
2020-03-30 03:51:54 +08:00
|
|
|
const LLT BigTy = Query.Types[BigTyIdx];
|
|
|
|
return BigTy.getSizeInBits() == 32;
|
2020-03-30 06:04:53 +08:00
|
|
|
})
|
2020-01-21 22:02:42 +08:00
|
|
|
// Try to widen to s16 first for small types.
|
|
|
|
// TODO: Only do this on targets with legal s16 shifts
|
2020-05-24 06:28:12 +08:00
|
|
|
.minScalarOrEltIf(scalarNarrowerThan(LitTyIdx, 16), LitTyIdx, S16)
|
2019-01-30 07:17:35 +08:00
|
|
|
.widenScalarToNextPow2(LitTyIdx, /*Min*/ 16)
|
2019-08-22 00:59:10 +08:00
|
|
|
.moreElementsIf(isSmallOddVector(BigTyIdx), oneMoreElement(BigTyIdx))
|
2019-08-14 00:26:28 +08:00
|
|
|
.fewerElementsIf(all(typeIs(0, S16), vectorWiderThan(1, 32),
|
|
|
|
elementTypeIs(1, S16)),
|
|
|
|
changeTo(1, V2S16))
|
2020-01-21 22:02:42 +08:00
|
|
|
// Clamp the little scalar to s8-s256 and make it a power of 2. It's not
|
|
|
|
// worth considering the multiples of 64 since 2*192 and 2*384 are not
|
|
|
|
// valid.
|
2020-03-16 22:42:15 +08:00
|
|
|
.clampScalar(LitTyIdx, S32, S512)
|
2020-01-21 22:02:42 +08:00
|
|
|
.widenScalarToNextPow2(LitTyIdx, /*Min*/ 32)
|
2019-01-21 02:40:36 +08:00
|
|
|
// Break up vectors with weird elements into scalars
|
|
|
|
.fewerElementsIf(
|
2020-03-16 22:42:15 +08:00
|
|
|
[=](const LegalityQuery &Query) { return notValidElt(Query, LitTyIdx); },
|
2019-01-25 08:51:00 +08:00
|
|
|
scalarize(0))
|
2019-01-21 02:40:36 +08:00
|
|
|
.fewerElementsIf(
|
2020-03-16 22:42:15 +08:00
|
|
|
[=](const LegalityQuery &Query) { return notValidElt(Query, BigTyIdx); },
|
2019-01-25 08:51:00 +08:00
|
|
|
scalarize(1))
|
2020-06-14 06:32:30 +08:00
|
|
|
.clampScalar(BigTyIdx, S32, MaxScalar);
|
2019-10-08 03:05:58 +08:00
|
|
|
|
|
|
|
if (Op == G_MERGE_VALUES) {
|
|
|
|
Builder.widenScalarIf(
|
|
|
|
// TODO: Use 16-bit shifts if legal for 8-bit values?
|
2019-01-21 02:40:36 +08:00
|
|
|
[=](const LegalityQuery &Query) {
|
2019-10-08 03:05:58 +08:00
|
|
|
const LLT Ty = Query.Types[LitTyIdx];
|
|
|
|
return Ty.getSizeInBits() < 32;
|
2019-01-21 02:40:36 +08:00
|
|
|
},
|
2019-10-08 03:05:58 +08:00
|
|
|
changeTo(LitTyIdx, S32));
|
|
|
|
}
|
|
|
|
|
|
|
|
Builder.widenScalarIf(
|
|
|
|
[=](const LegalityQuery &Query) {
|
|
|
|
const LLT Ty = Query.Types[BigTyIdx];
|
|
|
|
return !isPowerOf2_32(Ty.getSizeInBits()) &&
|
|
|
|
Ty.getSizeInBits() % 16 != 0;
|
|
|
|
},
|
|
|
|
[=](const LegalityQuery &Query) {
|
|
|
|
// Pick the next power of 2, or a multiple of 64 over 128.
|
|
|
|
// Whichever is smaller.
|
|
|
|
const LLT &Ty = Query.Types[BigTyIdx];
|
|
|
|
unsigned NewSizeInBits = 1 << Log2_32_Ceil(Ty.getSizeInBits() + 1);
|
|
|
|
if (NewSizeInBits >= 256) {
|
|
|
|
unsigned RoundedTo = alignTo<64>(Ty.getSizeInBits() + 1);
|
|
|
|
if (RoundedTo < NewSizeInBits)
|
|
|
|
NewSizeInBits = RoundedTo;
|
|
|
|
}
|
|
|
|
return std::make_pair(BigTyIdx, LLT::scalar(NewSizeInBits));
|
|
|
|
})
|
2018-03-12 21:35:43 +08:00
|
|
|
// Any vectors left are the wrong size. Scalarize them.
|
2019-01-25 08:51:00 +08:00
|
|
|
.scalarize(0)
|
|
|
|
.scalarize(1);
|
2018-03-12 21:35:43 +08:00
|
|
|
}
|
|
|
|
|
2020-02-05 05:06:34 +08:00
|
|
|
// S64 is only legal on SALU, and needs to be broken into 32-bit elements in
|
|
|
|
// RegBankSelect.
|
|
|
|
auto &SextInReg = getActionDefinitionsBuilder(G_SEXT_INREG)
|
|
|
|
.legalFor({{S32}, {S64}});
|
|
|
|
|
2020-01-12 08:05:06 +08:00
|
|
|
if (ST.hasVOP3PInsts()) {
|
2020-02-05 05:06:34 +08:00
|
|
|
SextInReg.lowerFor({{V2S16}})
|
2020-01-12 08:05:06 +08:00
|
|
|
// Prefer to reduce vector widths for 16-bit vectors before lowering, to
|
|
|
|
// get more vector shift opportunities, since we'll get those when
|
|
|
|
// expanded.
|
2021-12-23 21:09:51 +08:00
|
|
|
.clampMaxNumElementsStrict(0, S16, 2);
|
2020-01-12 08:05:06 +08:00
|
|
|
} else if (ST.has16BitInsts()) {
|
|
|
|
SextInReg.lowerFor({{S32}, {S64}, {S16}});
|
|
|
|
} else {
|
|
|
|
// Prefer to promote to s32 before lowering if we don't have 16-bit
|
|
|
|
// shifts. This avoid a lot of intermediate truncate and extend operations.
|
|
|
|
SextInReg.lowerFor({{S32}, {S64}});
|
|
|
|
}
|
|
|
|
|
|
|
|
SextInReg
|
|
|
|
.scalarize(0)
|
2020-02-05 05:06:34 +08:00
|
|
|
.clampScalar(0, S32, S64)
|
2020-01-12 07:03:18 +08:00
|
|
|
.lower();
|
[globalisel] Add G_SEXT_INREG
Summary:
Targets often have instructions that can sign-extend certain cases faster
than the equivalent shift-left/arithmetic-shift-right. Such cases can be
identified by matching a shift-left/shift-right pair but there are some
issues with this in the context of combines. For example, suppose you can
sign-extend 8-bit up to 32-bit with a target extend instruction.
%1:_(s32) = G_SHL %0:_(s32), i32 24 # (I've inlined the G_CONSTANT for brevity)
%2:_(s32) = G_ASHR %1:_(s32), i32 24
%3:_(s32) = G_ASHR %2:_(s32), i32 1
would reasonably combine to:
%1:_(s32) = G_SHL %0:_(s32), i32 24
%2:_(s32) = G_ASHR %1:_(s32), i32 25
which no longer matches the special case. If your shifts and extend are
equal cost, this would break even as a pair of shifts but if your shift is
more expensive than the extend then it's cheaper as:
%2:_(s32) = G_SEXT_INREG %0:_(s32), i32 8
%3:_(s32) = G_ASHR %2:_(s32), i32 1
It's possible to match the shift-pair in ISel and emit an extend and ashr.
However, this is far from the only way to break this shift pair and make
it hard to match the extends. Another example is that with the right
known-zeros, this:
%1:_(s32) = G_SHL %0:_(s32), i32 24
%2:_(s32) = G_ASHR %1:_(s32), i32 24
%3:_(s32) = G_MUL %2:_(s32), i32 2
can become:
%1:_(s32) = G_SHL %0:_(s32), i32 24
%2:_(s32) = G_ASHR %1:_(s32), i32 23
All upstream targets have been configured to lower it to the current
G_SHL,G_ASHR pair but will likely want to make it legal in some cases to
handle their faster cases.
To follow-up: Provide a way to legalize based on the constant. At the
moment, I'm thinking that the best way to achieve this is to provide the
MI in LegalityQuery but that opens the door to breaking core principles
of the legalizer (legality is not context sensitive). That said, it's
worth noting that looking at other instructions and acting on that
information doesn't violate this principle in itself. It's only a
violation if, at the end of legalization, a pass that checks legality
without being able to see the context would say an instruction might not be
legal. That's a fairly subtle distinction so to give a concrete example,
saying %2 in:
%1 = G_CONSTANT 16
%2 = G_SEXT_INREG %0, %1
is legal is in violation of that principle if the legality of %2 depends
on %1 being constant and/or being 16. However, legalizing to either:
%2 = G_SEXT_INREG %0, 16
or:
%1 = G_CONSTANT 16
%2:_(s32) = G_SHL %0, %1
%3:_(s32) = G_ASHR %2, %1
depending on whether %1 is constant and 16 does not violate that principle
since both outputs are genuinely legal.
Reviewers: bogner, aditya_nandakumar, volkan, aemerson, paquette, arsenm
Subscribers: sdardis, jvesely, wdng, nhaehnle, rovka, kristof.beyls, javed.absar, hiraditya, jrtc27, atanasyan, Petar.Avramovic, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D61289
llvm-svn: 368487
2019-08-10 05:11:20 +08:00
|
|
|
|
2021-09-07 22:18:19 +08:00
|
|
|
getActionDefinitionsBuilder({G_ROTR, G_ROTL})
|
|
|
|
.scalarize(0)
|
|
|
|
.lower();
|
|
|
|
|
2020-03-20 10:48:13 +08:00
|
|
|
// TODO: Only Try to form v2s16 with legal packed instructions.
|
2020-03-20 09:25:27 +08:00
|
|
|
getActionDefinitionsBuilder(G_FSHR)
|
|
|
|
.legalFor({{S32, S32}})
|
2020-03-20 10:48:13 +08:00
|
|
|
.lowerFor({{V2S16, V2S16}})
|
2021-12-23 21:09:51 +08:00
|
|
|
.clampMaxNumElementsStrict(0, S16, 2)
|
2020-03-20 09:25:27 +08:00
|
|
|
.scalarize(0)
|
|
|
|
.lower();
|
|
|
|
|
2020-03-20 10:48:13 +08:00
|
|
|
if (ST.hasVOP3PInsts()) {
|
|
|
|
getActionDefinitionsBuilder(G_FSHL)
|
|
|
|
.lowerFor({{V2S16, V2S16}})
|
2021-12-23 21:09:51 +08:00
|
|
|
.clampMaxNumElementsStrict(0, S16, 2)
|
2020-03-20 10:48:13 +08:00
|
|
|
.scalarize(0)
|
|
|
|
.lower();
|
|
|
|
} else {
|
|
|
|
getActionDefinitionsBuilder(G_FSHL)
|
|
|
|
.scalarize(0)
|
|
|
|
.lower();
|
|
|
|
}
|
|
|
|
|
2020-01-05 01:50:18 +08:00
|
|
|
getActionDefinitionsBuilder(G_READCYCLECOUNTER)
|
|
|
|
.legalFor({S64});
|
|
|
|
|
2020-07-25 22:27:16 +08:00
|
|
|
getActionDefinitionsBuilder(G_FENCE)
|
|
|
|
.alwaysLegal();
|
|
|
|
|
2021-03-09 14:10:00 +08:00
|
|
|
getActionDefinitionsBuilder({G_SMULO, G_UMULO})
|
|
|
|
.scalarize(0)
|
|
|
|
.minScalar(0, S32)
|
|
|
|
.lower();
|
|
|
|
|
2021-04-30 21:57:44 +08:00
|
|
|
getActionDefinitionsBuilder({G_SBFX, G_UBFX})
|
|
|
|
.legalFor({{S32, S32}, {S64, S32}})
|
|
|
|
.clampScalar(1, S32, S32)
|
|
|
|
.clampScalar(0, S32, S64)
|
|
|
|
.widenScalarToNextPow2(0)
|
|
|
|
.scalarize(0);
|
|
|
|
|
2020-01-22 06:12:26 +08:00
|
|
|
getActionDefinitionsBuilder({
|
|
|
|
// TODO: Verify V_BFI_B32 is generated from expanded bit ops
|
|
|
|
G_FCOPYSIGN,
|
|
|
|
|
|
|
|
G_ATOMIC_CMPXCHG_WITH_SUCCESS,
|
2020-07-25 22:17:49 +08:00
|
|
|
G_ATOMICRMW_NAND,
|
|
|
|
G_ATOMICRMW_FSUB,
|
2020-01-22 06:12:26 +08:00
|
|
|
G_READ_REGISTER,
|
|
|
|
G_WRITE_REGISTER,
|
|
|
|
|
|
|
|
G_SADDO, G_SSUBO,
|
|
|
|
|
|
|
|
// TODO: Implement
|
2020-03-20 10:48:13 +08:00
|
|
|
G_FMINIMUM, G_FMAXIMUM}).lower();
|
2020-01-22 06:12:26 +08:00
|
|
|
|
2021-09-07 17:30:11 +08:00
|
|
|
getActionDefinitionsBuilder({G_MEMCPY, G_MEMCPY_INLINE, G_MEMMOVE, G_MEMSET})
|
|
|
|
.lower();
|
|
|
|
|
2019-09-10 04:55:49 +08:00
|
|
|
getActionDefinitionsBuilder({G_VASTART, G_VAARG, G_BRJT, G_JUMP_TABLE,
|
2020-05-30 23:04:15 +08:00
|
|
|
G_INDEXED_LOAD, G_INDEXED_SEXTLOAD,
|
2019-09-10 04:55:49 +08:00
|
|
|
G_INDEXED_ZEXTLOAD, G_INDEXED_STORE})
|
|
|
|
.unsupported();
|
|
|
|
|
2021-05-29 10:36:56 +08:00
|
|
|
getLegacyLegalizerInfo().computeTables();
|
2018-06-01 00:16:48 +08:00
|
|
|
verify(*ST.getInstrInfo());
|
Re-commit AMDGPU/GlobalISel: Add support for simple shaders
Fix build when global-isel is disabled and fix a warning.
Summary: We can select constant/global G_LOAD, global G_STORE, and G_GEP.
Reviewers: qcolombet, MatzeB, t.p.northover, ab, arsenm
Subscribers: mehdi_amini, vkalintiris, kzhuravl, wdng, nhaehnle, mgorny, yaxunl, tony-tye, modocache, llvm-commits, dberris
Differential Revision: https://reviews.llvm.org/D26730
llvm-svn: 293551
2017-01-31 05:56:46 +08:00
|
|
|
}
|
2019-02-08 10:40:47 +08:00
|
|
|
|
2020-06-10 05:02:12 +08:00
|
|
|
bool AMDGPULegalizerInfo::legalizeCustom(LegalizerHelper &Helper,
|
|
|
|
MachineInstr &MI) const {
|
|
|
|
MachineIRBuilder &B = Helper.MIRBuilder;
|
|
|
|
MachineRegisterInfo &MRI = *B.getMRI();
|
|
|
|
|
2019-02-08 10:40:47 +08:00
|
|
|
switch (MI.getOpcode()) {
|
|
|
|
case TargetOpcode::G_ADDRSPACE_CAST:
|
AMDGPU/GlobalISel: Rename MIRBuilder to B. NFC
Reviewers: arsenm
Reviewed By: arsenm
Subscribers: kzhuravl, jvesely, wdng, nhaehnle, yaxunl, rovka, dstuttard, tpr, t-tye, hiraditya, Petar.Avramovic, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D67374
llvm-svn: 371467
2019-09-10 07:06:13 +08:00
|
|
|
return legalizeAddrSpaceCast(MI, MRI, B);
|
2019-05-17 20:19:57 +08:00
|
|
|
case TargetOpcode::G_FRINT:
|
AMDGPU/GlobalISel: Rename MIRBuilder to B. NFC
Reviewers: arsenm
Reviewed By: arsenm
Subscribers: kzhuravl, jvesely, wdng, nhaehnle, yaxunl, rovka, dstuttard, tpr, t-tye, hiraditya, Petar.Avramovic, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D67374
llvm-svn: 371467
2019-09-10 07:06:13 +08:00
|
|
|
return legalizeFrint(MI, MRI, B);
|
2019-05-17 20:20:05 +08:00
|
|
|
case TargetOpcode::G_FCEIL:
|
AMDGPU/GlobalISel: Rename MIRBuilder to B. NFC
Reviewers: arsenm
Reviewed By: arsenm
Subscribers: kzhuravl, jvesely, wdng, nhaehnle, yaxunl, rovka, dstuttard, tpr, t-tye, hiraditya, Petar.Avramovic, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D67374
llvm-svn: 371467
2019-09-10 07:06:13 +08:00
|
|
|
return legalizeFceil(MI, MRI, B);
|
2020-08-10 16:10:46 +08:00
|
|
|
case TargetOpcode::G_FREM:
|
|
|
|
return legalizeFrem(MI, MRI, B);
|
2019-05-17 20:20:01 +08:00
|
|
|
case TargetOpcode::G_INTRINSIC_TRUNC:
|
AMDGPU/GlobalISel: Rename MIRBuilder to B. NFC
Reviewers: arsenm
Reviewed By: arsenm
Subscribers: kzhuravl, jvesely, wdng, nhaehnle, yaxunl, rovka, dstuttard, tpr, t-tye, hiraditya, Petar.Avramovic, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D67374
llvm-svn: 371467
2019-09-10 07:06:13 +08:00
|
|
|
return legalizeIntrinsicTrunc(MI, MRI, B);
|
2019-05-18 07:05:18 +08:00
|
|
|
case TargetOpcode::G_SITOFP:
|
AMDGPU/GlobalISel: Rename MIRBuilder to B. NFC
Reviewers: arsenm
Reviewed By: arsenm
Subscribers: kzhuravl, jvesely, wdng, nhaehnle, yaxunl, rovka, dstuttard, tpr, t-tye, hiraditya, Petar.Avramovic, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D67374
llvm-svn: 371467
2019-09-10 07:06:13 +08:00
|
|
|
return legalizeITOFP(MI, MRI, B, true);
|
2019-05-18 07:05:18 +08:00
|
|
|
case TargetOpcode::G_UITOFP:
|
AMDGPU/GlobalISel: Rename MIRBuilder to B. NFC
Reviewers: arsenm
Reviewed By: arsenm
Subscribers: kzhuravl, jvesely, wdng, nhaehnle, yaxunl, rovka, dstuttard, tpr, t-tye, hiraditya, Petar.Avramovic, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D67374
llvm-svn: 371467
2019-09-10 07:06:13 +08:00
|
|
|
return legalizeITOFP(MI, MRI, B, false);
|
2020-01-05 05:40:45 +08:00
|
|
|
case TargetOpcode::G_FPTOSI:
|
|
|
|
return legalizeFPTOI(MI, MRI, B, true);
|
|
|
|
case TargetOpcode::G_FPTOUI:
|
|
|
|
return legalizeFPTOI(MI, MRI, B, false);
|
2019-07-11 00:31:19 +08:00
|
|
|
case TargetOpcode::G_FMINNUM:
|
|
|
|
case TargetOpcode::G_FMAXNUM:
|
|
|
|
case TargetOpcode::G_FMINNUM_IEEE:
|
|
|
|
case TargetOpcode::G_FMAXNUM_IEEE:
|
2020-06-10 05:02:12 +08:00
|
|
|
return legalizeMinNumMaxNum(Helper, MI);
|
2019-07-16 03:40:59 +08:00
|
|
|
case TargetOpcode::G_EXTRACT_VECTOR_ELT:
|
AMDGPU/GlobalISel: Rename MIRBuilder to B. NFC
Reviewers: arsenm
Reviewed By: arsenm
Subscribers: kzhuravl, jvesely, wdng, nhaehnle, yaxunl, rovka, dstuttard, tpr, t-tye, hiraditya, Petar.Avramovic, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D67374
llvm-svn: 371467
2019-09-10 07:06:13 +08:00
|
|
|
return legalizeExtractVectorElt(MI, MRI, B);
|
2019-07-16 03:40:59 +08:00
|
|
|
case TargetOpcode::G_INSERT_VECTOR_ELT:
|
AMDGPU/GlobalISel: Rename MIRBuilder to B. NFC
Reviewers: arsenm
Reviewed By: arsenm
Subscribers: kzhuravl, jvesely, wdng, nhaehnle, yaxunl, rovka, dstuttard, tpr, t-tye, hiraditya, Petar.Avramovic, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D67374
llvm-svn: 371467
2019-09-10 07:06:13 +08:00
|
|
|
return legalizeInsertVectorElt(MI, MRI, B);
|
2020-01-02 04:51:46 +08:00
|
|
|
case TargetOpcode::G_SHUFFLE_VECTOR:
|
|
|
|
return legalizeShuffleVector(MI, MRI, B);
|
2019-08-30 04:06:48 +08:00
|
|
|
case TargetOpcode::G_FSIN:
|
|
|
|
case TargetOpcode::G_FCOS:
|
AMDGPU/GlobalISel: Rename MIRBuilder to B. NFC
Reviewers: arsenm
Reviewed By: arsenm
Subscribers: kzhuravl, jvesely, wdng, nhaehnle, yaxunl, rovka, dstuttard, tpr, t-tye, hiraditya, Petar.Avramovic, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D67374
llvm-svn: 371467
2019-09-10 07:06:13 +08:00
|
|
|
return legalizeSinCos(MI, MRI, B);
|
2019-09-10 01:13:44 +08:00
|
|
|
case TargetOpcode::G_GLOBAL_VALUE:
|
AMDGPU/GlobalISel: Rename MIRBuilder to B. NFC
Reviewers: arsenm
Reviewed By: arsenm
Subscribers: kzhuravl, jvesely, wdng, nhaehnle, yaxunl, rovka, dstuttard, tpr, t-tye, hiraditya, Petar.Avramovic, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D67374
llvm-svn: 371467
2019-09-10 07:06:13 +08:00
|
|
|
return legalizeGlobalValue(MI, MRI, B);
|
2019-09-11 00:42:31 +08:00
|
|
|
case TargetOpcode::G_LOAD:
|
2021-05-19 06:22:09 +08:00
|
|
|
case TargetOpcode::G_SEXTLOAD:
|
|
|
|
case TargetOpcode::G_ZEXTLOAD:
|
2020-05-25 02:31:06 +08:00
|
|
|
return legalizeLoad(Helper, MI);
|
2019-09-13 08:44:35 +08:00
|
|
|
case TargetOpcode::G_FMAD:
|
|
|
|
return legalizeFMad(MI, MRI, B);
|
AMDGPU/GlobalISel: Legalize fast unsafe FDIV
Reviewers: arsenm
Reviewed By: arsenm
Subscribers: kzhuravl, jvesely, wdng, nhaehnle, yaxunl, rovka, dstuttard, tpr, t-tye, hiraditya, Petar.Avramovic, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D69231
llvm-svn: 375460
2019-10-22 06:18:26 +08:00
|
|
|
case TargetOpcode::G_FDIV:
|
|
|
|
return legalizeFDIV(MI, MRI, B);
|
2020-02-12 09:51:02 +08:00
|
|
|
case TargetOpcode::G_UDIV:
|
|
|
|
case TargetOpcode::G_UREM:
|
2021-04-12 18:19:47 +08:00
|
|
|
case TargetOpcode::G_UDIVREM:
|
|
|
|
return legalizeUnsignedDIV_REM(MI, MRI, B);
|
2020-02-12 09:48:45 +08:00
|
|
|
case TargetOpcode::G_SDIV:
|
|
|
|
case TargetOpcode::G_SREM:
|
2021-04-12 18:19:47 +08:00
|
|
|
case TargetOpcode::G_SDIVREM:
|
|
|
|
return legalizeSignedDIV_REM(MI, MRI, B);
|
2019-10-09 01:04:41 +08:00
|
|
|
case TargetOpcode::G_ATOMIC_CMPXCHG:
|
|
|
|
return legalizeAtomicCmpXChg(MI, MRI, B);
|
2020-01-22 11:29:30 +08:00
|
|
|
case TargetOpcode::G_FLOG:
|
2020-05-29 16:42:00 +08:00
|
|
|
return legalizeFlog(MI, B, numbers::ln2f);
|
2020-01-22 11:29:30 +08:00
|
|
|
case TargetOpcode::G_FLOG10:
|
|
|
|
return legalizeFlog(MI, B, numbers::ln2f / numbers::ln10f);
|
2020-01-25 09:53:26 +08:00
|
|
|
case TargetOpcode::G_FEXP:
|
|
|
|
return legalizeFExp(MI, B);
|
2020-02-21 07:59:08 +08:00
|
|
|
case TargetOpcode::G_FPOW:
|
|
|
|
return legalizeFPow(MI, B);
|
2020-01-24 23:01:15 +08:00
|
|
|
case TargetOpcode::G_FFLOOR:
|
|
|
|
return legalizeFFloor(MI, MRI, B);
|
2020-01-05 04:35:26 +08:00
|
|
|
case TargetOpcode::G_BUILD_VECTOR:
|
|
|
|
return legalizeBuildVector(MI, MRI, B);
|
2021-08-04 00:11:08 +08:00
|
|
|
case TargetOpcode::G_CTLZ:
|
|
|
|
case TargetOpcode::G_CTTZ:
|
|
|
|
return legalizeCTLZ_CTTZ(MI, MRI, B);
|
2019-02-08 10:40:47 +08:00
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
llvm_unreachable("expected switch to return");
|
|
|
|
}
|
|
|
|
|
2019-06-28 09:16:46 +08:00
|
|
|
Register AMDGPULegalizerInfo::getSegmentAperture(
|
2019-02-08 10:40:47 +08:00
|
|
|
unsigned AS,
|
|
|
|
MachineRegisterInfo &MRI,
|
AMDGPU/GlobalISel: Rename MIRBuilder to B. NFC
Reviewers: arsenm
Reviewed By: arsenm
Subscribers: kzhuravl, jvesely, wdng, nhaehnle, yaxunl, rovka, dstuttard, tpr, t-tye, hiraditya, Petar.Avramovic, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D67374
llvm-svn: 371467
2019-09-10 07:06:13 +08:00
|
|
|
MachineIRBuilder &B) const {
|
|
|
|
MachineFunction &MF = B.getMF();
|
2019-02-08 10:40:47 +08:00
|
|
|
const GCNSubtarget &ST = MF.getSubtarget<GCNSubtarget>();
|
|
|
|
const LLT S32 = LLT::scalar(32);
|
|
|
|
|
2019-10-04 16:35:38 +08:00
|
|
|
assert(AS == AMDGPUAS::LOCAL_ADDRESS || AS == AMDGPUAS::PRIVATE_ADDRESS);
|
|
|
|
|
2019-02-08 10:40:47 +08:00
|
|
|
if (ST.hasApertureRegs()) {
|
|
|
|
// FIXME: Use inline constants (src_{shared, private}_base) instead of
|
|
|
|
// getreg.
|
|
|
|
unsigned Offset = AS == AMDGPUAS::LOCAL_ADDRESS ?
|
|
|
|
AMDGPU::Hwreg::OFFSET_SRC_SHARED_BASE :
|
|
|
|
AMDGPU::Hwreg::OFFSET_SRC_PRIVATE_BASE;
|
|
|
|
unsigned WidthM1 = AS == AMDGPUAS::LOCAL_ADDRESS ?
|
|
|
|
AMDGPU::Hwreg::WIDTH_M1_SRC_SHARED_BASE :
|
|
|
|
AMDGPU::Hwreg::WIDTH_M1_SRC_PRIVATE_BASE;
|
|
|
|
unsigned Encoding =
|
|
|
|
AMDGPU::Hwreg::ID_MEM_BASES << AMDGPU::Hwreg::ID_SHIFT_ |
|
|
|
|
Offset << AMDGPU::Hwreg::OFFSET_SHIFT_ |
|
|
|
|
WidthM1 << AMDGPU::Hwreg::WIDTH_M1_SHIFT_;
|
|
|
|
|
2019-06-28 09:16:46 +08:00
|
|
|
Register GetReg = MRI.createVirtualRegister(&AMDGPU::SReg_32RegClass);
|
2019-02-08 10:40:47 +08:00
|
|
|
|
AMDGPU/GlobalISel: Rename MIRBuilder to B. NFC
Reviewers: arsenm
Reviewed By: arsenm
Subscribers: kzhuravl, jvesely, wdng, nhaehnle, yaxunl, rovka, dstuttard, tpr, t-tye, hiraditya, Petar.Avramovic, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D67374
llvm-svn: 371467
2019-09-10 07:06:13 +08:00
|
|
|
B.buildInstr(AMDGPU::S_GETREG_B32)
|
2019-02-08 10:40:47 +08:00
|
|
|
.addDef(GetReg)
|
|
|
|
.addImm(Encoding);
|
|
|
|
MRI.setType(GetReg, S32);
|
|
|
|
|
AMDGPU/GlobalISel: Rename MIRBuilder to B. NFC
Reviewers: arsenm
Reviewed By: arsenm
Subscribers: kzhuravl, jvesely, wdng, nhaehnle, yaxunl, rovka, dstuttard, tpr, t-tye, hiraditya, Petar.Avramovic, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D67374
llvm-svn: 371467
2019-09-10 07:06:13 +08:00
|
|
|
auto ShiftAmt = B.buildConstant(S32, WidthM1 + 1);
|
[GlobalISel] Tidy up unnecessary calls to createGenericVirtualRegister
Summary:
As a side effect some redundant copies of constant values are removed by
CSEMIRBuilder.
Reviewers: aemerson, arsenm, dsanders, aditya_nandakumar
Subscribers: sdardis, jvesely, wdng, nhaehnle, rovka, hiraditya, jrtc27, atanasyan, volkan, Petar.Avramovic, kerbowa, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D73789
2020-01-31 20:40:31 +08:00
|
|
|
return B.buildShl(S32, GetReg, ShiftAmt).getReg(0);
|
2019-02-08 10:40:47 +08:00
|
|
|
}
|
|
|
|
|
2019-06-28 09:16:46 +08:00
|
|
|
Register QueuePtr = MRI.createGenericVirtualRegister(
|
2019-02-08 10:40:47 +08:00
|
|
|
LLT::pointer(AMDGPUAS::CONSTANT_ADDRESS, 64));
|
|
|
|
|
2020-07-21 03:56:39 +08:00
|
|
|
if (!loadInputValue(QueuePtr, B, AMDGPUFunctionArgInfo::QUEUE_PTR))
|
2019-09-05 10:20:29 +08:00
|
|
|
return Register();
|
2019-02-08 10:40:47 +08:00
|
|
|
|
|
|
|
// Offset into amd_queue_t for group_segment_aperture_base_hi /
|
|
|
|
// private_segment_aperture_base_hi.
|
|
|
|
uint32_t StructOffset = (AS == AMDGPUAS::LOCAL_ADDRESS) ? 0x40 : 0x44;
|
|
|
|
|
[AMDGPU] Don't create MachinePointerInfos with an UndefValue pointer
Summary:
The only useful information the UndefValue conveys is the address space,
which MachinePointerInfo can represent directly without referring to an
IR value.
Reviewers: arsenm, rampitec
Subscribers: kzhuravl, jvesely, wdng, nhaehnle, yaxunl, dstuttard, tpr, t-tye, hiraditya, Petar.Avramovic, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D71838
2019-12-23 21:42:12 +08:00
|
|
|
// TODO: can we be smarter about machine pointer info?
|
|
|
|
MachinePointerInfo PtrInfo(AMDGPUAS::CONSTANT_ADDRESS);
|
2019-02-08 10:40:47 +08:00
|
|
|
MachineMemOperand *MMO = MF.getMachineMemOperand(
|
[Alignment][NFC] Transitionning more getMachineMemOperand call sites
Summary:
This is patch is part of a series to introduce an Alignment type.
See this thread for context: http://lists.llvm.org/pipermail/llvm-dev/2019-July/133851.html
See this patch for the introduction of the type: https://reviews.llvm.org/D64790
Reviewers: courbet
Subscribers: arsenm, dylanmckay, sdardis, nemanjai, jvesely, nhaehnle, hiraditya, kbarton, jrtc27, atanasyan, Jim, kerbowa, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D77121
2020-03-31 16:05:00 +08:00
|
|
|
PtrInfo,
|
|
|
|
MachineMemOperand::MOLoad | MachineMemOperand::MODereferenceable |
|
|
|
|
MachineMemOperand::MOInvariant,
|
2021-07-16 02:24:00 +08:00
|
|
|
LLT::scalar(32), commonAlignment(Align(64), StructOffset));
|
2019-02-08 10:40:47 +08:00
|
|
|
|
2019-06-24 23:50:29 +08:00
|
|
|
Register LoadAddr;
|
2019-02-08 10:40:47 +08:00
|
|
|
|
[globalisel] Rename G_GEP to G_PTR_ADD
Summary:
G_GEP is rather poorly named. It's a simple pointer+scalar addition and
doesn't support any of the complexities of getelementptr. I therefore
propose that we rename it. There's a G_PTR_MASK so let's follow that
convention and go with G_PTR_ADD
Reviewers: volkan, aditya_nandakumar, bogner, rovka, arsenm
Subscribers: sdardis, jvesely, wdng, nhaehnle, hiraditya, jrtc27, atanasyan, arphaman, Petar.Avramovic, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D69734
2019-11-02 04:18:00 +08:00
|
|
|
B.materializePtrAdd(LoadAddr, QueuePtr, LLT::scalar(64), StructOffset);
|
[GlobalISel] Tidy up unnecessary calls to createGenericVirtualRegister
Summary:
As a side effect some redundant copies of constant values are removed by
CSEMIRBuilder.
Reviewers: aemerson, arsenm, dsanders, aditya_nandakumar
Subscribers: sdardis, jvesely, wdng, nhaehnle, rovka, hiraditya, jrtc27, atanasyan, volkan, Petar.Avramovic, kerbowa, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D73789
2020-01-31 20:40:31 +08:00
|
|
|
return B.buildLoad(S32, LoadAddr, *MMO).getReg(0);
|
2019-02-08 10:40:47 +08:00
|
|
|
}
|
|
|
|
|
2021-12-28 23:22:13 +08:00
|
|
|
/// Return true if the value is a known valid address, such that a null check is
|
|
|
|
/// not necessary.
|
|
|
|
static bool isKnownNonNull(Register Val, MachineRegisterInfo &MRI,
|
|
|
|
const AMDGPUTargetMachine &TM, unsigned AddrSpace) {
|
|
|
|
MachineInstr *Def = MRI.getVRegDef(Val);
|
|
|
|
switch (Def->getOpcode()) {
|
|
|
|
case AMDGPU::G_FRAME_INDEX:
|
|
|
|
case AMDGPU::G_GLOBAL_VALUE:
|
|
|
|
case AMDGPU::G_BLOCK_ADDR:
|
|
|
|
return true;
|
|
|
|
case AMDGPU::G_CONSTANT: {
|
|
|
|
const ConstantInt *CI = Def->getOperand(1).getCImm();
|
|
|
|
return CI->getSExtValue() != TM.getNullPointerValue(AddrSpace);
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-02-08 10:40:47 +08:00
|
|
|
bool AMDGPULegalizerInfo::legalizeAddrSpaceCast(
|
|
|
|
MachineInstr &MI, MachineRegisterInfo &MRI,
|
AMDGPU/GlobalISel: Rename MIRBuilder to B. NFC
Reviewers: arsenm
Reviewed By: arsenm
Subscribers: kzhuravl, jvesely, wdng, nhaehnle, yaxunl, rovka, dstuttard, tpr, t-tye, hiraditya, Petar.Avramovic, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D67374
llvm-svn: 371467
2019-09-10 07:06:13 +08:00
|
|
|
MachineIRBuilder &B) const {
|
|
|
|
MachineFunction &MF = B.getMF();
|
2019-02-08 10:40:47 +08:00
|
|
|
|
2019-08-28 08:58:24 +08:00
|
|
|
const LLT S32 = LLT::scalar(32);
|
2019-06-24 23:50:29 +08:00
|
|
|
Register Dst = MI.getOperand(0).getReg();
|
|
|
|
Register Src = MI.getOperand(1).getReg();
|
2019-02-08 10:40:47 +08:00
|
|
|
|
|
|
|
LLT DstTy = MRI.getType(Dst);
|
|
|
|
LLT SrcTy = MRI.getType(Src);
|
|
|
|
unsigned DestAS = DstTy.getAddressSpace();
|
|
|
|
unsigned SrcAS = SrcTy.getAddressSpace();
|
|
|
|
|
|
|
|
// TODO: Avoid reloading from the queue ptr for each cast, or at least each
|
|
|
|
// vector element.
|
|
|
|
assert(!DstTy.isVector());
|
|
|
|
|
|
|
|
const AMDGPUTargetMachine &TM
|
|
|
|
= static_cast<const AMDGPUTargetMachine &>(MF.getTarget());
|
|
|
|
|
2016-05-28 06:50:12 +08:00
|
|
|
if (TM.isNoopAddrSpaceCast(SrcAS, DestAS)) {
|
AMDGPU/GlobalISel: Rename MIRBuilder to B. NFC
Reviewers: arsenm
Reviewed By: arsenm
Subscribers: kzhuravl, jvesely, wdng, nhaehnle, yaxunl, rovka, dstuttard, tpr, t-tye, hiraditya, Petar.Avramovic, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D67374
llvm-svn: 371467
2019-09-10 07:06:13 +08:00
|
|
|
MI.setDesc(B.getTII().get(TargetOpcode::G_BITCAST));
|
2019-02-08 10:40:47 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-08-28 08:58:24 +08:00
|
|
|
if (DestAS == AMDGPUAS::CONSTANT_ADDRESS_32BIT) {
|
|
|
|
// Truncate.
|
AMDGPU/GlobalISel: Rename MIRBuilder to B. NFC
Reviewers: arsenm
Reviewed By: arsenm
Subscribers: kzhuravl, jvesely, wdng, nhaehnle, yaxunl, rovka, dstuttard, tpr, t-tye, hiraditya, Petar.Avramovic, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D67374
llvm-svn: 371467
2019-09-10 07:06:13 +08:00
|
|
|
B.buildExtract(Dst, Src, 0);
|
2019-08-28 08:58:24 +08:00
|
|
|
MI.eraseFromParent();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (SrcAS == AMDGPUAS::CONSTANT_ADDRESS_32BIT) {
|
|
|
|
const SIMachineFunctionInfo *Info = MF.getInfo<SIMachineFunctionInfo>();
|
|
|
|
uint32_t AddrHiVal = Info->get32BitAddressHighBits();
|
|
|
|
|
|
|
|
// FIXME: This is a bit ugly due to creating a merge of 2 pointers to
|
|
|
|
// another. Merge operands are required to be the same type, but creating an
|
|
|
|
// extra ptrtoint would be kind of pointless.
|
AMDGPU/GlobalISel: Rename MIRBuilder to B. NFC
Reviewers: arsenm
Reviewed By: arsenm
Subscribers: kzhuravl, jvesely, wdng, nhaehnle, yaxunl, rovka, dstuttard, tpr, t-tye, hiraditya, Petar.Avramovic, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D67374
llvm-svn: 371467
2019-09-10 07:06:13 +08:00
|
|
|
auto HighAddr = B.buildConstant(
|
2019-08-28 08:58:24 +08:00
|
|
|
LLT::pointer(AMDGPUAS::CONSTANT_ADDRESS_32BIT, 32), AddrHiVal);
|
2020-02-08 00:38:01 +08:00
|
|
|
B.buildMerge(Dst, {Src, HighAddr});
|
2019-08-28 08:58:24 +08:00
|
|
|
MI.eraseFromParent();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-02-08 10:40:47 +08:00
|
|
|
if (SrcAS == AMDGPUAS::FLAT_ADDRESS) {
|
|
|
|
assert(DestAS == AMDGPUAS::LOCAL_ADDRESS ||
|
|
|
|
DestAS == AMDGPUAS::PRIVATE_ADDRESS);
|
2021-12-28 23:22:13 +08:00
|
|
|
|
|
|
|
if (isKnownNonNull(Src, MRI, TM, SrcAS)) {
|
|
|
|
// Extract low 32-bits of the pointer.
|
|
|
|
B.buildExtract(Dst, Src, 0);
|
|
|
|
MI.eraseFromParent();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-02-08 10:40:47 +08:00
|
|
|
unsigned NullVal = TM.getNullPointerValue(DestAS);
|
|
|
|
|
AMDGPU/GlobalISel: Rename MIRBuilder to B. NFC
Reviewers: arsenm
Reviewed By: arsenm
Subscribers: kzhuravl, jvesely, wdng, nhaehnle, yaxunl, rovka, dstuttard, tpr, t-tye, hiraditya, Petar.Avramovic, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D67374
llvm-svn: 371467
2019-09-10 07:06:13 +08:00
|
|
|
auto SegmentNull = B.buildConstant(DstTy, NullVal);
|
|
|
|
auto FlatNull = B.buildConstant(SrcTy, 0);
|
2019-02-08 10:40:47 +08:00
|
|
|
|
|
|
|
// Extract low 32-bits of the pointer.
|
[GlobalISel] Tidy up unnecessary calls to createGenericVirtualRegister
Summary:
As a side effect some redundant copies of constant values are removed by
CSEMIRBuilder.
Reviewers: aemerson, arsenm, dsanders, aditya_nandakumar
Subscribers: sdardis, jvesely, wdng, nhaehnle, rovka, hiraditya, jrtc27, atanasyan, volkan, Petar.Avramovic, kerbowa, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D73789
2020-01-31 20:40:31 +08:00
|
|
|
auto PtrLo32 = B.buildExtract(DstTy, Src, 0);
|
2019-02-08 10:40:47 +08:00
|
|
|
|
[GlobalISel] Tidy up unnecessary calls to createGenericVirtualRegister
Summary:
As a side effect some redundant copies of constant values are removed by
CSEMIRBuilder.
Reviewers: aemerson, arsenm, dsanders, aditya_nandakumar
Subscribers: sdardis, jvesely, wdng, nhaehnle, rovka, hiraditya, jrtc27, atanasyan, volkan, Petar.Avramovic, kerbowa, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D73789
2020-01-31 20:40:31 +08:00
|
|
|
auto CmpRes =
|
|
|
|
B.buildICmp(CmpInst::ICMP_NE, LLT::scalar(1), Src, FlatNull.getReg(0));
|
AMDGPU/GlobalISel: Rename MIRBuilder to B. NFC
Reviewers: arsenm
Reviewed By: arsenm
Subscribers: kzhuravl, jvesely, wdng, nhaehnle, yaxunl, rovka, dstuttard, tpr, t-tye, hiraditya, Petar.Avramovic, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D67374
llvm-svn: 371467
2019-09-10 07:06:13 +08:00
|
|
|
B.buildSelect(Dst, CmpRes, PtrLo32, SegmentNull.getReg(0));
|
2019-02-08 10:40:47 +08:00
|
|
|
|
|
|
|
MI.eraseFromParent();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-08-28 08:58:24 +08:00
|
|
|
if (SrcAS != AMDGPUAS::LOCAL_ADDRESS && SrcAS != AMDGPUAS::PRIVATE_ADDRESS)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (!ST.hasFlatAddressSpace())
|
|
|
|
return false;
|
2019-02-08 10:40:47 +08:00
|
|
|
|
2019-10-04 16:35:38 +08:00
|
|
|
Register ApertureReg = getSegmentAperture(SrcAS, MRI, B);
|
2019-09-05 10:20:29 +08:00
|
|
|
if (!ApertureReg.isValid())
|
|
|
|
return false;
|
2019-02-08 10:40:47 +08:00
|
|
|
|
|
|
|
// Coerce the type of the low half of the result so we can use merge_values.
|
[GlobalISel] Tidy up unnecessary calls to createGenericVirtualRegister
Summary:
As a side effect some redundant copies of constant values are removed by
CSEMIRBuilder.
Reviewers: aemerson, arsenm, dsanders, aditya_nandakumar
Subscribers: sdardis, jvesely, wdng, nhaehnle, rovka, hiraditya, jrtc27, atanasyan, volkan, Petar.Avramovic, kerbowa, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D73789
2020-01-31 20:40:31 +08:00
|
|
|
Register SrcAsInt = B.buildPtrToInt(S32, Src).getReg(0);
|
2019-02-08 10:40:47 +08:00
|
|
|
|
|
|
|
// TODO: Should we allow mismatched types but matching sizes in merges to
|
|
|
|
// avoid the ptrtoint?
|
[GlobalISel] Tidy up unnecessary calls to createGenericVirtualRegister
Summary:
As a side effect some redundant copies of constant values are removed by
CSEMIRBuilder.
Reviewers: aemerson, arsenm, dsanders, aditya_nandakumar
Subscribers: sdardis, jvesely, wdng, nhaehnle, rovka, hiraditya, jrtc27, atanasyan, volkan, Petar.Avramovic, kerbowa, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D73789
2020-01-31 20:40:31 +08:00
|
|
|
auto BuildPtr = B.buildMerge(DstTy, {SrcAsInt, ApertureReg});
|
2021-12-28 23:22:13 +08:00
|
|
|
|
|
|
|
if (isKnownNonNull(Src, MRI, TM, SrcAS)) {
|
|
|
|
B.buildCopy(Dst, BuildPtr);
|
|
|
|
MI.eraseFromParent();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto SegmentNull = B.buildConstant(SrcTy, TM.getNullPointerValue(SrcAS));
|
|
|
|
auto FlatNull = B.buildConstant(DstTy, TM.getNullPointerValue(DestAS));
|
|
|
|
|
|
|
|
auto CmpRes =
|
|
|
|
B.buildICmp(CmpInst::ICMP_NE, LLT::scalar(1), Src, SegmentNull.getReg(0));
|
|
|
|
|
[GlobalISel] Tidy up unnecessary calls to createGenericVirtualRegister
Summary:
As a side effect some redundant copies of constant values are removed by
CSEMIRBuilder.
Reviewers: aemerson, arsenm, dsanders, aditya_nandakumar
Subscribers: sdardis, jvesely, wdng, nhaehnle, rovka, hiraditya, jrtc27, atanasyan, volkan, Petar.Avramovic, kerbowa, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D73789
2020-01-31 20:40:31 +08:00
|
|
|
B.buildSelect(Dst, CmpRes, BuildPtr, FlatNull);
|
2019-02-08 10:40:47 +08:00
|
|
|
|
|
|
|
MI.eraseFromParent();
|
|
|
|
return true;
|
|
|
|
}
|
2019-05-17 20:19:57 +08:00
|
|
|
|
|
|
|
bool AMDGPULegalizerInfo::legalizeFrint(
|
|
|
|
MachineInstr &MI, MachineRegisterInfo &MRI,
|
AMDGPU/GlobalISel: Rename MIRBuilder to B. NFC
Reviewers: arsenm
Reviewed By: arsenm
Subscribers: kzhuravl, jvesely, wdng, nhaehnle, yaxunl, rovka, dstuttard, tpr, t-tye, hiraditya, Petar.Avramovic, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D67374
llvm-svn: 371467
2019-09-10 07:06:13 +08:00
|
|
|
MachineIRBuilder &B) const {
|
2019-06-25 00:16:12 +08:00
|
|
|
Register Src = MI.getOperand(1).getReg();
|
2019-05-17 20:19:57 +08:00
|
|
|
LLT Ty = MRI.getType(Src);
|
|
|
|
assert(Ty.isScalar() && Ty.getSizeInBits() == 64);
|
|
|
|
|
|
|
|
APFloat C1Val(APFloat::IEEEdouble(), "0x1.0p+52");
|
|
|
|
APFloat C2Val(APFloat::IEEEdouble(), "0x1.fffffffffffffp+51");
|
|
|
|
|
AMDGPU/GlobalISel: Rename MIRBuilder to B. NFC
Reviewers: arsenm
Reviewed By: arsenm
Subscribers: kzhuravl, jvesely, wdng, nhaehnle, yaxunl, rovka, dstuttard, tpr, t-tye, hiraditya, Petar.Avramovic, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D67374
llvm-svn: 371467
2019-09-10 07:06:13 +08:00
|
|
|
auto C1 = B.buildFConstant(Ty, C1Val);
|
|
|
|
auto CopySign = B.buildFCopysign(Ty, C1, Src);
|
2019-05-17 20:19:57 +08:00
|
|
|
|
|
|
|
// TODO: Should this propagate fast-math-flags?
|
AMDGPU/GlobalISel: Rename MIRBuilder to B. NFC
Reviewers: arsenm
Reviewed By: arsenm
Subscribers: kzhuravl, jvesely, wdng, nhaehnle, yaxunl, rovka, dstuttard, tpr, t-tye, hiraditya, Petar.Avramovic, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D67374
llvm-svn: 371467
2019-09-10 07:06:13 +08:00
|
|
|
auto Tmp1 = B.buildFAdd(Ty, Src, CopySign);
|
|
|
|
auto Tmp2 = B.buildFSub(Ty, Tmp1, CopySign);
|
2019-05-17 20:19:57 +08:00
|
|
|
|
AMDGPU/GlobalISel: Rename MIRBuilder to B. NFC
Reviewers: arsenm
Reviewed By: arsenm
Subscribers: kzhuravl, jvesely, wdng, nhaehnle, yaxunl, rovka, dstuttard, tpr, t-tye, hiraditya, Petar.Avramovic, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D67374
llvm-svn: 371467
2019-09-10 07:06:13 +08:00
|
|
|
auto C2 = B.buildFConstant(Ty, C2Val);
|
|
|
|
auto Fabs = B.buildFAbs(Ty, Src);
|
2019-05-17 20:19:57 +08:00
|
|
|
|
AMDGPU/GlobalISel: Rename MIRBuilder to B. NFC
Reviewers: arsenm
Reviewed By: arsenm
Subscribers: kzhuravl, jvesely, wdng, nhaehnle, yaxunl, rovka, dstuttard, tpr, t-tye, hiraditya, Petar.Avramovic, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D67374
llvm-svn: 371467
2019-09-10 07:06:13 +08:00
|
|
|
auto Cond = B.buildFCmp(CmpInst::FCMP_OGT, LLT::scalar(1), Fabs, C2);
|
|
|
|
B.buildSelect(MI.getOperand(0).getReg(), Cond, Src, Tmp2);
|
2020-07-22 06:24:03 +08:00
|
|
|
MI.eraseFromParent();
|
2019-05-17 20:19:57 +08:00
|
|
|
return true;
|
2019-05-17 20:20:05 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool AMDGPULegalizerInfo::legalizeFceil(
|
|
|
|
MachineInstr &MI, MachineRegisterInfo &MRI,
|
|
|
|
MachineIRBuilder &B) const {
|
|
|
|
|
2019-05-17 20:59:27 +08:00
|
|
|
const LLT S1 = LLT::scalar(1);
|
|
|
|
const LLT S64 = LLT::scalar(64);
|
|
|
|
|
2019-06-25 00:16:12 +08:00
|
|
|
Register Src = MI.getOperand(1).getReg();
|
2019-05-17 20:59:27 +08:00
|
|
|
assert(MRI.getType(Src) == S64);
|
2019-05-17 20:20:05 +08:00
|
|
|
|
|
|
|
// result = trunc(src)
|
|
|
|
// if (src > 0.0 && src != result)
|
|
|
|
// result += 1.0
|
|
|
|
|
2020-01-31 21:52:33 +08:00
|
|
|
auto Trunc = B.buildIntrinsicTrunc(S64, Src);
|
2019-05-17 20:20:05 +08:00
|
|
|
|
|
|
|
const auto Zero = B.buildFConstant(S64, 0.0);
|
|
|
|
const auto One = B.buildFConstant(S64, 1.0);
|
|
|
|
auto Lt0 = B.buildFCmp(CmpInst::FCMP_OGT, S1, Src, Zero);
|
|
|
|
auto NeTrunc = B.buildFCmp(CmpInst::FCMP_ONE, S1, Src, Trunc);
|
|
|
|
auto And = B.buildAnd(S1, Lt0, NeTrunc);
|
|
|
|
auto Add = B.buildSelect(S64, And, One, Zero);
|
|
|
|
|
|
|
|
// TODO: Should this propagate fast-math-flags?
|
|
|
|
B.buildFAdd(MI.getOperand(0).getReg(), Trunc, Add);
|
2022-01-13 21:28:00 +08:00
|
|
|
MI.eraseFromParent();
|
2019-05-17 20:20:05 +08:00
|
|
|
return true;
|
2019-05-17 20:19:57 +08:00
|
|
|
}
|
2019-05-17 20:20:01 +08:00
|
|
|
|
2020-08-10 16:10:46 +08:00
|
|
|
bool AMDGPULegalizerInfo::legalizeFrem(
|
|
|
|
MachineInstr &MI, MachineRegisterInfo &MRI,
|
|
|
|
MachineIRBuilder &B) const {
|
|
|
|
Register DstReg = MI.getOperand(0).getReg();
|
|
|
|
Register Src0Reg = MI.getOperand(1).getReg();
|
|
|
|
Register Src1Reg = MI.getOperand(2).getReg();
|
|
|
|
auto Flags = MI.getFlags();
|
|
|
|
LLT Ty = MRI.getType(DstReg);
|
|
|
|
|
|
|
|
auto Div = B.buildFDiv(Ty, Src0Reg, Src1Reg, Flags);
|
|
|
|
auto Trunc = B.buildIntrinsicTrunc(Ty, Div, Flags);
|
|
|
|
auto Neg = B.buildFNeg(Ty, Trunc, Flags);
|
|
|
|
B.buildFMA(DstReg, Neg, Src1Reg, Src0Reg, Flags);
|
|
|
|
MI.eraseFromParent();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-07-19 23:57:49 +08:00
|
|
|
static MachineInstrBuilder extractF64Exponent(Register Hi,
|
2019-05-17 20:20:01 +08:00
|
|
|
MachineIRBuilder &B) {
|
|
|
|
const unsigned FractBits = 52;
|
|
|
|
const unsigned ExpBits = 11;
|
|
|
|
LLT S32 = LLT::scalar(32);
|
|
|
|
|
|
|
|
auto Const0 = B.buildConstant(S32, FractBits - 32);
|
|
|
|
auto Const1 = B.buildConstant(S32, ExpBits);
|
|
|
|
|
|
|
|
auto ExpPart = B.buildIntrinsic(Intrinsic::amdgcn_ubfe, {S32}, false)
|
2020-07-19 23:57:49 +08:00
|
|
|
.addUse(Hi)
|
2019-05-17 20:20:01 +08:00
|
|
|
.addUse(Const0.getReg(0))
|
|
|
|
.addUse(Const1.getReg(0));
|
|
|
|
|
|
|
|
return B.buildSub(S32, ExpPart, B.buildConstant(S32, 1023));
|
|
|
|
}
|
|
|
|
|
|
|
|
bool AMDGPULegalizerInfo::legalizeIntrinsicTrunc(
|
|
|
|
MachineInstr &MI, MachineRegisterInfo &MRI,
|
|
|
|
MachineIRBuilder &B) const {
|
2019-05-17 20:59:27 +08:00
|
|
|
const LLT S1 = LLT::scalar(1);
|
|
|
|
const LLT S32 = LLT::scalar(32);
|
|
|
|
const LLT S64 = LLT::scalar(64);
|
2019-05-17 20:20:01 +08:00
|
|
|
|
2019-06-25 00:16:12 +08:00
|
|
|
Register Src = MI.getOperand(1).getReg();
|
2019-05-17 20:59:27 +08:00
|
|
|
assert(MRI.getType(Src) == S64);
|
2019-05-17 20:20:01 +08:00
|
|
|
|
|
|
|
// TODO: Should this use extract since the low half is unused?
|
|
|
|
auto Unmerge = B.buildUnmerge({S32, S32}, Src);
|
2019-06-25 00:16:12 +08:00
|
|
|
Register Hi = Unmerge.getReg(1);
|
2019-05-17 20:20:01 +08:00
|
|
|
|
|
|
|
// Extract the upper half, since this is where we will find the sign and
|
|
|
|
// exponent.
|
|
|
|
auto Exp = extractF64Exponent(Hi, B);
|
|
|
|
|
|
|
|
const unsigned FractBits = 52;
|
|
|
|
|
|
|
|
// Extract the sign bit.
|
|
|
|
const auto SignBitMask = B.buildConstant(S32, UINT32_C(1) << 31);
|
|
|
|
auto SignBit = B.buildAnd(S32, Hi, SignBitMask);
|
|
|
|
|
|
|
|
const auto FractMask = B.buildConstant(S64, (UINT64_C(1) << FractBits) - 1);
|
|
|
|
|
|
|
|
const auto Zero32 = B.buildConstant(S32, 0);
|
|
|
|
|
|
|
|
// Extend back to 64-bits.
|
2020-02-08 00:38:01 +08:00
|
|
|
auto SignBit64 = B.buildMerge(S64, {Zero32, SignBit});
|
2019-05-17 20:20:01 +08:00
|
|
|
|
|
|
|
auto Shr = B.buildAShr(S64, FractMask, Exp);
|
|
|
|
auto Not = B.buildNot(S64, Shr);
|
|
|
|
auto Tmp0 = B.buildAnd(S64, Src, Not);
|
|
|
|
auto FiftyOne = B.buildConstant(S32, FractBits - 1);
|
|
|
|
|
|
|
|
auto ExpLt0 = B.buildICmp(CmpInst::ICMP_SLT, S1, Exp, Zero32);
|
|
|
|
auto ExpGt51 = B.buildICmp(CmpInst::ICMP_SGT, S1, Exp, FiftyOne);
|
|
|
|
|
|
|
|
auto Tmp1 = B.buildSelect(S64, ExpLt0, SignBit64, Tmp0);
|
|
|
|
B.buildSelect(MI.getOperand(0).getReg(), ExpGt51, Src, Tmp1);
|
2020-07-19 23:57:49 +08:00
|
|
|
MI.eraseFromParent();
|
2019-05-17 20:20:01 +08:00
|
|
|
return true;
|
|
|
|
}
|
2019-05-18 07:05:18 +08:00
|
|
|
|
|
|
|
bool AMDGPULegalizerInfo::legalizeITOFP(
|
|
|
|
MachineInstr &MI, MachineRegisterInfo &MRI,
|
|
|
|
MachineIRBuilder &B, bool Signed) const {
|
|
|
|
|
2019-06-25 00:16:12 +08:00
|
|
|
Register Dst = MI.getOperand(0).getReg();
|
|
|
|
Register Src = MI.getOperand(1).getReg();
|
2019-05-18 07:05:18 +08:00
|
|
|
|
|
|
|
const LLT S64 = LLT::scalar(64);
|
|
|
|
const LLT S32 = LLT::scalar(32);
|
|
|
|
|
2021-07-25 11:42:26 +08:00
|
|
|
assert(MRI.getType(Src) == S64);
|
2019-05-18 07:05:18 +08:00
|
|
|
|
|
|
|
auto Unmerge = B.buildUnmerge({S32, S32}, Src);
|
2021-07-25 11:42:26 +08:00
|
|
|
auto ThirtyTwo = B.buildConstant(S32, 32);
|
2019-05-18 07:05:18 +08:00
|
|
|
|
2021-07-25 11:42:26 +08:00
|
|
|
if (MRI.getType(Dst) == S64) {
|
|
|
|
auto CvtHi = Signed ? B.buildSITOFP(S64, Unmerge.getReg(1))
|
|
|
|
: B.buildUITOFP(S64, Unmerge.getReg(1));
|
2019-05-18 07:05:18 +08:00
|
|
|
|
2021-07-25 11:42:26 +08:00
|
|
|
auto CvtLo = B.buildUITOFP(S64, Unmerge.getReg(0));
|
|
|
|
auto LdExp = B.buildIntrinsic(Intrinsic::amdgcn_ldexp, {S64}, false)
|
|
|
|
.addUse(CvtHi.getReg(0))
|
|
|
|
.addUse(ThirtyTwo.getReg(0));
|
2019-05-18 07:05:18 +08:00
|
|
|
|
2021-07-25 11:42:26 +08:00
|
|
|
// TODO: Should this propagate fast-math-flags?
|
|
|
|
B.buildFAdd(Dst, LdExp, CvtLo);
|
|
|
|
MI.eraseFromParent();
|
|
|
|
return true;
|
|
|
|
}
|
2019-05-18 07:05:18 +08:00
|
|
|
|
2021-07-25 11:42:26 +08:00
|
|
|
assert(MRI.getType(Dst) == S32);
|
|
|
|
|
|
|
|
auto One = B.buildConstant(S32, 1);
|
|
|
|
|
|
|
|
MachineInstrBuilder ShAmt;
|
|
|
|
if (Signed) {
|
2021-08-05 04:22:51 +08:00
|
|
|
auto ThirtyOne = B.buildConstant(S32, 31);
|
2021-07-25 11:42:26 +08:00
|
|
|
auto X = B.buildXor(S32, Unmerge.getReg(0), Unmerge.getReg(1));
|
2021-08-05 04:22:51 +08:00
|
|
|
auto OppositeSign = B.buildAShr(S32, X, ThirtyOne);
|
|
|
|
auto MaxShAmt = B.buildAdd(S32, ThirtyTwo, OppositeSign);
|
2021-07-25 11:42:26 +08:00
|
|
|
auto LS = B.buildIntrinsic(Intrinsic::amdgcn_sffbh, {S32},
|
|
|
|
/*HasSideEffects=*/false)
|
|
|
|
.addUse(Unmerge.getReg(1));
|
2021-08-05 04:22:51 +08:00
|
|
|
auto LS2 = B.buildSub(S32, LS, One);
|
|
|
|
ShAmt = B.buildUMin(S32, LS2, MaxShAmt);
|
2021-07-25 11:42:26 +08:00
|
|
|
} else
|
|
|
|
ShAmt = B.buildCTLZ(S32, Unmerge.getReg(1));
|
|
|
|
auto Norm = B.buildShl(S64, Src, ShAmt);
|
|
|
|
auto Unmerge2 = B.buildUnmerge({S32, S32}, Norm);
|
2021-08-05 04:22:51 +08:00
|
|
|
auto Adjust = B.buildUMin(S32, One, Unmerge2.getReg(0));
|
2021-07-25 11:42:26 +08:00
|
|
|
auto Norm2 = B.buildOr(S32, Unmerge2.getReg(1), Adjust);
|
|
|
|
auto FVal = Signed ? B.buildSITOFP(S32, Norm2) : B.buildUITOFP(S32, Norm2);
|
|
|
|
auto Scale = B.buildSub(S32, ThirtyTwo, ShAmt);
|
|
|
|
B.buildIntrinsic(Intrinsic::amdgcn_ldexp, ArrayRef<Register>{Dst},
|
|
|
|
/*HasSideEffects=*/false)
|
|
|
|
.addUse(FVal.getReg(0))
|
|
|
|
.addUse(Scale.getReg(0));
|
2019-05-18 07:05:18 +08:00
|
|
|
MI.eraseFromParent();
|
|
|
|
return true;
|
|
|
|
}
|
2019-07-02 02:40:23 +08:00
|
|
|
|
2020-01-05 05:40:45 +08:00
|
|
|
// TODO: Copied from DAG implementation. Verify logic and document how this
|
|
|
|
// actually works.
|
2021-06-12 05:21:09 +08:00
|
|
|
bool AMDGPULegalizerInfo::legalizeFPTOI(MachineInstr &MI,
|
|
|
|
MachineRegisterInfo &MRI,
|
|
|
|
MachineIRBuilder &B,
|
|
|
|
bool Signed) const {
|
2020-01-05 05:40:45 +08:00
|
|
|
|
|
|
|
Register Dst = MI.getOperand(0).getReg();
|
|
|
|
Register Src = MI.getOperand(1).getReg();
|
|
|
|
|
|
|
|
const LLT S64 = LLT::scalar(64);
|
|
|
|
const LLT S32 = LLT::scalar(32);
|
|
|
|
|
2021-06-12 05:21:09 +08:00
|
|
|
const LLT SrcLT = MRI.getType(Src);
|
2021-06-21 02:09:07 +08:00
|
|
|
assert((SrcLT == S32 || SrcLT == S64) && MRI.getType(Dst) == S64);
|
2020-01-05 05:40:45 +08:00
|
|
|
|
|
|
|
unsigned Flags = MI.getFlags();
|
|
|
|
|
2021-06-12 05:21:09 +08:00
|
|
|
// The basic idea of converting a floating point number into a pair of 32-bit
|
|
|
|
// integers is illustrated as follows:
|
|
|
|
//
|
|
|
|
// tf := trunc(val);
|
|
|
|
// hif := floor(tf * 2^-32);
|
|
|
|
// lof := tf - hif * 2^32; // lof is always positive due to floor.
|
|
|
|
// hi := fptoi(hif);
|
|
|
|
// lo := fptoi(lof);
|
|
|
|
//
|
|
|
|
auto Trunc = B.buildIntrinsicTrunc(SrcLT, Src, Flags);
|
|
|
|
MachineInstrBuilder Sign;
|
|
|
|
if (Signed && SrcLT == S32) {
|
|
|
|
// However, a 32-bit floating point number has only 23 bits mantissa and
|
|
|
|
// it's not enough to hold all the significant bits of `lof` if val is
|
|
|
|
// negative. To avoid the loss of precision, We need to take the absolute
|
|
|
|
// value after truncating and flip the result back based on the original
|
|
|
|
// signedness.
|
|
|
|
Sign = B.buildAShr(S32, Src, B.buildConstant(S32, 31));
|
|
|
|
Trunc = B.buildFAbs(S32, Trunc, Flags);
|
|
|
|
}
|
|
|
|
MachineInstrBuilder K0, K1;
|
|
|
|
if (SrcLT == S64) {
|
|
|
|
K0 = B.buildFConstant(S64,
|
|
|
|
BitsToDouble(UINT64_C(/*2^-32*/ 0x3df0000000000000)));
|
|
|
|
K1 = B.buildFConstant(S64,
|
|
|
|
BitsToDouble(UINT64_C(/*-2^32*/ 0xc1f0000000000000)));
|
|
|
|
} else {
|
|
|
|
K0 = B.buildFConstant(S32, BitsToFloat(UINT32_C(/*2^-32*/ 0x2f800000)));
|
|
|
|
K1 = B.buildFConstant(S32, BitsToFloat(UINT32_C(/*-2^32*/ 0xcf800000)));
|
|
|
|
}
|
2020-01-05 05:40:45 +08:00
|
|
|
|
2021-06-12 05:21:09 +08:00
|
|
|
auto Mul = B.buildFMul(SrcLT, Trunc, K0, Flags);
|
|
|
|
auto FloorMul = B.buildFFloor(SrcLT, Mul, Flags);
|
|
|
|
auto Fma = B.buildFMA(SrcLT, FloorMul, K1, Trunc, Flags);
|
2020-01-05 05:40:45 +08:00
|
|
|
|
2021-06-12 05:21:09 +08:00
|
|
|
auto Hi = (Signed && SrcLT == S64) ? B.buildFPTOSI(S32, FloorMul)
|
|
|
|
: B.buildFPTOUI(S32, FloorMul);
|
2020-01-05 05:40:45 +08:00
|
|
|
auto Lo = B.buildFPTOUI(S32, Fma);
|
|
|
|
|
2021-06-12 05:21:09 +08:00
|
|
|
if (Signed && SrcLT == S32) {
|
|
|
|
// Flip the result based on the signedness, which is either all 0s or 1s.
|
|
|
|
Sign = B.buildMerge(S64, {Sign, Sign});
|
|
|
|
// r := xor({lo, hi}, sign) - sign;
|
|
|
|
B.buildSub(Dst, B.buildXor(S64, B.buildMerge(S64, {Lo, Hi}), Sign), Sign);
|
|
|
|
} else
|
|
|
|
B.buildMerge(Dst, {Lo, Hi});
|
2020-01-05 05:40:45 +08:00
|
|
|
MI.eraseFromParent();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-06-10 05:02:12 +08:00
|
|
|
bool AMDGPULegalizerInfo::legalizeMinNumMaxNum(LegalizerHelper &Helper,
|
|
|
|
MachineInstr &MI) const {
|
|
|
|
MachineFunction &MF = Helper.MIRBuilder.getMF();
|
2019-07-11 00:31:19 +08:00
|
|
|
const SIMachineFunctionInfo *MFI = MF.getInfo<SIMachineFunctionInfo>();
|
|
|
|
|
|
|
|
const bool IsIEEEOp = MI.getOpcode() == AMDGPU::G_FMINNUM_IEEE ||
|
|
|
|
MI.getOpcode() == AMDGPU::G_FMAXNUM_IEEE;
|
|
|
|
|
|
|
|
// With ieee_mode disabled, the instructions have the correct behavior
|
|
|
|
// already for G_FMINNUM/G_FMAXNUM
|
|
|
|
if (!MFI->getMode().IEEE)
|
|
|
|
return !IsIEEEOp;
|
|
|
|
|
|
|
|
if (IsIEEEOp)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return Helper.lowerFMinNumMaxNum(MI) == LegalizerHelper::Legalized;
|
|
|
|
}
|
|
|
|
|
2019-07-16 03:40:59 +08:00
|
|
|
bool AMDGPULegalizerInfo::legalizeExtractVectorElt(
|
|
|
|
MachineInstr &MI, MachineRegisterInfo &MRI,
|
|
|
|
MachineIRBuilder &B) const {
|
|
|
|
// TODO: Should move some of this into LegalizerHelper.
|
|
|
|
|
|
|
|
// TODO: Promote dynamic indexing of s16 to s32
|
2020-02-07 05:52:04 +08:00
|
|
|
|
|
|
|
// FIXME: Artifact combiner probably should have replaced the truncated
|
|
|
|
// constant before this, so we shouldn't need
|
2021-09-17 17:21:55 +08:00
|
|
|
// getIConstantVRegValWithLookThrough.
|
2020-11-03 22:50:17 +08:00
|
|
|
Optional<ValueAndVReg> MaybeIdxVal =
|
2021-09-17 17:21:55 +08:00
|
|
|
getIConstantVRegValWithLookThrough(MI.getOperand(2).getReg(), MRI);
|
2020-11-03 22:50:17 +08:00
|
|
|
if (!MaybeIdxVal) // Dynamic case will be selected to register indexing.
|
2019-07-16 03:40:59 +08:00
|
|
|
return true;
|
2020-11-03 22:50:17 +08:00
|
|
|
const int64_t IdxVal = MaybeIdxVal->Value.getSExtValue();
|
2019-07-16 03:40:59 +08:00
|
|
|
|
|
|
|
Register Dst = MI.getOperand(0).getReg();
|
|
|
|
Register Vec = MI.getOperand(1).getReg();
|
|
|
|
|
|
|
|
LLT VecTy = MRI.getType(Vec);
|
|
|
|
LLT EltTy = VecTy.getElementType();
|
|
|
|
assert(EltTy == MRI.getType(Dst));
|
|
|
|
|
2022-01-10 20:14:28 +08:00
|
|
|
if (IdxVal < VecTy.getNumElements()) {
|
|
|
|
auto Unmerge = B.buildUnmerge(EltTy, Vec);
|
|
|
|
B.buildCopy(Dst, Unmerge.getReg(IdxVal));
|
|
|
|
} else {
|
2019-07-16 03:40:59 +08:00
|
|
|
B.buildUndef(Dst);
|
2022-01-10 20:14:28 +08:00
|
|
|
}
|
2019-07-16 03:40:59 +08:00
|
|
|
|
|
|
|
MI.eraseFromParent();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-07-16 03:43:04 +08:00
|
|
|
bool AMDGPULegalizerInfo::legalizeInsertVectorElt(
|
|
|
|
MachineInstr &MI, MachineRegisterInfo &MRI,
|
|
|
|
MachineIRBuilder &B) const {
|
|
|
|
// TODO: Should move some of this into LegalizerHelper.
|
|
|
|
|
|
|
|
// TODO: Promote dynamic indexing of s16 to s32
|
2020-02-07 05:52:04 +08:00
|
|
|
|
|
|
|
// FIXME: Artifact combiner probably should have replaced the truncated
|
|
|
|
// constant before this, so we shouldn't need
|
2021-09-17 17:21:55 +08:00
|
|
|
// getIConstantVRegValWithLookThrough.
|
2020-11-03 22:50:17 +08:00
|
|
|
Optional<ValueAndVReg> MaybeIdxVal =
|
2021-09-17 17:21:55 +08:00
|
|
|
getIConstantVRegValWithLookThrough(MI.getOperand(3).getReg(), MRI);
|
2020-11-03 22:50:17 +08:00
|
|
|
if (!MaybeIdxVal) // Dynamic case will be selected to register indexing.
|
2019-07-16 03:43:04 +08:00
|
|
|
return true;
|
|
|
|
|
2020-11-03 22:50:17 +08:00
|
|
|
int64_t IdxVal = MaybeIdxVal->Value.getSExtValue();
|
2019-07-16 03:43:04 +08:00
|
|
|
Register Dst = MI.getOperand(0).getReg();
|
|
|
|
Register Vec = MI.getOperand(1).getReg();
|
|
|
|
Register Ins = MI.getOperand(2).getReg();
|
|
|
|
|
|
|
|
LLT VecTy = MRI.getType(Vec);
|
|
|
|
LLT EltTy = VecTy.getElementType();
|
|
|
|
assert(EltTy == MRI.getType(Ins));
|
2022-01-11 00:49:46 +08:00
|
|
|
(void)Ins;
|
2019-07-16 03:43:04 +08:00
|
|
|
|
2022-01-10 20:14:28 +08:00
|
|
|
unsigned NumElts = VecTy.getNumElements();
|
|
|
|
if (IdxVal < NumElts) {
|
|
|
|
SmallVector<Register, 8> SrcRegs;
|
|
|
|
for (unsigned i = 0; i < NumElts; ++i)
|
|
|
|
SrcRegs.push_back(MRI.createGenericVirtualRegister(EltTy));
|
|
|
|
B.buildUnmerge(SrcRegs, Vec);
|
|
|
|
|
|
|
|
SrcRegs[IdxVal] = MI.getOperand(2).getReg();
|
|
|
|
B.buildMerge(Dst, SrcRegs);
|
|
|
|
} else {
|
2019-07-16 03:43:04 +08:00
|
|
|
B.buildUndef(Dst);
|
2022-01-10 20:14:28 +08:00
|
|
|
}
|
2019-07-16 03:43:04 +08:00
|
|
|
|
|
|
|
MI.eraseFromParent();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-01-02 04:51:46 +08:00
|
|
|
bool AMDGPULegalizerInfo::legalizeShuffleVector(
|
|
|
|
MachineInstr &MI, MachineRegisterInfo &MRI,
|
|
|
|
MachineIRBuilder &B) const {
|
2021-06-24 16:58:21 +08:00
|
|
|
const LLT V2S16 = LLT::fixed_vector(2, 16);
|
2020-01-02 04:51:46 +08:00
|
|
|
|
|
|
|
Register Dst = MI.getOperand(0).getReg();
|
|
|
|
Register Src0 = MI.getOperand(1).getReg();
|
|
|
|
LLT DstTy = MRI.getType(Dst);
|
|
|
|
LLT SrcTy = MRI.getType(Src0);
|
|
|
|
|
|
|
|
if (SrcTy == V2S16 && DstTy == V2S16 &&
|
2020-02-16 12:56:56 +08:00
|
|
|
AMDGPU::isLegalVOP3PShuffleMask(MI.getOperand(3).getShuffleMask()))
|
2020-01-02 04:51:46 +08:00
|
|
|
return true;
|
|
|
|
|
|
|
|
MachineIRBuilder HelperBuilder(MI);
|
|
|
|
GISelObserverWrapper DummyObserver;
|
|
|
|
LegalizerHelper Helper(B.getMF(), DummyObserver, HelperBuilder);
|
|
|
|
return Helper.lowerShuffleVector(MI) == LegalizerHelper::Legalized;
|
|
|
|
}
|
|
|
|
|
2019-08-30 04:06:48 +08:00
|
|
|
bool AMDGPULegalizerInfo::legalizeSinCos(
|
|
|
|
MachineInstr &MI, MachineRegisterInfo &MRI,
|
|
|
|
MachineIRBuilder &B) const {
|
|
|
|
|
|
|
|
Register DstReg = MI.getOperand(0).getReg();
|
|
|
|
Register SrcReg = MI.getOperand(1).getReg();
|
|
|
|
LLT Ty = MRI.getType(DstReg);
|
|
|
|
unsigned Flags = MI.getFlags();
|
|
|
|
|
|
|
|
Register TrigVal;
|
2020-05-29 16:42:00 +08:00
|
|
|
auto OneOver2Pi = B.buildFConstant(Ty, 0.5 * numbers::inv_pi);
|
2019-08-30 04:06:48 +08:00
|
|
|
if (ST.hasTrigReducedRange()) {
|
|
|
|
auto MulVal = B.buildFMul(Ty, SrcReg, OneOver2Pi, Flags);
|
|
|
|
TrigVal = B.buildIntrinsic(Intrinsic::amdgcn_fract, {Ty}, false)
|
|
|
|
.addUse(MulVal.getReg(0))
|
|
|
|
.setMIFlags(Flags).getReg(0);
|
|
|
|
} else
|
|
|
|
TrigVal = B.buildFMul(Ty, SrcReg, OneOver2Pi, Flags).getReg(0);
|
|
|
|
|
|
|
|
Intrinsic::ID TrigIntrin = MI.getOpcode() == AMDGPU::G_FSIN ?
|
|
|
|
Intrinsic::amdgcn_sin : Intrinsic::amdgcn_cos;
|
|
|
|
B.buildIntrinsic(TrigIntrin, makeArrayRef<Register>(DstReg), false)
|
|
|
|
.addUse(TrigVal)
|
|
|
|
.setMIFlags(Flags);
|
|
|
|
MI.eraseFromParent();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
[amdgpu] Fix REL32 relocations with negative offsets.
Summary: - The offset should be treated as a signed one.
Reviewers: rampitec, arsenm
Subscribers: kzhuravl, jvesely, wdng, nhaehnle, yaxunl, dstuttard, tpr, t-tye, hiraditya, kerbowa, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D82234
2020-06-19 12:09:20 +08:00
|
|
|
bool AMDGPULegalizerInfo::buildPCRelGlobalAddress(Register DstReg, LLT PtrTy,
|
|
|
|
MachineIRBuilder &B,
|
|
|
|
const GlobalValue *GV,
|
|
|
|
int64_t Offset,
|
|
|
|
unsigned GAFlags) const {
|
|
|
|
assert(isInt<32>(Offset + 4) && "32-bit offset is expected!");
|
2019-10-01 09:06:43 +08:00
|
|
|
// In order to support pc-relative addressing, SI_PC_ADD_REL_OFFSET is lowered
|
|
|
|
// to the following code sequence:
|
|
|
|
//
|
|
|
|
// For constant address space:
|
|
|
|
// s_getpc_b64 s[0:1]
|
|
|
|
// s_add_u32 s0, s0, $symbol
|
|
|
|
// s_addc_u32 s1, s1, 0
|
|
|
|
//
|
|
|
|
// s_getpc_b64 returns the address of the s_add_u32 instruction and then
|
|
|
|
// a fixup or relocation is emitted to replace $symbol with a literal
|
|
|
|
// constant, which is a pc-relative offset from the encoding of the $symbol
|
|
|
|
// operand to the global variable.
|
|
|
|
//
|
|
|
|
// For global address space:
|
|
|
|
// s_getpc_b64 s[0:1]
|
|
|
|
// s_add_u32 s0, s0, $symbol@{gotpc}rel32@lo
|
|
|
|
// s_addc_u32 s1, s1, $symbol@{gotpc}rel32@hi
|
|
|
|
//
|
|
|
|
// s_getpc_b64 returns the address of the s_add_u32 instruction and then
|
|
|
|
// fixups or relocations are emitted to replace $symbol@*@lo and
|
|
|
|
// $symbol@*@hi with lower 32 bits and higher 32 bits of a literal constant,
|
|
|
|
// which is a 64-bit pc-relative offset from the encoding of the $symbol
|
|
|
|
// operand to the global variable.
|
|
|
|
//
|
|
|
|
// What we want here is an offset from the value returned by s_getpc
|
|
|
|
// (which is the address of the s_add_u32 instruction) to the global
|
|
|
|
// variable, but since the encoding of $symbol starts 4 bytes after the start
|
|
|
|
// of the s_add_u32 instruction, we end up with an offset that is 4 bytes too
|
|
|
|
// small. This requires us to add 4 to the global variable offset in order to
|
2020-09-01 21:52:01 +08:00
|
|
|
// compute the correct address. Similarly for the s_addc_u32 instruction, the
|
|
|
|
// encoding of $symbol starts 12 bytes after the start of the s_add_u32
|
|
|
|
// instruction.
|
2019-10-01 09:06:43 +08:00
|
|
|
|
|
|
|
LLT ConstPtrTy = LLT::pointer(AMDGPUAS::CONSTANT_ADDRESS, 64);
|
|
|
|
|
|
|
|
Register PCReg = PtrTy.getSizeInBits() != 32 ? DstReg :
|
|
|
|
B.getMRI()->createGenericVirtualRegister(ConstPtrTy);
|
|
|
|
|
|
|
|
MachineInstrBuilder MIB = B.buildInstr(AMDGPU::SI_PC_ADD_REL_OFFSET)
|
|
|
|
.addDef(PCReg);
|
|
|
|
|
|
|
|
MIB.addGlobalAddress(GV, Offset + 4, GAFlags);
|
|
|
|
if (GAFlags == SIInstrInfo::MO_NONE)
|
|
|
|
MIB.addImm(0);
|
|
|
|
else
|
2020-09-01 21:52:01 +08:00
|
|
|
MIB.addGlobalAddress(GV, Offset + 12, GAFlags + 1);
|
2019-10-01 09:06:43 +08:00
|
|
|
|
|
|
|
B.getMRI()->setRegClass(PCReg, &AMDGPU::SReg_64RegClass);
|
|
|
|
|
|
|
|
if (PtrTy.getSizeInBits() == 32)
|
|
|
|
B.buildExtract(DstReg, PCReg, 0);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-09-10 01:13:44 +08:00
|
|
|
bool AMDGPULegalizerInfo::legalizeGlobalValue(
|
|
|
|
MachineInstr &MI, MachineRegisterInfo &MRI,
|
|
|
|
MachineIRBuilder &B) const {
|
|
|
|
Register DstReg = MI.getOperand(0).getReg();
|
|
|
|
LLT Ty = MRI.getType(DstReg);
|
|
|
|
unsigned AS = Ty.getAddressSpace();
|
|
|
|
|
|
|
|
const GlobalValue *GV = MI.getOperand(1).getGlobal();
|
|
|
|
MachineFunction &MF = B.getMF();
|
|
|
|
SIMachineFunctionInfo *MFI = MF.getInfo<SIMachineFunctionInfo>();
|
|
|
|
|
|
|
|
if (AS == AMDGPUAS::LOCAL_ADDRESS || AS == AMDGPUAS::REGION_ADDRESS) {
|
2021-05-21 06:32:43 +08:00
|
|
|
if (!MFI->isModuleEntryFunction() &&
|
|
|
|
!GV->getName().equals("llvm.amdgcn.module.lds")) {
|
2019-09-10 01:13:44 +08:00
|
|
|
const Function &Fn = MF.getFunction();
|
|
|
|
DiagnosticInfoUnsupported BadLDSDecl(
|
2020-03-11 23:49:03 +08:00
|
|
|
Fn, "local memory global used by non-kernel function", MI.getDebugLoc(),
|
|
|
|
DS_Warning);
|
2019-09-10 01:13:44 +08:00
|
|
|
Fn.getContext().diagnose(BadLDSDecl);
|
2020-03-11 23:49:03 +08:00
|
|
|
|
|
|
|
// We currently don't have a way to correctly allocate LDS objects that
|
|
|
|
// aren't directly associated with a kernel. We do force inlining of
|
|
|
|
// functions that use local objects. However, if these dead functions are
|
|
|
|
// not eliminated, we don't want a compile time error. Just emit a warning
|
|
|
|
// and a trap, since there should be no callable path here.
|
|
|
|
B.buildIntrinsic(Intrinsic::trap, ArrayRef<Register>(), true);
|
|
|
|
B.buildUndef(DstReg);
|
|
|
|
MI.eraseFromParent();
|
|
|
|
return true;
|
2019-09-10 01:13:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: We could emit code to handle the initialization somewhere.
|
2021-09-17 00:06:16 +08:00
|
|
|
// We ignore the initializer for now and legalize it to allow selection.
|
|
|
|
// The initializer will anyway get errored out during assembly emission.
|
|
|
|
const SITargetLowering *TLI = ST.getTargetLowering();
|
|
|
|
if (!TLI->shouldUseLDSConstAddress(GV)) {
|
|
|
|
MI.getOperand(1).setTargetFlags(SIInstrInfo::MO_ABS32_LO);
|
|
|
|
return true; // Leave in place;
|
|
|
|
}
|
2020-01-26 12:20:38 +08:00
|
|
|
|
2021-09-17 00:06:16 +08:00
|
|
|
if (AS == AMDGPUAS::LOCAL_ADDRESS && GV->hasExternalLinkage()) {
|
|
|
|
Type *Ty = GV->getValueType();
|
|
|
|
// HIP uses an unsized array `extern __shared__ T s[]` or similar
|
|
|
|
// zero-sized type in other languages to declare the dynamic shared
|
|
|
|
// memory which size is not known at the compile time. They will be
|
|
|
|
// allocated by the runtime and placed directly after the static
|
|
|
|
// allocated ones. They all share the same offset.
|
|
|
|
if (B.getDataLayout().getTypeAllocSize(Ty).isZero()) {
|
|
|
|
// Adjust alignment for that dynamic shared memory array.
|
|
|
|
MFI->setDynLDSAlign(B.getDataLayout(), *cast<GlobalVariable>(GV));
|
|
|
|
LLT S32 = LLT::scalar(32);
|
|
|
|
auto Sz =
|
|
|
|
B.buildIntrinsic(Intrinsic::amdgcn_groupstaticsize, {S32}, false);
|
|
|
|
B.buildIntToPtr(DstReg, Sz);
|
|
|
|
MI.eraseFromParent();
|
|
|
|
return true;
|
[amdgpu] Add codegen support for HIP dynamic shared memory.
Summary:
- HIP uses an unsized extern array `extern __shared__ T s[]` to declare
the dynamic shared memory, which size is not known at the
compile time.
Reviewers: arsenm, yaxunl, kpyzhov, b-sumner
Subscribers: kzhuravl, jvesely, wdng, nhaehnle, dstuttard, tpr, t-tye, hiraditya, kerbowa, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D82496
2020-06-25 00:13:10 +08:00
|
|
|
}
|
2019-09-10 01:13:44 +08:00
|
|
|
}
|
2019-10-01 09:06:43 +08:00
|
|
|
|
2021-09-17 00:06:16 +08:00
|
|
|
B.buildConstant(DstReg, MFI->allocateLDSGlobal(B.getDataLayout(),
|
|
|
|
*cast<GlobalVariable>(GV)));
|
|
|
|
MI.eraseFromParent();
|
2019-10-01 09:06:43 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
const SITargetLowering *TLI = ST.getTargetLowering();
|
|
|
|
|
|
|
|
if (TLI->shouldEmitFixup(GV)) {
|
|
|
|
buildPCRelGlobalAddress(DstReg, Ty, B, GV, 0);
|
|
|
|
MI.eraseFromParent();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (TLI->shouldEmitPCReloc(GV)) {
|
|
|
|
buildPCRelGlobalAddress(DstReg, Ty, B, GV, 0, SIInstrInfo::MO_REL32);
|
|
|
|
MI.eraseFromParent();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
LLT PtrTy = LLT::pointer(AMDGPUAS::CONSTANT_ADDRESS, 64);
|
|
|
|
Register GOTAddr = MRI.createGenericVirtualRegister(PtrTy);
|
|
|
|
|
2021-07-16 02:24:00 +08:00
|
|
|
LLT LoadTy = Ty.getSizeInBits() == 32 ? PtrTy : Ty;
|
2019-10-01 09:06:43 +08:00
|
|
|
MachineMemOperand *GOTMMO = MF.getMachineMemOperand(
|
[Alignment][NFC] Transitionning more getMachineMemOperand call sites
Summary:
This is patch is part of a series to introduce an Alignment type.
See this thread for context: http://lists.llvm.org/pipermail/llvm-dev/2019-July/133851.html
See this patch for the introduction of the type: https://reviews.llvm.org/D64790
Reviewers: courbet
Subscribers: arsenm, dylanmckay, sdardis, nemanjai, jvesely, nhaehnle, hiraditya, kbarton, jrtc27, atanasyan, Jim, kerbowa, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D77121
2020-03-31 16:05:00 +08:00
|
|
|
MachinePointerInfo::getGOT(MF),
|
|
|
|
MachineMemOperand::MOLoad | MachineMemOperand::MODereferenceable |
|
|
|
|
MachineMemOperand::MOInvariant,
|
2021-07-16 02:24:00 +08:00
|
|
|
LoadTy, Align(8));
|
2019-10-01 09:06:43 +08:00
|
|
|
|
|
|
|
buildPCRelGlobalAddress(GOTAddr, PtrTy, B, GV, 0, SIInstrInfo::MO_GOTPCREL32);
|
|
|
|
|
|
|
|
if (Ty.getSizeInBits() == 32) {
|
2021-09-21 05:28:10 +08:00
|
|
|
// Truncate if this is a 32-bit constant address.
|
2019-10-01 09:06:43 +08:00
|
|
|
auto Load = B.buildLoad(PtrTy, GOTAddr, *GOTMMO);
|
|
|
|
B.buildExtract(DstReg, Load, 0);
|
2019-09-10 01:13:44 +08:00
|
|
|
} else
|
2019-10-01 09:06:43 +08:00
|
|
|
B.buildLoad(DstReg, GOTAddr, *GOTMMO);
|
2019-09-10 01:13:44 +08:00
|
|
|
|
2019-10-01 09:06:43 +08:00
|
|
|
MI.eraseFromParent();
|
2019-09-10 01:13:44 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-06-27 07:02:46 +08:00
|
|
|
static LLT widenToNextPowerOf2(LLT Ty) {
|
|
|
|
if (Ty.isVector())
|
2021-06-25 18:27:41 +08:00
|
|
|
return Ty.changeElementCount(
|
|
|
|
ElementCount::getFixed(PowerOf2Ceil(Ty.getNumElements())));
|
2020-06-27 07:02:46 +08:00
|
|
|
return LLT::scalar(PowerOf2Ceil(Ty.getSizeInBits()));
|
|
|
|
}
|
|
|
|
|
2020-05-25 02:31:06 +08:00
|
|
|
bool AMDGPULegalizerInfo::legalizeLoad(LegalizerHelper &Helper,
|
|
|
|
MachineInstr &MI) const {
|
|
|
|
MachineIRBuilder &B = Helper.MIRBuilder;
|
|
|
|
MachineRegisterInfo &MRI = *B.getMRI();
|
|
|
|
GISelChangeObserver &Observer = Helper.Observer;
|
|
|
|
|
|
|
|
Register PtrReg = MI.getOperand(1).getReg();
|
|
|
|
LLT PtrTy = MRI.getType(PtrReg);
|
|
|
|
unsigned AddrSpace = PtrTy.getAddressSpace();
|
|
|
|
|
|
|
|
if (AddrSpace == AMDGPUAS::CONSTANT_ADDRESS_32BIT) {
|
|
|
|
LLT ConstPtr = LLT::pointer(AMDGPUAS::CONSTANT_ADDRESS, 64);
|
|
|
|
auto Cast = B.buildAddrSpaceCast(ConstPtr, PtrReg);
|
|
|
|
Observer.changingInstr(MI);
|
|
|
|
MI.getOperand(1).setReg(Cast.getReg(0));
|
|
|
|
Observer.changedInstr(MI);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2021-05-19 06:22:09 +08:00
|
|
|
if (MI.getOpcode() != AMDGPU::G_LOAD)
|
|
|
|
return false;
|
|
|
|
|
2020-06-27 07:02:46 +08:00
|
|
|
Register ValReg = MI.getOperand(0).getReg();
|
|
|
|
LLT ValTy = MRI.getType(ValReg);
|
|
|
|
|
|
|
|
MachineMemOperand *MMO = *MI.memoperands_begin();
|
|
|
|
const unsigned ValSize = ValTy.getSizeInBits();
|
2021-06-09 08:22:45 +08:00
|
|
|
const LLT MemTy = MMO->getMemoryType();
|
2020-06-27 07:02:46 +08:00
|
|
|
const Align MemAlign = MMO->getAlign();
|
2021-06-09 08:22:45 +08:00
|
|
|
const unsigned MemSize = MemTy.getSizeInBits();
|
2022-01-13 04:01:27 +08:00
|
|
|
const uint64_t AlignInBits = 8 * MemAlign.value();
|
2020-06-27 07:02:46 +08:00
|
|
|
|
|
|
|
// Widen non-power-of-2 loads to the alignment if needed
|
2021-06-09 08:22:45 +08:00
|
|
|
if (shouldWidenLoad(ST, MemTy, AlignInBits, AddrSpace, MI.getOpcode())) {
|
2020-06-27 07:02:46 +08:00
|
|
|
const unsigned WideMemSize = PowerOf2Ceil(MemSize);
|
|
|
|
|
|
|
|
// This was already the correct extending load result type, so just adjust
|
|
|
|
// the memory type.
|
|
|
|
if (WideMemSize == ValSize) {
|
|
|
|
MachineFunction &MF = B.getMF();
|
|
|
|
|
|
|
|
MachineMemOperand *WideMMO =
|
|
|
|
MF.getMachineMemOperand(MMO, 0, WideMemSize / 8);
|
|
|
|
Observer.changingInstr(MI);
|
|
|
|
MI.setMemRefs(MF, {WideMMO});
|
|
|
|
Observer.changedInstr(MI);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Don't bother handling edge case that should probably never be produced.
|
|
|
|
if (ValSize > WideMemSize)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
LLT WideTy = widenToNextPowerOf2(ValTy);
|
|
|
|
|
|
|
|
Register WideLoad;
|
|
|
|
if (!WideTy.isVector()) {
|
|
|
|
WideLoad = B.buildLoadFromOffset(WideTy, PtrReg, *MMO, 0).getReg(0);
|
|
|
|
B.buildTrunc(ValReg, WideLoad).getReg(0);
|
|
|
|
} else {
|
|
|
|
// Extract the subvector.
|
|
|
|
|
|
|
|
if (isRegisterType(ValTy)) {
|
|
|
|
// If this a case where G_EXTRACT is legal, use it.
|
|
|
|
// (e.g. <3 x s32> -> <4 x s32>)
|
|
|
|
WideLoad = B.buildLoadFromOffset(WideTy, PtrReg, *MMO, 0).getReg(0);
|
|
|
|
B.buildExtract(ValReg, WideLoad, 0);
|
|
|
|
} else {
|
|
|
|
// For cases where the widened type isn't a nice register value, unmerge
|
|
|
|
// from a widened register (e.g. <3 x s16> -> <4 x s16>)
|
2021-12-23 21:09:51 +08:00
|
|
|
WideLoad = B.buildLoadFromOffset(WideTy, PtrReg, *MMO, 0).getReg(0);
|
|
|
|
B.buildDeleteTrailingVectorElements(ValReg, WideLoad);
|
2020-06-27 07:02:46 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
MI.eraseFromParent();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-05-25 02:31:06 +08:00
|
|
|
return false;
|
2019-09-11 00:42:31 +08:00
|
|
|
}
|
|
|
|
|
2019-09-13 08:44:35 +08:00
|
|
|
bool AMDGPULegalizerInfo::legalizeFMad(
|
|
|
|
MachineInstr &MI, MachineRegisterInfo &MRI,
|
|
|
|
MachineIRBuilder &B) const {
|
|
|
|
LLT Ty = MRI.getType(MI.getOperand(0).getReg());
|
|
|
|
assert(Ty.isScalar());
|
|
|
|
|
2019-11-02 00:44:56 +08:00
|
|
|
MachineFunction &MF = B.getMF();
|
|
|
|
const SIMachineFunctionInfo *MFI = MF.getInfo<SIMachineFunctionInfo>();
|
|
|
|
|
2019-09-13 08:44:35 +08:00
|
|
|
// TODO: Always legal with future ftz flag.
|
2019-12-03 15:01:21 +08:00
|
|
|
// FIXME: Do we need just output?
|
|
|
|
if (Ty == LLT::scalar(32) && !MFI->getMode().allFP32Denormals())
|
2019-09-13 08:44:35 +08:00
|
|
|
return true;
|
2019-12-03 15:01:21 +08:00
|
|
|
if (Ty == LLT::scalar(16) && !MFI->getMode().allFP64FP16Denormals())
|
2019-09-13 08:44:35 +08:00
|
|
|
return true;
|
|
|
|
|
|
|
|
MachineIRBuilder HelperBuilder(MI);
|
|
|
|
GISelObserverWrapper DummyObserver;
|
|
|
|
LegalizerHelper Helper(MF, DummyObserver, HelperBuilder);
|
|
|
|
return Helper.lowerFMad(MI) == LegalizerHelper::Legalized;
|
|
|
|
}
|
|
|
|
|
2019-10-09 01:04:41 +08:00
|
|
|
bool AMDGPULegalizerInfo::legalizeAtomicCmpXChg(
|
|
|
|
MachineInstr &MI, MachineRegisterInfo &MRI, MachineIRBuilder &B) const {
|
|
|
|
Register DstReg = MI.getOperand(0).getReg();
|
|
|
|
Register PtrReg = MI.getOperand(1).getReg();
|
|
|
|
Register CmpVal = MI.getOperand(2).getReg();
|
|
|
|
Register NewVal = MI.getOperand(3).getReg();
|
|
|
|
|
2016-05-28 06:50:12 +08:00
|
|
|
assert(AMDGPU::isFlatGlobalAddrSpace(MRI.getType(PtrReg).getAddressSpace()) &&
|
2019-10-09 01:04:41 +08:00
|
|
|
"this should not have been custom lowered");
|
|
|
|
|
|
|
|
LLT ValTy = MRI.getType(CmpVal);
|
2021-06-24 16:58:21 +08:00
|
|
|
LLT VecTy = LLT::fixed_vector(2, ValTy);
|
2019-10-09 01:04:41 +08:00
|
|
|
|
|
|
|
Register PackedVal = B.buildBuildVector(VecTy, { NewVal, CmpVal }).getReg(0);
|
|
|
|
|
|
|
|
B.buildInstr(AMDGPU::G_AMDGPU_ATOMIC_CMPXCHG)
|
|
|
|
.addDef(DstReg)
|
|
|
|
.addUse(PtrReg)
|
|
|
|
.addUse(PackedVal)
|
|
|
|
.setMemRefs(MI.memoperands());
|
|
|
|
|
|
|
|
MI.eraseFromParent();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-01-22 11:29:30 +08:00
|
|
|
bool AMDGPULegalizerInfo::legalizeFlog(
|
|
|
|
MachineInstr &MI, MachineIRBuilder &B, double Log2BaseInverted) const {
|
|
|
|
Register Dst = MI.getOperand(0).getReg();
|
|
|
|
Register Src = MI.getOperand(1).getReg();
|
|
|
|
LLT Ty = B.getMRI()->getType(Dst);
|
|
|
|
unsigned Flags = MI.getFlags();
|
|
|
|
|
|
|
|
auto Log2Operand = B.buildFLog2(Ty, Src, Flags);
|
|
|
|
auto Log2BaseInvertedOperand = B.buildFConstant(Ty, Log2BaseInverted);
|
|
|
|
|
|
|
|
B.buildFMul(Dst, Log2Operand, Log2BaseInvertedOperand, Flags);
|
|
|
|
MI.eraseFromParent();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-01-25 09:53:26 +08:00
|
|
|
bool AMDGPULegalizerInfo::legalizeFExp(MachineInstr &MI,
|
|
|
|
MachineIRBuilder &B) const {
|
|
|
|
Register Dst = MI.getOperand(0).getReg();
|
|
|
|
Register Src = MI.getOperand(1).getReg();
|
|
|
|
unsigned Flags = MI.getFlags();
|
|
|
|
LLT Ty = B.getMRI()->getType(Dst);
|
|
|
|
|
|
|
|
auto K = B.buildFConstant(Ty, numbers::log2e);
|
|
|
|
auto Mul = B.buildFMul(Ty, Src, K, Flags);
|
|
|
|
B.buildFExp2(Dst, Mul, Flags);
|
2020-01-05 04:35:26 +08:00
|
|
|
MI.eraseFromParent();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-02-21 07:59:08 +08:00
|
|
|
bool AMDGPULegalizerInfo::legalizeFPow(MachineInstr &MI,
|
|
|
|
MachineIRBuilder &B) const {
|
|
|
|
Register Dst = MI.getOperand(0).getReg();
|
|
|
|
Register Src0 = MI.getOperand(1).getReg();
|
|
|
|
Register Src1 = MI.getOperand(2).getReg();
|
|
|
|
unsigned Flags = MI.getFlags();
|
|
|
|
LLT Ty = B.getMRI()->getType(Dst);
|
|
|
|
const LLT S16 = LLT::scalar(16);
|
|
|
|
const LLT S32 = LLT::scalar(32);
|
|
|
|
|
|
|
|
if (Ty == S32) {
|
|
|
|
auto Log = B.buildFLog2(S32, Src0, Flags);
|
|
|
|
auto Mul = B.buildIntrinsic(Intrinsic::amdgcn_fmul_legacy, {S32}, false)
|
|
|
|
.addUse(Log.getReg(0))
|
|
|
|
.addUse(Src1)
|
|
|
|
.setMIFlags(Flags);
|
|
|
|
B.buildFExp2(Dst, Mul, Flags);
|
|
|
|
} else if (Ty == S16) {
|
|
|
|
// There's no f16 fmul_legacy, so we need to convert for it.
|
|
|
|
auto Log = B.buildFLog2(S16, Src0, Flags);
|
|
|
|
auto Ext0 = B.buildFPExt(S32, Log, Flags);
|
|
|
|
auto Ext1 = B.buildFPExt(S32, Src1, Flags);
|
|
|
|
auto Mul = B.buildIntrinsic(Intrinsic::amdgcn_fmul_legacy, {S32}, false)
|
|
|
|
.addUse(Ext0.getReg(0))
|
|
|
|
.addUse(Ext1.getReg(0))
|
|
|
|
.setMIFlags(Flags);
|
|
|
|
|
|
|
|
B.buildFExp2(Dst, B.buildFPTrunc(S16, Mul), Flags);
|
|
|
|
} else
|
|
|
|
return false;
|
|
|
|
|
|
|
|
MI.eraseFromParent();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-01-24 23:01:15 +08:00
|
|
|
// Find a source register, ignoring any possible source modifiers.
|
|
|
|
static Register stripAnySourceMods(Register OrigSrc, MachineRegisterInfo &MRI) {
|
|
|
|
Register ModSrc = OrigSrc;
|
|
|
|
if (MachineInstr *SrcFNeg = getOpcodeDef(AMDGPU::G_FNEG, ModSrc, MRI)) {
|
|
|
|
ModSrc = SrcFNeg->getOperand(1).getReg();
|
|
|
|
if (MachineInstr *SrcFAbs = getOpcodeDef(AMDGPU::G_FABS, ModSrc, MRI))
|
|
|
|
ModSrc = SrcFAbs->getOperand(1).getReg();
|
|
|
|
} else if (MachineInstr *SrcFAbs = getOpcodeDef(AMDGPU::G_FABS, ModSrc, MRI))
|
|
|
|
ModSrc = SrcFAbs->getOperand(1).getReg();
|
|
|
|
return ModSrc;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool AMDGPULegalizerInfo::legalizeFFloor(MachineInstr &MI,
|
|
|
|
MachineRegisterInfo &MRI,
|
|
|
|
MachineIRBuilder &B) const {
|
|
|
|
|
|
|
|
const LLT S1 = LLT::scalar(1);
|
|
|
|
const LLT S64 = LLT::scalar(64);
|
|
|
|
Register Dst = MI.getOperand(0).getReg();
|
|
|
|
Register OrigSrc = MI.getOperand(1).getReg();
|
|
|
|
unsigned Flags = MI.getFlags();
|
|
|
|
assert(ST.hasFractBug() && MRI.getType(Dst) == S64 &&
|
|
|
|
"this should not have been custom lowered");
|
|
|
|
|
|
|
|
// V_FRACT is buggy on SI, so the F32 version is never used and (x-floor(x))
|
|
|
|
// is used instead. However, SI doesn't have V_FLOOR_F64, so the most
|
|
|
|
// efficient way to implement it is using V_FRACT_F64. The workaround for the
|
|
|
|
// V_FRACT bug is:
|
|
|
|
// fract(x) = isnan(x) ? x : min(V_FRACT(x), 0.99999999999999999)
|
|
|
|
//
|
|
|
|
// Convert floor(x) to (x - fract(x))
|
|
|
|
|
|
|
|
auto Fract = B.buildIntrinsic(Intrinsic::amdgcn_fract, {S64}, false)
|
|
|
|
.addUse(OrigSrc)
|
|
|
|
.setMIFlags(Flags);
|
|
|
|
|
|
|
|
// Give source modifier matching some assistance before obscuring a foldable
|
|
|
|
// pattern.
|
|
|
|
|
|
|
|
// TODO: We can avoid the neg on the fract? The input sign to fract
|
|
|
|
// shouldn't matter?
|
|
|
|
Register ModSrc = stripAnySourceMods(OrigSrc, MRI);
|
|
|
|
|
|
|
|
auto Const = B.buildFConstant(S64, BitsToDouble(0x3fefffffffffffff));
|
|
|
|
|
|
|
|
Register Min = MRI.createGenericVirtualRegister(S64);
|
|
|
|
|
|
|
|
// We don't need to concern ourselves with the snan handling difference, so
|
|
|
|
// use the one which will directly select.
|
|
|
|
const SIMachineFunctionInfo *MFI = B.getMF().getInfo<SIMachineFunctionInfo>();
|
|
|
|
if (MFI->getMode().IEEE)
|
|
|
|
B.buildFMinNumIEEE(Min, Fract, Const, Flags);
|
|
|
|
else
|
|
|
|
B.buildFMinNum(Min, Fract, Const, Flags);
|
|
|
|
|
|
|
|
Register CorrectedFract = Min;
|
|
|
|
if (!MI.getFlag(MachineInstr::FmNoNans)) {
|
|
|
|
auto IsNan = B.buildFCmp(CmpInst::FCMP_ORD, S1, ModSrc, ModSrc, Flags);
|
|
|
|
CorrectedFract = B.buildSelect(S64, IsNan, ModSrc, Min, Flags).getReg(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
auto NegFract = B.buildFNeg(S64, CorrectedFract, Flags);
|
|
|
|
B.buildFAdd(Dst, OrigSrc, NegFract, Flags);
|
|
|
|
|
|
|
|
MI.eraseFromParent();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-01-05 04:35:26 +08:00
|
|
|
// Turn an illegal packed v2s16 build vector into bit operations.
|
|
|
|
// TODO: This should probably be a bitcast action in LegalizerHelper.
|
|
|
|
bool AMDGPULegalizerInfo::legalizeBuildVector(
|
|
|
|
MachineInstr &MI, MachineRegisterInfo &MRI, MachineIRBuilder &B) const {
|
|
|
|
Register Dst = MI.getOperand(0).getReg();
|
|
|
|
const LLT S32 = LLT::scalar(32);
|
2021-06-24 16:58:21 +08:00
|
|
|
assert(MRI.getType(Dst) == LLT::fixed_vector(2, 16));
|
2020-01-05 04:35:26 +08:00
|
|
|
|
|
|
|
Register Src0 = MI.getOperand(1).getReg();
|
|
|
|
Register Src1 = MI.getOperand(2).getReg();
|
|
|
|
assert(MRI.getType(Src0) == LLT::scalar(16));
|
|
|
|
|
|
|
|
auto Merge = B.buildMerge(S32, {Src0, Src1});
|
|
|
|
B.buildBitcast(Dst, Merge);
|
2020-01-25 09:53:26 +08:00
|
|
|
|
|
|
|
MI.eraseFromParent();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2021-08-04 00:11:08 +08:00
|
|
|
// Legalize ctlz/cttz to ffbh/ffbl instead of the default legalization to
|
|
|
|
// ctlz/cttz_zero_undef. This allows us to fix up the result for the zero input
|
|
|
|
// case with a single min instruction instead of a compare+select.
|
|
|
|
bool AMDGPULegalizerInfo::legalizeCTLZ_CTTZ(MachineInstr &MI,
|
|
|
|
MachineRegisterInfo &MRI,
|
|
|
|
MachineIRBuilder &B) const {
|
|
|
|
Register Dst = MI.getOperand(0).getReg();
|
|
|
|
Register Src = MI.getOperand(1).getReg();
|
|
|
|
LLT DstTy = MRI.getType(Dst);
|
|
|
|
LLT SrcTy = MRI.getType(Src);
|
|
|
|
|
|
|
|
unsigned NewOpc = MI.getOpcode() == AMDGPU::G_CTLZ
|
|
|
|
? AMDGPU::G_AMDGPU_FFBH_U32
|
|
|
|
: AMDGPU::G_AMDGPU_FFBL_B32;
|
|
|
|
auto Tmp = B.buildInstr(NewOpc, {DstTy}, {Src});
|
|
|
|
B.buildUMin(Dst, Tmp, B.buildConstant(DstTy, SrcTy.getSizeInBits()));
|
|
|
|
|
|
|
|
MI.eraseFromParent();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-08-26 07:53:32 +08:00
|
|
|
// Check that this is a G_XOR x, -1
|
|
|
|
static bool isNot(const MachineRegisterInfo &MRI, const MachineInstr &MI) {
|
|
|
|
if (MI.getOpcode() != TargetOpcode::G_XOR)
|
|
|
|
return false;
|
2021-09-17 17:21:55 +08:00
|
|
|
auto ConstVal = getIConstantVRegSExtVal(MI.getOperand(2).getReg(), MRI);
|
2020-08-26 07:53:32 +08:00
|
|
|
return ConstVal && *ConstVal == -1;
|
|
|
|
}
|
|
|
|
|
2019-07-02 02:40:23 +08:00
|
|
|
// Return the use branch instruction, otherwise null if the usage is invalid.
|
2020-08-26 07:53:32 +08:00
|
|
|
static MachineInstr *
|
|
|
|
verifyCFIntrinsic(MachineInstr &MI, MachineRegisterInfo &MRI, MachineInstr *&Br,
|
|
|
|
MachineBasicBlock *&UncondBrTarget, bool &Negated) {
|
2019-07-02 02:40:23 +08:00
|
|
|
Register CondDef = MI.getOperand(0).getReg();
|
|
|
|
if (!MRI.hasOneNonDBGUse(CondDef))
|
|
|
|
return nullptr;
|
|
|
|
|
2020-05-17 22:51:22 +08:00
|
|
|
MachineBasicBlock *Parent = MI.getParent();
|
2020-08-26 07:53:32 +08:00
|
|
|
MachineInstr *UseMI = &*MRI.use_instr_nodbg_begin(CondDef);
|
|
|
|
|
|
|
|
if (isNot(MRI, *UseMI)) {
|
|
|
|
Register NegatedCond = UseMI->getOperand(0).getReg();
|
|
|
|
if (!MRI.hasOneNonDBGUse(NegatedCond))
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
// We're deleting the def of this value, so we need to remove it.
|
2021-09-20 19:00:13 +08:00
|
|
|
eraseInstr(*UseMI, MRI);
|
2020-08-26 07:53:32 +08:00
|
|
|
|
|
|
|
UseMI = &*MRI.use_instr_nodbg_begin(NegatedCond);
|
|
|
|
Negated = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (UseMI->getParent() != Parent || UseMI->getOpcode() != AMDGPU::G_BRCOND)
|
2020-01-06 11:09:24 +08:00
|
|
|
return nullptr;
|
|
|
|
|
2020-05-17 22:51:22 +08:00
|
|
|
// Make sure the cond br is followed by a G_BR, or is the last instruction.
|
2020-08-26 07:53:32 +08:00
|
|
|
MachineBasicBlock::iterator Next = std::next(UseMI->getIterator());
|
2020-05-17 22:51:22 +08:00
|
|
|
if (Next == Parent->end()) {
|
|
|
|
MachineFunction::iterator NextMBB = std::next(Parent->getIterator());
|
|
|
|
if (NextMBB == Parent->getParent()->end()) // Illegal intrinsic use.
|
|
|
|
return nullptr;
|
|
|
|
UncondBrTarget = &*NextMBB;
|
|
|
|
} else {
|
2020-01-06 11:09:24 +08:00
|
|
|
if (Next->getOpcode() != AMDGPU::G_BR)
|
|
|
|
return nullptr;
|
|
|
|
Br = &*Next;
|
2020-05-17 22:51:22 +08:00
|
|
|
UncondBrTarget = Br->getOperand(0).getMBB();
|
2020-01-06 11:09:24 +08:00
|
|
|
}
|
|
|
|
|
2020-08-26 07:53:32 +08:00
|
|
|
return UseMI;
|
2019-07-02 02:40:23 +08:00
|
|
|
}
|
|
|
|
|
2019-07-02 02:45:36 +08:00
|
|
|
bool AMDGPULegalizerInfo::loadInputValue(Register DstReg, MachineIRBuilder &B,
|
2020-07-21 03:56:39 +08:00
|
|
|
const ArgDescriptor *Arg,
|
|
|
|
const TargetRegisterClass *ArgRC,
|
|
|
|
LLT ArgTy) const {
|
|
|
|
MCRegister SrcReg = Arg->getRegister();
|
2020-10-09 13:08:13 +08:00
|
|
|
assert(Register::isPhysicalRegister(SrcReg) && "Physical register expected");
|
AMDGPU/GlobalISel: Support llvm.trap and llvm.debugtrap intrinsics
Summary: Lower trap and debugtrap intrinsics to AMDGPU machine instruction(s).
Reviewers: arsenm, nhaehnle, kerbowa, cdevadas, t-tye, kzhuravl
Reviewed By: arsenm
Subscribers: kzhuravl, jvesely, wdng, yaxunl, rovka, dstuttard, tpr, hiraditya, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D74688
2020-03-05 10:45:55 +08:00
|
|
|
assert(DstReg.isVirtual() && "Virtual register expected");
|
2019-07-02 02:45:36 +08:00
|
|
|
|
2022-01-09 23:25:36 +08:00
|
|
|
Register LiveIn = getFunctionLiveInPhysReg(B.getMF(), B.getTII(), SrcReg,
|
|
|
|
*ArgRC, B.getDebugLoc(), ArgTy);
|
2019-07-02 02:45:36 +08:00
|
|
|
if (Arg->isMasked()) {
|
|
|
|
// TODO: Should we try to emit this once in the entry block?
|
|
|
|
const LLT S32 = LLT::scalar(32);
|
|
|
|
const unsigned Mask = Arg->getMask();
|
|
|
|
const unsigned Shift = countTrailingZeros<unsigned>(Mask);
|
|
|
|
|
2019-10-01 09:44:46 +08:00
|
|
|
Register AndMaskSrc = LiveIn;
|
|
|
|
|
2022-01-10 08:33:57 +08:00
|
|
|
// TODO: Avoid clearing the high bits if we know workitem id y/z are always
|
|
|
|
// 0.
|
2019-10-01 09:44:46 +08:00
|
|
|
if (Shift != 0) {
|
|
|
|
auto ShiftAmt = B.buildConstant(S32, Shift);
|
|
|
|
AndMaskSrc = B.buildLShr(S32, LiveIn, ShiftAmt).getReg(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
B.buildAnd(DstReg, AndMaskSrc, B.buildConstant(S32, Mask >> Shift));
|
AMDGPU/GlobalISel: Support llvm.trap and llvm.debugtrap intrinsics
Summary: Lower trap and debugtrap intrinsics to AMDGPU machine instruction(s).
Reviewers: arsenm, nhaehnle, kerbowa, cdevadas, t-tye, kzhuravl
Reviewed By: arsenm
Subscribers: kzhuravl, jvesely, wdng, yaxunl, rovka, dstuttard, tpr, hiraditya, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D74688
2020-03-05 10:45:55 +08:00
|
|
|
} else {
|
2019-07-02 02:45:36 +08:00
|
|
|
B.buildCopy(DstReg, LiveIn);
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-07-21 03:56:39 +08:00
|
|
|
bool AMDGPULegalizerInfo::loadInputValue(
|
|
|
|
Register DstReg, MachineIRBuilder &B,
|
AMDGPU/GlobalISel: Support llvm.trap and llvm.debugtrap intrinsics
Summary: Lower trap and debugtrap intrinsics to AMDGPU machine instruction(s).
Reviewers: arsenm, nhaehnle, kerbowa, cdevadas, t-tye, kzhuravl
Reviewed By: arsenm
Subscribers: kzhuravl, jvesely, wdng, yaxunl, rovka, dstuttard, tpr, hiraditya, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D74688
2020-03-05 10:45:55 +08:00
|
|
|
AMDGPUFunctionArgInfo::PreloadedValue ArgType) const {
|
2020-07-21 03:56:39 +08:00
|
|
|
const SIMachineFunctionInfo *MFI = B.getMF().getInfo<SIMachineFunctionInfo>();
|
|
|
|
const ArgDescriptor *Arg;
|
|
|
|
const TargetRegisterClass *ArgRC;
|
|
|
|
LLT ArgTy;
|
|
|
|
std::tie(Arg, ArgRC, ArgTy) = MFI->getPreloadedValue(ArgType);
|
2019-07-02 02:45:36 +08:00
|
|
|
|
2021-08-14 08:43:32 +08:00
|
|
|
if (!Arg) {
|
2021-08-14 09:45:46 +08:00
|
|
|
if (ArgType == AMDGPUFunctionArgInfo::KERNARG_SEGMENT_PTR) {
|
|
|
|
// The intrinsic may appear when we have a 0 sized kernarg segment, in which
|
|
|
|
// case the pointer argument may be missing and we use null.
|
|
|
|
B.buildConstant(DstReg, 0);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// It's undefined behavior if a function marked with the amdgpu-no-*
|
|
|
|
// attributes uses the corresponding intrinsic.
|
|
|
|
B.buildUndef(DstReg);
|
2021-08-14 08:43:32 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-07-21 03:56:39 +08:00
|
|
|
if (!Arg->isRegister() || !Arg->getRegister().isValid())
|
|
|
|
return false; // TODO: Handle these
|
|
|
|
return loadInputValue(DstReg, B, Arg, ArgRC, ArgTy);
|
|
|
|
}
|
2019-07-02 02:45:36 +08:00
|
|
|
|
2020-07-21 03:56:39 +08:00
|
|
|
bool AMDGPULegalizerInfo::legalizePreloadedArgIntrin(
|
|
|
|
MachineInstr &MI, MachineRegisterInfo &MRI, MachineIRBuilder &B,
|
|
|
|
AMDGPUFunctionArgInfo::PreloadedValue ArgType) const {
|
|
|
|
if (!loadInputValue(MI.getOperand(0).getReg(), B, ArgType))
|
AMDGPU/GlobalISel: Support llvm.trap and llvm.debugtrap intrinsics
Summary: Lower trap and debugtrap intrinsics to AMDGPU machine instruction(s).
Reviewers: arsenm, nhaehnle, kerbowa, cdevadas, t-tye, kzhuravl
Reviewed By: arsenm
Subscribers: kzhuravl, jvesely, wdng, yaxunl, rovka, dstuttard, tpr, hiraditya, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D74688
2020-03-05 10:45:55 +08:00
|
|
|
return false;
|
2019-07-02 02:45:36 +08:00
|
|
|
|
AMDGPU/GlobalISel: Support llvm.trap and llvm.debugtrap intrinsics
Summary: Lower trap and debugtrap intrinsics to AMDGPU machine instruction(s).
Reviewers: arsenm, nhaehnle, kerbowa, cdevadas, t-tye, kzhuravl
Reviewed By: arsenm
Subscribers: kzhuravl, jvesely, wdng, yaxunl, rovka, dstuttard, tpr, hiraditya, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D74688
2020-03-05 10:45:55 +08:00
|
|
|
MI.eraseFromParent();
|
|
|
|
return true;
|
2019-07-02 02:45:36 +08:00
|
|
|
}
|
|
|
|
|
AMDGPU/GlobalISel: Legalize fast unsafe FDIV
Reviewers: arsenm
Reviewed By: arsenm
Subscribers: kzhuravl, jvesely, wdng, nhaehnle, yaxunl, rovka, dstuttard, tpr, t-tye, hiraditya, Petar.Avramovic, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D69231
llvm-svn: 375460
2019-10-22 06:18:26 +08:00
|
|
|
bool AMDGPULegalizerInfo::legalizeFDIV(MachineInstr &MI,
|
|
|
|
MachineRegisterInfo &MRI,
|
|
|
|
MachineIRBuilder &B) const {
|
AMDGPU/GlobalISel: Legalize FDIV16
Reviewers: arsenm
Reviewed By: arsenm
Subscribers: kzhuravl, jvesely, wdng, nhaehnle, yaxunl, rovka, dstuttard, tpr, t-tye, hiraditya, volkan, Petar.Avramovic, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D69347
2019-10-23 08:39:26 +08:00
|
|
|
Register Dst = MI.getOperand(0).getReg();
|
|
|
|
LLT DstTy = MRI.getType(Dst);
|
|
|
|
LLT S16 = LLT::scalar(16);
|
AMDGPU/GlobalISel: Legalize FDIV32
Reviewers: arsenm
Subscribers: kzhuravl, jvesely, wdng, nhaehnle, yaxunl, rovka, dstuttard, tpr, t-tye, hiraditya, Petar.Avramovic, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D69581
2019-10-30 00:55:49 +08:00
|
|
|
LLT S32 = LLT::scalar(32);
|
AMDGPU/GlobalISel: Legalize FDIV64
Reviewers: arsenm
Reviewed By: arsenm
Subscribers: kzhuravl, jvesely, wdng, nhaehnle, yaxunl, rovka, dstuttard, tpr, t-tye, hiraditya, Petar.Avramovic, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D70403
2019-11-18 08:43:59 +08:00
|
|
|
LLT S64 = LLT::scalar(64);
|
AMDGPU/GlobalISel: Legalize fast unsafe FDIV
Reviewers: arsenm
Reviewed By: arsenm
Subscribers: kzhuravl, jvesely, wdng, nhaehnle, yaxunl, rovka, dstuttard, tpr, t-tye, hiraditya, Petar.Avramovic, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D69231
llvm-svn: 375460
2019-10-22 06:18:26 +08:00
|
|
|
|
AMDGPU/GlobalISel: Legalize FDIV16
Reviewers: arsenm
Reviewed By: arsenm
Subscribers: kzhuravl, jvesely, wdng, nhaehnle, yaxunl, rovka, dstuttard, tpr, t-tye, hiraditya, volkan, Petar.Avramovic, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D69347
2019-10-23 08:39:26 +08:00
|
|
|
if (DstTy == S16)
|
|
|
|
return legalizeFDIV16(MI, MRI, B);
|
AMDGPU/GlobalISel: Legalize FDIV32
Reviewers: arsenm
Subscribers: kzhuravl, jvesely, wdng, nhaehnle, yaxunl, rovka, dstuttard, tpr, t-tye, hiraditya, Petar.Avramovic, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D69581
2019-10-30 00:55:49 +08:00
|
|
|
if (DstTy == S32)
|
|
|
|
return legalizeFDIV32(MI, MRI, B);
|
AMDGPU/GlobalISel: Legalize FDIV64
Reviewers: arsenm
Reviewed By: arsenm
Subscribers: kzhuravl, jvesely, wdng, nhaehnle, yaxunl, rovka, dstuttard, tpr, t-tye, hiraditya, Petar.Avramovic, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D70403
2019-11-18 08:43:59 +08:00
|
|
|
if (DstTy == S64)
|
|
|
|
return legalizeFDIV64(MI, MRI, B);
|
AMDGPU/GlobalISel: Legalize FDIV16
Reviewers: arsenm
Reviewed By: arsenm
Subscribers: kzhuravl, jvesely, wdng, nhaehnle, yaxunl, rovka, dstuttard, tpr, t-tye, hiraditya, volkan, Petar.Avramovic, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D69347
2019-10-23 08:39:26 +08:00
|
|
|
|
AMDGPU/GlobalISel: Legalize fast unsafe FDIV
Reviewers: arsenm
Reviewed By: arsenm
Subscribers: kzhuravl, jvesely, wdng, nhaehnle, yaxunl, rovka, dstuttard, tpr, t-tye, hiraditya, Petar.Avramovic, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D69231
llvm-svn: 375460
2019-10-22 06:18:26 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2021-04-12 18:19:47 +08:00
|
|
|
void AMDGPULegalizerInfo::legalizeUnsignedDIV_REM32Impl(MachineIRBuilder &B,
|
|
|
|
Register DstDivReg,
|
|
|
|
Register DstRemReg,
|
|
|
|
Register X,
|
|
|
|
Register Y) const {
|
2020-02-12 09:51:02 +08:00
|
|
|
const LLT S1 = LLT::scalar(1);
|
|
|
|
const LLT S32 = LLT::scalar(32);
|
|
|
|
|
2020-06-23 00:17:17 +08:00
|
|
|
// See AMDGPUCodeGenPrepare::expandDivRem32 for a description of the
|
|
|
|
// algorithm used here.
|
2020-02-12 09:51:02 +08:00
|
|
|
|
2020-06-23 00:17:17 +08:00
|
|
|
// Initial estimate of inv(y).
|
|
|
|
auto FloatY = B.buildUITOFP(S32, Y);
|
|
|
|
auto RcpIFlag = B.buildInstr(AMDGPU::G_AMDGPU_RCP_IFLAG, {S32}, {FloatY});
|
|
|
|
auto Scale = B.buildFConstant(S32, BitsToFloat(0x4f7ffffe));
|
|
|
|
auto ScaledY = B.buildFMul(S32, RcpIFlag, Scale);
|
|
|
|
auto Z = B.buildFPTOUI(S32, ScaledY);
|
2020-02-12 09:51:02 +08:00
|
|
|
|
2020-06-23 00:17:17 +08:00
|
|
|
// One round of UNR.
|
|
|
|
auto NegY = B.buildSub(S32, B.buildConstant(S32, 0), Y);
|
|
|
|
auto NegYZ = B.buildMul(S32, NegY, Z);
|
|
|
|
Z = B.buildAdd(S32, Z, B.buildUMulH(S32, Z, NegYZ));
|
2020-02-12 09:51:02 +08:00
|
|
|
|
2020-06-23 00:17:17 +08:00
|
|
|
// Quotient/remainder estimate.
|
|
|
|
auto Q = B.buildUMulH(S32, X, Z);
|
|
|
|
auto R = B.buildSub(S32, X, B.buildMul(S32, Q, Y));
|
2020-02-12 09:51:02 +08:00
|
|
|
|
2020-06-23 00:17:17 +08:00
|
|
|
// First quotient/remainder refinement.
|
2020-02-12 09:51:02 +08:00
|
|
|
auto One = B.buildConstant(S32, 1);
|
2020-06-23 00:17:17 +08:00
|
|
|
auto Cond = B.buildICmp(CmpInst::ICMP_UGE, S1, R, Y);
|
2021-04-12 18:19:47 +08:00
|
|
|
if (DstDivReg)
|
2020-06-23 00:17:17 +08:00
|
|
|
Q = B.buildSelect(S32, Cond, B.buildAdd(S32, Q, One), Q);
|
|
|
|
R = B.buildSelect(S32, Cond, B.buildSub(S32, R, Y), R);
|
|
|
|
|
|
|
|
// Second quotient/remainder refinement.
|
|
|
|
Cond = B.buildICmp(CmpInst::ICMP_UGE, S1, R, Y);
|
2021-04-12 18:19:47 +08:00
|
|
|
if (DstDivReg)
|
|
|
|
B.buildSelect(DstDivReg, Cond, B.buildAdd(S32, Q, One), Q);
|
|
|
|
|
|
|
|
if (DstRemReg)
|
|
|
|
B.buildSelect(DstRemReg, Cond, B.buildSub(S32, R, Y), R);
|
2020-02-12 09:48:45 +08:00
|
|
|
}
|
2020-02-12 09:51:02 +08:00
|
|
|
|
2021-09-21 05:28:10 +08:00
|
|
|
// Build integer reciprocal sequence around V_RCP_IFLAG_F32
|
2020-02-26 23:17:07 +08:00
|
|
|
//
|
|
|
|
// Return lo, hi of result
|
|
|
|
//
|
|
|
|
// %cvt.lo = G_UITOFP Val.lo
|
|
|
|
// %cvt.hi = G_UITOFP Val.hi
|
|
|
|
// %mad = G_FMAD %cvt.hi, 2**32, %cvt.lo
|
|
|
|
// %rcp = G_AMDGPU_RCP_IFLAG %mad
|
|
|
|
// %mul1 = G_FMUL %rcp, 0x5f7ffffc
|
|
|
|
// %mul2 = G_FMUL %mul1, 2**(-32)
|
|
|
|
// %trunc = G_INTRINSIC_TRUNC %mul2
|
|
|
|
// %mad2 = G_FMAD %trunc, -(2**32), %mul1
|
|
|
|
// return {G_FPTOUI %mad2, G_FPTOUI %trunc}
|
|
|
|
static std::pair<Register, Register> emitReciprocalU64(MachineIRBuilder &B,
|
|
|
|
Register Val) {
|
|
|
|
const LLT S32 = LLT::scalar(32);
|
|
|
|
auto Unmerge = B.buildUnmerge(S32, Val);
|
|
|
|
|
|
|
|
auto CvtLo = B.buildUITOFP(S32, Unmerge.getReg(0));
|
|
|
|
auto CvtHi = B.buildUITOFP(S32, Unmerge.getReg(1));
|
|
|
|
|
|
|
|
auto Mad = B.buildFMAD(S32, CvtHi, // 2**32
|
|
|
|
B.buildFConstant(S32, BitsToFloat(0x4f800000)), CvtLo);
|
|
|
|
|
|
|
|
auto Rcp = B.buildInstr(AMDGPU::G_AMDGPU_RCP_IFLAG, {S32}, {Mad});
|
|
|
|
auto Mul1 =
|
|
|
|
B.buildFMul(S32, Rcp, B.buildFConstant(S32, BitsToFloat(0x5f7ffffc)));
|
|
|
|
|
|
|
|
// 2**(-32)
|
|
|
|
auto Mul2 =
|
|
|
|
B.buildFMul(S32, Mul1, B.buildFConstant(S32, BitsToFloat(0x2f800000)));
|
|
|
|
auto Trunc = B.buildIntrinsicTrunc(S32, Mul2);
|
|
|
|
|
|
|
|
// -(2**32)
|
|
|
|
auto Mad2 = B.buildFMAD(S32, Trunc,
|
|
|
|
B.buildFConstant(S32, BitsToFloat(0xcf800000)), Mul1);
|
|
|
|
|
|
|
|
auto ResultLo = B.buildFPTOUI(S32, Mad2);
|
|
|
|
auto ResultHi = B.buildFPTOUI(S32, Trunc);
|
|
|
|
|
|
|
|
return {ResultLo.getReg(0), ResultHi.getReg(0)};
|
|
|
|
}
|
|
|
|
|
2021-04-12 18:19:47 +08:00
|
|
|
void AMDGPULegalizerInfo::legalizeUnsignedDIV_REM64Impl(MachineIRBuilder &B,
|
|
|
|
Register DstDivReg,
|
|
|
|
Register DstRemReg,
|
|
|
|
Register Numer,
|
|
|
|
Register Denom) const {
|
2020-02-26 23:17:07 +08:00
|
|
|
const LLT S32 = LLT::scalar(32);
|
|
|
|
const LLT S64 = LLT::scalar(64);
|
|
|
|
const LLT S1 = LLT::scalar(1);
|
|
|
|
Register RcpLo, RcpHi;
|
|
|
|
|
|
|
|
std::tie(RcpLo, RcpHi) = emitReciprocalU64(B, Denom);
|
|
|
|
|
|
|
|
auto Rcp = B.buildMerge(S64, {RcpLo, RcpHi});
|
|
|
|
|
|
|
|
auto Zero64 = B.buildConstant(S64, 0);
|
|
|
|
auto NegDenom = B.buildSub(S64, Zero64, Denom);
|
|
|
|
|
|
|
|
auto MulLo1 = B.buildMul(S64, NegDenom, Rcp);
|
|
|
|
auto MulHi1 = B.buildUMulH(S64, Rcp, MulLo1);
|
|
|
|
|
|
|
|
auto UnmergeMulHi1 = B.buildUnmerge(S32, MulHi1);
|
|
|
|
Register MulHi1_Lo = UnmergeMulHi1.getReg(0);
|
|
|
|
Register MulHi1_Hi = UnmergeMulHi1.getReg(1);
|
|
|
|
|
|
|
|
auto Add1_Lo = B.buildUAddo(S32, S1, RcpLo, MulHi1_Lo);
|
|
|
|
auto Add1_Hi = B.buildUAdde(S32, S1, RcpHi, MulHi1_Hi, Add1_Lo.getReg(1));
|
|
|
|
auto Add1 = B.buildMerge(S64, {Add1_Lo, Add1_Hi});
|
|
|
|
|
|
|
|
auto MulLo2 = B.buildMul(S64, NegDenom, Add1);
|
|
|
|
auto MulHi2 = B.buildUMulH(S64, Add1, MulLo2);
|
|
|
|
auto UnmergeMulHi2 = B.buildUnmerge(S32, MulHi2);
|
|
|
|
Register MulHi2_Lo = UnmergeMulHi2.getReg(0);
|
|
|
|
Register MulHi2_Hi = UnmergeMulHi2.getReg(1);
|
|
|
|
|
|
|
|
auto Zero32 = B.buildConstant(S32, 0);
|
|
|
|
auto Add2_Lo = B.buildUAddo(S32, S1, Add1_Lo, MulHi2_Lo);
|
2021-11-11 22:45:56 +08:00
|
|
|
auto Add2_Hi = B.buildUAdde(S32, S1, Add1_Hi, MulHi2_Hi, Add2_Lo.getReg(1));
|
2020-02-26 23:17:07 +08:00
|
|
|
auto Add2 = B.buildMerge(S64, {Add2_Lo, Add2_Hi});
|
|
|
|
|
|
|
|
auto UnmergeNumer = B.buildUnmerge(S32, Numer);
|
|
|
|
Register NumerLo = UnmergeNumer.getReg(0);
|
|
|
|
Register NumerHi = UnmergeNumer.getReg(1);
|
|
|
|
|
|
|
|
auto MulHi3 = B.buildUMulH(S64, Numer, Add2);
|
|
|
|
auto Mul3 = B.buildMul(S64, Denom, MulHi3);
|
|
|
|
auto UnmergeMul3 = B.buildUnmerge(S32, Mul3);
|
|
|
|
Register Mul3_Lo = UnmergeMul3.getReg(0);
|
|
|
|
Register Mul3_Hi = UnmergeMul3.getReg(1);
|
|
|
|
auto Sub1_Lo = B.buildUSubo(S32, S1, NumerLo, Mul3_Lo);
|
|
|
|
auto Sub1_Hi = B.buildUSube(S32, S1, NumerHi, Mul3_Hi, Sub1_Lo.getReg(1));
|
|
|
|
auto Sub1_Mi = B.buildSub(S32, NumerHi, Mul3_Hi);
|
|
|
|
auto Sub1 = B.buildMerge(S64, {Sub1_Lo, Sub1_Hi});
|
|
|
|
|
|
|
|
auto UnmergeDenom = B.buildUnmerge(S32, Denom);
|
|
|
|
Register DenomLo = UnmergeDenom.getReg(0);
|
|
|
|
Register DenomHi = UnmergeDenom.getReg(1);
|
|
|
|
|
|
|
|
auto CmpHi = B.buildICmp(CmpInst::ICMP_UGE, S1, Sub1_Hi, DenomHi);
|
|
|
|
auto C1 = B.buildSExt(S32, CmpHi);
|
|
|
|
|
|
|
|
auto CmpLo = B.buildICmp(CmpInst::ICMP_UGE, S1, Sub1_Lo, DenomLo);
|
|
|
|
auto C2 = B.buildSExt(S32, CmpLo);
|
|
|
|
|
|
|
|
auto CmpEq = B.buildICmp(CmpInst::ICMP_EQ, S1, Sub1_Hi, DenomHi);
|
|
|
|
auto C3 = B.buildSelect(S32, CmpEq, C2, C1);
|
|
|
|
|
|
|
|
// TODO: Here and below portions of the code can be enclosed into if/endif.
|
|
|
|
// Currently control flow is unconditional and we have 4 selects after
|
|
|
|
// potential endif to substitute PHIs.
|
|
|
|
|
|
|
|
// if C3 != 0 ...
|
|
|
|
auto Sub2_Lo = B.buildUSubo(S32, S1, Sub1_Lo, DenomLo);
|
|
|
|
auto Sub2_Mi = B.buildUSube(S32, S1, Sub1_Mi, DenomHi, Sub1_Lo.getReg(1));
|
|
|
|
auto Sub2_Hi = B.buildUSube(S32, S1, Sub2_Mi, Zero32, Sub2_Lo.getReg(1));
|
|
|
|
auto Sub2 = B.buildMerge(S64, {Sub2_Lo, Sub2_Hi});
|
|
|
|
|
|
|
|
auto One64 = B.buildConstant(S64, 1);
|
|
|
|
auto Add3 = B.buildAdd(S64, MulHi3, One64);
|
|
|
|
|
|
|
|
auto C4 =
|
|
|
|
B.buildSExt(S32, B.buildICmp(CmpInst::ICMP_UGE, S1, Sub2_Hi, DenomHi));
|
|
|
|
auto C5 =
|
|
|
|
B.buildSExt(S32, B.buildICmp(CmpInst::ICMP_UGE, S1, Sub2_Lo, DenomLo));
|
|
|
|
auto C6 = B.buildSelect(
|
|
|
|
S32, B.buildICmp(CmpInst::ICMP_EQ, S1, Sub2_Hi, DenomHi), C5, C4);
|
|
|
|
|
|
|
|
// if (C6 != 0)
|
|
|
|
auto Add4 = B.buildAdd(S64, Add3, One64);
|
|
|
|
auto Sub3_Lo = B.buildUSubo(S32, S1, Sub2_Lo, DenomLo);
|
|
|
|
|
|
|
|
auto Sub3_Mi = B.buildUSube(S32, S1, Sub2_Mi, DenomHi, Sub2_Lo.getReg(1));
|
|
|
|
auto Sub3_Hi = B.buildUSube(S32, S1, Sub3_Mi, Zero32, Sub3_Lo.getReg(1));
|
|
|
|
auto Sub3 = B.buildMerge(S64, {Sub3_Lo, Sub3_Hi});
|
|
|
|
|
|
|
|
// endif C6
|
|
|
|
// endif C3
|
|
|
|
|
2021-04-12 18:19:47 +08:00
|
|
|
if (DstDivReg) {
|
2020-02-26 23:17:07 +08:00
|
|
|
auto Sel1 = B.buildSelect(
|
|
|
|
S64, B.buildICmp(CmpInst::ICMP_NE, S1, C6, Zero32), Add4, Add3);
|
2021-04-12 18:19:47 +08:00
|
|
|
B.buildSelect(DstDivReg, B.buildICmp(CmpInst::ICMP_NE, S1, C3, Zero32),
|
|
|
|
Sel1, MulHi3);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (DstRemReg) {
|
2020-02-26 23:17:07 +08:00
|
|
|
auto Sel2 = B.buildSelect(
|
|
|
|
S64, B.buildICmp(CmpInst::ICMP_NE, S1, C6, Zero32), Sub3, Sub2);
|
2021-04-12 18:19:47 +08:00
|
|
|
B.buildSelect(DstRemReg, B.buildICmp(CmpInst::ICMP_NE, S1, C3, Zero32),
|
|
|
|
Sel2, Sub1);
|
2020-02-26 23:17:07 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-12 18:19:47 +08:00
|
|
|
bool AMDGPULegalizerInfo::legalizeUnsignedDIV_REM(MachineInstr &MI,
|
|
|
|
MachineRegisterInfo &MRI,
|
|
|
|
MachineIRBuilder &B) const {
|
|
|
|
Register DstDivReg, DstRemReg;
|
|
|
|
switch (MI.getOpcode()) {
|
|
|
|
default:
|
|
|
|
llvm_unreachable("Unexpected opcode!");
|
|
|
|
case AMDGPU::G_UDIV: {
|
|
|
|
DstDivReg = MI.getOperand(0).getReg();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case AMDGPU::G_UREM: {
|
|
|
|
DstRemReg = MI.getOperand(0).getReg();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case AMDGPU::G_UDIVREM: {
|
|
|
|
DstDivReg = MI.getOperand(0).getReg();
|
|
|
|
DstRemReg = MI.getOperand(1).getReg();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-17 09:38:29 +08:00
|
|
|
const LLT S64 = LLT::scalar(64);
|
|
|
|
const LLT S32 = LLT::scalar(32);
|
2021-04-12 18:19:47 +08:00
|
|
|
const unsigned FirstSrcOpIdx = MI.getNumExplicitDefs();
|
|
|
|
Register Num = MI.getOperand(FirstSrcOpIdx).getReg();
|
|
|
|
Register Den = MI.getOperand(FirstSrcOpIdx + 1).getReg();
|
|
|
|
LLT Ty = MRI.getType(MI.getOperand(0).getReg());
|
2020-06-17 09:38:29 +08:00
|
|
|
|
|
|
|
if (Ty == S32)
|
2021-04-12 18:19:47 +08:00
|
|
|
legalizeUnsignedDIV_REM32Impl(B, DstDivReg, DstRemReg, Num, Den);
|
2020-06-17 09:38:29 +08:00
|
|
|
else if (Ty == S64)
|
2021-04-12 18:19:47 +08:00
|
|
|
legalizeUnsignedDIV_REM64Impl(B, DstDivReg, DstRemReg, Num, Den);
|
2020-06-17 09:38:29 +08:00
|
|
|
else
|
|
|
|
return false;
|
|
|
|
|
|
|
|
MI.eraseFromParent();
|
|
|
|
return true;
|
2020-02-12 09:51:02 +08:00
|
|
|
}
|
|
|
|
|
2021-04-12 18:19:47 +08:00
|
|
|
bool AMDGPULegalizerInfo::legalizeSignedDIV_REM(MachineInstr &MI,
|
|
|
|
MachineRegisterInfo &MRI,
|
|
|
|
MachineIRBuilder &B) const {
|
2020-06-17 09:38:29 +08:00
|
|
|
const LLT S64 = LLT::scalar(64);
|
2020-02-12 09:48:45 +08:00
|
|
|
const LLT S32 = LLT::scalar(32);
|
|
|
|
|
2021-04-12 18:19:47 +08:00
|
|
|
LLT Ty = MRI.getType(MI.getOperand(0).getReg());
|
2020-06-17 09:38:29 +08:00
|
|
|
if (Ty != S32 && Ty != S64)
|
|
|
|
return false;
|
|
|
|
|
2021-04-12 18:19:47 +08:00
|
|
|
const unsigned FirstSrcOpIdx = MI.getNumExplicitDefs();
|
|
|
|
Register LHS = MI.getOperand(FirstSrcOpIdx).getReg();
|
|
|
|
Register RHS = MI.getOperand(FirstSrcOpIdx + 1).getReg();
|
2020-02-12 09:48:45 +08:00
|
|
|
|
2020-06-17 09:38:29 +08:00
|
|
|
auto SignBitOffset = B.buildConstant(S32, Ty.getSizeInBits() - 1);
|
|
|
|
auto LHSign = B.buildAShr(Ty, LHS, SignBitOffset);
|
|
|
|
auto RHSign = B.buildAShr(Ty, RHS, SignBitOffset);
|
2020-02-12 09:48:45 +08:00
|
|
|
|
2020-06-17 09:38:29 +08:00
|
|
|
LHS = B.buildAdd(Ty, LHS, LHSign).getReg(0);
|
|
|
|
RHS = B.buildAdd(Ty, RHS, RHSign).getReg(0);
|
2020-02-12 09:48:45 +08:00
|
|
|
|
2020-06-17 09:38:29 +08:00
|
|
|
LHS = B.buildXor(Ty, LHS, LHSign).getReg(0);
|
|
|
|
RHS = B.buildXor(Ty, RHS, RHSign).getReg(0);
|
2020-02-12 09:48:45 +08:00
|
|
|
|
2021-04-12 18:19:47 +08:00
|
|
|
Register DstDivReg, DstRemReg, TmpDivReg, TmpRemReg;
|
|
|
|
switch (MI.getOpcode()) {
|
|
|
|
default:
|
|
|
|
llvm_unreachable("Unexpected opcode!");
|
|
|
|
case AMDGPU::G_SDIV: {
|
|
|
|
DstDivReg = MI.getOperand(0).getReg();
|
|
|
|
TmpDivReg = MRI.createGenericVirtualRegister(Ty);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case AMDGPU::G_SREM: {
|
|
|
|
DstRemReg = MI.getOperand(0).getReg();
|
|
|
|
TmpRemReg = MRI.createGenericVirtualRegister(Ty);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case AMDGPU::G_SDIVREM: {
|
|
|
|
DstDivReg = MI.getOperand(0).getReg();
|
|
|
|
DstRemReg = MI.getOperand(1).getReg();
|
|
|
|
TmpDivReg = MRI.createGenericVirtualRegister(Ty);
|
|
|
|
TmpRemReg = MRI.createGenericVirtualRegister(Ty);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-17 09:38:29 +08:00
|
|
|
if (Ty == S32)
|
2021-04-12 18:19:47 +08:00
|
|
|
legalizeUnsignedDIV_REM32Impl(B, TmpDivReg, TmpRemReg, LHS, RHS);
|
2020-06-17 09:38:29 +08:00
|
|
|
else
|
2021-04-12 18:19:47 +08:00
|
|
|
legalizeUnsignedDIV_REM64Impl(B, TmpDivReg, TmpRemReg, LHS, RHS);
|
2020-02-12 09:48:45 +08:00
|
|
|
|
2021-04-12 18:19:47 +08:00
|
|
|
if (DstDivReg) {
|
|
|
|
auto Sign = B.buildXor(Ty, LHSign, RHSign).getReg(0);
|
|
|
|
auto SignXor = B.buildXor(Ty, TmpDivReg, Sign).getReg(0);
|
|
|
|
B.buildSub(DstDivReg, SignXor, Sign);
|
|
|
|
}
|
2020-06-17 09:38:29 +08:00
|
|
|
|
2021-04-12 18:19:47 +08:00
|
|
|
if (DstRemReg) {
|
|
|
|
auto Sign = LHSign.getReg(0); // Remainder sign is the same as LHS
|
|
|
|
auto SignXor = B.buildXor(Ty, TmpRemReg, Sign).getReg(0);
|
|
|
|
B.buildSub(DstRemReg, SignXor, Sign);
|
|
|
|
}
|
2020-02-12 09:48:45 +08:00
|
|
|
|
|
|
|
MI.eraseFromParent();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
AMDGPU/GlobalISel: Legalize fast unsafe FDIV
Reviewers: arsenm
Reviewed By: arsenm
Subscribers: kzhuravl, jvesely, wdng, nhaehnle, yaxunl, rovka, dstuttard, tpr, t-tye, hiraditya, Petar.Avramovic, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D69231
llvm-svn: 375460
2019-10-22 06:18:26 +08:00
|
|
|
bool AMDGPULegalizerInfo::legalizeFastUnsafeFDIV(MachineInstr &MI,
|
|
|
|
MachineRegisterInfo &MRI,
|
|
|
|
MachineIRBuilder &B) const {
|
|
|
|
Register Res = MI.getOperand(0).getReg();
|
|
|
|
Register LHS = MI.getOperand(1).getReg();
|
|
|
|
Register RHS = MI.getOperand(2).getReg();
|
|
|
|
uint16_t Flags = MI.getFlags();
|
|
|
|
LLT ResTy = MRI.getType(Res);
|
|
|
|
|
|
|
|
const MachineFunction &MF = B.getMF();
|
2021-01-06 10:14:42 +08:00
|
|
|
bool AllowInaccurateRcp = MF.getTarget().Options.UnsafeFPMath ||
|
|
|
|
MI.getFlag(MachineInstr::FmAfn);
|
AMDGPU/GlobalISel: Legalize fast unsafe FDIV
Reviewers: arsenm
Reviewed By: arsenm
Subscribers: kzhuravl, jvesely, wdng, nhaehnle, yaxunl, rovka, dstuttard, tpr, t-tye, hiraditya, Petar.Avramovic, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D69231
llvm-svn: 375460
2019-10-22 06:18:26 +08:00
|
|
|
|
2021-01-06 10:14:42 +08:00
|
|
|
if (!AllowInaccurateRcp)
|
AMDGPU/GlobalISel: Legalize fast unsafe FDIV
Reviewers: arsenm
Reviewed By: arsenm
Subscribers: kzhuravl, jvesely, wdng, nhaehnle, yaxunl, rovka, dstuttard, tpr, t-tye, hiraditya, Petar.Avramovic, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D69231
llvm-svn: 375460
2019-10-22 06:18:26 +08:00
|
|
|
return false;
|
|
|
|
|
|
|
|
if (auto CLHS = getConstantFPVRegVal(LHS, MRI)) {
|
|
|
|
// 1 / x -> RCP(x)
|
|
|
|
if (CLHS->isExactlyValue(1.0)) {
|
|
|
|
B.buildIntrinsic(Intrinsic::amdgcn_rcp, Res, false)
|
|
|
|
.addUse(RHS)
|
|
|
|
.setMIFlags(Flags);
|
|
|
|
|
|
|
|
MI.eraseFromParent();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// -1 / x -> RCP( FNEG(x) )
|
|
|
|
if (CLHS->isExactlyValue(-1.0)) {
|
|
|
|
auto FNeg = B.buildFNeg(ResTy, RHS, Flags);
|
|
|
|
B.buildIntrinsic(Intrinsic::amdgcn_rcp, Res, false)
|
|
|
|
.addUse(FNeg.getReg(0))
|
|
|
|
.setMIFlags(Flags);
|
|
|
|
|
|
|
|
MI.eraseFromParent();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// x / y -> x * (1.0 / y)
|
2021-01-06 10:14:42 +08:00
|
|
|
auto RCP = B.buildIntrinsic(Intrinsic::amdgcn_rcp, {ResTy}, false)
|
|
|
|
.addUse(RHS)
|
|
|
|
.setMIFlags(Flags);
|
|
|
|
B.buildFMul(Res, LHS, RCP, Flags);
|
AMDGPU/GlobalISel: Legalize fast unsafe FDIV
Reviewers: arsenm
Reviewed By: arsenm
Subscribers: kzhuravl, jvesely, wdng, nhaehnle, yaxunl, rovka, dstuttard, tpr, t-tye, hiraditya, Petar.Avramovic, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D69231
llvm-svn: 375460
2019-10-22 06:18:26 +08:00
|
|
|
|
2021-01-06 10:14:42 +08:00
|
|
|
MI.eraseFromParent();
|
|
|
|
return true;
|
AMDGPU/GlobalISel: Legalize fast unsafe FDIV
Reviewers: arsenm
Reviewed By: arsenm
Subscribers: kzhuravl, jvesely, wdng, nhaehnle, yaxunl, rovka, dstuttard, tpr, t-tye, hiraditya, Petar.Avramovic, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D69231
llvm-svn: 375460
2019-10-22 06:18:26 +08:00
|
|
|
}
|
|
|
|
|
2021-01-21 02:55:55 +08:00
|
|
|
bool AMDGPULegalizerInfo::legalizeFastUnsafeFDIV64(MachineInstr &MI,
|
|
|
|
MachineRegisterInfo &MRI,
|
|
|
|
MachineIRBuilder &B) const {
|
|
|
|
Register Res = MI.getOperand(0).getReg();
|
|
|
|
Register X = MI.getOperand(1).getReg();
|
|
|
|
Register Y = MI.getOperand(2).getReg();
|
|
|
|
uint16_t Flags = MI.getFlags();
|
|
|
|
LLT ResTy = MRI.getType(Res);
|
|
|
|
|
|
|
|
const MachineFunction &MF = B.getMF();
|
|
|
|
bool AllowInaccurateRcp = MF.getTarget().Options.UnsafeFPMath ||
|
|
|
|
MI.getFlag(MachineInstr::FmAfn);
|
|
|
|
|
|
|
|
if (!AllowInaccurateRcp)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
auto NegY = B.buildFNeg(ResTy, Y);
|
|
|
|
auto One = B.buildFConstant(ResTy, 1.0);
|
|
|
|
|
|
|
|
auto R = B.buildIntrinsic(Intrinsic::amdgcn_rcp, {ResTy}, false)
|
|
|
|
.addUse(Y)
|
|
|
|
.setMIFlags(Flags);
|
|
|
|
|
|
|
|
auto Tmp0 = B.buildFMA(ResTy, NegY, R, One);
|
|
|
|
R = B.buildFMA(ResTy, Tmp0, R, R);
|
|
|
|
|
|
|
|
auto Tmp1 = B.buildFMA(ResTy, NegY, R, One);
|
|
|
|
R = B.buildFMA(ResTy, Tmp1, R, R);
|
|
|
|
|
|
|
|
auto Ret = B.buildFMul(ResTy, X, R);
|
|
|
|
auto Tmp2 = B.buildFMA(ResTy, NegY, Ret, X);
|
|
|
|
|
|
|
|
B.buildFMA(Res, Tmp2, R, Ret);
|
|
|
|
MI.eraseFromParent();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
AMDGPU/GlobalISel: Legalize FDIV16
Reviewers: arsenm
Reviewed By: arsenm
Subscribers: kzhuravl, jvesely, wdng, nhaehnle, yaxunl, rovka, dstuttard, tpr, t-tye, hiraditya, volkan, Petar.Avramovic, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D69347
2019-10-23 08:39:26 +08:00
|
|
|
bool AMDGPULegalizerInfo::legalizeFDIV16(MachineInstr &MI,
|
|
|
|
MachineRegisterInfo &MRI,
|
|
|
|
MachineIRBuilder &B) const {
|
2021-01-21 02:55:55 +08:00
|
|
|
if (legalizeFastUnsafeFDIV(MI, MRI, B))
|
|
|
|
return true;
|
|
|
|
|
AMDGPU/GlobalISel: Legalize FDIV16
Reviewers: arsenm
Reviewed By: arsenm
Subscribers: kzhuravl, jvesely, wdng, nhaehnle, yaxunl, rovka, dstuttard, tpr, t-tye, hiraditya, volkan, Petar.Avramovic, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D69347
2019-10-23 08:39:26 +08:00
|
|
|
Register Res = MI.getOperand(0).getReg();
|
|
|
|
Register LHS = MI.getOperand(1).getReg();
|
|
|
|
Register RHS = MI.getOperand(2).getReg();
|
|
|
|
|
|
|
|
uint16_t Flags = MI.getFlags();
|
|
|
|
|
|
|
|
LLT S16 = LLT::scalar(16);
|
|
|
|
LLT S32 = LLT::scalar(32);
|
|
|
|
|
|
|
|
auto LHSExt = B.buildFPExt(S32, LHS, Flags);
|
|
|
|
auto RHSExt = B.buildFPExt(S32, RHS, Flags);
|
|
|
|
|
|
|
|
auto RCP = B.buildIntrinsic(Intrinsic::amdgcn_rcp, {S32}, false)
|
|
|
|
.addUse(RHSExt.getReg(0))
|
|
|
|
.setMIFlags(Flags);
|
|
|
|
|
|
|
|
auto QUOT = B.buildFMul(S32, LHSExt, RCP, Flags);
|
|
|
|
auto RDst = B.buildFPTrunc(S16, QUOT, Flags);
|
|
|
|
|
|
|
|
B.buildIntrinsic(Intrinsic::amdgcn_div_fixup, Res, false)
|
|
|
|
.addUse(RDst.getReg(0))
|
|
|
|
.addUse(RHS)
|
|
|
|
.addUse(LHS)
|
|
|
|
.setMIFlags(Flags);
|
|
|
|
|
|
|
|
MI.eraseFromParent();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
AMDGPU/GlobalISel: Legalize FDIV32
Reviewers: arsenm
Subscribers: kzhuravl, jvesely, wdng, nhaehnle, yaxunl, rovka, dstuttard, tpr, t-tye, hiraditya, Petar.Avramovic, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D69581
2019-10-30 00:55:49 +08:00
|
|
|
// Enable or disable FP32 denorm mode. When 'Enable' is true, emit instructions
|
|
|
|
// to enable denorm mode. When 'Enable' is false, disable denorm mode.
|
|
|
|
static void toggleSPDenormMode(bool Enable,
|
2019-11-02 00:44:56 +08:00
|
|
|
MachineIRBuilder &B,
|
AMDGPU/GlobalISel: Legalize FDIV32
Reviewers: arsenm
Subscribers: kzhuravl, jvesely, wdng, nhaehnle, yaxunl, rovka, dstuttard, tpr, t-tye, hiraditya, Petar.Avramovic, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D69581
2019-10-30 00:55:49 +08:00
|
|
|
const GCNSubtarget &ST,
|
2019-11-02 00:44:56 +08:00
|
|
|
AMDGPU::SIModeRegisterDefaults Mode) {
|
AMDGPU/GlobalISel: Legalize FDIV32
Reviewers: arsenm
Subscribers: kzhuravl, jvesely, wdng, nhaehnle, yaxunl, rovka, dstuttard, tpr, t-tye, hiraditya, Petar.Avramovic, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D69581
2019-10-30 00:55:49 +08:00
|
|
|
// Set SP denorm mode to this value.
|
|
|
|
unsigned SPDenormMode =
|
2019-12-03 15:01:21 +08:00
|
|
|
Enable ? FP_DENORM_FLUSH_NONE : Mode.fpDenormModeSPValue();
|
AMDGPU/GlobalISel: Legalize FDIV32
Reviewers: arsenm
Subscribers: kzhuravl, jvesely, wdng, nhaehnle, yaxunl, rovka, dstuttard, tpr, t-tye, hiraditya, Petar.Avramovic, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D69581
2019-10-30 00:55:49 +08:00
|
|
|
|
|
|
|
if (ST.hasDenormModeInst()) {
|
|
|
|
// Preserve default FP64FP16 denorm mode while updating FP32 mode.
|
2019-12-03 15:01:21 +08:00
|
|
|
uint32_t DPDenormModeDefault = Mode.fpDenormModeDPValue();
|
AMDGPU/GlobalISel: Legalize FDIV32
Reviewers: arsenm
Subscribers: kzhuravl, jvesely, wdng, nhaehnle, yaxunl, rovka, dstuttard, tpr, t-tye, hiraditya, Petar.Avramovic, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D69581
2019-10-30 00:55:49 +08:00
|
|
|
|
2019-12-03 15:01:21 +08:00
|
|
|
uint32_t NewDenormModeValue = SPDenormMode | (DPDenormModeDefault << 2);
|
AMDGPU/GlobalISel: Legalize FDIV32
Reviewers: arsenm
Subscribers: kzhuravl, jvesely, wdng, nhaehnle, yaxunl, rovka, dstuttard, tpr, t-tye, hiraditya, Petar.Avramovic, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D69581
2019-10-30 00:55:49 +08:00
|
|
|
B.buildInstr(AMDGPU::S_DENORM_MODE)
|
|
|
|
.addImm(NewDenormModeValue);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
// Select FP32 bit field in mode register.
|
|
|
|
unsigned SPDenormModeBitField = AMDGPU::Hwreg::ID_MODE |
|
|
|
|
(4 << AMDGPU::Hwreg::OFFSET_SHIFT_) |
|
|
|
|
(1 << AMDGPU::Hwreg::WIDTH_M1_SHIFT_);
|
|
|
|
|
|
|
|
B.buildInstr(AMDGPU::S_SETREG_IMM32_B32)
|
|
|
|
.addImm(SPDenormMode)
|
|
|
|
.addImm(SPDenormModeBitField);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool AMDGPULegalizerInfo::legalizeFDIV32(MachineInstr &MI,
|
|
|
|
MachineRegisterInfo &MRI,
|
|
|
|
MachineIRBuilder &B) const {
|
2021-01-21 02:55:55 +08:00
|
|
|
if (legalizeFastUnsafeFDIV(MI, MRI, B))
|
|
|
|
return true;
|
|
|
|
|
AMDGPU/GlobalISel: Legalize FDIV32
Reviewers: arsenm
Subscribers: kzhuravl, jvesely, wdng, nhaehnle, yaxunl, rovka, dstuttard, tpr, t-tye, hiraditya, Petar.Avramovic, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D69581
2019-10-30 00:55:49 +08:00
|
|
|
Register Res = MI.getOperand(0).getReg();
|
|
|
|
Register LHS = MI.getOperand(1).getReg();
|
|
|
|
Register RHS = MI.getOperand(2).getReg();
|
2019-11-02 00:44:56 +08:00
|
|
|
const SIMachineFunctionInfo *MFI = B.getMF().getInfo<SIMachineFunctionInfo>();
|
|
|
|
AMDGPU::SIModeRegisterDefaults Mode = MFI->getMode();
|
AMDGPU/GlobalISel: Legalize FDIV32
Reviewers: arsenm
Subscribers: kzhuravl, jvesely, wdng, nhaehnle, yaxunl, rovka, dstuttard, tpr, t-tye, hiraditya, Petar.Avramovic, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D69581
2019-10-30 00:55:49 +08:00
|
|
|
|
|
|
|
uint16_t Flags = MI.getFlags();
|
|
|
|
|
|
|
|
LLT S32 = LLT::scalar(32);
|
|
|
|
LLT S1 = LLT::scalar(1);
|
|
|
|
|
|
|
|
auto One = B.buildFConstant(S32, 1.0f);
|
|
|
|
|
|
|
|
auto DenominatorScaled =
|
|
|
|
B.buildIntrinsic(Intrinsic::amdgcn_div_scale, {S32, S1}, false)
|
|
|
|
.addUse(LHS)
|
2020-04-13 14:25:18 +08:00
|
|
|
.addUse(RHS)
|
|
|
|
.addImm(0)
|
AMDGPU/GlobalISel: Legalize FDIV32
Reviewers: arsenm
Subscribers: kzhuravl, jvesely, wdng, nhaehnle, yaxunl, rovka, dstuttard, tpr, t-tye, hiraditya, Petar.Avramovic, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D69581
2019-10-30 00:55:49 +08:00
|
|
|
.setMIFlags(Flags);
|
|
|
|
auto NumeratorScaled =
|
|
|
|
B.buildIntrinsic(Intrinsic::amdgcn_div_scale, {S32, S1}, false)
|
|
|
|
.addUse(LHS)
|
|
|
|
.addUse(RHS)
|
2020-04-13 14:25:18 +08:00
|
|
|
.addImm(1)
|
AMDGPU/GlobalISel: Legalize FDIV32
Reviewers: arsenm
Subscribers: kzhuravl, jvesely, wdng, nhaehnle, yaxunl, rovka, dstuttard, tpr, t-tye, hiraditya, Petar.Avramovic, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D69581
2019-10-30 00:55:49 +08:00
|
|
|
.setMIFlags(Flags);
|
|
|
|
|
|
|
|
auto ApproxRcp = B.buildIntrinsic(Intrinsic::amdgcn_rcp, {S32}, false)
|
|
|
|
.addUse(DenominatorScaled.getReg(0))
|
|
|
|
.setMIFlags(Flags);
|
|
|
|
auto NegDivScale0 = B.buildFNeg(S32, DenominatorScaled, Flags);
|
|
|
|
|
|
|
|
// FIXME: Doesn't correctly model the FP mode switch, and the FP operations
|
|
|
|
// aren't modeled as reading it.
|
2019-12-03 15:01:21 +08:00
|
|
|
if (!Mode.allFP32Denormals())
|
2019-11-02 00:44:56 +08:00
|
|
|
toggleSPDenormMode(true, B, ST, Mode);
|
AMDGPU/GlobalISel: Legalize FDIV32
Reviewers: arsenm
Subscribers: kzhuravl, jvesely, wdng, nhaehnle, yaxunl, rovka, dstuttard, tpr, t-tye, hiraditya, Petar.Avramovic, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D69581
2019-10-30 00:55:49 +08:00
|
|
|
|
|
|
|
auto Fma0 = B.buildFMA(S32, NegDivScale0, ApproxRcp, One, Flags);
|
|
|
|
auto Fma1 = B.buildFMA(S32, Fma0, ApproxRcp, ApproxRcp, Flags);
|
|
|
|
auto Mul = B.buildFMul(S32, NumeratorScaled, Fma1, Flags);
|
|
|
|
auto Fma2 = B.buildFMA(S32, NegDivScale0, Mul, NumeratorScaled, Flags);
|
|
|
|
auto Fma3 = B.buildFMA(S32, Fma2, Fma1, Mul, Flags);
|
|
|
|
auto Fma4 = B.buildFMA(S32, NegDivScale0, Fma3, NumeratorScaled, Flags);
|
|
|
|
|
2019-12-03 15:01:21 +08:00
|
|
|
if (!Mode.allFP32Denormals())
|
2019-11-02 00:44:56 +08:00
|
|
|
toggleSPDenormMode(false, B, ST, Mode);
|
AMDGPU/GlobalISel: Legalize FDIV32
Reviewers: arsenm
Subscribers: kzhuravl, jvesely, wdng, nhaehnle, yaxunl, rovka, dstuttard, tpr, t-tye, hiraditya, Petar.Avramovic, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D69581
2019-10-30 00:55:49 +08:00
|
|
|
|
|
|
|
auto Fmas = B.buildIntrinsic(Intrinsic::amdgcn_div_fmas, {S32}, false)
|
|
|
|
.addUse(Fma4.getReg(0))
|
|
|
|
.addUse(Fma1.getReg(0))
|
|
|
|
.addUse(Fma3.getReg(0))
|
|
|
|
.addUse(NumeratorScaled.getReg(1))
|
|
|
|
.setMIFlags(Flags);
|
|
|
|
|
|
|
|
B.buildIntrinsic(Intrinsic::amdgcn_div_fixup, Res, false)
|
|
|
|
.addUse(Fmas.getReg(0))
|
|
|
|
.addUse(RHS)
|
|
|
|
.addUse(LHS)
|
|
|
|
.setMIFlags(Flags);
|
|
|
|
|
|
|
|
MI.eraseFromParent();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
AMDGPU/GlobalISel: Legalize FDIV64
Reviewers: arsenm
Reviewed By: arsenm
Subscribers: kzhuravl, jvesely, wdng, nhaehnle, yaxunl, rovka, dstuttard, tpr, t-tye, hiraditya, Petar.Avramovic, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D70403
2019-11-18 08:43:59 +08:00
|
|
|
bool AMDGPULegalizerInfo::legalizeFDIV64(MachineInstr &MI,
|
|
|
|
MachineRegisterInfo &MRI,
|
|
|
|
MachineIRBuilder &B) const {
|
2021-01-21 02:55:55 +08:00
|
|
|
if (legalizeFastUnsafeFDIV64(MI, MRI, B))
|
|
|
|
return true;
|
|
|
|
|
AMDGPU/GlobalISel: Legalize FDIV64
Reviewers: arsenm
Reviewed By: arsenm
Subscribers: kzhuravl, jvesely, wdng, nhaehnle, yaxunl, rovka, dstuttard, tpr, t-tye, hiraditya, Petar.Avramovic, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D70403
2019-11-18 08:43:59 +08:00
|
|
|
Register Res = MI.getOperand(0).getReg();
|
|
|
|
Register LHS = MI.getOperand(1).getReg();
|
|
|
|
Register RHS = MI.getOperand(2).getReg();
|
|
|
|
|
|
|
|
uint16_t Flags = MI.getFlags();
|
|
|
|
|
|
|
|
LLT S64 = LLT::scalar(64);
|
|
|
|
LLT S1 = LLT::scalar(1);
|
|
|
|
|
|
|
|
auto One = B.buildFConstant(S64, 1.0);
|
|
|
|
|
|
|
|
auto DivScale0 = B.buildIntrinsic(Intrinsic::amdgcn_div_scale, {S64, S1}, false)
|
|
|
|
.addUse(LHS)
|
2019-12-21 00:09:19 +08:00
|
|
|
.addUse(RHS)
|
2020-04-13 14:25:18 +08:00
|
|
|
.addImm(0)
|
AMDGPU/GlobalISel: Legalize FDIV64
Reviewers: arsenm
Reviewed By: arsenm
Subscribers: kzhuravl, jvesely, wdng, nhaehnle, yaxunl, rovka, dstuttard, tpr, t-tye, hiraditya, Petar.Avramovic, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D70403
2019-11-18 08:43:59 +08:00
|
|
|
.setMIFlags(Flags);
|
|
|
|
|
|
|
|
auto NegDivScale0 = B.buildFNeg(S64, DivScale0.getReg(0), Flags);
|
|
|
|
|
|
|
|
auto Rcp = B.buildIntrinsic(Intrinsic::amdgcn_rcp, {S64}, false)
|
|
|
|
.addUse(DivScale0.getReg(0))
|
|
|
|
.setMIFlags(Flags);
|
|
|
|
|
|
|
|
auto Fma0 = B.buildFMA(S64, NegDivScale0, Rcp, One, Flags);
|
|
|
|
auto Fma1 = B.buildFMA(S64, Rcp, Fma0, Rcp, Flags);
|
|
|
|
auto Fma2 = B.buildFMA(S64, NegDivScale0, Fma1, One, Flags);
|
|
|
|
|
|
|
|
auto DivScale1 = B.buildIntrinsic(Intrinsic::amdgcn_div_scale, {S64, S1}, false)
|
|
|
|
.addUse(LHS)
|
|
|
|
.addUse(RHS)
|
2020-04-13 14:25:18 +08:00
|
|
|
.addImm(1)
|
AMDGPU/GlobalISel: Legalize FDIV64
Reviewers: arsenm
Reviewed By: arsenm
Subscribers: kzhuravl, jvesely, wdng, nhaehnle, yaxunl, rovka, dstuttard, tpr, t-tye, hiraditya, Petar.Avramovic, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D70403
2019-11-18 08:43:59 +08:00
|
|
|
.setMIFlags(Flags);
|
|
|
|
|
|
|
|
auto Fma3 = B.buildFMA(S64, Fma1, Fma2, Fma1, Flags);
|
2020-05-19 02:53:26 +08:00
|
|
|
auto Mul = B.buildFMul(S64, DivScale1.getReg(0), Fma3, Flags);
|
AMDGPU/GlobalISel: Legalize FDIV64
Reviewers: arsenm
Reviewed By: arsenm
Subscribers: kzhuravl, jvesely, wdng, nhaehnle, yaxunl, rovka, dstuttard, tpr, t-tye, hiraditya, Petar.Avramovic, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D70403
2019-11-18 08:43:59 +08:00
|
|
|
auto Fma4 = B.buildFMA(S64, NegDivScale0, Mul, DivScale1.getReg(0), Flags);
|
|
|
|
|
|
|
|
Register Scale;
|
|
|
|
if (!ST.hasUsableDivScaleConditionOutput()) {
|
|
|
|
// Workaround a hardware bug on SI where the condition output from div_scale
|
|
|
|
// is not usable.
|
|
|
|
|
|
|
|
LLT S32 = LLT::scalar(32);
|
|
|
|
|
|
|
|
auto NumUnmerge = B.buildUnmerge(S32, LHS);
|
|
|
|
auto DenUnmerge = B.buildUnmerge(S32, RHS);
|
|
|
|
auto Scale0Unmerge = B.buildUnmerge(S32, DivScale0);
|
|
|
|
auto Scale1Unmerge = B.buildUnmerge(S32, DivScale1);
|
|
|
|
|
|
|
|
auto CmpNum = B.buildICmp(ICmpInst::ICMP_EQ, S1, NumUnmerge.getReg(1),
|
|
|
|
Scale1Unmerge.getReg(1));
|
|
|
|
auto CmpDen = B.buildICmp(ICmpInst::ICMP_EQ, S1, DenUnmerge.getReg(1),
|
|
|
|
Scale0Unmerge.getReg(1));
|
[GlobalISel] Tidy up unnecessary calls to createGenericVirtualRegister
Summary:
As a side effect some redundant copies of constant values are removed by
CSEMIRBuilder.
Reviewers: aemerson, arsenm, dsanders, aditya_nandakumar
Subscribers: sdardis, jvesely, wdng, nhaehnle, rovka, hiraditya, jrtc27, atanasyan, volkan, Petar.Avramovic, kerbowa, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D73789
2020-01-31 20:40:31 +08:00
|
|
|
Scale = B.buildXor(S1, CmpNum, CmpDen).getReg(0);
|
AMDGPU/GlobalISel: Legalize FDIV64
Reviewers: arsenm
Reviewed By: arsenm
Subscribers: kzhuravl, jvesely, wdng, nhaehnle, yaxunl, rovka, dstuttard, tpr, t-tye, hiraditya, Petar.Avramovic, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D70403
2019-11-18 08:43:59 +08:00
|
|
|
} else {
|
|
|
|
Scale = DivScale1.getReg(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
auto Fmas = B.buildIntrinsic(Intrinsic::amdgcn_div_fmas, {S64}, false)
|
|
|
|
.addUse(Fma4.getReg(0))
|
|
|
|
.addUse(Fma3.getReg(0))
|
|
|
|
.addUse(Mul.getReg(0))
|
|
|
|
.addUse(Scale)
|
|
|
|
.setMIFlags(Flags);
|
|
|
|
|
2019-12-25 20:48:37 +08:00
|
|
|
B.buildIntrinsic(Intrinsic::amdgcn_div_fixup, makeArrayRef(Res), false)
|
AMDGPU/GlobalISel: Legalize FDIV64
Reviewers: arsenm
Reviewed By: arsenm
Subscribers: kzhuravl, jvesely, wdng, nhaehnle, yaxunl, rovka, dstuttard, tpr, t-tye, hiraditya, Petar.Avramovic, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D70403
2019-11-18 08:43:59 +08:00
|
|
|
.addUse(Fmas.getReg(0))
|
|
|
|
.addUse(RHS)
|
|
|
|
.addUse(LHS)
|
|
|
|
.setMIFlags(Flags);
|
|
|
|
|
|
|
|
MI.eraseFromParent();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
AMDGPU/GlobalISel: Legalize fast unsafe FDIV
Reviewers: arsenm
Reviewed By: arsenm
Subscribers: kzhuravl, jvesely, wdng, nhaehnle, yaxunl, rovka, dstuttard, tpr, t-tye, hiraditya, Petar.Avramovic, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D69231
llvm-svn: 375460
2019-10-22 06:18:26 +08:00
|
|
|
bool AMDGPULegalizerInfo::legalizeFDIVFastIntrin(MachineInstr &MI,
|
|
|
|
MachineRegisterInfo &MRI,
|
|
|
|
MachineIRBuilder &B) const {
|
[AMDGPU/GlobalISel] Add llvm.amdgcn.fdiv.fast legalization.
Reviewers: arsenm
Reviewed By: arsenm
Subscribers: volkan, kzhuravl, jvesely, wdng, nhaehnle, yaxunl, rovka, dstuttard, tpr, t-tye, hiraditya, Petar.Avramovic, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D64966
llvm-svn: 367344
2019-07-31 02:49:16 +08:00
|
|
|
Register Res = MI.getOperand(0).getReg();
|
|
|
|
Register LHS = MI.getOperand(2).getReg();
|
|
|
|
Register RHS = MI.getOperand(3).getReg();
|
|
|
|
uint16_t Flags = MI.getFlags();
|
|
|
|
|
|
|
|
LLT S32 = LLT::scalar(32);
|
|
|
|
LLT S1 = LLT::scalar(1);
|
|
|
|
|
|
|
|
auto Abs = B.buildFAbs(S32, RHS, Flags);
|
|
|
|
const APFloat C0Val(1.0f);
|
|
|
|
|
|
|
|
auto C0 = B.buildConstant(S32, 0x6f800000);
|
|
|
|
auto C1 = B.buildConstant(S32, 0x2f800000);
|
|
|
|
auto C2 = B.buildConstant(S32, FloatToBits(1.0f));
|
|
|
|
|
|
|
|
auto CmpRes = B.buildFCmp(CmpInst::FCMP_OGT, S1, Abs, C0, Flags);
|
|
|
|
auto Sel = B.buildSelect(S32, CmpRes, C1, C2, Flags);
|
|
|
|
|
|
|
|
auto Mul0 = B.buildFMul(S32, RHS, Sel, Flags);
|
|
|
|
|
|
|
|
auto RCP = B.buildIntrinsic(Intrinsic::amdgcn_rcp, {S32}, false)
|
|
|
|
.addUse(Mul0.getReg(0))
|
|
|
|
.setMIFlags(Flags);
|
|
|
|
|
|
|
|
auto Mul1 = B.buildFMul(S32, LHS, RCP, Flags);
|
|
|
|
|
|
|
|
B.buildFMul(Res, Sel, Mul1, Flags);
|
|
|
|
|
|
|
|
MI.eraseFromParent();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-07-26 04:26:33 +08:00
|
|
|
// Expand llvm.amdgcn.rsq.clamp on targets that don't support the instruction.
|
|
|
|
// FIXME: Why do we handle this one but not other removed instructions?
|
|
|
|
//
|
|
|
|
// Reciprocal square root. The clamp prevents infinite results, clamping
|
|
|
|
// infinities to max_float. D.f = 1.0 / sqrt(S0.f), result clamped to
|
|
|
|
// +-max_float.
|
|
|
|
bool AMDGPULegalizerInfo::legalizeRsqClampIntrinsic(MachineInstr &MI,
|
|
|
|
MachineRegisterInfo &MRI,
|
|
|
|
MachineIRBuilder &B) const {
|
|
|
|
if (ST.getGeneration() < AMDGPUSubtarget::VOLCANIC_ISLANDS)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
Register Dst = MI.getOperand(0).getReg();
|
|
|
|
Register Src = MI.getOperand(2).getReg();
|
|
|
|
auto Flags = MI.getFlags();
|
|
|
|
|
|
|
|
LLT Ty = MRI.getType(Dst);
|
|
|
|
|
|
|
|
const fltSemantics *FltSemantics;
|
|
|
|
if (Ty == LLT::scalar(32))
|
|
|
|
FltSemantics = &APFloat::IEEEsingle();
|
|
|
|
else if (Ty == LLT::scalar(64))
|
|
|
|
FltSemantics = &APFloat::IEEEdouble();
|
|
|
|
else
|
|
|
|
return false;
|
|
|
|
|
|
|
|
auto Rsq = B.buildIntrinsic(Intrinsic::amdgcn_rsq, {Ty}, false)
|
|
|
|
.addUse(Src)
|
|
|
|
.setMIFlags(Flags);
|
|
|
|
|
|
|
|
// We don't need to concern ourselves with the snan handling difference, since
|
|
|
|
// the rsq quieted (or not) so use the one which will directly select.
|
|
|
|
const SIMachineFunctionInfo *MFI = B.getMF().getInfo<SIMachineFunctionInfo>();
|
|
|
|
const bool UseIEEE = MFI->getMode().IEEE;
|
|
|
|
|
|
|
|
auto MaxFlt = B.buildFConstant(Ty, APFloat::getLargest(*FltSemantics));
|
|
|
|
auto ClampMax = UseIEEE ? B.buildFMinNumIEEE(Ty, Rsq, MaxFlt, Flags) :
|
|
|
|
B.buildFMinNum(Ty, Rsq, MaxFlt, Flags);
|
|
|
|
|
|
|
|
auto MinFlt = B.buildFConstant(Ty, APFloat::getLargest(*FltSemantics, true));
|
|
|
|
|
|
|
|
if (UseIEEE)
|
|
|
|
B.buildFMaxNumIEEE(Dst, ClampMax, MinFlt, Flags);
|
|
|
|
else
|
|
|
|
B.buildFMaxNum(Dst, ClampMax, MinFlt, Flags);
|
|
|
|
MI.eraseFromParent();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-07-26 23:46:23 +08:00
|
|
|
static unsigned getDSFPAtomicOpcode(Intrinsic::ID IID) {
|
|
|
|
switch (IID) {
|
|
|
|
case Intrinsic::amdgcn_ds_fadd:
|
|
|
|
return AMDGPU::G_ATOMICRMW_FADD;
|
|
|
|
case Intrinsic::amdgcn_ds_fmin:
|
|
|
|
return AMDGPU::G_AMDGPU_ATOMIC_FMIN;
|
|
|
|
case Intrinsic::amdgcn_ds_fmax:
|
|
|
|
return AMDGPU::G_AMDGPU_ATOMIC_FMAX;
|
|
|
|
default:
|
|
|
|
llvm_unreachable("not a DS FP intrinsic");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool AMDGPULegalizerInfo::legalizeDSAtomicFPIntrinsic(LegalizerHelper &Helper,
|
|
|
|
MachineInstr &MI,
|
|
|
|
Intrinsic::ID IID) const {
|
|
|
|
GISelChangeObserver &Observer = Helper.Observer;
|
|
|
|
Observer.changingInstr(MI);
|
|
|
|
|
|
|
|
MI.setDesc(ST.getInstrInfo()->get(getDSFPAtomicOpcode(IID)));
|
|
|
|
|
|
|
|
// The remaining operands were used to set fields in the MemOperand on
|
|
|
|
// construction.
|
|
|
|
for (int I = 6; I > 3; --I)
|
|
|
|
MI.RemoveOperand(I);
|
|
|
|
|
|
|
|
MI.RemoveOperand(1); // Remove the intrinsic ID.
|
|
|
|
Observer.changedInstr(MI);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-07-04 02:47:23 +08:00
|
|
|
bool AMDGPULegalizerInfo::getImplicitArgPtr(Register DstReg,
|
|
|
|
MachineRegisterInfo &MRI,
|
|
|
|
MachineIRBuilder &B) const {
|
2019-07-02 02:49:01 +08:00
|
|
|
uint64_t Offset =
|
|
|
|
ST.getTargetLowering()->getImplicitParameterOffset(
|
|
|
|
B.getMF(), AMDGPUTargetLowering::FIRST_IMPLICIT);
|
|
|
|
LLT DstTy = MRI.getType(DstReg);
|
|
|
|
LLT IdxTy = LLT::scalar(DstTy.getSizeInBits());
|
|
|
|
|
|
|
|
Register KernargPtrReg = MRI.createGenericVirtualRegister(DstTy);
|
2020-07-21 03:56:39 +08:00
|
|
|
if (!loadInputValue(KernargPtrReg, B,
|
|
|
|
AMDGPUFunctionArgInfo::KERNARG_SEGMENT_PTR))
|
2019-07-02 02:49:01 +08:00
|
|
|
return false;
|
|
|
|
|
2020-07-04 02:47:23 +08:00
|
|
|
// FIXME: This should be nuw
|
[globalisel] Rename G_GEP to G_PTR_ADD
Summary:
G_GEP is rather poorly named. It's a simple pointer+scalar addition and
doesn't support any of the complexities of getelementptr. I therefore
propose that we rename it. There's a G_PTR_MASK so let's follow that
convention and go with G_PTR_ADD
Reviewers: volkan, aditya_nandakumar, bogner, rovka, arsenm
Subscribers: sdardis, jvesely, wdng, nhaehnle, hiraditya, jrtc27, atanasyan, arphaman, Petar.Avramovic, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D69734
2019-11-02 04:18:00 +08:00
|
|
|
B.buildPtrAdd(DstReg, KernargPtrReg, B.buildConstant(IdxTy, Offset).getReg(0));
|
2020-07-04 02:47:23 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool AMDGPULegalizerInfo::legalizeImplicitArgPtr(MachineInstr &MI,
|
|
|
|
MachineRegisterInfo &MRI,
|
|
|
|
MachineIRBuilder &B) const {
|
|
|
|
const SIMachineFunctionInfo *MFI = B.getMF().getInfo<SIMachineFunctionInfo>();
|
|
|
|
if (!MFI->isEntryFunction()) {
|
|
|
|
return legalizePreloadedArgIntrin(MI, MRI, B,
|
|
|
|
AMDGPUFunctionArgInfo::IMPLICIT_ARG_PTR);
|
|
|
|
}
|
|
|
|
|
|
|
|
Register DstReg = MI.getOperand(0).getReg();
|
|
|
|
if (!getImplicitArgPtr(DstReg, MRI, B))
|
|
|
|
return false;
|
|
|
|
|
2019-07-02 02:49:01 +08:00
|
|
|
MI.eraseFromParent();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-09-05 10:20:39 +08:00
|
|
|
bool AMDGPULegalizerInfo::legalizeIsAddrSpace(MachineInstr &MI,
|
|
|
|
MachineRegisterInfo &MRI,
|
|
|
|
MachineIRBuilder &B,
|
|
|
|
unsigned AddrSpace) const {
|
|
|
|
Register ApertureReg = getSegmentAperture(AddrSpace, MRI, B);
|
2020-08-20 04:26:22 +08:00
|
|
|
auto Unmerge = B.buildUnmerge(LLT::scalar(32), MI.getOperand(2).getReg());
|
|
|
|
Register Hi32 = Unmerge.getReg(1);
|
|
|
|
|
2019-09-05 10:20:39 +08:00
|
|
|
B.buildICmp(ICmpInst::ICMP_EQ, MI.getOperand(0), Hi32, ApertureReg);
|
|
|
|
MI.eraseFromParent();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-09-19 12:29:20 +08:00
|
|
|
// The raw.(t)buffer and struct.(t)buffer intrinsics have two offset args:
|
|
|
|
// offset (the offset that is included in bounds checking and swizzling, to be
|
|
|
|
// split between the instruction's voffset and immoffset fields) and soffset
|
|
|
|
// (the offset that is excluded from bounds checking and swizzling, to go in
|
|
|
|
// the instruction's soffset field). This function takes the first kind of
|
|
|
|
// offset and figures out how to split it between voffset and immoffset.
|
2021-07-21 22:53:59 +08:00
|
|
|
std::pair<Register, unsigned>
|
2019-09-19 12:29:20 +08:00
|
|
|
AMDGPULegalizerInfo::splitBufferOffsets(MachineIRBuilder &B,
|
|
|
|
Register OrigOffset) const {
|
|
|
|
const unsigned MaxImm = 4095;
|
|
|
|
Register BaseReg;
|
2021-07-21 22:53:59 +08:00
|
|
|
unsigned ImmOffset;
|
2019-09-19 12:29:20 +08:00
|
|
|
const LLT S32 = LLT::scalar(32);
|
2021-01-28 18:08:11 +08:00
|
|
|
MachineRegisterInfo &MRI = *B.getMRI();
|
2019-09-19 12:29:20 +08:00
|
|
|
|
2021-07-21 22:53:59 +08:00
|
|
|
std::tie(BaseReg, ImmOffset) =
|
2021-01-28 18:08:11 +08:00
|
|
|
AMDGPU::getBaseWithConstantOffset(MRI, OrigOffset);
|
2019-09-19 12:29:20 +08:00
|
|
|
|
2021-01-28 18:08:11 +08:00
|
|
|
// If BaseReg is a pointer, convert it to int.
|
|
|
|
if (MRI.getType(BaseReg).isPointer())
|
|
|
|
BaseReg = B.buildPtrToInt(MRI.getType(OrigOffset), BaseReg).getReg(0);
|
|
|
|
|
2019-09-19 12:29:20 +08:00
|
|
|
// If the immediate value is too big for the immoffset field, put the value
|
|
|
|
// and -4096 into the immoffset field so that the value that is copied/added
|
|
|
|
// for the voffset field is a multiple of 4096, and it stands more chance
|
|
|
|
// of being CSEd with the copy/add for another similar load/store.
|
|
|
|
// However, do not do that rounding down to a multiple of 4096 if that is a
|
|
|
|
// negative number, as it appears to be illegal to have a negative offset
|
|
|
|
// in the vgpr, even if adding the immediate offset makes it positive.
|
|
|
|
unsigned Overflow = ImmOffset & ~MaxImm;
|
|
|
|
ImmOffset -= Overflow;
|
|
|
|
if ((int32_t)Overflow < 0) {
|
|
|
|
Overflow += ImmOffset;
|
|
|
|
ImmOffset = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Overflow != 0) {
|
|
|
|
if (!BaseReg) {
|
|
|
|
BaseReg = B.buildConstant(S32, Overflow).getReg(0);
|
|
|
|
} else {
|
|
|
|
auto OverflowVal = B.buildConstant(S32, Overflow);
|
|
|
|
BaseReg = B.buildAdd(S32, BaseReg, OverflowVal).getReg(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!BaseReg)
|
|
|
|
BaseReg = B.buildConstant(S32, 0).getReg(0);
|
|
|
|
|
2021-07-21 22:53:59 +08:00
|
|
|
return std::make_pair(BaseReg, ImmOffset);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Update \p MMO based on the offset inputs to a raw/struct buffer intrinsic.
|
|
|
|
void AMDGPULegalizerInfo::updateBufferMMO(MachineMemOperand *MMO,
|
|
|
|
Register VOffset, Register SOffset,
|
|
|
|
unsigned ImmOffset, Register VIndex,
|
|
|
|
MachineRegisterInfo &MRI) const {
|
|
|
|
Optional<ValueAndVReg> MaybeVOffsetVal =
|
2021-09-17 17:21:55 +08:00
|
|
|
getIConstantVRegValWithLookThrough(VOffset, MRI);
|
2021-07-21 22:53:59 +08:00
|
|
|
Optional<ValueAndVReg> MaybeSOffsetVal =
|
2021-09-17 17:21:55 +08:00
|
|
|
getIConstantVRegValWithLookThrough(SOffset, MRI);
|
2021-07-21 22:53:59 +08:00
|
|
|
Optional<ValueAndVReg> MaybeVIndexVal =
|
2021-09-17 17:21:55 +08:00
|
|
|
getIConstantVRegValWithLookThrough(VIndex, MRI);
|
2021-07-21 22:53:59 +08:00
|
|
|
// If the combined VOffset + SOffset + ImmOffset + strided VIndex is constant,
|
|
|
|
// update the MMO with that offset. The stride is unknown so we can only do
|
|
|
|
// this if VIndex is constant 0.
|
|
|
|
if (MaybeVOffsetVal && MaybeSOffsetVal && MaybeVIndexVal &&
|
|
|
|
MaybeVIndexVal->Value == 0) {
|
|
|
|
uint64_t TotalOffset = MaybeVOffsetVal->Value.getZExtValue() +
|
|
|
|
MaybeSOffsetVal->Value.getZExtValue() + ImmOffset;
|
|
|
|
MMO->setOffset(TotalOffset);
|
|
|
|
} else {
|
|
|
|
// We don't have a constant combined offset to use in the MMO. Give up.
|
|
|
|
MMO->setValue((Value *)nullptr);
|
|
|
|
}
|
2019-09-19 12:29:20 +08:00
|
|
|
}
|
|
|
|
|
2019-09-20 00:26:14 +08:00
|
|
|
/// Handle register layout difference for f16 images for some subtargets.
|
|
|
|
Register AMDGPULegalizerInfo::handleD16VData(MachineIRBuilder &B,
|
|
|
|
MachineRegisterInfo &MRI,
|
[AMDGPU] Implement hardware bug workaround for image instructions
Summary:
This implements a workaround for a hardware bug in gfx8 and gfx9,
where register usage is not estimated correctly for image_store and
image_gather4 instructions when D16 is used.
Change-Id: I4e30744da6796acac53a9b5ad37ac1c2035c8899
Subscribers: arsenm, kzhuravl, jvesely, wdng, nhaehnle, yaxunl, dstuttard, tpr, t-tye, hiraditya, kerbowa, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D81172
2020-04-04 05:37:51 +08:00
|
|
|
Register Reg,
|
|
|
|
bool ImageStore) const {
|
2019-09-20 00:26:14 +08:00
|
|
|
const LLT S16 = LLT::scalar(16);
|
|
|
|
const LLT S32 = LLT::scalar(32);
|
|
|
|
LLT StoreVT = MRI.getType(Reg);
|
|
|
|
assert(StoreVT.isVector() && StoreVT.getElementType() == S16);
|
|
|
|
|
[AMDGPU] Implement hardware bug workaround for image instructions
Summary:
This implements a workaround for a hardware bug in gfx8 and gfx9,
where register usage is not estimated correctly for image_store and
image_gather4 instructions when D16 is used.
Change-Id: I4e30744da6796acac53a9b5ad37ac1c2035c8899
Subscribers: arsenm, kzhuravl, jvesely, wdng, nhaehnle, yaxunl, dstuttard, tpr, t-tye, hiraditya, kerbowa, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D81172
2020-04-04 05:37:51 +08:00
|
|
|
if (ST.hasUnpackedD16VMem()) {
|
|
|
|
auto Unmerge = B.buildUnmerge(S16, Reg);
|
|
|
|
|
|
|
|
SmallVector<Register, 4> WideRegs;
|
|
|
|
for (int I = 0, E = Unmerge->getNumOperands() - 1; I != E; ++I)
|
|
|
|
WideRegs.push_back(B.buildAnyExt(S32, Unmerge.getReg(I)).getReg(0));
|
|
|
|
|
|
|
|
int NumElts = StoreVT.getNumElements();
|
|
|
|
|
2021-06-24 16:58:21 +08:00
|
|
|
return B.buildBuildVector(LLT::fixed_vector(NumElts, S32), WideRegs)
|
|
|
|
.getReg(0);
|
[AMDGPU] Implement hardware bug workaround for image instructions
Summary:
This implements a workaround for a hardware bug in gfx8 and gfx9,
where register usage is not estimated correctly for image_store and
image_gather4 instructions when D16 is used.
Change-Id: I4e30744da6796acac53a9b5ad37ac1c2035c8899
Subscribers: arsenm, kzhuravl, jvesely, wdng, nhaehnle, yaxunl, dstuttard, tpr, t-tye, hiraditya, kerbowa, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D81172
2020-04-04 05:37:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (ImageStore && ST.hasImageStoreD16Bug()) {
|
|
|
|
if (StoreVT.getNumElements() == 2) {
|
|
|
|
SmallVector<Register, 4> PackedRegs;
|
|
|
|
Reg = B.buildBitcast(S32, Reg).getReg(0);
|
|
|
|
PackedRegs.push_back(Reg);
|
|
|
|
PackedRegs.resize(2, B.buildUndef(S32).getReg(0));
|
2021-06-24 16:58:21 +08:00
|
|
|
return B.buildBuildVector(LLT::fixed_vector(2, S32), PackedRegs)
|
|
|
|
.getReg(0);
|
[AMDGPU] Implement hardware bug workaround for image instructions
Summary:
This implements a workaround for a hardware bug in gfx8 and gfx9,
where register usage is not estimated correctly for image_store and
image_gather4 instructions when D16 is used.
Change-Id: I4e30744da6796acac53a9b5ad37ac1c2035c8899
Subscribers: arsenm, kzhuravl, jvesely, wdng, nhaehnle, yaxunl, dstuttard, tpr, t-tye, hiraditya, kerbowa, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D81172
2020-04-04 05:37:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (StoreVT.getNumElements() == 3) {
|
|
|
|
SmallVector<Register, 4> PackedRegs;
|
|
|
|
auto Unmerge = B.buildUnmerge(S16, Reg);
|
|
|
|
for (int I = 0, E = Unmerge->getNumOperands() - 1; I != E; ++I)
|
|
|
|
PackedRegs.push_back(Unmerge.getReg(I));
|
2020-11-05 22:09:56 +08:00
|
|
|
PackedRegs.resize(6, B.buildUndef(S16).getReg(0));
|
2021-06-24 16:58:21 +08:00
|
|
|
Reg = B.buildBuildVector(LLT::fixed_vector(6, S16), PackedRegs).getReg(0);
|
|
|
|
return B.buildBitcast(LLT::fixed_vector(3, S32), Reg).getReg(0);
|
[AMDGPU] Implement hardware bug workaround for image instructions
Summary:
This implements a workaround for a hardware bug in gfx8 and gfx9,
where register usage is not estimated correctly for image_store and
image_gather4 instructions when D16 is used.
Change-Id: I4e30744da6796acac53a9b5ad37ac1c2035c8899
Subscribers: arsenm, kzhuravl, jvesely, wdng, nhaehnle, yaxunl, dstuttard, tpr, t-tye, hiraditya, kerbowa, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D81172
2020-04-04 05:37:51 +08:00
|
|
|
}
|
2019-09-20 00:26:14 +08:00
|
|
|
|
[AMDGPU] Implement hardware bug workaround for image instructions
Summary:
This implements a workaround for a hardware bug in gfx8 and gfx9,
where register usage is not estimated correctly for image_store and
image_gather4 instructions when D16 is used.
Change-Id: I4e30744da6796acac53a9b5ad37ac1c2035c8899
Subscribers: arsenm, kzhuravl, jvesely, wdng, nhaehnle, yaxunl, dstuttard, tpr, t-tye, hiraditya, kerbowa, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D81172
2020-04-04 05:37:51 +08:00
|
|
|
if (StoreVT.getNumElements() == 4) {
|
|
|
|
SmallVector<Register, 4> PackedRegs;
|
2021-06-24 16:58:21 +08:00
|
|
|
Reg = B.buildBitcast(LLT::fixed_vector(2, S32), Reg).getReg(0);
|
[AMDGPU] Implement hardware bug workaround for image instructions
Summary:
This implements a workaround for a hardware bug in gfx8 and gfx9,
where register usage is not estimated correctly for image_store and
image_gather4 instructions when D16 is used.
Change-Id: I4e30744da6796acac53a9b5ad37ac1c2035c8899
Subscribers: arsenm, kzhuravl, jvesely, wdng, nhaehnle, yaxunl, dstuttard, tpr, t-tye, hiraditya, kerbowa, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D81172
2020-04-04 05:37:51 +08:00
|
|
|
auto Unmerge = B.buildUnmerge(S32, Reg);
|
|
|
|
for (int I = 0, E = Unmerge->getNumOperands() - 1; I != E; ++I)
|
|
|
|
PackedRegs.push_back(Unmerge.getReg(I));
|
|
|
|
PackedRegs.resize(4, B.buildUndef(S32).getReg(0));
|
2021-06-24 16:58:21 +08:00
|
|
|
return B.buildBuildVector(LLT::fixed_vector(4, S32), PackedRegs)
|
|
|
|
.getReg(0);
|
[AMDGPU] Implement hardware bug workaround for image instructions
Summary:
This implements a workaround for a hardware bug in gfx8 and gfx9,
where register usage is not estimated correctly for image_store and
image_gather4 instructions when D16 is used.
Change-Id: I4e30744da6796acac53a9b5ad37ac1c2035c8899
Subscribers: arsenm, kzhuravl, jvesely, wdng, nhaehnle, yaxunl, dstuttard, tpr, t-tye, hiraditya, kerbowa, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D81172
2020-04-04 05:37:51 +08:00
|
|
|
}
|
2019-09-20 00:26:14 +08:00
|
|
|
|
[AMDGPU] Implement hardware bug workaround for image instructions
Summary:
This implements a workaround for a hardware bug in gfx8 and gfx9,
where register usage is not estimated correctly for image_store and
image_gather4 instructions when D16 is used.
Change-Id: I4e30744da6796acac53a9b5ad37ac1c2035c8899
Subscribers: arsenm, kzhuravl, jvesely, wdng, nhaehnle, yaxunl, dstuttard, tpr, t-tye, hiraditya, kerbowa, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D81172
2020-04-04 05:37:51 +08:00
|
|
|
llvm_unreachable("invalid data type");
|
|
|
|
}
|
2019-09-20 00:26:14 +08:00
|
|
|
|
2021-12-23 21:09:51 +08:00
|
|
|
if (StoreVT == LLT::fixed_vector(3, S16)) {
|
|
|
|
Reg = B.buildPadVectorWithUndefElements(LLT::fixed_vector(4, S16), Reg)
|
|
|
|
.getReg(0);
|
|
|
|
}
|
[AMDGPU] Implement hardware bug workaround for image instructions
Summary:
This implements a workaround for a hardware bug in gfx8 and gfx9,
where register usage is not estimated correctly for image_store and
image_gather4 instructions when D16 is used.
Change-Id: I4e30744da6796acac53a9b5ad37ac1c2035c8899
Subscribers: arsenm, kzhuravl, jvesely, wdng, nhaehnle, yaxunl, dstuttard, tpr, t-tye, hiraditya, kerbowa, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D81172
2020-04-04 05:37:51 +08:00
|
|
|
return Reg;
|
2019-09-20 00:26:14 +08:00
|
|
|
}
|
|
|
|
|
2020-01-14 09:39:09 +08:00
|
|
|
Register AMDGPULegalizerInfo::fixStoreSourceType(
|
|
|
|
MachineIRBuilder &B, Register VData, bool IsFormat) const {
|
|
|
|
MachineRegisterInfo *MRI = B.getMRI();
|
|
|
|
LLT Ty = MRI->getType(VData);
|
2019-09-20 00:26:14 +08:00
|
|
|
|
|
|
|
const LLT S16 = LLT::scalar(16);
|
|
|
|
|
|
|
|
// Fixup illegal register types for i8 stores.
|
|
|
|
if (Ty == LLT::scalar(8) || Ty == S16) {
|
|
|
|
Register AnyExt = B.buildAnyExt(LLT::scalar(32), VData).getReg(0);
|
2020-01-14 09:39:09 +08:00
|
|
|
return AnyExt;
|
2019-09-20 00:26:14 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (Ty.isVector()) {
|
|
|
|
if (Ty.getElementType() == S16 && Ty.getNumElements() <= 4) {
|
|
|
|
if (IsFormat)
|
2020-01-14 09:39:09 +08:00
|
|
|
return handleD16VData(B, *MRI, VData);
|
2019-09-20 00:26:14 +08:00
|
|
|
}
|
2020-01-14 09:39:09 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return VData;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool AMDGPULegalizerInfo::legalizeBufferStore(MachineInstr &MI,
|
|
|
|
MachineRegisterInfo &MRI,
|
|
|
|
MachineIRBuilder &B,
|
|
|
|
bool IsTyped,
|
|
|
|
bool IsFormat) const {
|
|
|
|
Register VData = MI.getOperand(1).getReg();
|
|
|
|
LLT Ty = MRI.getType(VData);
|
|
|
|
LLT EltTy = Ty.getScalarType();
|
|
|
|
const bool IsD16 = IsFormat && (EltTy.getSizeInBits() == 16);
|
|
|
|
const LLT S32 = LLT::scalar(32);
|
|
|
|
|
|
|
|
VData = fixStoreSourceType(B, VData, IsFormat);
|
|
|
|
Register RSrc = MI.getOperand(2).getReg();
|
|
|
|
|
|
|
|
MachineMemOperand *MMO = *MI.memoperands_begin();
|
|
|
|
const int MemSize = MMO->getSize();
|
2019-09-20 00:26:14 +08:00
|
|
|
|
2020-01-14 09:39:09 +08:00
|
|
|
unsigned ImmOffset;
|
|
|
|
|
|
|
|
// The typed intrinsics add an immediate after the registers.
|
|
|
|
const unsigned NumVIndexOps = IsTyped ? 8 : 7;
|
|
|
|
|
|
|
|
// The struct intrinsic variants add one additional operand over raw.
|
|
|
|
const bool HasVIndex = MI.getNumOperands() == NumVIndexOps;
|
|
|
|
Register VIndex;
|
|
|
|
int OpOffset = 0;
|
|
|
|
if (HasVIndex) {
|
|
|
|
VIndex = MI.getOperand(3).getReg();
|
|
|
|
OpOffset = 1;
|
2021-07-21 22:53:59 +08:00
|
|
|
} else {
|
|
|
|
VIndex = B.buildConstant(S32, 0).getReg(0);
|
2019-09-20 00:26:14 +08:00
|
|
|
}
|
|
|
|
|
2020-01-14 09:39:09 +08:00
|
|
|
Register VOffset = MI.getOperand(3 + OpOffset).getReg();
|
|
|
|
Register SOffset = MI.getOperand(4 + OpOffset).getReg();
|
|
|
|
|
|
|
|
unsigned Format = 0;
|
|
|
|
if (IsTyped) {
|
|
|
|
Format = MI.getOperand(5 + OpOffset).getImm();
|
|
|
|
++OpOffset;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned AuxiliaryData = MI.getOperand(5 + OpOffset).getImm();
|
|
|
|
|
2021-07-21 22:53:59 +08:00
|
|
|
std::tie(VOffset, ImmOffset) = splitBufferOffsets(B, VOffset);
|
|
|
|
updateBufferMMO(MMO, VOffset, SOffset, ImmOffset, VIndex, MRI);
|
2020-01-14 09:39:09 +08:00
|
|
|
|
|
|
|
unsigned Opc;
|
|
|
|
if (IsTyped) {
|
|
|
|
Opc = IsD16 ? AMDGPU::G_AMDGPU_TBUFFER_STORE_FORMAT_D16 :
|
|
|
|
AMDGPU::G_AMDGPU_TBUFFER_STORE_FORMAT;
|
|
|
|
} else if (IsFormat) {
|
|
|
|
Opc = IsD16 ? AMDGPU::G_AMDGPU_BUFFER_STORE_FORMAT_D16 :
|
|
|
|
AMDGPU::G_AMDGPU_BUFFER_STORE_FORMAT;
|
|
|
|
} else {
|
|
|
|
switch (MemSize) {
|
|
|
|
case 1:
|
|
|
|
Opc = AMDGPU::G_AMDGPU_BUFFER_STORE_BYTE;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
Opc = AMDGPU::G_AMDGPU_BUFFER_STORE_SHORT;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
Opc = AMDGPU::G_AMDGPU_BUFFER_STORE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
auto MIB = B.buildInstr(Opc)
|
|
|
|
.addUse(VData) // vdata
|
|
|
|
.addUse(RSrc) // rsrc
|
|
|
|
.addUse(VIndex) // vindex
|
|
|
|
.addUse(VOffset) // voffset
|
|
|
|
.addUse(SOffset) // soffset
|
|
|
|
.addImm(ImmOffset); // offset(imm)
|
|
|
|
|
|
|
|
if (IsTyped)
|
|
|
|
MIB.addImm(Format);
|
|
|
|
|
|
|
|
MIB.addImm(AuxiliaryData) // cachepolicy, swizzled buffer(imm)
|
|
|
|
.addImm(HasVIndex ? -1 : 0) // idxen(imm)
|
|
|
|
.addMemOperand(MMO);
|
|
|
|
|
|
|
|
MI.eraseFromParent();
|
|
|
|
return true;
|
2019-09-20 00:26:14 +08:00
|
|
|
}
|
|
|
|
|
2020-01-14 05:02:14 +08:00
|
|
|
bool AMDGPULegalizerInfo::legalizeBufferLoad(MachineInstr &MI,
|
|
|
|
MachineRegisterInfo &MRI,
|
|
|
|
MachineIRBuilder &B,
|
2020-01-14 07:18:56 +08:00
|
|
|
bool IsFormat,
|
|
|
|
bool IsTyped) const {
|
2019-09-19 12:29:20 +08:00
|
|
|
// FIXME: Verifier should enforce 1 MMO for these intrinsics.
|
|
|
|
MachineMemOperand *MMO = *MI.memoperands_begin();
|
2021-07-16 02:24:00 +08:00
|
|
|
const LLT MemTy = MMO->getMemoryType();
|
2019-09-19 12:29:20 +08:00
|
|
|
const LLT S32 = LLT::scalar(32);
|
|
|
|
|
|
|
|
Register Dst = MI.getOperand(0).getReg();
|
|
|
|
Register RSrc = MI.getOperand(2).getReg();
|
2020-01-14 05:02:14 +08:00
|
|
|
|
2020-01-14 07:18:56 +08:00
|
|
|
// The typed intrinsics add an immediate after the registers.
|
|
|
|
const unsigned NumVIndexOps = IsTyped ? 8 : 7;
|
|
|
|
|
2020-01-14 05:02:14 +08:00
|
|
|
// The struct intrinsic variants add one additional operand over raw.
|
2020-01-14 07:18:56 +08:00
|
|
|
const bool HasVIndex = MI.getNumOperands() == NumVIndexOps;
|
2020-01-14 05:02:14 +08:00
|
|
|
Register VIndex;
|
|
|
|
int OpOffset = 0;
|
|
|
|
if (HasVIndex) {
|
|
|
|
VIndex = MI.getOperand(3).getReg();
|
|
|
|
OpOffset = 1;
|
2021-07-21 22:53:59 +08:00
|
|
|
} else {
|
|
|
|
VIndex = B.buildConstant(S32, 0).getReg(0);
|
2020-01-14 05:02:14 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
Register VOffset = MI.getOperand(3 + OpOffset).getReg();
|
|
|
|
Register SOffset = MI.getOperand(4 + OpOffset).getReg();
|
2020-01-14 07:18:56 +08:00
|
|
|
|
|
|
|
unsigned Format = 0;
|
|
|
|
if (IsTyped) {
|
|
|
|
Format = MI.getOperand(5 + OpOffset).getImm();
|
|
|
|
++OpOffset;
|
|
|
|
}
|
|
|
|
|
2020-01-14 05:02:14 +08:00
|
|
|
unsigned AuxiliaryData = MI.getOperand(5 + OpOffset).getImm();
|
2019-09-19 12:29:20 +08:00
|
|
|
unsigned ImmOffset;
|
|
|
|
|
2020-01-09 11:35:23 +08:00
|
|
|
LLT Ty = MRI.getType(Dst);
|
|
|
|
LLT EltTy = Ty.getScalarType();
|
|
|
|
const bool IsD16 = IsFormat && (EltTy.getSizeInBits() == 16);
|
|
|
|
const bool Unpacked = ST.hasUnpackedD16VMem();
|
|
|
|
|
2021-07-21 22:53:59 +08:00
|
|
|
std::tie(VOffset, ImmOffset) = splitBufferOffsets(B, VOffset);
|
|
|
|
updateBufferMMO(MMO, VOffset, SOffset, ImmOffset, VIndex, MRI);
|
2019-09-19 12:29:20 +08:00
|
|
|
|
|
|
|
unsigned Opc;
|
2020-01-14 07:18:56 +08:00
|
|
|
|
|
|
|
if (IsTyped) {
|
|
|
|
Opc = IsD16 ? AMDGPU::G_AMDGPU_TBUFFER_LOAD_FORMAT_D16 :
|
|
|
|
AMDGPU::G_AMDGPU_TBUFFER_LOAD_FORMAT;
|
|
|
|
} else if (IsFormat) {
|
2020-01-09 11:35:23 +08:00
|
|
|
Opc = IsD16 ? AMDGPU::G_AMDGPU_BUFFER_LOAD_FORMAT_D16 :
|
|
|
|
AMDGPU::G_AMDGPU_BUFFER_LOAD_FORMAT;
|
|
|
|
} else {
|
2021-07-16 02:24:00 +08:00
|
|
|
switch (MemTy.getSizeInBits()) {
|
|
|
|
case 8:
|
2020-01-09 11:35:23 +08:00
|
|
|
Opc = AMDGPU::G_AMDGPU_BUFFER_LOAD_UBYTE;
|
|
|
|
break;
|
2021-07-16 02:24:00 +08:00
|
|
|
case 16:
|
2020-01-09 11:35:23 +08:00
|
|
|
Opc = AMDGPU::G_AMDGPU_BUFFER_LOAD_USHORT;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
Opc = AMDGPU::G_AMDGPU_BUFFER_LOAD;
|
|
|
|
break;
|
|
|
|
}
|
2019-09-19 12:29:20 +08:00
|
|
|
}
|
|
|
|
|
2020-01-09 11:35:23 +08:00
|
|
|
Register LoadDstReg;
|
|
|
|
|
2021-07-16 02:24:00 +08:00
|
|
|
bool IsExtLoad =
|
|
|
|
(!IsD16 && MemTy.getSizeInBits() < 32) || (IsD16 && !Ty.isVector());
|
2020-01-09 11:35:23 +08:00
|
|
|
LLT UnpackedTy = Ty.changeElementSize(32);
|
|
|
|
|
|
|
|
if (IsExtLoad)
|
|
|
|
LoadDstReg = B.getMRI()->createGenericVirtualRegister(S32);
|
|
|
|
else if (Unpacked && IsD16 && Ty.isVector())
|
|
|
|
LoadDstReg = B.getMRI()->createGenericVirtualRegister(UnpackedTy);
|
|
|
|
else
|
|
|
|
LoadDstReg = Dst;
|
2019-09-19 12:29:20 +08:00
|
|
|
|
2020-01-14 07:18:56 +08:00
|
|
|
auto MIB = B.buildInstr(Opc)
|
2020-01-14 05:02:14 +08:00
|
|
|
.addDef(LoadDstReg) // vdata
|
|
|
|
.addUse(RSrc) // rsrc
|
|
|
|
.addUse(VIndex) // vindex
|
|
|
|
.addUse(VOffset) // voffset
|
|
|
|
.addUse(SOffset) // soffset
|
2020-01-14 07:18:56 +08:00
|
|
|
.addImm(ImmOffset); // offset(imm)
|
|
|
|
|
|
|
|
if (IsTyped)
|
|
|
|
MIB.addImm(Format);
|
|
|
|
|
|
|
|
MIB.addImm(AuxiliaryData) // cachepolicy, swizzled buffer(imm)
|
|
|
|
.addImm(HasVIndex ? -1 : 0) // idxen(imm)
|
|
|
|
.addMemOperand(MMO);
|
2019-09-19 12:29:20 +08:00
|
|
|
|
|
|
|
if (LoadDstReg != Dst) {
|
|
|
|
B.setInsertPt(B.getMBB(), ++B.getInsertPt());
|
2020-01-09 11:35:23 +08:00
|
|
|
|
|
|
|
// Widen result for extending loads was widened.
|
|
|
|
if (IsExtLoad)
|
|
|
|
B.buildTrunc(Dst, LoadDstReg);
|
|
|
|
else {
|
|
|
|
// Repack to original 16-bit vector result
|
|
|
|
// FIXME: G_TRUNC should work, but legalization currently fails
|
|
|
|
auto Unmerge = B.buildUnmerge(S32, LoadDstReg);
|
|
|
|
SmallVector<Register, 4> Repack;
|
|
|
|
for (unsigned I = 0, N = Unmerge->getNumOperands() - 1; I != N; ++I)
|
|
|
|
Repack.push_back(B.buildTrunc(EltTy, Unmerge.getReg(I)).getReg(0));
|
|
|
|
B.buildMerge(Dst, Repack);
|
|
|
|
}
|
2019-09-19 12:29:20 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
MI.eraseFromParent();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-01-18 09:51:01 +08:00
|
|
|
bool AMDGPULegalizerInfo::legalizeAtomicIncDec(MachineInstr &MI,
|
|
|
|
MachineIRBuilder &B,
|
|
|
|
bool IsInc) const {
|
|
|
|
unsigned Opc = IsInc ? AMDGPU::G_AMDGPU_ATOMIC_INC :
|
|
|
|
AMDGPU::G_AMDGPU_ATOMIC_DEC;
|
|
|
|
B.buildInstr(Opc)
|
|
|
|
.addDef(MI.getOperand(0).getReg())
|
|
|
|
.addUse(MI.getOperand(2).getReg())
|
|
|
|
.addUse(MI.getOperand(3).getReg())
|
|
|
|
.cloneMemRefs(MI);
|
|
|
|
MI.eraseFromParent();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-01-14 12:17:59 +08:00
|
|
|
static unsigned getBufferAtomicPseudo(Intrinsic::ID IntrID) {
|
|
|
|
switch (IntrID) {
|
|
|
|
case Intrinsic::amdgcn_raw_buffer_atomic_swap:
|
|
|
|
case Intrinsic::amdgcn_struct_buffer_atomic_swap:
|
|
|
|
return AMDGPU::G_AMDGPU_BUFFER_ATOMIC_SWAP;
|
|
|
|
case Intrinsic::amdgcn_raw_buffer_atomic_add:
|
|
|
|
case Intrinsic::amdgcn_struct_buffer_atomic_add:
|
|
|
|
return AMDGPU::G_AMDGPU_BUFFER_ATOMIC_ADD;
|
|
|
|
case Intrinsic::amdgcn_raw_buffer_atomic_sub:
|
|
|
|
case Intrinsic::amdgcn_struct_buffer_atomic_sub:
|
|
|
|
return AMDGPU::G_AMDGPU_BUFFER_ATOMIC_SUB;
|
|
|
|
case Intrinsic::amdgcn_raw_buffer_atomic_smin:
|
|
|
|
case Intrinsic::amdgcn_struct_buffer_atomic_smin:
|
|
|
|
return AMDGPU::G_AMDGPU_BUFFER_ATOMIC_SMIN;
|
|
|
|
case Intrinsic::amdgcn_raw_buffer_atomic_umin:
|
|
|
|
case Intrinsic::amdgcn_struct_buffer_atomic_umin:
|
|
|
|
return AMDGPU::G_AMDGPU_BUFFER_ATOMIC_UMIN;
|
|
|
|
case Intrinsic::amdgcn_raw_buffer_atomic_smax:
|
|
|
|
case Intrinsic::amdgcn_struct_buffer_atomic_smax:
|
|
|
|
return AMDGPU::G_AMDGPU_BUFFER_ATOMIC_SMAX;
|
|
|
|
case Intrinsic::amdgcn_raw_buffer_atomic_umax:
|
|
|
|
case Intrinsic::amdgcn_struct_buffer_atomic_umax:
|
|
|
|
return AMDGPU::G_AMDGPU_BUFFER_ATOMIC_UMAX;
|
|
|
|
case Intrinsic::amdgcn_raw_buffer_atomic_and:
|
|
|
|
case Intrinsic::amdgcn_struct_buffer_atomic_and:
|
|
|
|
return AMDGPU::G_AMDGPU_BUFFER_ATOMIC_AND;
|
|
|
|
case Intrinsic::amdgcn_raw_buffer_atomic_or:
|
|
|
|
case Intrinsic::amdgcn_struct_buffer_atomic_or:
|
|
|
|
return AMDGPU::G_AMDGPU_BUFFER_ATOMIC_OR;
|
|
|
|
case Intrinsic::amdgcn_raw_buffer_atomic_xor:
|
|
|
|
case Intrinsic::amdgcn_struct_buffer_atomic_xor:
|
|
|
|
return AMDGPU::G_AMDGPU_BUFFER_ATOMIC_XOR;
|
|
|
|
case Intrinsic::amdgcn_raw_buffer_atomic_inc:
|
|
|
|
case Intrinsic::amdgcn_struct_buffer_atomic_inc:
|
|
|
|
return AMDGPU::G_AMDGPU_BUFFER_ATOMIC_INC;
|
|
|
|
case Intrinsic::amdgcn_raw_buffer_atomic_dec:
|
|
|
|
case Intrinsic::amdgcn_struct_buffer_atomic_dec:
|
|
|
|
return AMDGPU::G_AMDGPU_BUFFER_ATOMIC_DEC;
|
2020-01-14 22:29:05 +08:00
|
|
|
case Intrinsic::amdgcn_raw_buffer_atomic_cmpswap:
|
|
|
|
case Intrinsic::amdgcn_struct_buffer_atomic_cmpswap:
|
|
|
|
return AMDGPU::G_AMDGPU_BUFFER_ATOMIC_CMPSWAP;
|
2021-02-18 05:37:46 +08:00
|
|
|
case Intrinsic::amdgcn_buffer_atomic_fadd:
|
2020-08-05 05:42:47 +08:00
|
|
|
case Intrinsic::amdgcn_raw_buffer_atomic_fadd:
|
|
|
|
case Intrinsic::amdgcn_struct_buffer_atomic_fadd:
|
|
|
|
return AMDGPU::G_AMDGPU_BUFFER_ATOMIC_FADD;
|
2021-02-18 05:37:46 +08:00
|
|
|
case Intrinsic::amdgcn_raw_buffer_atomic_fmin:
|
|
|
|
case Intrinsic::amdgcn_struct_buffer_atomic_fmin:
|
|
|
|
return AMDGPU::G_AMDGPU_BUFFER_ATOMIC_FMIN;
|
|
|
|
case Intrinsic::amdgcn_raw_buffer_atomic_fmax:
|
|
|
|
case Intrinsic::amdgcn_struct_buffer_atomic_fmax:
|
|
|
|
return AMDGPU::G_AMDGPU_BUFFER_ATOMIC_FMAX;
|
2020-01-14 12:17:59 +08:00
|
|
|
default:
|
|
|
|
llvm_unreachable("unhandled atomic opcode");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool AMDGPULegalizerInfo::legalizeBufferAtomic(MachineInstr &MI,
|
|
|
|
MachineIRBuilder &B,
|
|
|
|
Intrinsic::ID IID) const {
|
|
|
|
const bool IsCmpSwap = IID == Intrinsic::amdgcn_raw_buffer_atomic_cmpswap ||
|
|
|
|
IID == Intrinsic::amdgcn_struct_buffer_atomic_cmpswap;
|
2020-08-05 05:42:47 +08:00
|
|
|
const bool HasReturn = MI.getNumExplicitDefs() != 0;
|
2020-01-14 12:17:59 +08:00
|
|
|
|
2020-08-05 05:42:47 +08:00
|
|
|
Register Dst;
|
2020-01-14 12:17:59 +08:00
|
|
|
|
|
|
|
int OpOffset = 0;
|
2020-08-05 05:42:47 +08:00
|
|
|
if (HasReturn) {
|
|
|
|
// A few FP atomics do not support return values.
|
|
|
|
Dst = MI.getOperand(0).getReg();
|
|
|
|
} else {
|
|
|
|
OpOffset = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
Register VData = MI.getOperand(2 + OpOffset).getReg();
|
|
|
|
Register CmpVal;
|
2020-01-14 12:17:59 +08:00
|
|
|
|
|
|
|
if (IsCmpSwap) {
|
|
|
|
CmpVal = MI.getOperand(3 + OpOffset).getReg();
|
|
|
|
++OpOffset;
|
|
|
|
}
|
|
|
|
|
|
|
|
Register RSrc = MI.getOperand(3 + OpOffset).getReg();
|
2020-08-05 05:42:47 +08:00
|
|
|
const unsigned NumVIndexOps = (IsCmpSwap ? 8 : 7) + HasReturn;
|
2020-01-14 12:17:59 +08:00
|
|
|
|
|
|
|
// The struct intrinsic variants add one additional operand over raw.
|
|
|
|
const bool HasVIndex = MI.getNumOperands() == NumVIndexOps;
|
|
|
|
Register VIndex;
|
|
|
|
if (HasVIndex) {
|
2020-01-14 22:29:05 +08:00
|
|
|
VIndex = MI.getOperand(4 + OpOffset).getReg();
|
2020-01-14 12:17:59 +08:00
|
|
|
++OpOffset;
|
2021-07-21 22:53:59 +08:00
|
|
|
} else {
|
|
|
|
VIndex = B.buildConstant(LLT::scalar(32), 0).getReg(0);
|
2020-01-14 12:17:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
Register VOffset = MI.getOperand(4 + OpOffset).getReg();
|
|
|
|
Register SOffset = MI.getOperand(5 + OpOffset).getReg();
|
|
|
|
unsigned AuxiliaryData = MI.getOperand(6 + OpOffset).getImm();
|
|
|
|
|
|
|
|
MachineMemOperand *MMO = *MI.memoperands_begin();
|
|
|
|
|
|
|
|
unsigned ImmOffset;
|
2021-07-21 22:53:59 +08:00
|
|
|
std::tie(VOffset, ImmOffset) = splitBufferOffsets(B, VOffset);
|
|
|
|
updateBufferMMO(MMO, VOffset, SOffset, ImmOffset, VIndex, *B.getMRI());
|
2020-01-14 12:17:59 +08:00
|
|
|
|
2020-08-05 05:42:47 +08:00
|
|
|
auto MIB = B.buildInstr(getBufferAtomicPseudo(IID));
|
|
|
|
|
|
|
|
if (HasReturn)
|
|
|
|
MIB.addDef(Dst);
|
|
|
|
|
|
|
|
MIB.addUse(VData); // vdata
|
2020-01-14 12:17:59 +08:00
|
|
|
|
|
|
|
if (IsCmpSwap)
|
|
|
|
MIB.addReg(CmpVal);
|
|
|
|
|
|
|
|
MIB.addUse(RSrc) // rsrc
|
|
|
|
.addUse(VIndex) // vindex
|
|
|
|
.addUse(VOffset) // voffset
|
|
|
|
.addUse(SOffset) // soffset
|
|
|
|
.addImm(ImmOffset) // offset(imm)
|
|
|
|
.addImm(AuxiliaryData) // cachepolicy, swizzled buffer(imm)
|
|
|
|
.addImm(HasVIndex ? -1 : 0) // idxen(imm)
|
|
|
|
.addMemOperand(MMO);
|
|
|
|
|
|
|
|
MI.eraseFromParent();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2021-05-07 18:43:29 +08:00
|
|
|
/// Turn a set of s16 typed registers in \p AddrRegs into a dword sized
|
2020-01-27 03:39:56 +08:00
|
|
|
/// vector with s16 typed elements.
|
2021-05-07 18:43:29 +08:00
|
|
|
static void packImage16bitOpsToDwords(MachineIRBuilder &B, MachineInstr &MI,
|
|
|
|
SmallVectorImpl<Register> &PackedAddrs,
|
|
|
|
unsigned ArgOffset,
|
|
|
|
const AMDGPU::ImageDimIntrinsicInfo *Intr,
|
|
|
|
bool IsA16, bool IsG16) {
|
2020-01-27 03:39:56 +08:00
|
|
|
const LLT S16 = LLT::scalar(16);
|
2021-06-24 16:58:21 +08:00
|
|
|
const LLT V2S16 = LLT::fixed_vector(2, 16);
|
2021-05-07 18:43:29 +08:00
|
|
|
auto EndIdx = Intr->VAddrEnd;
|
2020-01-27 03:39:56 +08:00
|
|
|
|
2020-09-30 20:15:24 +08:00
|
|
|
for (unsigned I = Intr->VAddrStart; I < EndIdx; I++) {
|
|
|
|
MachineOperand &SrcOp = MI.getOperand(ArgOffset + I);
|
2020-02-08 22:28:27 +08:00
|
|
|
if (!SrcOp.isReg())
|
|
|
|
continue; // _L to _LZ may have eliminated this.
|
|
|
|
|
|
|
|
Register AddrReg = SrcOp.getReg();
|
2020-01-27 03:39:56 +08:00
|
|
|
|
2021-07-22 09:43:25 +08:00
|
|
|
if ((I < Intr->GradientStart) ||
|
|
|
|
(I >= Intr->GradientStart && I < Intr->CoordStart && !IsG16) ||
|
|
|
|
(I >= Intr->CoordStart && !IsA16)) {
|
2021-05-07 18:43:29 +08:00
|
|
|
// Handle any gradient or coordinate operands that should not be packed
|
2021-12-17 15:26:38 +08:00
|
|
|
if ((I < Intr->GradientStart) && IsA16 &&
|
|
|
|
(B.getMRI()->getType(AddrReg) == S16)) {
|
|
|
|
// Special handling of bias when A16 is on. Bias is of type half but
|
|
|
|
// occupies full 32-bit.
|
|
|
|
PackedAddrs.push_back(
|
|
|
|
B.buildBuildVector(V2S16, {AddrReg, B.buildUndef(S16).getReg(0)})
|
|
|
|
.getReg(0));
|
|
|
|
} else {
|
|
|
|
AddrReg = B.buildBitcast(V2S16, AddrReg).getReg(0);
|
|
|
|
PackedAddrs.push_back(AddrReg);
|
|
|
|
}
|
2020-02-08 08:10:02 +08:00
|
|
|
} else {
|
|
|
|
// Dz/dh, dz/dv and the last odd coord are packed with undef. Also, in 1D,
|
|
|
|
// derivatives dx/dh and dx/dv are packed with undef.
|
2020-03-25 15:38:22 +08:00
|
|
|
if (((I + 1) >= EndIdx) ||
|
2020-09-30 20:15:24 +08:00
|
|
|
((Intr->NumGradients / 2) % 2 == 1 &&
|
2020-10-06 16:45:31 +08:00
|
|
|
(I == static_cast<unsigned>(Intr->GradientStart +
|
|
|
|
(Intr->NumGradients / 2) - 1) ||
|
|
|
|
I == static_cast<unsigned>(Intr->GradientStart +
|
|
|
|
Intr->NumGradients - 1))) ||
|
2020-02-08 22:28:27 +08:00
|
|
|
// Check for _L to _LZ optimization
|
2020-09-30 20:15:24 +08:00
|
|
|
!MI.getOperand(ArgOffset + I + 1).isReg()) {
|
2020-02-08 08:10:02 +08:00
|
|
|
PackedAddrs.push_back(
|
|
|
|
B.buildBuildVector(V2S16, {AddrReg, B.buildUndef(S16).getReg(0)})
|
|
|
|
.getReg(0));
|
|
|
|
} else {
|
|
|
|
PackedAddrs.push_back(
|
2020-09-30 20:15:24 +08:00
|
|
|
B.buildBuildVector(
|
|
|
|
V2S16, {AddrReg, MI.getOperand(ArgOffset + I + 1).getReg()})
|
2020-02-08 08:10:02 +08:00
|
|
|
.getReg(0));
|
|
|
|
++I;
|
|
|
|
}
|
|
|
|
}
|
2020-01-27 03:39:56 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-27 09:02:51 +08:00
|
|
|
/// Convert from separate vaddr components to a single vector address register,
|
|
|
|
/// and replace the remaining operands with $noreg.
|
|
|
|
static void convertImageAddrToPacked(MachineIRBuilder &B, MachineInstr &MI,
|
|
|
|
int DimIdx, int NumVAddrs) {
|
2020-02-08 22:28:27 +08:00
|
|
|
const LLT S32 = LLT::scalar(32);
|
|
|
|
|
|
|
|
SmallVector<Register, 8> AddrRegs;
|
2020-01-27 09:02:51 +08:00
|
|
|
for (int I = 0; I != NumVAddrs; ++I) {
|
2020-02-08 22:28:27 +08:00
|
|
|
MachineOperand &SrcOp = MI.getOperand(DimIdx + I);
|
|
|
|
if (SrcOp.isReg()) {
|
|
|
|
AddrRegs.push_back(SrcOp.getReg());
|
|
|
|
assert(B.getMRI()->getType(SrcOp.getReg()) == S32);
|
|
|
|
}
|
2020-01-27 09:02:51 +08:00
|
|
|
}
|
|
|
|
|
2020-02-09 05:53:04 +08:00
|
|
|
int NumAddrRegs = AddrRegs.size();
|
|
|
|
if (NumAddrRegs != 1) {
|
2021-07-22 09:43:25 +08:00
|
|
|
// Above 8 elements round up to next power of 2 (i.e. 16).
|
|
|
|
if (NumAddrRegs > 8 && !isPowerOf2_32(NumAddrRegs)) {
|
2020-02-09 05:53:04 +08:00
|
|
|
const int RoundedNumRegs = NextPowerOf2(NumAddrRegs);
|
|
|
|
auto Undef = B.buildUndef(S32);
|
|
|
|
AddrRegs.append(RoundedNumRegs - NumAddrRegs, Undef.getReg(0));
|
|
|
|
NumAddrRegs = RoundedNumRegs;
|
|
|
|
}
|
|
|
|
|
2021-06-24 16:58:21 +08:00
|
|
|
auto VAddr =
|
|
|
|
B.buildBuildVector(LLT::fixed_vector(NumAddrRegs, 32), AddrRegs);
|
2020-02-08 22:28:27 +08:00
|
|
|
MI.getOperand(DimIdx).setReg(VAddr.getReg(0));
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int I = 1; I != NumVAddrs; ++I) {
|
|
|
|
MachineOperand &SrcOp = MI.getOperand(DimIdx + I);
|
|
|
|
if (SrcOp.isReg())
|
|
|
|
MI.getOperand(DimIdx + I).setReg(AMDGPU::NoRegister);
|
|
|
|
}
|
2020-01-27 09:02:51 +08:00
|
|
|
}
|
|
|
|
|
2020-01-27 03:39:56 +08:00
|
|
|
/// Rewrite image intrinsics to use register layouts expected by the subtarget.
|
|
|
|
///
|
|
|
|
/// Depending on the subtarget, load/store with 16-bit element data need to be
|
|
|
|
/// rewritten to use the low half of 32-bit registers, or directly use a packed
|
|
|
|
/// layout. 16-bit addresses should also sometimes be packed into 32-bit
|
|
|
|
/// registers.
|
|
|
|
///
|
|
|
|
/// We don't want to directly select image instructions just yet, but also want
|
|
|
|
/// to exposes all register repacking to the legalizer/combiners. We also don't
|
|
|
|
/// want a selected instrution entering RegBankSelect. In order to avoid
|
|
|
|
/// defining a multitude of intermediate image instructions, directly hack on
|
2021-09-21 05:28:10 +08:00
|
|
|
/// the intrinsic's arguments. In cases like a16 addresses, this requires
|
|
|
|
/// padding now unnecessary arguments with $noreg.
|
2020-01-16 03:23:20 +08:00
|
|
|
bool AMDGPULegalizerInfo::legalizeImageIntrinsic(
|
2020-09-30 20:15:24 +08:00
|
|
|
MachineInstr &MI, MachineIRBuilder &B, GISelChangeObserver &Observer,
|
|
|
|
const AMDGPU::ImageDimIntrinsicInfo *Intr) const {
|
2020-03-18 22:11:09 +08:00
|
|
|
|
2020-09-30 20:15:24 +08:00
|
|
|
const unsigned NumDefs = MI.getNumExplicitDefs();
|
|
|
|
const unsigned ArgOffset = NumDefs + 1;
|
2020-01-27 03:39:56 +08:00
|
|
|
bool IsTFE = NumDefs == 2;
|
2020-01-16 03:23:20 +08:00
|
|
|
// We are only processing the operands of d16 image operations on subtargets
|
2020-01-18 03:16:58 +08:00
|
|
|
// that use the unpacked register layout, or need to repack the TFE result.
|
|
|
|
|
|
|
|
// TODO: Do we need to guard against already legalized intrinsics?
|
2020-01-16 03:23:20 +08:00
|
|
|
const AMDGPU::MIMGBaseOpcodeInfo *BaseOpcode =
|
2020-09-30 20:15:24 +08:00
|
|
|
AMDGPU::getMIMGBaseOpcodeInfo(Intr->BaseOpcode);
|
2020-01-16 03:23:20 +08:00
|
|
|
|
|
|
|
MachineRegisterInfo *MRI = B.getMRI();
|
|
|
|
const LLT S32 = LLT::scalar(32);
|
|
|
|
const LLT S16 = LLT::scalar(16);
|
2021-06-24 16:58:21 +08:00
|
|
|
const LLT V2S16 = LLT::fixed_vector(2, 16);
|
2020-01-16 03:23:20 +08:00
|
|
|
|
2020-03-18 22:11:09 +08:00
|
|
|
unsigned DMask = 0;
|
2022-01-10 01:32:15 +08:00
|
|
|
Register VData = MI.getOperand(NumDefs == 0 ? 1 : 0).getReg();
|
|
|
|
LLT Ty = MRI->getType(VData);
|
2020-03-18 22:11:09 +08:00
|
|
|
|
2020-03-25 15:38:22 +08:00
|
|
|
// Check for 16 bit addresses and pack if true.
|
2020-09-30 20:15:24 +08:00
|
|
|
LLT GradTy =
|
|
|
|
MRI->getType(MI.getOperand(ArgOffset + Intr->GradientStart).getReg());
|
|
|
|
LLT AddrTy =
|
|
|
|
MRI->getType(MI.getOperand(ArgOffset + Intr->CoordStart).getReg());
|
2020-03-25 15:38:22 +08:00
|
|
|
const bool IsG16 = GradTy == S16;
|
|
|
|
const bool IsA16 = AddrTy == S16;
|
2022-01-10 01:32:15 +08:00
|
|
|
const bool IsD16 = Ty.getScalarType() == S16;
|
2020-03-25 15:38:22 +08:00
|
|
|
|
2020-03-18 22:11:09 +08:00
|
|
|
int DMaskLanes = 0;
|
|
|
|
if (!BaseOpcode->Atomic) {
|
2020-09-30 20:15:24 +08:00
|
|
|
DMask = MI.getOperand(ArgOffset + Intr->DMaskIndex).getImm();
|
2020-03-18 22:11:09 +08:00
|
|
|
if (BaseOpcode->Gather4) {
|
|
|
|
DMaskLanes = 4;
|
|
|
|
} else if (DMask != 0) {
|
|
|
|
DMaskLanes = countPopulation(DMask);
|
|
|
|
} else if (!IsTFE && !BaseOpcode->Store) {
|
|
|
|
// If dmask is 0, this is a no-op load. This can be eliminated.
|
|
|
|
B.buildUndef(MI.getOperand(0));
|
|
|
|
MI.eraseFromParent();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Observer.changingInstr(MI);
|
|
|
|
auto ChangedInstr = make_scope_exit([&] { Observer.changedInstr(MI); });
|
|
|
|
|
2022-01-10 01:32:15 +08:00
|
|
|
const unsigned StoreOpcode = IsD16 ? AMDGPU::G_AMDGPU_INTRIN_IMAGE_STORE_D16
|
|
|
|
: AMDGPU::G_AMDGPU_INTRIN_IMAGE_STORE;
|
|
|
|
const unsigned LoadOpcode = IsD16 ? AMDGPU::G_AMDGPU_INTRIN_IMAGE_LOAD_D16
|
|
|
|
: AMDGPU::G_AMDGPU_INTRIN_IMAGE_LOAD;
|
|
|
|
unsigned NewOpcode = NumDefs == 0 ? StoreOpcode : LoadOpcode;
|
2020-03-18 22:11:09 +08:00
|
|
|
|
|
|
|
// Track that we legalized this
|
|
|
|
MI.setDesc(B.getTII().get(NewOpcode));
|
|
|
|
|
|
|
|
// Expecting to get an error flag since TFC is on - and dmask is 0 Force
|
|
|
|
// dmask to be at least 1 otherwise the instruction will fail
|
|
|
|
if (IsTFE && DMask == 0) {
|
|
|
|
DMask = 0x1;
|
|
|
|
DMaskLanes = 1;
|
2020-09-30 20:15:24 +08:00
|
|
|
MI.getOperand(ArgOffset + Intr->DMaskIndex).setImm(DMask);
|
2020-03-18 22:11:09 +08:00
|
|
|
}
|
2020-01-27 09:02:51 +08:00
|
|
|
|
2020-02-09 08:08:34 +08:00
|
|
|
if (BaseOpcode->Atomic) {
|
|
|
|
Register VData0 = MI.getOperand(2).getReg();
|
|
|
|
LLT Ty = MRI->getType(VData0);
|
|
|
|
|
|
|
|
// TODO: Allow atomic swap and bit ops for v2s16/v4s16
|
|
|
|
if (Ty.isVector())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (BaseOpcode->AtomicX2) {
|
|
|
|
Register VData1 = MI.getOperand(3).getReg();
|
|
|
|
// The two values are packed in one register.
|
2021-06-24 16:58:21 +08:00
|
|
|
LLT PackedTy = LLT::fixed_vector(2, Ty);
|
2020-02-09 08:08:34 +08:00
|
|
|
auto Concat = B.buildBuildVector(PackedTy, {VData0, VData1});
|
|
|
|
MI.getOperand(2).setReg(Concat.getReg(0));
|
|
|
|
MI.getOperand(3).setReg(AMDGPU::NoRegister);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-30 20:15:24 +08:00
|
|
|
unsigned CorrectedNumVAddrs = Intr->NumVAddrs;
|
2020-02-08 22:28:27 +08:00
|
|
|
|
|
|
|
// Optimize _L to _LZ when _L is zero
|
2020-03-31 03:24:35 +08:00
|
|
|
if (const AMDGPU::MIMGLZMappingInfo *LZMappingInfo =
|
2020-09-30 20:15:24 +08:00
|
|
|
AMDGPU::getMIMGLZMappingInfo(Intr->BaseOpcode)) {
|
2020-02-08 22:28:27 +08:00
|
|
|
const ConstantFP *ConstantLod;
|
|
|
|
|
2020-09-30 20:15:24 +08:00
|
|
|
if (mi_match(MI.getOperand(ArgOffset + Intr->LodIndex).getReg(), *MRI,
|
|
|
|
m_GFCst(ConstantLod))) {
|
2020-02-08 22:28:27 +08:00
|
|
|
if (ConstantLod->isZero() || ConstantLod->isNegative()) {
|
2020-03-31 03:24:35 +08:00
|
|
|
// Set new opcode to _lz variant of _l, and change the intrinsic ID.
|
2020-09-30 20:15:24 +08:00
|
|
|
const AMDGPU::ImageDimIntrinsicInfo *NewImageDimIntr =
|
2021-11-11 22:58:42 +08:00
|
|
|
AMDGPU::getImageDimIntrinsicByBaseOpcode(LZMappingInfo->LZ,
|
|
|
|
Intr->Dim);
|
2020-03-31 03:24:35 +08:00
|
|
|
|
|
|
|
// The starting indexes should remain in the same place.
|
2020-02-08 22:28:27 +08:00
|
|
|
--CorrectedNumVAddrs;
|
2020-03-31 03:24:35 +08:00
|
|
|
|
2022-01-10 01:32:15 +08:00
|
|
|
MI.getOperand(NumDefs).setIntrinsicID(
|
|
|
|
static_cast<Intrinsic::ID>(NewImageDimIntr->Intr));
|
2020-09-30 20:15:24 +08:00
|
|
|
MI.RemoveOperand(ArgOffset + Intr->LodIndex);
|
|
|
|
Intr = NewImageDimIntr;
|
2020-02-08 22:28:27 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Optimize _mip away, when 'lod' is zero
|
2020-09-30 20:15:24 +08:00
|
|
|
if (AMDGPU::getMIMGMIPMappingInfo(Intr->BaseOpcode)) {
|
2020-02-08 22:28:27 +08:00
|
|
|
int64_t ConstantLod;
|
2020-09-30 20:15:24 +08:00
|
|
|
if (mi_match(MI.getOperand(ArgOffset + Intr->MipIndex).getReg(), *MRI,
|
|
|
|
m_ICst(ConstantLod))) {
|
2020-02-08 22:28:27 +08:00
|
|
|
if (ConstantLod == 0) {
|
2020-03-31 03:24:35 +08:00
|
|
|
// TODO: Change intrinsic opcode and remove operand instead or replacing
|
|
|
|
// it with 0, as the _L to _LZ handling is done above.
|
2020-09-30 20:15:24 +08:00
|
|
|
MI.getOperand(ArgOffset + Intr->MipIndex).ChangeToImmediate(0);
|
2020-02-08 22:28:27 +08:00
|
|
|
--CorrectedNumVAddrs;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-27 03:39:56 +08:00
|
|
|
// Rewrite the addressing register layout before doing anything else.
|
2021-05-07 18:43:29 +08:00
|
|
|
if (BaseOpcode->Gradients && !ST.hasG16() && (IsA16 != IsG16)) {
|
|
|
|
// 16 bit gradients are supported, but are tied to the A16 control
|
|
|
|
// so both gradients and addresses must be 16 bit
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (IsA16 && !ST.hasA16()) {
|
|
|
|
// A16 not supported
|
|
|
|
return false;
|
|
|
|
}
|
2020-01-27 03:39:56 +08:00
|
|
|
|
2021-05-07 18:43:29 +08:00
|
|
|
if (IsA16 || IsG16) {
|
2020-09-30 20:15:24 +08:00
|
|
|
if (Intr->NumVAddrs > 1) {
|
2020-01-27 03:39:56 +08:00
|
|
|
SmallVector<Register, 4> PackedRegs;
|
2021-05-07 18:43:29 +08:00
|
|
|
|
|
|
|
packImage16bitOpsToDwords(B, MI, PackedRegs, ArgOffset, Intr, IsA16,
|
|
|
|
IsG16);
|
2020-03-25 15:38:22 +08:00
|
|
|
|
|
|
|
// See also below in the non-a16 branch
|
2021-07-22 09:43:25 +08:00
|
|
|
const bool UseNSA = ST.hasNSAEncoding() && PackedRegs.size() >= 3 &&
|
|
|
|
PackedRegs.size() <= ST.getNSAMaxSize();
|
2020-01-27 03:39:56 +08:00
|
|
|
|
|
|
|
if (!UseNSA && PackedRegs.size() > 1) {
|
2021-06-24 16:58:21 +08:00
|
|
|
LLT PackedAddrTy = LLT::fixed_vector(2 * PackedRegs.size(), 16);
|
2020-01-27 03:39:56 +08:00
|
|
|
auto Concat = B.buildConcatVectors(PackedAddrTy, PackedRegs);
|
|
|
|
PackedRegs[0] = Concat.getReg(0);
|
|
|
|
PackedRegs.resize(1);
|
|
|
|
}
|
|
|
|
|
2020-09-30 20:15:24 +08:00
|
|
|
const unsigned NumPacked = PackedRegs.size();
|
|
|
|
for (unsigned I = Intr->VAddrStart; I < Intr->VAddrEnd; I++) {
|
|
|
|
MachineOperand &SrcOp = MI.getOperand(ArgOffset + I);
|
2020-02-08 22:28:27 +08:00
|
|
|
if (!SrcOp.isReg()) {
|
|
|
|
assert(SrcOp.isImm() && SrcOp.getImm() == 0);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
assert(SrcOp.getReg() != AMDGPU::NoRegister);
|
2020-01-27 03:39:56 +08:00
|
|
|
|
2020-09-30 20:15:24 +08:00
|
|
|
if (I - Intr->VAddrStart < NumPacked)
|
|
|
|
SrcOp.setReg(PackedRegs[I - Intr->VAddrStart]);
|
2020-01-27 03:39:56 +08:00
|
|
|
else
|
2020-02-08 22:28:27 +08:00
|
|
|
SrcOp.setReg(AMDGPU::NoRegister);
|
2020-01-27 03:39:56 +08:00
|
|
|
}
|
|
|
|
}
|
2020-03-25 15:38:22 +08:00
|
|
|
} else {
|
|
|
|
// If the register allocator cannot place the address registers contiguously
|
|
|
|
// without introducing moves, then using the non-sequential address encoding
|
|
|
|
// is always preferable, since it saves VALU instructions and is usually a
|
|
|
|
// wash in terms of code size or even better.
|
|
|
|
//
|
|
|
|
// However, we currently have no way of hinting to the register allocator
|
|
|
|
// that MIMG addresses should be placed contiguously when it is possible to
|
|
|
|
// do so, so force non-NSA for the common 2-address case as a heuristic.
|
|
|
|
//
|
|
|
|
// SIShrinkInstructions will convert NSA encodings to non-NSA after register
|
|
|
|
// allocation when possible.
|
2021-07-22 09:43:25 +08:00
|
|
|
const bool UseNSA = ST.hasNSAEncoding() && CorrectedNumVAddrs >= 3 &&
|
|
|
|
CorrectedNumVAddrs <= ST.getNSAMaxSize();
|
2020-03-25 15:38:22 +08:00
|
|
|
|
2020-09-30 20:15:24 +08:00
|
|
|
if (!UseNSA && Intr->NumVAddrs > 1)
|
|
|
|
convertImageAddrToPacked(B, MI, ArgOffset + Intr->VAddrStart,
|
|
|
|
Intr->NumVAddrs);
|
2020-01-27 03:39:56 +08:00
|
|
|
}
|
|
|
|
|
2020-03-25 15:38:22 +08:00
|
|
|
int Flags = 0;
|
|
|
|
if (IsA16)
|
|
|
|
Flags |= 1;
|
|
|
|
if (IsG16)
|
|
|
|
Flags |= 2;
|
|
|
|
MI.addOperand(MachineOperand::CreateImm(Flags));
|
2020-02-09 08:08:34 +08:00
|
|
|
|
2020-01-18 03:16:58 +08:00
|
|
|
if (BaseOpcode->Store) { // No TFE for stores?
|
2020-01-28 22:05:11 +08:00
|
|
|
// TODO: Handle dmask trim
|
2022-01-10 01:32:15 +08:00
|
|
|
if (!Ty.isVector() || !IsD16)
|
2020-01-16 03:23:20 +08:00
|
|
|
return true;
|
|
|
|
|
[AMDGPU] Implement hardware bug workaround for image instructions
Summary:
This implements a workaround for a hardware bug in gfx8 and gfx9,
where register usage is not estimated correctly for image_store and
image_gather4 instructions when D16 is used.
Change-Id: I4e30744da6796acac53a9b5ad37ac1c2035c8899
Subscribers: arsenm, kzhuravl, jvesely, wdng, nhaehnle, yaxunl, dstuttard, tpr, t-tye, hiraditya, kerbowa, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D81172
2020-04-04 05:37:51 +08:00
|
|
|
Register RepackedReg = handleD16VData(B, *MRI, VData, true);
|
2020-01-27 03:39:56 +08:00
|
|
|
if (RepackedReg != VData) {
|
|
|
|
MI.getOperand(1).setReg(RepackedReg);
|
|
|
|
}
|
|
|
|
|
2020-01-16 03:23:20 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
Register DstReg = MI.getOperand(0).getReg();
|
2020-01-27 01:50:24 +08:00
|
|
|
const LLT EltTy = Ty.getScalarType();
|
2020-01-28 22:05:11 +08:00
|
|
|
const int NumElts = Ty.isVector() ? Ty.getNumElements() : 1;
|
2020-01-18 03:16:58 +08:00
|
|
|
|
2020-01-28 22:05:11 +08:00
|
|
|
// Confirm that the return type is large enough for the dmask specified
|
|
|
|
if (NumElts < DMaskLanes)
|
|
|
|
return false;
|
2020-01-18 03:16:58 +08:00
|
|
|
|
2020-01-28 22:05:11 +08:00
|
|
|
if (NumElts > 4 || DMaskLanes > 4)
|
|
|
|
return false;
|
2020-01-18 03:16:58 +08:00
|
|
|
|
2020-01-28 22:05:11 +08:00
|
|
|
const unsigned AdjustedNumElts = DMaskLanes == 0 ? 1 : DMaskLanes;
|
2021-06-25 18:27:41 +08:00
|
|
|
const LLT AdjustedTy =
|
|
|
|
Ty.changeElementCount(ElementCount::getFixed(AdjustedNumElts));
|
2020-01-18 03:16:58 +08:00
|
|
|
|
2020-01-28 22:05:11 +08:00
|
|
|
// The raw dword aligned data component of the load. The only legal cases
|
|
|
|
// where this matters should be when using the packed D16 format, for
|
|
|
|
// s16 -> <2 x s16>, and <3 x s16> -> <4 x s16>,
|
|
|
|
LLT RoundedTy;
|
2020-01-18 03:16:58 +08:00
|
|
|
|
2020-01-28 22:05:11 +08:00
|
|
|
// S32 vector to to cover all data, plus TFE result element.
|
|
|
|
LLT TFETy;
|
2020-01-18 03:16:58 +08:00
|
|
|
|
2020-01-28 22:05:11 +08:00
|
|
|
// Register type to use for each loaded component. Will be S32 or V2S16.
|
|
|
|
LLT RegTy;
|
|
|
|
|
|
|
|
if (IsD16 && ST.hasUnpackedD16VMem()) {
|
2021-06-25 15:25:41 +08:00
|
|
|
RoundedTy =
|
|
|
|
LLT::scalarOrVector(ElementCount::getFixed(AdjustedNumElts), 32);
|
2021-06-24 16:58:21 +08:00
|
|
|
TFETy = LLT::fixed_vector(AdjustedNumElts + 1, 32);
|
2020-01-28 22:05:11 +08:00
|
|
|
RegTy = S32;
|
|
|
|
} else {
|
|
|
|
unsigned EltSize = EltTy.getSizeInBits();
|
|
|
|
unsigned RoundedElts = (AdjustedTy.getSizeInBits() + 31) / 32;
|
|
|
|
unsigned RoundedSize = 32 * RoundedElts;
|
2021-06-25 15:25:41 +08:00
|
|
|
RoundedTy = LLT::scalarOrVector(
|
|
|
|
ElementCount::getFixed(RoundedSize / EltSize), EltSize);
|
2021-06-24 16:58:21 +08:00
|
|
|
TFETy = LLT::fixed_vector(RoundedSize / 32 + 1, S32);
|
2020-01-28 22:05:11 +08:00
|
|
|
RegTy = !IsTFE && EltSize == 16 ? V2S16 : S32;
|
|
|
|
}
|
|
|
|
|
|
|
|
// The return type does not need adjustment.
|
|
|
|
// TODO: Should we change s16 case to s32 or <2 x s16>?
|
|
|
|
if (!IsTFE && (RoundedTy == Ty || !Ty.isVector()))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
Register Dst1Reg;
|
|
|
|
|
|
|
|
// Insert after the instruction.
|
|
|
|
B.setInsertPt(*MI.getParent(), ++MI.getIterator());
|
2020-01-18 03:16:58 +08:00
|
|
|
|
2020-01-28 22:05:11 +08:00
|
|
|
// TODO: For TFE with d16, if we used a TFE type that was a multiple of <2 x
|
|
|
|
// s16> instead of s32, we would only need 1 bitcast instead of multiple.
|
|
|
|
const LLT LoadResultTy = IsTFE ? TFETy : RoundedTy;
|
|
|
|
const int ResultNumRegs = LoadResultTy.getSizeInBits() / 32;
|
2020-01-18 03:16:58 +08:00
|
|
|
|
2020-01-28 22:05:11 +08:00
|
|
|
Register NewResultReg = MRI->createGenericVirtualRegister(LoadResultTy);
|
2020-01-27 01:50:24 +08:00
|
|
|
|
2020-01-28 22:05:11 +08:00
|
|
|
MI.getOperand(0).setReg(NewResultReg);
|
2020-01-27 01:50:24 +08:00
|
|
|
|
2020-01-28 22:05:11 +08:00
|
|
|
// In the IR, TFE is supposed to be used with a 2 element struct return
|
2021-09-21 05:28:10 +08:00
|
|
|
// type. The instruction really returns these two values in one contiguous
|
2020-01-28 22:05:11 +08:00
|
|
|
// register, with one additional dword beyond the loaded data. Rewrite the
|
|
|
|
// return type to use a single register result.
|
2020-01-27 01:50:24 +08:00
|
|
|
|
2020-01-28 22:05:11 +08:00
|
|
|
if (IsTFE) {
|
|
|
|
Dst1Reg = MI.getOperand(1).getReg();
|
|
|
|
if (MRI->getType(Dst1Reg) != S32)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// TODO: Make sure the TFE operand bit is set.
|
|
|
|
MI.RemoveOperand(1);
|
|
|
|
|
|
|
|
// Handle the easy case that requires no repack instructions.
|
|
|
|
if (Ty == S32) {
|
|
|
|
B.buildUnmerge({DstReg, Dst1Reg}, NewResultReg);
|
2020-01-27 01:50:24 +08:00
|
|
|
return true;
|
2020-01-18 03:16:58 +08:00
|
|
|
}
|
2020-01-28 22:05:11 +08:00
|
|
|
}
|
2020-01-18 03:16:58 +08:00
|
|
|
|
2020-01-28 22:05:11 +08:00
|
|
|
// Now figure out how to copy the new result register back into the old
|
|
|
|
// result.
|
|
|
|
SmallVector<Register, 5> ResultRegs(ResultNumRegs, Dst1Reg);
|
2020-01-27 01:50:24 +08:00
|
|
|
|
2020-01-28 22:05:11 +08:00
|
|
|
const int NumDataRegs = IsTFE ? ResultNumRegs - 1 : ResultNumRegs;
|
2020-01-27 01:50:24 +08:00
|
|
|
|
2020-01-28 22:05:11 +08:00
|
|
|
if (ResultNumRegs == 1) {
|
|
|
|
assert(!IsTFE);
|
|
|
|
ResultRegs[0] = NewResultReg;
|
|
|
|
} else {
|
|
|
|
// We have to repack into a new vector of some kind.
|
|
|
|
for (int I = 0; I != NumDataRegs; ++I)
|
|
|
|
ResultRegs[I] = MRI->createGenericVirtualRegister(RegTy);
|
|
|
|
B.buildUnmerge(ResultRegs, NewResultReg);
|
|
|
|
|
|
|
|
// Drop the final TFE element to get the data part. The TFE result is
|
|
|
|
// directly written to the right place already.
|
|
|
|
if (IsTFE)
|
|
|
|
ResultRegs.resize(NumDataRegs);
|
|
|
|
}
|
2020-01-27 01:50:24 +08:00
|
|
|
|
2020-01-28 22:05:11 +08:00
|
|
|
// For an s16 scalar result, we form an s32 result with a truncate regardless
|
|
|
|
// of packed vs. unpacked.
|
|
|
|
if (IsD16 && !Ty.isVector()) {
|
|
|
|
B.buildTrunc(DstReg, ResultRegs[0]);
|
2020-01-18 03:16:58 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-01-28 22:05:11 +08:00
|
|
|
// Avoid a build/concat_vector of 1 entry.
|
|
|
|
if (Ty == V2S16 && NumDataRegs == 1 && !ST.hasUnpackedD16VMem()) {
|
|
|
|
B.buildBitcast(DstReg, ResultRegs[0]);
|
2020-01-16 03:23:20 +08:00
|
|
|
return true;
|
2020-01-28 22:05:11 +08:00
|
|
|
}
|
2020-01-16 03:23:20 +08:00
|
|
|
|
2020-01-28 22:05:11 +08:00
|
|
|
assert(Ty.isVector());
|
|
|
|
|
|
|
|
if (IsD16) {
|
|
|
|
// For packed D16 results with TFE enabled, all the data components are
|
|
|
|
// S32. Cast back to the expected type.
|
|
|
|
//
|
|
|
|
// TODO: We don't really need to use load s32 elements. We would only need one
|
|
|
|
// cast for the TFE result if a multiple of v2s16 was used.
|
|
|
|
if (RegTy != V2S16 && !ST.hasUnpackedD16VMem()) {
|
|
|
|
for (Register &Reg : ResultRegs)
|
|
|
|
Reg = B.buildBitcast(V2S16, Reg).getReg(0);
|
|
|
|
} else if (ST.hasUnpackedD16VMem()) {
|
|
|
|
for (Register &Reg : ResultRegs)
|
|
|
|
Reg = B.buildTrunc(S16, Reg).getReg(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
auto padWithUndef = [&](LLT Ty, int NumElts) {
|
|
|
|
if (NumElts == 0)
|
|
|
|
return;
|
|
|
|
Register Undef = B.buildUndef(Ty).getReg(0);
|
|
|
|
for (int I = 0; I != NumElts; ++I)
|
|
|
|
ResultRegs.push_back(Undef);
|
|
|
|
};
|
2020-01-16 03:23:20 +08:00
|
|
|
|
2020-01-28 22:05:11 +08:00
|
|
|
// Pad out any elements eliminated due to the dmask.
|
|
|
|
LLT ResTy = MRI->getType(ResultRegs[0]);
|
|
|
|
if (!ResTy.isVector()) {
|
|
|
|
padWithUndef(ResTy, NumElts - ResultRegs.size());
|
|
|
|
B.buildBuildVector(DstReg, ResultRegs);
|
|
|
|
return true;
|
|
|
|
}
|
2020-01-16 03:23:20 +08:00
|
|
|
|
2020-01-28 22:05:11 +08:00
|
|
|
assert(!ST.hasUnpackedD16VMem() && ResTy == V2S16);
|
|
|
|
const int RegsToCover = (Ty.getSizeInBits() + 31) / 32;
|
|
|
|
|
|
|
|
// Deal with the one annoying legal case.
|
2021-06-24 16:58:21 +08:00
|
|
|
const LLT V3S16 = LLT::fixed_vector(3, 16);
|
2020-01-28 22:05:11 +08:00
|
|
|
if (Ty == V3S16) {
|
2021-12-23 21:09:51 +08:00
|
|
|
if (IsTFE) {
|
|
|
|
if (ResultRegs.size() == 1) {
|
|
|
|
NewResultReg = ResultRegs[0];
|
|
|
|
} else if (ResultRegs.size() == 2) {
|
|
|
|
LLT V4S16 = LLT::fixed_vector(4, 16);
|
|
|
|
NewResultReg = B.buildConcatVectors(V4S16, ResultRegs).getReg(0);
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (MRI->getType(DstReg).getNumElements() <
|
|
|
|
MRI->getType(NewResultReg).getNumElements()) {
|
|
|
|
B.buildDeleteTrailingVectorElements(DstReg, NewResultReg);
|
|
|
|
} else {
|
|
|
|
B.buildPadVectorWithUndefElements(DstReg, NewResultReg);
|
|
|
|
}
|
2020-01-28 22:05:11 +08:00
|
|
|
return true;
|
|
|
|
}
|
2020-01-16 03:23:20 +08:00
|
|
|
|
2020-01-28 22:05:11 +08:00
|
|
|
padWithUndef(ResTy, RegsToCover - ResultRegs.size());
|
|
|
|
B.buildConcatVectors(DstReg, ResultRegs);
|
2020-01-16 03:23:20 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-01-31 06:34:33 +08:00
|
|
|
bool AMDGPULegalizerInfo::legalizeSBufferLoad(
|
2020-06-17 02:52:14 +08:00
|
|
|
LegalizerHelper &Helper, MachineInstr &MI) const {
|
|
|
|
MachineIRBuilder &B = Helper.MIRBuilder;
|
|
|
|
GISelChangeObserver &Observer = Helper.Observer;
|
|
|
|
|
2020-01-31 06:34:33 +08:00
|
|
|
Register Dst = MI.getOperand(0).getReg();
|
|
|
|
LLT Ty = B.getMRI()->getType(Dst);
|
|
|
|
unsigned Size = Ty.getSizeInBits();
|
2020-02-03 01:13:48 +08:00
|
|
|
MachineFunction &MF = B.getMF();
|
|
|
|
|
|
|
|
Observer.changingInstr(MI);
|
|
|
|
|
2021-06-09 08:22:45 +08:00
|
|
|
if (shouldBitcastLoadStoreType(ST, Ty, LLT::scalar(Size))) {
|
2020-06-17 02:52:14 +08:00
|
|
|
Ty = getBitcastRegisterType(Ty);
|
|
|
|
Helper.bitcastDst(MI, Ty, 0);
|
|
|
|
Dst = MI.getOperand(0).getReg();
|
|
|
|
B.setInsertPt(B.getMBB(), MI);
|
|
|
|
}
|
|
|
|
|
2020-02-03 01:13:48 +08:00
|
|
|
// FIXME: We don't really need this intermediate instruction. The intrinsic
|
|
|
|
// should be fixed to have a memory operand. Since it's readnone, we're not
|
|
|
|
// allowed to add one.
|
|
|
|
MI.setDesc(B.getTII().get(AMDGPU::G_AMDGPU_S_BUFFER_LOAD));
|
|
|
|
MI.RemoveOperand(1); // Remove intrinsic ID
|
|
|
|
|
|
|
|
// FIXME: When intrinsic definition is fixed, this should have an MMO already.
|
|
|
|
// TODO: Should this use datalayout alignment?
|
|
|
|
const unsigned MemSize = (Size + 7) / 8;
|
[Alignment][NFC] Transitionning more getMachineMemOperand call sites
Summary:
This is patch is part of a series to introduce an Alignment type.
See this thread for context: http://lists.llvm.org/pipermail/llvm-dev/2019-July/133851.html
See this patch for the introduction of the type: https://reviews.llvm.org/D64790
Reviewers: courbet
Subscribers: arsenm, dylanmckay, sdardis, nemanjai, jvesely, nhaehnle, hiraditya, kbarton, jrtc27, atanasyan, Jim, kerbowa, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D77121
2020-03-31 16:05:00 +08:00
|
|
|
const Align MemAlign(4);
|
2020-02-03 01:13:48 +08:00
|
|
|
MachineMemOperand *MMO = MF.getMachineMemOperand(
|
[Alignment][NFC] Transitionning more getMachineMemOperand call sites
Summary:
This is patch is part of a series to introduce an Alignment type.
See this thread for context: http://lists.llvm.org/pipermail/llvm-dev/2019-July/133851.html
See this patch for the introduction of the type: https://reviews.llvm.org/D64790
Reviewers: courbet
Subscribers: arsenm, dylanmckay, sdardis, nemanjai, jvesely, nhaehnle, hiraditya, kbarton, jrtc27, atanasyan, Jim, kerbowa, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D77121
2020-03-31 16:05:00 +08:00
|
|
|
MachinePointerInfo(),
|
|
|
|
MachineMemOperand::MOLoad | MachineMemOperand::MODereferenceable |
|
|
|
|
MachineMemOperand::MOInvariant,
|
|
|
|
MemSize, MemAlign);
|
2020-02-03 01:13:48 +08:00
|
|
|
MI.addMemOperand(MF, MMO);
|
2020-01-31 06:34:33 +08:00
|
|
|
|
|
|
|
// There are no 96-bit result scalar loads, but widening to 128-bit should
|
|
|
|
// always be legal. We may need to restore this to a 96-bit result if it turns
|
|
|
|
// out this needs to be converted to a vector load during RegBankSelect.
|
2020-02-03 01:13:48 +08:00
|
|
|
if (!isPowerOf2_32(Size)) {
|
|
|
|
if (Ty.isVector())
|
|
|
|
Helper.moreElementsVectorDst(MI, getPow2VectorType(Ty), 0);
|
|
|
|
else
|
|
|
|
Helper.widenScalarDst(MI, getPow2ScalarType(Ty), 0);
|
|
|
|
}
|
2020-01-31 06:34:33 +08:00
|
|
|
|
|
|
|
Observer.changedInstr(MI);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-07-20 20:26:33 +08:00
|
|
|
// TODO: Move to selection
|
AMDGPU/GlobalISel: Support llvm.trap and llvm.debugtrap intrinsics
Summary: Lower trap and debugtrap intrinsics to AMDGPU machine instruction(s).
Reviewers: arsenm, nhaehnle, kerbowa, cdevadas, t-tye, kzhuravl
Reviewed By: arsenm
Subscribers: kzhuravl, jvesely, wdng, yaxunl, rovka, dstuttard, tpr, hiraditya, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D74688
2020-03-05 10:45:55 +08:00
|
|
|
bool AMDGPULegalizerInfo::legalizeTrapIntrinsic(MachineInstr &MI,
|
|
|
|
MachineRegisterInfo &MRI,
|
|
|
|
MachineIRBuilder &B) const {
|
2021-03-24 23:52:10 +08:00
|
|
|
if (!ST.isTrapHandlerEnabled() ||
|
|
|
|
ST.getTrapHandlerAbi() != GCNSubtarget::TrapHandlerAbi::AMDHSA)
|
|
|
|
return legalizeTrapEndpgm(MI, MRI, B);
|
|
|
|
|
|
|
|
if (Optional<uint8_t> HsaAbiVer = AMDGPU::getHsaAbiVersion(&ST)) {
|
|
|
|
switch (*HsaAbiVer) {
|
|
|
|
case ELF::ELFABIVERSION_AMDGPU_HSA_V2:
|
|
|
|
case ELF::ELFABIVERSION_AMDGPU_HSA_V3:
|
|
|
|
return legalizeTrapHsaQueuePtr(MI, MRI, B);
|
|
|
|
case ELF::ELFABIVERSION_AMDGPU_HSA_V4:
|
|
|
|
return ST.supportsGetDoorbellID() ?
|
|
|
|
legalizeTrapHsa(MI, MRI, B) :
|
|
|
|
legalizeTrapHsaQueuePtr(MI, MRI, B);
|
|
|
|
}
|
|
|
|
}
|
2020-07-20 20:26:33 +08:00
|
|
|
|
2021-03-24 23:52:10 +08:00
|
|
|
llvm_unreachable("Unknown trap handler");
|
|
|
|
}
|
2020-07-20 20:26:33 +08:00
|
|
|
|
2021-03-24 23:52:10 +08:00
|
|
|
bool AMDGPULegalizerInfo::legalizeTrapEndpgm(
|
|
|
|
MachineInstr &MI, MachineRegisterInfo &MRI, MachineIRBuilder &B) const {
|
|
|
|
B.buildInstr(AMDGPU::S_ENDPGM).addImm(0);
|
|
|
|
MI.eraseFromParent();
|
|
|
|
return true;
|
|
|
|
}
|
AMDGPU/GlobalISel: Support llvm.trap and llvm.debugtrap intrinsics
Summary: Lower trap and debugtrap intrinsics to AMDGPU machine instruction(s).
Reviewers: arsenm, nhaehnle, kerbowa, cdevadas, t-tye, kzhuravl
Reviewed By: arsenm
Subscribers: kzhuravl, jvesely, wdng, yaxunl, rovka, dstuttard, tpr, hiraditya, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D74688
2020-03-05 10:45:55 +08:00
|
|
|
|
2021-03-24 23:52:10 +08:00
|
|
|
bool AMDGPULegalizerInfo::legalizeTrapHsaQueuePtr(
|
|
|
|
MachineInstr &MI, MachineRegisterInfo &MRI, MachineIRBuilder &B) const {
|
|
|
|
// Pass queue pointer to trap handler as input, and insert trap instruction
|
|
|
|
// Reference: https://llvm.org/docs/AMDGPUUsage.html#trap-handler-abi
|
|
|
|
Register LiveIn =
|
|
|
|
MRI.createGenericVirtualRegister(LLT::pointer(AMDGPUAS::CONSTANT_ADDRESS, 64));
|
|
|
|
if (!loadInputValue(LiveIn, B, AMDGPUFunctionArgInfo::QUEUE_PTR))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
Register SGPR01(AMDGPU::SGPR0_SGPR1);
|
|
|
|
B.buildCopy(SGPR01, LiveIn);
|
|
|
|
B.buildInstr(AMDGPU::S_TRAP)
|
|
|
|
.addImm(static_cast<unsigned>(GCNSubtarget::TrapID::LLVMAMDHSATrap))
|
|
|
|
.addReg(SGPR01, RegState::Implicit);
|
|
|
|
|
|
|
|
MI.eraseFromParent();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool AMDGPULegalizerInfo::legalizeTrapHsa(
|
|
|
|
MachineInstr &MI, MachineRegisterInfo &MRI, MachineIRBuilder &B) const {
|
|
|
|
B.buildInstr(AMDGPU::S_TRAP)
|
|
|
|
.addImm(static_cast<unsigned>(GCNSubtarget::TrapID::LLVMAMDHSATrap));
|
AMDGPU/GlobalISel: Support llvm.trap and llvm.debugtrap intrinsics
Summary: Lower trap and debugtrap intrinsics to AMDGPU machine instruction(s).
Reviewers: arsenm, nhaehnle, kerbowa, cdevadas, t-tye, kzhuravl
Reviewed By: arsenm
Subscribers: kzhuravl, jvesely, wdng, yaxunl, rovka, dstuttard, tpr, hiraditya, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D74688
2020-03-05 10:45:55 +08:00
|
|
|
MI.eraseFromParent();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool AMDGPULegalizerInfo::legalizeDebugTrapIntrinsic(
|
|
|
|
MachineInstr &MI, MachineRegisterInfo &MRI, MachineIRBuilder &B) const {
|
2021-09-21 05:28:10 +08:00
|
|
|
// Is non-HSA path or trap-handler disabled? Then, report a warning
|
AMDGPU/GlobalISel: Support llvm.trap and llvm.debugtrap intrinsics
Summary: Lower trap and debugtrap intrinsics to AMDGPU machine instruction(s).
Reviewers: arsenm, nhaehnle, kerbowa, cdevadas, t-tye, kzhuravl
Reviewed By: arsenm
Subscribers: kzhuravl, jvesely, wdng, yaxunl, rovka, dstuttard, tpr, hiraditya, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D74688
2020-03-05 10:45:55 +08:00
|
|
|
// accordingly
|
2021-03-24 23:52:10 +08:00
|
|
|
if (!ST.isTrapHandlerEnabled() ||
|
|
|
|
ST.getTrapHandlerAbi() != GCNSubtarget::TrapHandlerAbi::AMDHSA) {
|
AMDGPU/GlobalISel: Support llvm.trap and llvm.debugtrap intrinsics
Summary: Lower trap and debugtrap intrinsics to AMDGPU machine instruction(s).
Reviewers: arsenm, nhaehnle, kerbowa, cdevadas, t-tye, kzhuravl
Reviewed By: arsenm
Subscribers: kzhuravl, jvesely, wdng, yaxunl, rovka, dstuttard, tpr, hiraditya, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D74688
2020-03-05 10:45:55 +08:00
|
|
|
DiagnosticInfoUnsupported NoTrap(B.getMF().getFunction(),
|
|
|
|
"debugtrap handler not supported",
|
|
|
|
MI.getDebugLoc(), DS_Warning);
|
|
|
|
LLVMContext &Ctx = B.getMF().getFunction().getContext();
|
|
|
|
Ctx.diagnose(NoTrap);
|
|
|
|
} else {
|
|
|
|
// Insert debug-trap instruction
|
2021-03-24 23:52:10 +08:00
|
|
|
B.buildInstr(AMDGPU::S_TRAP)
|
|
|
|
.addImm(static_cast<unsigned>(GCNSubtarget::TrapID::LLVMAMDHSADebugTrap));
|
AMDGPU/GlobalISel: Support llvm.trap and llvm.debugtrap intrinsics
Summary: Lower trap and debugtrap intrinsics to AMDGPU machine instruction(s).
Reviewers: arsenm, nhaehnle, kerbowa, cdevadas, t-tye, kzhuravl
Reviewed By: arsenm
Subscribers: kzhuravl, jvesely, wdng, yaxunl, rovka, dstuttard, tpr, hiraditya, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D74688
2020-03-05 10:45:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
MI.eraseFromParent();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-09-18 02:44:52 +08:00
|
|
|
bool AMDGPULegalizerInfo::legalizeBVHIntrinsic(MachineInstr &MI,
|
|
|
|
MachineIRBuilder &B) const {
|
|
|
|
MachineRegisterInfo &MRI = *B.getMRI();
|
|
|
|
const LLT S16 = LLT::scalar(16);
|
|
|
|
const LLT S32 = LLT::scalar(32);
|
|
|
|
|
|
|
|
Register DstReg = MI.getOperand(0).getReg();
|
|
|
|
Register NodePtr = MI.getOperand(2).getReg();
|
|
|
|
Register RayExtent = MI.getOperand(3).getReg();
|
|
|
|
Register RayOrigin = MI.getOperand(4).getReg();
|
|
|
|
Register RayDir = MI.getOperand(5).getReg();
|
|
|
|
Register RayInvDir = MI.getOperand(6).getReg();
|
|
|
|
Register TDescr = MI.getOperand(7).getReg();
|
|
|
|
|
2021-06-09 04:54:42 +08:00
|
|
|
if (!ST.hasGFX10_AEncoding()) {
|
|
|
|
DiagnosticInfoUnsupported BadIntrin(B.getMF().getFunction(),
|
|
|
|
"intrinsic not supported on subtarget",
|
|
|
|
MI.getDebugLoc());
|
|
|
|
B.getMF().getFunction().getContext().diagnose(BadIntrin);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2021-08-02 18:27:40 +08:00
|
|
|
const bool IsA16 = MRI.getType(RayDir).getElementType().getSizeInBits() == 16;
|
|
|
|
const bool Is64 = MRI.getType(NodePtr).getSizeInBits() == 64;
|
2021-08-17 09:24:49 +08:00
|
|
|
const unsigned NumVDataDwords = 4;
|
|
|
|
const unsigned NumVAddrDwords = IsA16 ? (Is64 ? 9 : 8) : (Is64 ? 12 : 11);
|
|
|
|
const bool UseNSA =
|
|
|
|
ST.hasNSAEncoding() && NumVAddrDwords <= ST.getNSAMaxSize();
|
|
|
|
const unsigned BaseOpcodes[2][2] = {
|
|
|
|
{AMDGPU::IMAGE_BVH_INTERSECT_RAY, AMDGPU::IMAGE_BVH_INTERSECT_RAY_a16},
|
|
|
|
{AMDGPU::IMAGE_BVH64_INTERSECT_RAY,
|
|
|
|
AMDGPU::IMAGE_BVH64_INTERSECT_RAY_a16}};
|
|
|
|
int Opcode;
|
|
|
|
if (UseNSA) {
|
|
|
|
Opcode =
|
|
|
|
AMDGPU::getMIMGOpcode(BaseOpcodes[Is64][IsA16], AMDGPU::MIMGEncGfx10NSA,
|
|
|
|
NumVDataDwords, NumVAddrDwords);
|
|
|
|
} else {
|
|
|
|
Opcode = AMDGPU::getMIMGOpcode(BaseOpcodes[Is64][IsA16],
|
|
|
|
AMDGPU::MIMGEncGfx10Default, NumVDataDwords,
|
|
|
|
PowerOf2Ceil(NumVAddrDwords));
|
|
|
|
}
|
|
|
|
assert(Opcode != -1);
|
2020-09-18 02:44:52 +08:00
|
|
|
|
|
|
|
SmallVector<Register, 12> Ops;
|
|
|
|
if (Is64) {
|
|
|
|
auto Unmerge = B.buildUnmerge({S32, S32}, NodePtr);
|
|
|
|
Ops.push_back(Unmerge.getReg(0));
|
|
|
|
Ops.push_back(Unmerge.getReg(1));
|
|
|
|
} else {
|
|
|
|
Ops.push_back(NodePtr);
|
|
|
|
}
|
|
|
|
Ops.push_back(RayExtent);
|
|
|
|
|
2021-12-02 20:26:59 +08:00
|
|
|
auto packLanes = [&Ops, &S32, &B](Register Src) {
|
|
|
|
auto Unmerge = B.buildUnmerge({S32, S32, S32}, Src);
|
2020-09-18 02:44:52 +08:00
|
|
|
Ops.push_back(Unmerge.getReg(0));
|
|
|
|
Ops.push_back(Unmerge.getReg(1));
|
|
|
|
Ops.push_back(Unmerge.getReg(2));
|
|
|
|
};
|
|
|
|
|
|
|
|
packLanes(RayOrigin);
|
|
|
|
if (IsA16) {
|
2021-12-02 20:26:59 +08:00
|
|
|
auto UnmergeRayDir = B.buildUnmerge({S16, S16, S16}, RayDir);
|
|
|
|
auto UnmergeRayInvDir = B.buildUnmerge({S16, S16, S16}, RayInvDir);
|
2020-09-18 02:44:52 +08:00
|
|
|
Register R1 = MRI.createGenericVirtualRegister(S32);
|
|
|
|
Register R2 = MRI.createGenericVirtualRegister(S32);
|
|
|
|
Register R3 = MRI.createGenericVirtualRegister(S32);
|
|
|
|
B.buildMerge(R1, {UnmergeRayDir.getReg(0), UnmergeRayDir.getReg(1)});
|
|
|
|
B.buildMerge(R2, {UnmergeRayDir.getReg(2), UnmergeRayInvDir.getReg(0)});
|
|
|
|
B.buildMerge(R3, {UnmergeRayInvDir.getReg(1), UnmergeRayInvDir.getReg(2)});
|
|
|
|
Ops.push_back(R1);
|
|
|
|
Ops.push_back(R2);
|
|
|
|
Ops.push_back(R3);
|
|
|
|
} else {
|
|
|
|
packLanes(RayDir);
|
|
|
|
packLanes(RayInvDir);
|
|
|
|
}
|
|
|
|
|
2021-08-02 18:27:40 +08:00
|
|
|
if (!UseNSA) {
|
|
|
|
// Build a single vector containing all the operands so far prepared.
|
|
|
|
LLT OpTy = LLT::fixed_vector(Ops.size(), 32);
|
|
|
|
Register MergedOps = B.buildMerge(OpTy, Ops).getReg(0);
|
|
|
|
Ops.clear();
|
|
|
|
Ops.push_back(MergedOps);
|
|
|
|
}
|
|
|
|
|
2020-09-18 02:44:52 +08:00
|
|
|
auto MIB = B.buildInstr(AMDGPU::G_AMDGPU_INTRIN_BVH_INTERSECT_RAY)
|
|
|
|
.addDef(DstReg)
|
|
|
|
.addImm(Opcode);
|
|
|
|
|
|
|
|
for (Register R : Ops) {
|
|
|
|
MIB.addUse(R);
|
|
|
|
}
|
|
|
|
|
|
|
|
MIB.addUse(TDescr)
|
|
|
|
.addImm(IsA16 ? 1 : 0)
|
|
|
|
.cloneMemRefs(MI);
|
|
|
|
|
|
|
|
MI.eraseFromParent();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2022-01-10 08:33:57 +08:00
|
|
|
static bool replaceWithConstant(MachineIRBuilder &B, MachineInstr &MI, int64_t C) {
|
|
|
|
B.buildConstant(MI.getOperand(0).getReg(), C);
|
|
|
|
MI.eraseFromParent();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-06-10 05:02:12 +08:00
|
|
|
bool AMDGPULegalizerInfo::legalizeIntrinsic(LegalizerHelper &Helper,
|
|
|
|
MachineInstr &MI) const {
|
|
|
|
MachineIRBuilder &B = Helper.MIRBuilder;
|
2020-01-28 04:50:55 +08:00
|
|
|
MachineRegisterInfo &MRI = *B.getMRI();
|
2020-01-16 03:23:20 +08:00
|
|
|
|
2019-07-02 02:40:23 +08:00
|
|
|
// Replace the use G_BRCOND with the exec manipulate and branch pseudos.
|
2019-12-21 02:35:18 +08:00
|
|
|
auto IntrID = MI.getIntrinsicID();
|
|
|
|
switch (IntrID) {
|
|
|
|
case Intrinsic::amdgcn_if:
|
|
|
|
case Intrinsic::amdgcn_else: {
|
2020-01-06 11:09:24 +08:00
|
|
|
MachineInstr *Br = nullptr;
|
2020-05-17 22:51:22 +08:00
|
|
|
MachineBasicBlock *UncondBrTarget = nullptr;
|
2020-08-26 07:53:32 +08:00
|
|
|
bool Negated = false;
|
|
|
|
if (MachineInstr *BrCond =
|
|
|
|
verifyCFIntrinsic(MI, MRI, Br, UncondBrTarget, Negated)) {
|
2019-07-02 02:40:23 +08:00
|
|
|
const SIRegisterInfo *TRI
|
|
|
|
= static_cast<const SIRegisterInfo *>(MRI.getTargetRegisterInfo());
|
|
|
|
|
|
|
|
Register Def = MI.getOperand(1).getReg();
|
|
|
|
Register Use = MI.getOperand(3).getReg();
|
2019-12-21 02:35:18 +08:00
|
|
|
|
2020-05-17 22:51:22 +08:00
|
|
|
MachineBasicBlock *CondBrTarget = BrCond->getOperand(1).getMBB();
|
2020-08-26 07:53:32 +08:00
|
|
|
|
|
|
|
if (Negated)
|
|
|
|
std::swap(CondBrTarget, UncondBrTarget);
|
|
|
|
|
2020-06-12 06:28:31 +08:00
|
|
|
B.setInsertPt(B.getMBB(), BrCond->getIterator());
|
2019-12-21 02:35:18 +08:00
|
|
|
if (IntrID == Intrinsic::amdgcn_if) {
|
|
|
|
B.buildInstr(AMDGPU::SI_IF)
|
|
|
|
.addDef(Def)
|
|
|
|
.addUse(Use)
|
2020-05-17 22:51:22 +08:00
|
|
|
.addMBB(UncondBrTarget);
|
2019-12-21 02:35:18 +08:00
|
|
|
} else {
|
|
|
|
B.buildInstr(AMDGPU::SI_ELSE)
|
2020-10-20 17:11:51 +08:00
|
|
|
.addDef(Def)
|
|
|
|
.addUse(Use)
|
|
|
|
.addMBB(UncondBrTarget);
|
2019-12-21 02:35:18 +08:00
|
|
|
}
|
2019-07-02 02:40:23 +08:00
|
|
|
|
2020-05-17 22:51:22 +08:00
|
|
|
if (Br) {
|
|
|
|
Br->getOperand(0).setMBB(CondBrTarget);
|
|
|
|
} else {
|
|
|
|
// The IRTranslator skips inserting the G_BR for fallthrough cases, but
|
|
|
|
// since we're swapping branch targets it needs to be reinserted.
|
|
|
|
// FIXME: IRTranslator should probably not do this
|
|
|
|
B.buildBr(*CondBrTarget);
|
|
|
|
}
|
2020-01-06 11:09:24 +08:00
|
|
|
|
2019-07-02 02:40:23 +08:00
|
|
|
MRI.setRegClass(Def, TRI->getWaveMaskRegClass());
|
|
|
|
MRI.setRegClass(Use, TRI->getWaveMaskRegClass());
|
|
|
|
MI.eraseFromParent();
|
|
|
|
BrCond->eraseFromParent();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
case Intrinsic::amdgcn_loop: {
|
2020-01-06 11:09:24 +08:00
|
|
|
MachineInstr *Br = nullptr;
|
2020-05-17 22:51:22 +08:00
|
|
|
MachineBasicBlock *UncondBrTarget = nullptr;
|
2020-08-26 07:53:32 +08:00
|
|
|
bool Negated = false;
|
|
|
|
if (MachineInstr *BrCond =
|
|
|
|
verifyCFIntrinsic(MI, MRI, Br, UncondBrTarget, Negated)) {
|
2019-07-02 02:40:23 +08:00
|
|
|
const SIRegisterInfo *TRI
|
|
|
|
= static_cast<const SIRegisterInfo *>(MRI.getTargetRegisterInfo());
|
|
|
|
|
2020-05-17 22:51:22 +08:00
|
|
|
MachineBasicBlock *CondBrTarget = BrCond->getOperand(1).getMBB();
|
2019-07-02 02:40:23 +08:00
|
|
|
Register Reg = MI.getOperand(2).getReg();
|
2020-06-12 06:28:31 +08:00
|
|
|
|
2020-08-26 07:53:32 +08:00
|
|
|
if (Negated)
|
|
|
|
std::swap(CondBrTarget, UncondBrTarget);
|
|
|
|
|
2020-06-12 06:28:31 +08:00
|
|
|
B.setInsertPt(B.getMBB(), BrCond->getIterator());
|
2019-07-02 02:40:23 +08:00
|
|
|
B.buildInstr(AMDGPU::SI_LOOP)
|
|
|
|
.addUse(Reg)
|
2020-05-17 22:51:22 +08:00
|
|
|
.addMBB(UncondBrTarget);
|
2020-02-15 10:47:37 +08:00
|
|
|
|
|
|
|
if (Br)
|
2020-05-17 22:51:22 +08:00
|
|
|
Br->getOperand(0).setMBB(CondBrTarget);
|
|
|
|
else
|
|
|
|
B.buildBr(*CondBrTarget);
|
2020-02-15 10:47:37 +08:00
|
|
|
|
2019-07-02 02:40:23 +08:00
|
|
|
MI.eraseFromParent();
|
|
|
|
BrCond->eraseFromParent();
|
|
|
|
MRI.setRegClass(Reg, TRI->getWaveMaskRegClass());
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
2019-07-02 02:49:01 +08:00
|
|
|
case Intrinsic::amdgcn_kernarg_segment_ptr:
|
2020-03-13 02:35:22 +08:00
|
|
|
if (!AMDGPU::isKernel(B.getMF().getFunction().getCallingConv())) {
|
|
|
|
// This only makes sense to call in a kernel, so just lower to null.
|
|
|
|
B.buildConstant(MI.getOperand(0).getReg(), 0);
|
|
|
|
MI.eraseFromParent();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-07-02 02:49:01 +08:00
|
|
|
return legalizePreloadedArgIntrin(
|
|
|
|
MI, MRI, B, AMDGPUFunctionArgInfo::KERNARG_SEGMENT_PTR);
|
|
|
|
case Intrinsic::amdgcn_implicitarg_ptr:
|
|
|
|
return legalizeImplicitArgPtr(MI, MRI, B);
|
2019-07-02 02:45:36 +08:00
|
|
|
case Intrinsic::amdgcn_workitem_id_x:
|
2022-01-10 08:33:57 +08:00
|
|
|
if (ST.getMaxWorkitemID(B.getMF().getFunction(), 0) == 0)
|
|
|
|
return replaceWithConstant(B, MI, 0);
|
2019-07-02 02:45:36 +08:00
|
|
|
return legalizePreloadedArgIntrin(MI, MRI, B,
|
|
|
|
AMDGPUFunctionArgInfo::WORKITEM_ID_X);
|
|
|
|
case Intrinsic::amdgcn_workitem_id_y:
|
2022-01-10 08:33:57 +08:00
|
|
|
if (ST.getMaxWorkitemID(B.getMF().getFunction(), 1) == 0)
|
|
|
|
return replaceWithConstant(B, MI, 0);
|
|
|
|
|
2019-07-02 02:45:36 +08:00
|
|
|
return legalizePreloadedArgIntrin(MI, MRI, B,
|
|
|
|
AMDGPUFunctionArgInfo::WORKITEM_ID_Y);
|
|
|
|
case Intrinsic::amdgcn_workitem_id_z:
|
2022-01-10 08:33:57 +08:00
|
|
|
if (ST.getMaxWorkitemID(B.getMF().getFunction(), 2) == 0)
|
|
|
|
return replaceWithConstant(B, MI, 0);
|
|
|
|
|
2019-07-02 02:45:36 +08:00
|
|
|
return legalizePreloadedArgIntrin(MI, MRI, B,
|
|
|
|
AMDGPUFunctionArgInfo::WORKITEM_ID_Z);
|
2019-07-02 02:47:22 +08:00
|
|
|
case Intrinsic::amdgcn_workgroup_id_x:
|
|
|
|
return legalizePreloadedArgIntrin(MI, MRI, B,
|
|
|
|
AMDGPUFunctionArgInfo::WORKGROUP_ID_X);
|
|
|
|
case Intrinsic::amdgcn_workgroup_id_y:
|
|
|
|
return legalizePreloadedArgIntrin(MI, MRI, B,
|
|
|
|
AMDGPUFunctionArgInfo::WORKGROUP_ID_Y);
|
|
|
|
case Intrinsic::amdgcn_workgroup_id_z:
|
|
|
|
return legalizePreloadedArgIntrin(MI, MRI, B,
|
|
|
|
AMDGPUFunctionArgInfo::WORKGROUP_ID_Z);
|
2019-07-02 02:50:50 +08:00
|
|
|
case Intrinsic::amdgcn_dispatch_ptr:
|
|
|
|
return legalizePreloadedArgIntrin(MI, MRI, B,
|
|
|
|
AMDGPUFunctionArgInfo::DISPATCH_PTR);
|
|
|
|
case Intrinsic::amdgcn_queue_ptr:
|
|
|
|
return legalizePreloadedArgIntrin(MI, MRI, B,
|
|
|
|
AMDGPUFunctionArgInfo::QUEUE_PTR);
|
|
|
|
case Intrinsic::amdgcn_implicit_buffer_ptr:
|
|
|
|
return legalizePreloadedArgIntrin(
|
|
|
|
MI, MRI, B, AMDGPUFunctionArgInfo::IMPLICIT_BUFFER_PTR);
|
|
|
|
case Intrinsic::amdgcn_dispatch_id:
|
|
|
|
return legalizePreloadedArgIntrin(MI, MRI, B,
|
|
|
|
AMDGPUFunctionArgInfo::DISPATCH_ID);
|
[AMDGPU/GlobalISel] Add llvm.amdgcn.fdiv.fast legalization.
Reviewers: arsenm
Reviewed By: arsenm
Subscribers: volkan, kzhuravl, jvesely, wdng, nhaehnle, yaxunl, rovka, dstuttard, tpr, t-tye, hiraditya, Petar.Avramovic, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D64966
llvm-svn: 367344
2019-07-31 02:49:16 +08:00
|
|
|
case Intrinsic::amdgcn_fdiv_fast:
|
AMDGPU/GlobalISel: Legalize fast unsafe FDIV
Reviewers: arsenm
Reviewed By: arsenm
Subscribers: kzhuravl, jvesely, wdng, nhaehnle, yaxunl, rovka, dstuttard, tpr, t-tye, hiraditya, Petar.Avramovic, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D69231
llvm-svn: 375460
2019-10-22 06:18:26 +08:00
|
|
|
return legalizeFDIVFastIntrin(MI, MRI, B);
|
2019-09-05 10:20:39 +08:00
|
|
|
case Intrinsic::amdgcn_is_shared:
|
|
|
|
return legalizeIsAddrSpace(MI, MRI, B, AMDGPUAS::LOCAL_ADDRESS);
|
|
|
|
case Intrinsic::amdgcn_is_private:
|
|
|
|
return legalizeIsAddrSpace(MI, MRI, B, AMDGPUAS::PRIVATE_ADDRESS);
|
2019-09-09 23:20:49 +08:00
|
|
|
case Intrinsic::amdgcn_wavefrontsize: {
|
|
|
|
B.buildConstant(MI.getOperand(0), ST.getWavefrontSize());
|
|
|
|
MI.eraseFromParent();
|
|
|
|
return true;
|
|
|
|
}
|
2020-01-31 06:34:33 +08:00
|
|
|
case Intrinsic::amdgcn_s_buffer_load:
|
2020-06-17 02:52:14 +08:00
|
|
|
return legalizeSBufferLoad(Helper, MI);
|
2019-09-20 00:26:14 +08:00
|
|
|
case Intrinsic::amdgcn_raw_buffer_store:
|
2020-01-14 12:01:23 +08:00
|
|
|
case Intrinsic::amdgcn_struct_buffer_store:
|
2020-01-14 09:39:09 +08:00
|
|
|
return legalizeBufferStore(MI, MRI, B, false, false);
|
2019-09-20 00:26:14 +08:00
|
|
|
case Intrinsic::amdgcn_raw_buffer_store_format:
|
2020-01-14 12:01:23 +08:00
|
|
|
case Intrinsic::amdgcn_struct_buffer_store_format:
|
2020-01-14 09:39:09 +08:00
|
|
|
return legalizeBufferStore(MI, MRI, B, false, true);
|
2020-01-14 11:06:01 +08:00
|
|
|
case Intrinsic::amdgcn_raw_tbuffer_store:
|
|
|
|
case Intrinsic::amdgcn_struct_tbuffer_store:
|
|
|
|
return legalizeBufferStore(MI, MRI, B, true, true);
|
2019-09-19 12:29:20 +08:00
|
|
|
case Intrinsic::amdgcn_raw_buffer_load:
|
2020-01-14 05:02:14 +08:00
|
|
|
case Intrinsic::amdgcn_struct_buffer_load:
|
2020-01-14 07:18:56 +08:00
|
|
|
return legalizeBufferLoad(MI, MRI, B, false, false);
|
2020-01-09 11:35:23 +08:00
|
|
|
case Intrinsic::amdgcn_raw_buffer_load_format:
|
2020-01-14 06:07:41 +08:00
|
|
|
case Intrinsic::amdgcn_struct_buffer_load_format:
|
2020-01-14 07:18:56 +08:00
|
|
|
return legalizeBufferLoad(MI, MRI, B, true, false);
|
|
|
|
case Intrinsic::amdgcn_raw_tbuffer_load:
|
2020-01-14 09:06:26 +08:00
|
|
|
case Intrinsic::amdgcn_struct_tbuffer_load:
|
2020-01-14 07:18:56 +08:00
|
|
|
return legalizeBufferLoad(MI, MRI, B, true, true);
|
2020-01-14 12:17:59 +08:00
|
|
|
case Intrinsic::amdgcn_raw_buffer_atomic_swap:
|
|
|
|
case Intrinsic::amdgcn_struct_buffer_atomic_swap:
|
|
|
|
case Intrinsic::amdgcn_raw_buffer_atomic_add:
|
|
|
|
case Intrinsic::amdgcn_struct_buffer_atomic_add:
|
|
|
|
case Intrinsic::amdgcn_raw_buffer_atomic_sub:
|
|
|
|
case Intrinsic::amdgcn_struct_buffer_atomic_sub:
|
|
|
|
case Intrinsic::amdgcn_raw_buffer_atomic_smin:
|
|
|
|
case Intrinsic::amdgcn_struct_buffer_atomic_smin:
|
|
|
|
case Intrinsic::amdgcn_raw_buffer_atomic_umin:
|
|
|
|
case Intrinsic::amdgcn_struct_buffer_atomic_umin:
|
|
|
|
case Intrinsic::amdgcn_raw_buffer_atomic_smax:
|
|
|
|
case Intrinsic::amdgcn_struct_buffer_atomic_smax:
|
|
|
|
case Intrinsic::amdgcn_raw_buffer_atomic_umax:
|
|
|
|
case Intrinsic::amdgcn_struct_buffer_atomic_umax:
|
|
|
|
case Intrinsic::amdgcn_raw_buffer_atomic_and:
|
|
|
|
case Intrinsic::amdgcn_struct_buffer_atomic_and:
|
|
|
|
case Intrinsic::amdgcn_raw_buffer_atomic_or:
|
|
|
|
case Intrinsic::amdgcn_struct_buffer_atomic_or:
|
|
|
|
case Intrinsic::amdgcn_raw_buffer_atomic_xor:
|
|
|
|
case Intrinsic::amdgcn_struct_buffer_atomic_xor:
|
|
|
|
case Intrinsic::amdgcn_raw_buffer_atomic_inc:
|
|
|
|
case Intrinsic::amdgcn_struct_buffer_atomic_inc:
|
|
|
|
case Intrinsic::amdgcn_raw_buffer_atomic_dec:
|
|
|
|
case Intrinsic::amdgcn_struct_buffer_atomic_dec:
|
2020-08-05 05:42:47 +08:00
|
|
|
case Intrinsic::amdgcn_raw_buffer_atomic_fadd:
|
|
|
|
case Intrinsic::amdgcn_struct_buffer_atomic_fadd:
|
2020-01-14 12:17:59 +08:00
|
|
|
case Intrinsic::amdgcn_raw_buffer_atomic_cmpswap:
|
|
|
|
case Intrinsic::amdgcn_struct_buffer_atomic_cmpswap:
|
2021-02-18 05:37:46 +08:00
|
|
|
case Intrinsic::amdgcn_buffer_atomic_fadd:
|
|
|
|
case Intrinsic::amdgcn_raw_buffer_atomic_fmin:
|
|
|
|
case Intrinsic::amdgcn_struct_buffer_atomic_fmin:
|
|
|
|
case Intrinsic::amdgcn_raw_buffer_atomic_fmax:
|
|
|
|
case Intrinsic::amdgcn_struct_buffer_atomic_fmax:
|
2020-01-14 12:17:59 +08:00
|
|
|
return legalizeBufferAtomic(MI, B, IntrID);
|
2020-01-18 09:51:01 +08:00
|
|
|
case Intrinsic::amdgcn_atomic_inc:
|
|
|
|
return legalizeAtomicIncDec(MI, B, true);
|
|
|
|
case Intrinsic::amdgcn_atomic_dec:
|
|
|
|
return legalizeAtomicIncDec(MI, B, false);
|
AMDGPU/GlobalISel: Support llvm.trap and llvm.debugtrap intrinsics
Summary: Lower trap and debugtrap intrinsics to AMDGPU machine instruction(s).
Reviewers: arsenm, nhaehnle, kerbowa, cdevadas, t-tye, kzhuravl
Reviewed By: arsenm
Subscribers: kzhuravl, jvesely, wdng, yaxunl, rovka, dstuttard, tpr, hiraditya, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D74688
2020-03-05 10:45:55 +08:00
|
|
|
case Intrinsic::trap:
|
|
|
|
return legalizeTrapIntrinsic(MI, MRI, B);
|
|
|
|
case Intrinsic::debugtrap:
|
|
|
|
return legalizeDebugTrapIntrinsic(MI, MRI, B);
|
2020-07-26 04:26:33 +08:00
|
|
|
case Intrinsic::amdgcn_rsq_clamp:
|
|
|
|
return legalizeRsqClampIntrinsic(MI, MRI, B);
|
2020-07-26 23:46:23 +08:00
|
|
|
case Intrinsic::amdgcn_ds_fadd:
|
|
|
|
case Intrinsic::amdgcn_ds_fmin:
|
|
|
|
case Intrinsic::amdgcn_ds_fmax:
|
|
|
|
return legalizeDSAtomicFPIntrinsic(Helper, MI, IntrID);
|
2020-09-18 02:44:52 +08:00
|
|
|
case Intrinsic::amdgcn_image_bvh_intersect_ray:
|
|
|
|
return legalizeBVHIntrinsic(MI, B);
|
2020-01-16 03:23:20 +08:00
|
|
|
default: {
|
|
|
|
if (const AMDGPU::ImageDimIntrinsicInfo *ImageDimIntr =
|
|
|
|
AMDGPU::getImageDimIntrinsicInfo(IntrID))
|
2020-06-10 05:02:12 +08:00
|
|
|
return legalizeImageIntrinsic(MI, B, Helper.Observer, ImageDimIntr);
|
2019-07-02 02:40:23 +08:00
|
|
|
return true;
|
|
|
|
}
|
2020-01-16 03:23:20 +08:00
|
|
|
}
|
2019-07-02 02:40:23 +08:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|