Skip to content

Commit 887cf1f

Browse files
authored
[AMDGPU][GlobalISel] Enable vector reductions (#131413)
- Enable llvm vector reductions for AMDGPU. fixes #114816
1 parent 128f381 commit 887cf1f

16 files changed

+53506
-0
lines changed

llvm/lib/Target/AMDGPU/AMDGPULegalizerInfo.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,12 @@ static std::initializer_list<LLT> AllS32Vectors = {
350350
static std::initializer_list<LLT> AllS64Vectors = {V2S64, V3S64, V4S64, V5S64,
351351
V6S64, V7S64, V8S64, V16S64};
352352

353+
static std::initializer_list<LLT> AllVectors{
354+
V2S16, V4S16, V6S16, V8S16, V10S16, V12S16, V16S16, V2S128,
355+
V4S128, V2S32, V3S32, V4S32, V5S32, V6S32, V7S32, V8S32,
356+
V9S32, V10S32, V11S32, V12S32, V16S32, V32S32, V2S64, V3S64,
357+
V4S64, V5S64, V6S64, V7S64, V8S64, V16S64};
358+
353359
// Checks whether a type is in the list of legal register types.
354360
static bool isRegisterClassType(const GCNSubtarget &ST, LLT Ty) {
355361
if (Ty.isPointerOrPointerVector())
@@ -2106,6 +2112,15 @@ AMDGPULegalizerInfo::AMDGPULegalizerInfo(const GCNSubtarget &ST_,
21062112

21072113
getActionDefinitionsBuilder(G_PREFETCH).alwaysLegal();
21082114

2115+
getActionDefinitionsBuilder(
2116+
{G_VECREDUCE_SMIN, G_VECREDUCE_SMAX, G_VECREDUCE_UMIN, G_VECREDUCE_UMAX,
2117+
G_VECREDUCE_ADD, G_VECREDUCE_MUL, G_VECREDUCE_FMUL, G_VECREDUCE_FMIN,
2118+
G_VECREDUCE_FMAX, G_VECREDUCE_FMINIMUM, G_VECREDUCE_FMAXIMUM,
2119+
G_VECREDUCE_OR, G_VECREDUCE_AND, G_VECREDUCE_XOR})
2120+
.legalFor(AllVectors)
2121+
.scalarize(1)
2122+
.lower();
2123+
21092124
getLegacyLegalizerInfo().computeTables();
21102125
verify(*ST.getInstrInfo());
21112126
}

llvm/test/CodeGen/AMDGPU/vector-reduce-add.ll

Lines changed: 3761 additions & 0 deletions
Large diffs are not rendered by default.

llvm/test/CodeGen/AMDGPU/vector-reduce-and.ll

Lines changed: 3725 additions & 0 deletions
Large diffs are not rendered by default.

llvm/test/CodeGen/AMDGPU/vector-reduce-fadd.ll

Lines changed: 1802 additions & 0 deletions
Large diffs are not rendered by default.

llvm/test/CodeGen/AMDGPU/vector-reduce-fmax.ll

Lines changed: 3197 additions & 0 deletions
Large diffs are not rendered by default.

llvm/test/CodeGen/AMDGPU/vector-reduce-fmaximum.ll

Lines changed: 2448 additions & 0 deletions
Large diffs are not rendered by default.

llvm/test/CodeGen/AMDGPU/vector-reduce-fmin.ll

Lines changed: 3196 additions & 0 deletions
Large diffs are not rendered by default.

llvm/test/CodeGen/AMDGPU/vector-reduce-fminimum.ll

Lines changed: 2664 additions & 0 deletions
Large diffs are not rendered by default.

llvm/test/CodeGen/AMDGPU/vector-reduce-fmul.ll

Lines changed: 1802 additions & 0 deletions
Large diffs are not rendered by default.

llvm/test/CodeGen/AMDGPU/vector-reduce-mul.ll

Lines changed: 4667 additions & 0 deletions
Large diffs are not rendered by default.

llvm/test/CodeGen/AMDGPU/vector-reduce-or.ll

Lines changed: 3536 additions & 0 deletions
Large diffs are not rendered by default.

llvm/test/CodeGen/AMDGPU/vector-reduce-smax.ll

Lines changed: 4895 additions & 0 deletions
Large diffs are not rendered by default.

llvm/test/CodeGen/AMDGPU/vector-reduce-smin.ll

Lines changed: 4895 additions & 0 deletions
Large diffs are not rendered by default.

llvm/test/CodeGen/AMDGPU/vector-reduce-umax.ll

Lines changed: 4816 additions & 0 deletions
Large diffs are not rendered by default.

llvm/test/CodeGen/AMDGPU/vector-reduce-umin.ll

Lines changed: 4465 additions & 0 deletions
Large diffs are not rendered by default.

llvm/test/CodeGen/AMDGPU/vector-reduce-xor.ll

Lines changed: 3622 additions & 0 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)