Skip to content

Commit 3a385f7

Browse files
committed
DAG: Fix assuming f16 is the only 16-bit fp type in concat vector combine
Fixes #121601
1 parent 11e482c commit 3a385f7

File tree

2 files changed

+32
-17
lines changed

2 files changed

+32
-17
lines changed

llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -24291,8 +24291,8 @@ static SDValue combineConcatVectorOfScalars(SDNode *N, SelectionDAG &DAG) {
2429124291
EVT SVT = EVT::getIntegerVT(*DAG.getContext(), OpVT.getSizeInBits());
2429224292

2429324293
// Keep track of what we encounter.
24294-
bool AnyInteger = false;
24295-
bool AnyFP = false;
24294+
EVT AnyFPVT;
24295+
2429624296
for (const SDValue &Op : N->ops()) {
2429724297
if (ISD::BITCAST == Op.getOpcode() &&
2429824298
!Op.getOperand(0).getValueType().isVector())
@@ -24306,27 +24306,23 @@ static SDValue combineConcatVectorOfScalars(SDNode *N, SelectionDAG &DAG) {
2430624306
// If it's neither, bail out, it could be something weird like x86mmx.
2430724307
EVT LastOpVT = Ops.back().getValueType();
2430824308
if (LastOpVT.isFloatingPoint())
24309-
AnyFP = true;
24310-
else if (LastOpVT.isInteger())
24311-
AnyInteger = true;
24312-
else
24309+
AnyFPVT = LastOpVT;
24310+
else if (!LastOpVT.isInteger())
2431324311
return SDValue();
2431424312
}
2431524313

2431624314
// If any of the operands is a floating point scalar bitcast to a vector,
2431724315
// use floating point types throughout, and bitcast everything.
2431824316
// Replace UNDEFs by another scalar UNDEF node, of the final desired type.
24319-
if (AnyFP) {
24320-
SVT = EVT::getFloatingPointVT(OpVT.getSizeInBits());
24321-
if (AnyInteger) {
24322-
for (SDValue &Op : Ops) {
24323-
if (Op.getValueType() == SVT)
24324-
continue;
24325-
if (Op.isUndef())
24326-
Op = DAG.getNode(ISD::UNDEF, DL, SVT);
24327-
else
24328-
Op = DAG.getBitcast(SVT, Op);
24329-
}
24317+
if (AnyFPVT != EVT()) {
24318+
SVT = AnyFPVT;
24319+
for (SDValue &Op : Ops) {
24320+
if (Op.getValueType() == SVT)
24321+
continue;
24322+
if (Op.isUndef())
24323+
Op = DAG.getNode(ISD::UNDEF, DL, SVT);
24324+
else
24325+
Op = DAG.getBitcast(SVT, Op);
2433024326
}
2433124327
}
2433224328

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 5
2+
; RUN: llc -mtriple=amdgcn-amd-amdhsa -mcpu=gfx942 < %s | FileCheck %s
3+
4+
define <4 x float> @issue121601(bfloat %fptrunc) {
5+
; CHECK-LABEL: issue121601:
6+
; CHECK: ; %bb.0: ; %bb
7+
; CHECK-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
8+
; CHECK-NEXT: v_lshlrev_b32_e32 v0, 16, v0
9+
; CHECK-NEXT: v_mov_b32_e32 v1, v0
10+
; CHECK-NEXT: v_mov_b32_e32 v2, 0
11+
; CHECK-NEXT: v_mov_b32_e32 v3, 0
12+
; CHECK-NEXT: s_setpc_b64 s[30:31]
13+
bb:
14+
%bitcast = bitcast bfloat %fptrunc to <1 x bfloat>
15+
%shufflevector = shufflevector <1 x bfloat> %bitcast, <1 x bfloat> zeroinitializer, <2 x i32> zeroinitializer
16+
%fpext = fpext <2 x bfloat> %shufflevector to <2 x float>
17+
%shufflevector1 = shufflevector <2 x float> %fpext, <2 x float> zeroinitializer, <4 x i32> <i32 0, i32 1, i32 2, i32 3>
18+
ret <4 x float> %shufflevector1
19+
}

0 commit comments

Comments
 (0)