Skip to content

Commit c552c6c

Browse files
committed
[AArch64][GlobalISel] Protect against non-reg operands in matchExtAddvToUdotAddv.
In some situations the first operand to an instruction might not be a register (for example with intrinsics). We are only interested in extend operations, so make sure the instruction is one we expect before we attempt to access the first reg.
1 parent 1c4ee06 commit c552c6c

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,10 +267,12 @@ bool matchExtAddvToUdotAddv(MachineInstr &MI, MachineRegisterInfo &MRI,
267267
SrcTy = MRI.getType(ExtMI1->getOperand(1).getReg());
268268
std::get<0>(MatchInfo) = ExtMI1->getOperand(1).getReg();
269269
std::get<1>(MatchInfo) = ExtMI2->getOperand(1).getReg();
270-
} else {
270+
} else if (I1Opc == TargetOpcode::G_ZEXT || I1Opc == TargetOpcode::G_SEXT) {
271271
SrcTy = MRI.getType(I1->getOperand(1).getReg());
272272
std::get<0>(MatchInfo) = I1->getOperand(1).getReg();
273273
std::get<1>(MatchInfo) = 0;
274+
} else {
275+
return false;
274276
}
275277

276278
if (I1Opc == TargetOpcode::G_ZEXT)
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py
2+
# RUN: llc -run-pass=aarch64-prelegalizer-combiner -mtriple aarch64-unknown-unknown -mattr=+dotprod %s -o - | FileCheck %s
3+
4+
---
5+
name: vecreduce_intrinsic
6+
body: |
7+
bb.0:
8+
liveins: $q0, $q1, $q2, $q3, $q4
9+
; CHECK-LABEL: name: vecreduce_intrinsic
10+
; CHECK: liveins: $q0, $q1, $q2, $q3, $q4
11+
; CHECK-NEXT: {{ $}}
12+
; CHECK-NEXT: [[COPY:%[0-9]+]]:_(<4 x s32>) = COPY $q0
13+
; CHECK-NEXT: [[COPY1:%[0-9]+]]:_(<4 x s32>) = COPY $q1
14+
; CHECK-NEXT: [[COPY2:%[0-9]+]]:_(<4 x s32>) = COPY $q2
15+
; CHECK-NEXT: [[COPY3:%[0-9]+]]:_(<4 x s32>) = COPY $q3
16+
; CHECK-NEXT: [[COPY4:%[0-9]+]]:_(<4 x s32>) = COPY $q4
17+
; CHECK-NEXT: [[CONCAT_VECTORS:%[0-9]+]]:_(<16 x s32>) = G_CONCAT_VECTORS [[COPY1]](<4 x s32>), [[COPY2]](<4 x s32>), [[COPY3]](<4 x s32>), [[COPY4]](<4 x s32>)
18+
; CHECK-NEXT: [[INT:%[0-9]+]]:_(<4 x s32>) = G_INTRINSIC intrinsic(@llvm.experimental.vector.partial.reduce.add), [[COPY]](<4 x s32>), [[CONCAT_VECTORS]](<16 x s32>)
19+
; CHECK-NEXT: [[VECREDUCE_ADD:%[0-9]+]]:_(s32) = G_VECREDUCE_ADD [[INT]](<4 x s32>)
20+
; CHECK-NEXT: $w0 = COPY [[VECREDUCE_ADD]](s32)
21+
; CHECK-NEXT: RET_ReallyLR implicit $w0
22+
%0:_(<4 x s32>) = COPY $q0
23+
%2:_(<4 x s32>) = COPY $q1
24+
%3:_(<4 x s32>) = COPY $q2
25+
%4:_(<4 x s32>) = COPY $q3
26+
%5:_(<4 x s32>) = COPY $q4
27+
%1:_(<16 x s32>) = G_CONCAT_VECTORS %2:_(<4 x s32>), %3:_(<4 x s32>), %4:_(<4 x s32>), %5:_(<4 x s32>)
28+
%6:_(<4 x s32>) = G_INTRINSIC intrinsic(@llvm.experimental.vector.partial.reduce.add), %0:_(<4 x s32>), %1:_(<16 x s32>)
29+
%7:_(s32) = G_VECREDUCE_ADD %6:_(<4 x s32>)
30+
$w0 = COPY %7:_(s32)
31+
RET_ReallyLR implicit $w0
32+
33+
...

0 commit comments

Comments
 (0)