Skip to content

Commit a1fdcfa

Browse files
committed
[AArch64] Protect against scalar types in isNVCastToHalfWidthElements.
Fixes #129227
1 parent 9869f84 commit a1fdcfa

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

llvm/lib/Target/AArch64/AArch64ISelLowering.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23079,8 +23079,9 @@ static SDValue isNVCastToHalfWidthElements(SDValue V) {
2307923079
return SDValue();
2308023080

2308123081
SDValue Op = V.getOperand(0);
23082-
if (V.getValueType().getVectorElementCount() !=
23083-
Op.getValueType().getVectorElementCount() * 2)
23082+
if (!Op.getValueType().isVector() ||
23083+
V.getValueType().getVectorElementCount() !=
23084+
Op.getValueType().getVectorElementCount() * 2)
2308423085
return SDValue();
2308523086

2308623087
return Op;

llvm/test/CodeGen/AArch64/hadd-combine.ll

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1020,6 +1020,19 @@ define <2 x i32> @srhadd_signbits_v2i32_negative(<2 x i32> %a0, <2 x i32> %a1, p
10201020
ret <2 x i32> %avg2
10211021
}
10221022

1023+
define <8 x i8> @dontcrashonnvcasts() {
1024+
; CHECK-LABEL: dontcrashonnvcasts:
1025+
; CHECK: // %bb.0:
1026+
; CHECK-NEXT: movi v0.2s, #128, lsl #24
1027+
; CHECK-NEXT: movi v1.2d, #0000000000000000
1028+
; CHECK-NEXT: fneg d0, d0
1029+
; CHECK-NEXT: uzp1 v0.8b, v0.8b, v1.8b
1030+
; CHECK-NEXT: ret
1031+
%vrhadd_v.i = tail call <8 x i8> @llvm.aarch64.neon.urhadd.v8i8(<8 x i8> <i8 0, i8 0, i8 0, i8 -1, i8 0, i8 0, i8 0, i8 0>, <8 x i8> zeroinitializer)
1032+
%shuffle.i = shufflevector <8 x i8> %vrhadd_v.i, <8 x i8> <i8 0, i8 poison, i8 0, i8 poison, i8 0, i8 poison, i8 0, i8 poison>, <8 x i32> <i32 0, i32 2, i32 4, i32 6, i32 8, i32 10, i32 12, i32 14>
1033+
ret <8 x i8> %shuffle.i
1034+
}
1035+
10231036
declare <8 x i8> @llvm.aarch64.neon.shadd.v8i8(<8 x i8>, <8 x i8>)
10241037
declare <4 x i16> @llvm.aarch64.neon.shadd.v4i16(<4 x i16>, <4 x i16>)
10251038
declare <2 x i32> @llvm.aarch64.neon.shadd.v2i32(<2 x i32>, <2 x i32>)

0 commit comments

Comments
 (0)