[PATCH] D134758: [RISCV][SelectionDAGBuilder] Fix crash when copying a v1f32 vector between basic blocks.
Craig Topper via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Sep 27 12:53:04 PDT 2022
craig.topper created this revision.
craig.topper added reviewers: asb, RKSimon, efriedma, reames, frasercrmck.
Herald added subscribers: sunshaoce, VincentWu, StephenFan, vkmr, evandro, luismarques, apazos, sameer.abuasal, s.egerton, Jim, benna, psnobl, jocewei, PkmX, the_o, brucehoult, MartinMosbeck, rogfer01, edward-jones, zzheng, jrtc27, shiva0217, kito-cheng, niosHD, sabuasal, simoncook, johnrusso, rbar, hiraditya, arichardson.
Herald added a project: All.
craig.topper requested review of this revision.
Herald added subscribers: pcwang-thead, eopXD, MaskRay.
Herald added a project: LLVM.
On a rv64 without f32 or vector support, this will be passed across
the basic block as an i64. We need use i32 as an intermediate type
with bitcast and anyext/trunc.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D134758
Files:
llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
llvm/test/CodeGen/RISCV/pr58025.ll
Index: llvm/test/CodeGen/RISCV/pr58025.ll
===================================================================
--- /dev/null
+++ llvm/test/CodeGen/RISCV/pr58025.ll
@@ -0,0 +1,21 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
+; RUN: llc < %s -mtriple=riscv64 | FileCheck %s
+
+define void @f() {
+; CHECK-LABEL: f:
+; CHECK: # %bb.0: # %BB
+; CHECK-NEXT: lui a0, 260096
+; CHECK-NEXT: addi sp, sp, -16
+; CHECK-NEXT: .cfi_def_cfa_offset 16
+; CHECK-NEXT: sw a0, 12(sp)
+; CHECK-NEXT: addi sp, sp, 16
+; CHECK-NEXT: ret
+BB:
+ %B = fdiv <1 x float> <float 0.5>, <float 0.5>
+ %PTR = alloca <1 x float>
+ br label %BB1
+
+BB1: ; preds = %BB
+ store <1 x float> %B, <1 x float>* %PTR
+ ret void
+}
Index: llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
===================================================================
--- llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
+++ llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
@@ -448,12 +448,18 @@
// Handle cases such as i8 -> <1 x i1>
EVT ValueSVT = ValueVT.getVectorElementType();
if (ValueVT.getVectorNumElements() == 1 && ValueSVT != PartEVT) {
- if (ValueSVT.getSizeInBits() == PartEVT.getSizeInBits())
+ unsigned ValueSize = ValueSVT.getSizeInBits();
+ if (ValueSize == PartEVT.getSizeInBits()) {
Val = DAG.getNode(ISD::BITCAST, DL, ValueSVT, Val);
- else
+ } else if (ValueSVT.isFloatingPoint() && PartEVT.isInteger()) {
+ EVT IntermediateType = EVT::getIntegerVT(*DAG.getContext(), ValueSize);
+ Val = DAG.getNode(ISD::TRUNCATE, DL, IntermediateType, Val);
+ Val = DAG.getBitcast(ValueSVT, Val);
+ } else {
Val = ValueVT.isFloatingPoint()
? DAG.getFPExtendOrRound(Val, DL, ValueSVT)
: DAG.getAnyExtOrTrunc(Val, DL, ValueSVT);
+ }
}
return DAG.getBuildVector(ValueVT, DL, Val);
@@ -679,7 +685,9 @@
SDValue Widened = widenVectorToPartType(DAG, Val, DL, WidenVT);
Val = DAG.getAnyExtOrTrunc(Widened, DL, PartVT);
} else {
- if (ValueVT.getVectorElementCount().isScalar()) {
+ // Don't extract an integer from a float vector.
+ if (ValueVT.getVectorElementCount().isScalar() &&
+ (!ValueVT.isFloatingPoint() || !PartVT.isInteger())) {
Val = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, DL, PartVT, Val,
DAG.getVectorIdxConstant(0, DL));
} else {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D134758.463316.patch
Type: text/x-patch
Size: 2502 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220927/30a846e7/attachment.bin>
More information about the llvm-commits
mailing list