Skip to content

Commit 6288f36

Browse files
authored
[AArch64][GlobalISel] Basic add_sat and sub_sat vector handling. (#80650)
This tries to fill in the basic vector handling for sadd_sat/uadd_sat and ssub_sat/usub_sat. It just handles the basics, marking legal types and clamping illegally sized vectors to legal ones.
1 parent 4b25053 commit 6288f36

File tree

8 files changed

+775
-427
lines changed

8 files changed

+775
-427
lines changed

llvm/lib/Target/AArch64/GISel/AArch64LegalizerInfo.cpp

+8-5
Original file line numberDiff line numberDiff line change
@@ -1141,9 +1141,6 @@ AArch64LegalizerInfo::AArch64LegalizerInfo(const AArch64Subtarget &ST)
11411141
.scalarize(1)
11421142
.lower();
11431143

1144-
getActionDefinitionsBuilder({G_UADDSAT, G_USUBSAT})
1145-
.lowerIf([=](const LegalityQuery &Q) { return Q.Types[0].isScalar(); });
1146-
11471144
getActionDefinitionsBuilder({G_FSHL, G_FSHR})
11481145
.customFor({{s32, s32}, {s32, s64}, {s64, s64}})
11491146
.lower();
@@ -1191,8 +1188,14 @@ AArch64LegalizerInfo::AArch64LegalizerInfo(const AArch64Subtarget &ST)
11911188
.minScalarEltSameAsIf(always, 1, 0)
11921189
.maxScalarEltSameAsIf(always, 1, 0);
11931190

1194-
// TODO: Vector types.
1195-
getActionDefinitionsBuilder({G_SADDSAT, G_SSUBSAT}).lowerIf(isScalar(0));
1191+
getActionDefinitionsBuilder({G_UADDSAT, G_SADDSAT, G_USUBSAT, G_SSUBSAT})
1192+
.legalFor({v2s64, v2s32, v4s32, v4s16, v8s16, v8s8, v16s8})
1193+
.clampNumElements(0, v8s8, v16s8)
1194+
.clampNumElements(0, v4s16, v8s16)
1195+
.clampNumElements(0, v2s32, v4s32)
1196+
.clampMaxNumElements(0, s64, 2)
1197+
.moreElementsToNextPow2(0)
1198+
.lower();
11961199

11971200
// TODO: Libcall support for s128.
11981201
// TODO: s16 should be legal with full FP16 support.

llvm/test/CodeGen/AArch64/GlobalISel/legalizer-info-validation.mir

+1
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,7 @@
395395
# DEBUG-NEXT: .. type index coverage check SKIPPED: user-defined predicate detected
396396
# DEBUG-NEXT: .. imm index coverage check SKIPPED: user-defined predicate detected
397397
# DEBUG-NEXT: G_SADDSAT (opcode {{[0-9]+}}): 1 type index, 0 imm indices
398+
# DEBUG-NEXT: .. opcode {{[0-9]+}} is aliased to {{[0-9]+}}
398399
# DEBUG-NEXT: .. type index coverage check SKIPPED: user-defined predicate detected
399400
# DEBUG-NEXT: .. imm index coverage check SKIPPED: user-defined predicate detected
400401
# DEBUG-NEXT: G_USUBSAT (opcode {{[0-9]+}}): 1 type index, 0 imm indices

llvm/test/CodeGen/AArch64/sadd_sat.ll

-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
; RUN: llc < %s -mtriple=aarch64-- | FileCheck %s --check-prefixes=CHECK,CHECK-SD
33
; RUN: llc < %s -mtriple=aarch64-- -global-isel -global-isel-abort=2 2>&1 | FileCheck %s --check-prefixes=CHECK,CHECK-GI
44

5-
; CHECK-GI: warning: Instruction selection used fallback path for vec
6-
75
declare i4 @llvm.sadd.sat.i4(i4, i4)
86
declare i8 @llvm.sadd.sat.i8(i8, i8)
97
declare i16 @llvm.sadd.sat.i16(i16, i16)

0 commit comments

Comments
 (0)