[PATCH] D75743: [GlobalISel] fix crash in narrowScalarExtract if DstRegs only has one register
Dominik Montada via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Mar 6 07:41:49 PST 2020
gargaroff created this revision.
Herald added subscribers: llvm-commits, volkan, hiraditya, rovka.
Herald added a project: LLVM.
gargaroff edited the summary of this revision.
gargaroff added reviewers: arsenm, dsanders.
Herald added a subscriber: wdng.
When narrowing a scalar G_EXTRACT where the destination lines up perfectly with a single result of the emitted G_UNMERGE_VALUES a COPY should be emitted instead of unconditionally trying to emit a G_MERGE_VALUES.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D75743
Files:
llvm/lib/CodeGen/GlobalISel/LegalizerHelper.cpp
llvm/unittests/CodeGen/GlobalISel/LegalizerHelperTest.cpp
Index: llvm/unittests/CodeGen/GlobalISel/LegalizerHelperTest.cpp
===================================================================
--- llvm/unittests/CodeGen/GlobalISel/LegalizerHelperTest.cpp
+++ llvm/unittests/CodeGen/GlobalISel/LegalizerHelperTest.cpp
@@ -2302,4 +2302,43 @@
// Check
EXPECT_TRUE(CheckMachineFunction(*MF, CheckStr)) << *MF;
}
+
+TEST_F(GISelMITest, NarrowScalarExtract) {
+ setUp();
+ if (!TM)
+ return;
+
+ // Declare your legalization info
+ DefineLegalizerInfo(A, {
+ getActionDefinitionsBuilder(G_UNMERGE_VALUES).legalFor({{s32, s64}});
+ getActionDefinitionsBuilder(G_EXTRACT).legalFor({{s16, s32}});
+ });
+
+ LLT S16{LLT::scalar(16)};
+ LLT S32{LLT::scalar(32)};
+
+ auto MIBExtractS32 = B.buildExtract(S32, Copies[1], 32);
+ auto MIBExtractS16 = B.buildExtract(S16, Copies[1], 0);
+
+ AInfo Info(MF->getSubtarget());
+ DummyGISelObserver Observer;
+ LegalizerHelper Helper(*MF, Info, Observer, B);
+
+ EXPECT_EQ(LegalizerHelper::LegalizeResult::Legalized,
+ Helper.narrowScalar(*MIBExtractS32, 1, S32));
+
+ EXPECT_EQ(LegalizerHelper::LegalizeResult::Legalized,
+ Helper.narrowScalar(*MIBExtractS16, 1, S32));
+
+ const auto *CheckStr = R"(
+ CHECK: [[UV:%[0-9]+]]:_(s32), [[UV1:%[0-9]+]]:_(s32) = G_UNMERGE_VALUES
+ CHECK: [[COPY:%[0-9]+]]:_(s32) = COPY [[UV1]]
+ CHECK: [[UV3:%[0-9]+]]:_(s32), [[UV4:%[0-9]+]]:_(s32) = G_UNMERGE_VALUES
+ CHECK: [[EXTR:%[0-9]+]]:_(s16) = G_EXTRACT [[UV3]]:_(s32), 0
+ CHECK: [[COPY:%[0-9]+]]:_(s16) = COPY [[EXTR]]
+ )";
+
+ // Check
+ EXPECT_TRUE(CheckMachineFunction(*MF, CheckStr)) << *MF;
+}
} // namespace
Index: llvm/lib/CodeGen/GlobalISel/LegalizerHelper.cpp
===================================================================
--- llvm/lib/CodeGen/GlobalISel/LegalizerHelper.cpp
+++ llvm/lib/CodeGen/GlobalISel/LegalizerHelper.cpp
@@ -3686,10 +3686,12 @@
}
Register DstReg = MI.getOperand(0).getReg();
- if(MRI.getType(DstReg).isVector())
+ if (MRI.getType(DstReg).isVector())
MIRBuilder.buildBuildVector(DstReg, DstRegs);
- else
+ else if (DstRegs.size() > 1)
MIRBuilder.buildMerge(DstReg, DstRegs);
+ else
+ MIRBuilder.buildCopy(DstReg, DstRegs[0]);
MI.eraseFromParent();
return Legalized;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D75743.248724.patch
Type: text/x-patch
Size: 2261 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200306/7df7dd77/attachment.bin>
More information about the llvm-commits
mailing list