Skip to content

Commit 00cef85

Browse files
committed
[GlobalIsel][AArch64] more legal icmps
In llvm#78181 the godbolt (https://llvm.godbolt.org/z/vMsnxMf1v) crashed with GlobalIsel. LLVM ERROR: unable to legalize instruction: %90:_(<3 x s32>) = G_ICMP intpred(uge), %15:_(<3 x s32>), %0:_ (in function: vec3_i32)
1 parent ef7ed19 commit 00cef85

File tree

3 files changed

+61
-8
lines changed

3 files changed

+61
-8
lines changed

llvm/lib/CodeGen/GlobalISel/LegalizerHelper.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5314,6 +5314,14 @@ LegalizerHelper::moreElementsVector(MachineInstr &MI, unsigned TypeIdx,
53145314
Observer.changedInstr(MI);
53155315
return Legalized;
53165316
}
5317+
case TargetOpcode::G_ICMP: {
5318+
Observer.changingInstr(MI);
5319+
moreElementsVectorSrc(MI, MoreTy, 2);
5320+
moreElementsVectorSrc(MI, MoreTy, 3);
5321+
moreElementsVectorDst(MI, MoreTy, 0);
5322+
Observer.changedInstr(MI);
5323+
return Legalized;
5324+
}
53175325
default:
53185326
return UnableToLegalize;
53195327
}

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -524,7 +524,11 @@ AArch64LegalizerInfo::AArch64LegalizerInfo(const AArch64Subtarget &ST)
524524
.minScalarOrEltIf(
525525
[=](const LegalityQuery &Query) { return Query.Types[1] == v2p0; }, 0,
526526
s64)
527-
.clampNumElements(0, v2s32, v4s32);
527+
.moreElementsToNextPow2(0)
528+
.clampMaxNumElements(0, s64, 2)
529+
.clampMaxNumElements(0, s32, 4)
530+
.clampMaxNumElements(0, s16, 8)
531+
.clampMaxNumElements(0, s8, 16);
528532

529533
getActionDefinitionsBuilder(G_FCMP)
530534
// If we don't have full FP16 support, then scalarize the elements of
@@ -863,6 +867,7 @@ AArch64LegalizerInfo::AArch64LegalizerInfo(const AArch64Subtarget &ST)
863867
},
864868
0, s8)
865869
.minScalarOrElt(0, s8) // Worst case, we need at least s8.
870+
.moreElementsToNextPow2(1)
866871
.clampMaxNumElements(1, s64, 2)
867872
.clampMaxNumElements(1, s32, 4)
868873
.clampMaxNumElements(1, s16, 8)

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

