Skip to content

Commit 6b6f272

Browse files
authored
[DAGCombiner] Require same type of splat & element for build_vector (#88284)
Only allow to change build_vector to concat_vector when the splat type and vector element type is same. It's to fix assertion of failing to bitcast types of different sizes.
1 parent 27ce513 commit 6b6f272

File tree

2 files changed

+31
-3
lines changed

2 files changed

+31
-3
lines changed

llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23428,7 +23428,10 @@ SDValue DAGCombiner::visitBUILD_VECTOR(SDNode *N) {
2342823428
// If X is a build_vector itself, the concat can become a larger build_vector.
2342923429
// TODO: Maybe this is useful for non-splat too?
2343023430
if (!LegalOperations) {
23431-
if (SDValue Splat = cast<BuildVectorSDNode>(N)->getSplatValue()) {
23431+
SDValue Splat = cast<BuildVectorSDNode>(N)->getSplatValue();
23432+
// Only change build_vector to a concat_vector if the splat value type is
23433+
// same as the vector element type.
23434+
if (Splat && Splat.getValueType() == VT.getVectorElementType()) {
2343223435
Splat = peekThroughBitcasts(Splat);
2343323436
EVT SrcVT = Splat.getValueType();
2343423437
if (SrcVT.isVector()) {
@@ -23437,8 +23440,8 @@ SDValue DAGCombiner::visitBUILD_VECTOR(SDNode *N) {
2343723440
SrcVT.getVectorElementType(), NumElts);
2343823441
if (!LegalTypes || TLI.isTypeLegal(NewVT)) {
2343923442
SmallVector<SDValue, 8> Ops(N->getNumOperands(), Splat);
23440-
SDValue Concat = DAG.getNode(ISD::CONCAT_VECTORS, SDLoc(N),
23441-
NewVT, Ops);
23443+
SDValue Concat =
23444+
DAG.getNode(ISD::CONCAT_VECTORS, SDLoc(N), NewVT, Ops);
2344223445
return DAG.getBitcast(VT, Concat);
2344323446
}
2344423447
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 4
2+
; RUN: llc < %s -mtriple=x86_64 -mattr=avx512bw | FileCheck %s
3+
4+
; Verify that the DAGCombiner doesn't change build_vector to concat_vectors if
5+
; the vector element type is different than splat type. The example here:
6+
; v8i1 = build_vector (i8 (bitcast (v8i1 X))), ..., (i8 (bitcast (v8i1 X))))
7+
8+
define <8 x i1> @foo(<8 x i1> %mask.i1) {
9+
; CHECK-LABEL: foo:
10+
; CHECK: # %bb.0: # %entry
11+
; CHECK-NEXT: vxorps %xmm0, %xmm0, %xmm0
12+
; CHECK-NEXT: retq
13+
entry:
14+
%0 = and <8 x i1> %mask.i1, <i1 true, i1 false, i1 false, i1 false, i1 false, i1 false, i1 false, i1 false>
15+
%1 = bitcast <8 x i1> %0 to i8
16+
%2 = icmp ne i8 %1, 0
17+
%insert54 = insertelement <8 x i1> zeroinitializer, i1 %2, i64 0
18+
%splat55 = shufflevector <8 x i1> %insert54, <8 x i1> zeroinitializer, <8 x i32> zeroinitializer
19+
%3 = and <8 x i1> %0, %splat55
20+
br label %end
21+
22+
end: ; preds = %entry
23+
%4 = select <8 x i1> %3, <8 x i1> zeroinitializer, <8 x i1> zeroinitializer
24+
ret <8 x i1> %4
25+
}

0 commit comments

Comments
 (0)