Skip to content

Commit d34f7ea

Browse files
authored
DAG: Fix assuming f16 is the only 16-bit fp type in concat vector combine (#121637)
This would see if there are mixed integer and FP types and pick an equivalently sized FP type to use as the vector element type, and only cast if there were mixed integers. We need to insert a cast if the types are mixed, which may include different FP types. Fixes #121601
1 parent f3590c1 commit d34f7ea

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
@@ -24308,8 +24308,8 @@ static SDValue combineConcatVectorOfScalars(SDNode *N, SelectionDAG &DAG) {
2430824308
EVT SVT = EVT::getIntegerVT(*DAG.getContext(), OpVT.getSizeInBits());
2430924309

2431024310
// Keep track of what we encounter.
24311-
bool AnyInteger = false;
24312-
bool AnyFP = false;
24311+
EVT AnyFPVT;
24312+
2431324313
for (const SDValue &Op : N->ops()) {
2431424314
if (ISD::BITCAST == Op.getOpcode() &&
2431524315
!Op.getOperand(0).getValueType().isVector())
@@ -24323,27 +24323,23 @@ static SDValue combineConcatVectorOfScalars(SDNode *N, SelectionDAG &DAG) {
2432324323
// If it's neither, bail out, it could be something weird like x86mmx.
2432424324
EVT LastOpVT = Ops.back().getValueType();
2432524325
if (LastOpVT.isFloatingPoint())
24326-
AnyFP = true;
24327-
else if (LastOpVT.isInteger())
24328-
AnyInteger = true;
24329-
else
24326+
AnyFPVT = LastOpVT;
24327+
else if (!LastOpVT.isInteger())
2433024328
return SDValue();
2433124329
}
2433224330

2433324331
// If any of the operands is a floating point scalar bitcast to a vector,
2433424332
// use floating point types throughout, and bitcast everything.
2433524333
// Replace UNDEFs by another scalar UNDEF node, of the final desired type.
24336-
if (AnyFP) {
24337-
SVT = EVT::getFloatingPointVT(OpVT.getSizeInBits());
24338-
if (AnyInteger) {
24339-
for (SDValue &Op : Ops) {
24340-
if (Op.getValueType() == SVT)
24341-
continue;
24342-
if (Op.isUndef())
24343-
Op = DAG.getNode(ISD::UNDEF, DL, SVT);
24344-
else
24345-
Op = DAG.getBitcast(SVT, Op);
24346-
}
24334+
if (AnyFPVT != EVT()) {
24335+
SVT = AnyFPVT;
24336+
for (SDValue &Op : Ops) {
24337+
if (Op.getValueType() == SVT)
24338+
continue;
24339+
if (Op.isUndef())
24340+
Op = DAG.getNode(ISD::UNDEF, DL, SVT);
24341+
else
24342+
Op = DAG.getBitcast(SVT, Op);
2434724343
}
2434824344
}
2434924345

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)