Skip to content

Commit 3185839

Browse files
author
Krzysztof Parzyszek
committed
[Hexagon] Avoid crash on CONCAT_VECTORS with illegal element types
Legal vector element types may not be legal as scalar types. When CONCAT_VECTORS is converted to BUILD_VECTOR, the individual vector elements become standalone operands to the build operation. If they have illegal (scalar) types, they need to be made legal. In doing so, the case of TRUNCATE was not handled, causing an assertion to fail.
1 parent 1ca6bd2 commit 3185839

File tree

2 files changed

+39
-6
lines changed

2 files changed

+39
-6
lines changed

llvm/lib/Target/Hexagon/HexagonISelLoweringHVX.cpp

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1248,12 +1248,19 @@ HexagonTargetLowering::LowerHvxConcatVectors(SDValue Op, SelectionDAG &DAG)
12481248
continue;
12491249
}
12501250
// A few less complicated cases.
1251-
if (V.getOpcode() == ISD::Constant)
1252-
Elems[i] = DAG.getSExtOrTrunc(V, dl, NTy);
1253-
else if (V.isUndef())
1254-
Elems[i] = DAG.getUNDEF(NTy);
1255-
else
1256-
llvm_unreachable("Unexpected vector element");
1251+
switch (V.getOpcode()) {
1252+
case ISD::Constant:
1253+
Elems[i] = DAG.getSExtOrTrunc(V, dl, NTy);
1254+
break;
1255+
case ISD::UNDEF:
1256+
Elems[i] = DAG.getUNDEF(NTy);
1257+
break;
1258+
case ISD::TRUNCATE:
1259+
Elems[i] = V.getOperand(0);
1260+
break;
1261+
default:
1262+
llvm_unreachable("Unexpected vector element");
1263+
}
12571264
}
12581265
}
12591266
return DAG.getBuildVector(VecTy, dl, Elems);
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
; RUN: llc -march=hexagon -hexagon-hvx-widen=32 < %s | FileCheck %s
2+
3+
; Check that this doesn't crash.
4+
; CHECK: memw
5+
6+
target datalayout = "e-m:e-p:32:32:32-a:0-n16:32-i64:64:64-i32:32:32-i16:16:16-i1:8:8-f32:32:32-f64:64:64-v32:32:32-v64:64:64-v512:512:512-v1024:1024:1024-v2048:2048:2048"
7+
target triple = "hexagon"
8+
9+
define dllexport void @f0(i8* %a0) #0 {
10+
b0:
11+
%v0 = bitcast i8* %a0 to i32*
12+
%v1 = getelementptr inbounds i32, i32* %v0, i32 undef
13+
%v2 = bitcast i32* %v1 to <7 x i32>*
14+
%v3 = load i8, i8* undef, align 1
15+
%v4 = insertelement <7 x i8> undef, i8 %v3, i32 0
16+
%v5 = shufflevector <7 x i8> %v4, <7 x i8> undef, <7 x i32> zeroinitializer
17+
%v6 = zext <7 x i8> %v5 to <7 x i32>
18+
%v7 = load <7 x i8>, <7 x i8>* undef, align 1
19+
%v8 = zext <7 x i8> %v7 to <7 x i32>
20+
%v9 = mul nsw <7 x i32> %v6, %v8
21+
%v10 = add nsw <7 x i32> %v9, zeroinitializer
22+
store <7 x i32> %v10, <7 x i32>* %v2, align 4
23+
ret void
24+
}
25+
26+
attributes #0 = { "target-features"="+hvx,+hvx-length128b" }

0 commit comments

Comments
 (0)