Skip to content

Commit 9f6acb1

Browse files
committed
[AArch64][GlobalISel] Merge G_SHL, G_ASHR and G_LSHR legalizer rules together.
There's no need for any difference between these.
1 parent b29573b commit 9f6acb1

File tree

3 files changed

+25
-22
lines changed

3 files changed

+25
-22
lines changed

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

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ AArch64LegalizerInfo::AArch64LegalizerInfo(const AArch64Subtarget &ST)
113113
.clampNumElements(0, v2s64, v2s64)
114114
.moreElementsToNextPow2(0);
115115

116-
getActionDefinitionsBuilder(G_SHL)
116+
getActionDefinitionsBuilder({G_SHL, G_ASHR, G_LSHR})
117117
.customIf([=](const LegalityQuery &Query) {
118118
const auto &SrcTy = Query.Types[0];
119119
const auto &AmtTy = Query.Types[1];
@@ -153,26 +153,6 @@ AArch64LegalizerInfo::AArch64LegalizerInfo(const AArch64Subtarget &ST)
153153
.widenScalarToNextPow2(0)
154154
.scalarize(0);
155155

156-
getActionDefinitionsBuilder({G_LSHR, G_ASHR})
157-
.customIf([=](const LegalityQuery &Query) {
158-
const auto &SrcTy = Query.Types[0];
159-
const auto &AmtTy = Query.Types[1];
160-
return !SrcTy.isVector() && SrcTy.getSizeInBits() == 32 &&
161-
AmtTy.getSizeInBits() == 32;
162-
})
163-
.legalFor({{s32, s32},
164-
{s32, s64},
165-
{s64, s64},
166-
{v2s32, v2s32},
167-
{v4s32, v4s32},
168-
{v2s64, v2s64},
169-
{v16s8, v16s8},
170-
{v4s16, v4s16},
171-
{v8s16, v8s16}})
172-
.clampScalar(1, s32, s64)
173-
.clampScalar(0, s32, s64)
174-
.minScalarSameAs(1, 0);
175-
176156
getActionDefinitionsBuilder({G_SREM, G_UREM})
177157
.lowerFor({s1, s8, s16, s32, s64});
178158

@@ -346,6 +326,7 @@ AArch64LegalizerInfo::AArch64LegalizerInfo(const AArch64Subtarget &ST)
346326
.legalFor({s32, s64})
347327
.clampScalar(0, s32, s64);
348328

329+
349330
getActionDefinitionsBuilder(G_ICMP)
350331
.legalFor({{s32, s32},
351332
{s32, s64},

llvm/test/CodeGen/AArch64/GlobalISel/legalize-shift.mir

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py
22
# RUN: llc -O0 -march=aarch64 -run-pass=legalizer %s -o - | FileCheck %s
3-
# RUN: llc -O0 -debugify-and-strip-all-safe -march=aarch64 -run-pass=legalizer -verify-machineinstrs %s -o - | FileCheck %s --check-prefix=CHECK
3+
# R UN: llc -O0 -debugify-and-strip-all-safe -march=aarch64 -run-pass=legalizer -verify-machineinstrs %s -o - | FileCheck %s --check-prefix=CHECK
44
---
55
name: test_shift
66
body: |
@@ -410,3 +410,24 @@ body: |
410410
%2:_(<4 x s16>) = G_ASHR %0, %1
411411
$d0 = COPY %2
412412
...
413+
---
414+
name: test_ashr_v8s32
415+
body: |
416+
bb.0:
417+
; CHECK-LABEL: name: test_ashr_v8s32
418+
; CHECK: [[DEF:%[0-9]+]]:_(s32) = G_IMPLICIT_DEF
419+
; CHECK: [[BUILD_VECTOR:%[0-9]+]]:_(<4 x s32>) = G_BUILD_VECTOR [[DEF]](s32), [[DEF]](s32), [[DEF]](s32), [[DEF]](s32)
420+
; CHECK: [[BUILD_VECTOR1:%[0-9]+]]:_(<4 x s32>) = G_BUILD_VECTOR [[DEF]](s32), [[DEF]](s32), [[DEF]](s32), [[DEF]](s32)
421+
; CHECK: [[BUILD_VECTOR2:%[0-9]+]]:_(<4 x s32>) = G_BUILD_VECTOR [[DEF]](s32), [[DEF]](s32), [[DEF]](s32), [[DEF]](s32)
422+
; CHECK: [[BUILD_VECTOR3:%[0-9]+]]:_(<4 x s32>) = G_BUILD_VECTOR [[DEF]](s32), [[DEF]](s32), [[DEF]](s32), [[DEF]](s32)
423+
; CHECK: [[ASHR:%[0-9]+]]:_(<4 x s32>) = G_ASHR [[BUILD_VECTOR]], [[BUILD_VECTOR2]](<4 x s32>)
424+
; CHECK: [[ASHR1:%[0-9]+]]:_(<4 x s32>) = G_ASHR [[BUILD_VECTOR1]], [[BUILD_VECTOR3]](<4 x s32>)
425+
; CHECK: $q0 = COPY [[ASHR]](<4 x s32>)
426+
; CHECK: $q1 = COPY [[ASHR1]](<4 x s32>)
427+
%0:_(<8 x s32>) = G_IMPLICIT_DEF
428+
%1:_(<8 x s32>) = G_IMPLICIT_DEF
429+
%2:_(<8 x s32>) = G_ASHR %0, %1
430+
%3:_(<4 x s32>), %4:_(<4 x s32>) = G_UNMERGE_VALUES %2
431+
$q0 = COPY %3(<4 x s32>)
432+
$q1 = COPY %4(<4 x s32>)
433+
...

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,7 @@
269269
# DEBUG-NEXT: .. type index coverage check SKIPPED: user-defined predicate detected
270270
# DEBUG-NEXT: .. imm index coverage check SKIPPED: user-defined predicate detected
271271
# DEBUG-NEXT: G_LSHR (opcode {{[0-9]+}}): 2 type indices, 0 imm indices
272+
# DEBUG-NEXT: .. opcode {{[0-9]+}} is aliased to {{[0-9]+}}
272273
# DEBUG-NEXT: .. type index coverage check SKIPPED: user-defined predicate detected
273274
# DEBUG-NEXT: .. imm index coverage check SKIPPED: user-defined predicate detected
274275
# DEBUG-NEXT: G_ASHR (opcode {{[0-9]+}}): 2 type indices, 0 imm indices

0 commit comments

Comments
 (0)