Lines changed: 47 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,9 @@ body: |
5656
; CHECK-NEXT: {{ $}}
5757
; CHECK-NEXT: bb.1:
5858
; CHECK-NEXT: successors:
59-
; CHECK: bb.2:
59+
; CHECK-NEXT: {{ $}}
60+
; CHECK-NEXT: {{ $}}
61+
; CHECK-NEXT: bb.2:
6062
; CHECK-NEXT: RET_ReallyLR
6163
bb.1:
6264
%0:_(s128) = G_IMPLICIT_DEF
@@ -93,7 +95,9 @@ body: |
9395
; CHECK-NEXT: {{ $}}
9496
; CHECK-NEXT: bb.1:
9597
; CHECK-NEXT: successors:
96-
; CHECK: bb.2:
98+
; CHECK-NEXT: {{ $}}
99+
; CHECK-NEXT: {{ $}}
100+
; CHECK-NEXT: bb.2:
97101
; CHECK-NEXT: RET_ReallyLR
98102
bb.1:
99103
%lhs:_(s128) = G_IMPLICIT_DEF
@@ -132,7 +136,9 @@ body: |
132136
; CHECK-NEXT: {{ $}}
133137
; CHECK-NEXT: bb.1:
134138
; CHECK-NEXT: successors:
135-
; CHECK: bb.2:
139+
; CHECK-NEXT: {{ $}}
140+
; CHECK-NEXT: {{ $}}
141+
; CHECK-NEXT: bb.2:
136142
; CHECK-NEXT: RET_ReallyLR
137143
bb.1:
138144
%lhs:_(s88) = G_IMPLICIT_DEF
@@ -171,7 +177,9 @@ body: |
171177
; CHECK-NEXT: {{ $}}
172178
; CHECK-NEXT: bb.1:
173179
; CHECK-NEXT: successors:
174-
; CHECK: bb.2:
180+
; CHECK-NEXT: {{ $}}
181+
; CHECK-NEXT: {{ $}}
182+
; CHECK-NEXT: bb.2:
175183
; CHECK-NEXT: RET_ReallyLR
176184
bb.1:
177185
%lhs:_(s88) = G_IMPLICIT_DEF
@@ -210,7 +218,9 @@ body: |
210218
; CHECK-NEXT: {{ $}}
211219
; CHECK-NEXT: bb.1:
212220
; CHECK-NEXT: successors:
213-
; CHECK: bb.2:
221+
; CHECK-NEXT: {{ $}}
222+
; CHECK-NEXT: {{ $}}
223+
; CHECK-NEXT: bb.2:
214224
; CHECK-NEXT: RET_ReallyLR
215225
bb.1:
216226
%lhs:_(s96) = G_IMPLICIT_DEF
@@ -272,7 +282,9 @@ body: |
272282
; CHECK-NEXT: {{ $}}
273283
; CHECK-NEXT: bb.1:
274284
; CHECK-NEXT: successors:
275-
; CHECK: bb.2:
285+
; CHECK-NEXT: {{ $}}
286+
; CHECK-NEXT: {{ $}}
287+
; CHECK-NEXT: bb.2:
276288
; CHECK-NEXT: RET_ReallyLR
277289
bb.1:
278290
%lhs:_(s318) = G_IMPLICIT_DEF
@@ -318,7 +330,9 @@ body: |
318330
; CHECK-NEXT: {{ $}}
319331
; CHECK-NEXT: bb.1:
320332
; CHECK-NEXT: successors:
321-
; CHECK: bb.2:
333+
; CHECK-NEXT: {{ $}}
334+
; CHECK-NEXT: {{ $}}
335+
; CHECK-NEXT: bb.2:
322336
; CHECK-NEXT: RET_ReallyLR
323337
bb.1:
324338
%lhs:_(s158) = G_IMPLICIT_DEF
@@ -330,3 +344,29 @@ body: |
330344
successors:
331345
bb.3:
332346
RET_ReallyLR
347+
...
348+
---
349+
name: test_3xs32_eq_pr_78181
350+
tracksRegLiveness: true
351+
body: |
352+
bb.1:
353+
liveins: $x0
354+
; CHECK-LABEL: name: test_3xs32_eq_pr_78181
355+
; CHECK: liveins: $x0
356+
; CHECK-NEXT: {{ $}}
357+
; CHECK-NEXT: %const:_(s32) = G_IMPLICIT_DEF
358+
; CHECK-NEXT: [[BUILD_VECTOR:%[0-9]+]]:_(<4 x s32>) = G_BUILD_VECTOR %const(s32), %const(s32), %const(s32), %const(s32)
359+
; CHECK-NEXT: [[BUILD_VECTOR1:%[0-9]+]]:_(<4 x s32>) = G_BUILD_VECTOR %const(s32), %const(s32), %const(s32), %const(s32)
360+
; CHECK-NEXT: [[ICMP:%[0-9]+]]:_(<4 x s32>) = G_ICMP intpred(eq), [[BUILD_VECTOR]](<4 x s32>), [[BUILD_VECTOR1]]
361+
; CHECK-NEXT: [[C:%[0-9]+]]:_(s64) = G_CONSTANT i64 1
362+
; CHECK-NEXT: [[EVEC:%[0-9]+]]:_(s32) = G_EXTRACT_VECTOR_ELT [[ICMP]](<4 x s32>), [[C]](s64)
363+
; CHECK-NEXT: $w0 = COPY [[EVEC]](s32)
364+
; CHECK-NEXT: RET_ReallyLR
365+
%const:_(s32) = G_IMPLICIT_DEF
366+
%rhs:_(<3 x s32>) = G_BUILD_VECTOR %const(s32), %const(s32), %const(s32)
367+
%lhs:_(<3 x s32>) = G_BUILD_VECTOR %const(s32), %const(s32), %const(s32)
368+
%cmp:_(<3 x s32>) = G_ICMP intpred(eq), %lhs(<3 x s32>), %rhs
369+
%1:_(s32) = G_CONSTANT i32 1
370+
%2:_(s32) = G_EXTRACT_VECTOR_ELT %cmp(<3 x s32>), %1(s32)
371+
$w0 = COPY %2(s32)
372+
RET_ReallyLR

0 commit comments

Comments
 (0)