Skip to content

Commit b9f2b3b

Browse files
committed
[AArch64][GlobalISel] Scalarize <2 x s64> G_MUL since we don't have native support for it.
Differential Revision: https://reviews.llvm.org/D88437
1 parent 10eb3bf commit b9f2b3b

File tree

3 files changed

+41
-3
lines changed

3 files changed

+41
-3
lines changed

llvm/include/llvm/CodeGen/GlobalISel/LegalizerInfo.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -827,6 +827,13 @@ class LegalizeRuleSet {
827827
LegalizeMutations::scalarize(TypeIdx));
828828
}
829829

830+
LegalizeRuleSet &scalarizeIf(LegalityPredicate Predicate, unsigned TypeIdx) {
831+
using namespace LegalityPredicates;
832+
return actionIf(LegalizeAction::FewerElements,
833+
all(Predicate, isVector(typeIdx(TypeIdx))),
834+
LegalizeMutations::scalarize(TypeIdx));
835+
}
836+
830837
/// Ensure the scalar or element is at least as wide as Ty.
831838
LegalizeRuleSet &minScalarOrElt(unsigned TypeIdx, const LLT Ty) {
832839
using namespace LegalityPredicates;

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,13 @@ AArch64LegalizerInfo::AArch64LegalizerInfo(const AArch64Subtarget &ST)
9090
.widenScalarToNextPow2(0);
9191

9292
getActionDefinitionsBuilder({G_ADD, G_SUB, G_MUL, G_AND, G_OR, G_XOR})
93-
.legalFor({s32, s64, v2s32, v4s32, v2s64, v4s16, v8s16, v16s8})
93+
.legalFor({s32, s64, v2s32, v4s32, v4s16, v8s16, v16s8})
94+
.scalarizeIf(
95+
[=](const LegalityQuery &Query) {
96+
return Query.Opcode == G_MUL && Query.Types[0] == v2s64;
97+
},
98+
0)
99+
.legalFor({v2s64})
94100
.clampScalar(0, s32, s64)
95101
.widenScalarToNextPow2(0)
96102
.clampNumElements(0, v2s32, v4s32)

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

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py
2-
# RUN: llc -march=aarch64 -run-pass=legalizer %s -o - | FileCheck %s
2+
# RUN: llc -march=aarch64 -run-pass=legalizer -global-isel-abort=1 %s -o - | FileCheck %s
33
---
44
name: test_scalar_mul_small
55
body: |
@@ -31,7 +31,7 @@ body: |
3131
; CHECK: [[MUL:%[0-9]+]]:_(s64) = G_MUL [[COPY]], [[COPY1]]
3232
; CHECK: [[SMULH:%[0-9]+]]:_(s64) = G_SMULH [[COPY]], [[COPY1]]
3333
; CHECK: [[C:%[0-9]+]]:_(s64) = G_CONSTANT i64 63
34-
; CHECK: [[ASHR:%[0-9]+]]:_(s64) = G_ASHR [[MUL]], [[C]]
34+
; CHECK: [[ASHR:%[0-9]+]]:_(s64) = G_ASHR [[MUL]], [[C]](s64)
3535
; CHECK: [[ICMP:%[0-9]+]]:_(s32) = G_ICMP intpred(ne), [[SMULH]](s64), [[ASHR]]
3636
; CHECK: $x0 = COPY [[MUL]](s64)
3737
; CHECK: [[COPY2:%[0-9]+]]:_(s32) = COPY [[ICMP]](s32)
@@ -66,3 +66,28 @@ body: |
6666
$w0 = COPY %4(s32)
6767
6868
...
69+
---
70+
name: vector_mul_scalarize
71+
liveins:
72+
- { reg: '$q0' }
73+
- { reg: '$q1' }
74+
body: |
75+
bb.1:
76+
liveins: $q0, $q1
77+
78+
; CHECK-LABEL: name: vector_mul_scalarize
79+
; CHECK: [[COPY:%[0-9]+]]:_(<2 x s64>) = COPY $q0
80+
; CHECK: [[COPY1:%[0-9]+]]:_(<2 x s64>) = COPY $q1
81+
; CHECK: [[UV:%[0-9]+]]:_(s64), [[UV1:%[0-9]+]]:_(s64) = G_UNMERGE_VALUES [[COPY]](<2 x s64>)
82+
; CHECK: [[UV2:%[0-9]+]]:_(s64), [[UV3:%[0-9]+]]:_(s64) = G_UNMERGE_VALUES [[COPY1]](<2 x s64>)
83+
; CHECK: [[MUL:%[0-9]+]]:_(s64) = G_MUL [[UV]], [[UV2]]
84+
; CHECK: [[MUL1:%[0-9]+]]:_(s64) = G_MUL [[UV1]], [[UV3]]
85+
; CHECK: [[BUILD_VECTOR:%[0-9]+]]:_(<2 x s64>) = G_BUILD_VECTOR [[MUL]](s64), [[MUL1]](s64)
86+
; CHECK: $q0 = COPY [[BUILD_VECTOR]](<2 x s64>)
87+
; CHECK: RET_ReallyLR implicit $q0
88+
%0:_(<2 x s64>) = COPY $q0
89+
%1:_(<2 x s64>) = COPY $q1
90+
%2:_(<2 x s64>) = G_MUL %0, %1
91+
$q0 = COPY %2(<2 x s64>)
92+
RET_ReallyLR implicit $q0
93+
...

0 commit comments

Comments
 (0)