Skip to content

Commit 37c96f1

Browse files
arsenmbcahoon
authored andcommitted
DAG: Fix assuming f16 is the only 16-bit fp type in concat vector combine (llvm#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 llvm#121601 (cherry picked from commit d34f7ea)
1 parent a79a105 commit 37c96f1

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

2382023820
// Keep track of what we encounter.
23821-
bool AnyInteger = false;
23822-
bool AnyFP = false;
23821+
EVT AnyFPVT;
23822+
2382323823
for (const SDValue &Op : N->ops()) {
2382423824
if (ISD::BITCAST == Op.getOpcode() &&
2382523825
!Op.getOperand(0).getValueType().isVector())
@@ -23833,27 +23833,23 @@ static SDValue combineConcatVectorOfScalars(SDNode *N, SelectionDAG &DAG) {
2383323833
// If it's neither, bail out, it could be something weird like x86mmx.
2383423834
EVT LastOpVT = Ops.back().getValueType();
2383523835
if (LastOpVT.isFloatingPoint())
23836-
AnyFP = true;
23837-
else if (LastOpVT.isInteger())
23838-
AnyInteger = true;
23839-
else
23836+
AnyFPVT = LastOpVT;
23837+
else if (!LastOpVT.isInteger())
2384023838
return SDValue();
2384123839
}
2384223840

2384323841
// If any of the operands is a floating point scalar bitcast to a vector,
2384423842
// use floating point types throughout, and bitcast everything.
2384523843
// Replace UNDEFs by another scalar UNDEF node, of the final desired type.
23846-
if (AnyFP) {
23847-
SVT = EVT::getFloatingPointVT(OpVT.getSizeInBits());
23848-
if (AnyInteger) {
23849-
for (SDValue &Op : Ops) {
23850-
if (Op.getValueType() == SVT)
23851-
continue;
23852-
if (Op.isUndef())
23853-
Op = DAG.getNode(ISD::UNDEF, DL, SVT);
23854-
else
23855-
Op = DAG.getBitcast(SVT, Op);
23856-
}
23844+
if (AnyFPVT != EVT()) {
23845+
SVT = AnyFPVT;
23846+
for (SDValue &Op : Ops) {
23847+
if (Op.getValueType() == SVT)
23848+
continue;
23849+
if (Op.isUndef())
23850+
Op = DAG.getNode(ISD::UNDEF, DL, SVT);
23851+
else
23852+
Op = DAG.getBitcast(SVT, Op);
2385723853
}
2385823854
}
2385923855

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)