Skip to content

Commit 0a8dc9e

Browse files
author
Volkan Keles
committedNov 1, 2018
[GlobalISel] Fix a bug in LegalizeRuleSet::clampMaxNumElements
Summary: This function was causing a crash when `MaxElements == 1` because it was trying to create a single element vector type. Reviewers: dsanders, aemerson, aditya_nandakumar Reviewed By: dsanders Subscribers: rovka, kristof.beyls, javed.absar, llvm-commits Differential Revision: https://reviews.llvm.org/D53734 llvm-svn: 345875
1 parent 2c0febe commit 0a8dc9e

File tree

4 files changed

+45
-23
lines changed

4 files changed

+45
-23
lines changed
 

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

+2
Original file line numberDiff line numberDiff line change
@@ -693,6 +693,8 @@ class LegalizeRuleSet {
693693
},
694694
[=](const LegalityQuery &Query) {
695695
LLT VecTy = Query.Types[TypeIdx];
696+
if (MaxElements == 1)
697+
return std::make_pair(TypeIdx, VecTy.getElementType());
696698
return std::make_pair(
697699
TypeIdx, LLT::vector(MaxElements, VecTy.getScalarSizeInBits()));
698700
});

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

+4-2
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,8 @@ AArch64LegalizerInfo::AArch64LegalizerInfo(const AArch64Subtarget &ST) {
169169
.lowerIf([=](const LegalityQuery &Query) {
170170
return Query.Types[0].getSizeInBits() != Query.MMODescrs[0].SizeInBits;
171171
})
172-
.clampNumElements(0, v2s32, v2s32);
172+
.clampNumElements(0, v2s32, v2s32)
173+
.clampMaxNumElements(0, s64, 1);
173174

174175
getActionDefinitionsBuilder(G_STORE)
175176
.legalForTypesWithMemSize({{s8, p0, 8},
@@ -187,7 +188,8 @@ AArch64LegalizerInfo::AArch64LegalizerInfo(const AArch64Subtarget &ST) {
187188
return Query.Types[0].isScalar() &&
188189
Query.Types[0].getSizeInBits() != Query.MMODescrs[0].SizeInBits;
189190
})
190-
.clampNumElements(0, v2s32, v2s32);
191+
.clampNumElements(0, v2s32, v2s32)
192+
.clampMaxNumElements(0, s64, 1);
191193

192194
// Constants
193195
getActionDefinitionsBuilder(G_CONSTANT)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# RUN: llc -march=aarch64 -o - -run-pass=legalizer -global-isel-abort=0 -debug-only=legalizer 2>&1 %s | FileCheck %s
2+
# REQUIRES: asserts
3+
4+
# CHECK: Legalize Machine IR for: load_v4s32
5+
# CHECK-NEXT: %{{[0-9]+}}:_(<4 x s32>) = G_LOAD %{{[0-9]+}}:_(p0)
6+
# CHECK-NEXT: Reduce number of elements
7+
---
8+
name: load_v4s32
9+
legalized: false
10+
tracksRegLiveness: true
11+
body: |
12+
bb.1:
13+
liveins: $x0
14+
15+
%0:_(p0) = COPY $x0
16+
%1:_(<4 x s32>) = G_LOAD %0(p0) :: (load 16, align 4)
17+
%2:_(s32), %3:_(s32), %4:_(s32), %5:_(s32) = G_UNMERGE_VALUES %1(<4 x s32>)
18+
$w0 = COPY %5(s32)
19+
20+
...
21+
22+
# Make sure we are able to scalarize v2s64.
23+
# CHECK: Legalize Machine IR for: load_v2s64
24+
# CHECK-NEXT: %{{[0-9]+}}:_(<2 x s64>) = G_LOAD %{{[0-9]+}}:_(p0)
25+
# CHECK-NEXT: Reduce number of elements
26+
---
27+
name: load_v2s64
28+
legalized: false
29+
tracksRegLiveness: true
30+
body: |
31+
bb.1:
32+
liveins: $x0
33+
34+
%0:_(p0) = COPY $x0
35+
%1:_(<2 x s64>) = G_LOAD %0(p0) :: (load 16)
36+
%2:_(s64), %3:_(s64) = G_UNMERGE_VALUES %1(<2 x s64>)
37+
$x0 = COPY %3(s64)
38+
39+
...

‎llvm/test/CodeGen/AArch64/GlobalISel/legalize-load-v4s32.mir

-21
This file was deleted.

0 commit comments

Comments
 (0)
Please sign in to comment.