[PATCH] D64248: GlobalISel: widenScalar for G_BUILD_VECTOR
Matt Arsenault via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Jul 5 07:27:00 PDT 2019
arsenm created this revision.
arsenm added reviewers: aemerson, aditya_nandakumar, paquette, dsanders.
Herald added subscribers: Petar.Avramovic, volkan, rovka, wdng.
https://reviews.llvm.org/D64248
Files:
lib/CodeGen/GlobalISel/LegalizerHelper.cpp
unittests/CodeGen/GlobalISel/LegalizerHelperTest.cpp
Index: unittests/CodeGen/GlobalISel/LegalizerHelperTest.cpp
===================================================================
--- unittests/CodeGen/GlobalISel/LegalizerHelperTest.cpp
+++ unittests/CodeGen/GlobalISel/LegalizerHelperTest.cpp
@@ -853,4 +853,51 @@
EXPECT_TRUE(CheckMachineFunction(*MF, CheckStr)) << *MF;
}
+
+TEST_F(GISelMITest, WidenScalarBuildVector) {
+ if (!TM)
+ return;
+
+ LLT S32 = LLT::scalar(32);
+ LLT S16 = LLT::scalar(16);
+ LLT V2S16 = LLT::vector(2, S16);
+ LLT V2S32 = LLT::vector(2, S32);
+
+ DefineLegalizerInfo(A, {
+ getActionDefinitionsBuilder({G_SMIN, G_SMAX, G_UMIN, G_UMAX})
+ .lowerFor({s64, LLT::vector(2, s32)});
+ });
+
+ AInfo Info(MF->getSubtarget());
+ DummyGISelObserver Observer;
+ LegalizerHelper Helper(*MF, Info, Observer, B);
+ B.setInsertPt(*EntryMBB, EntryMBB->end());
+
+ Register Constant0 = B.buildConstant(S16, 1).getReg(0);
+ Register Constant1 = B.buildConstant(S16, 2).getReg(0);
+ auto BV0 = B.buildBuildVector(V2S16, {Constant0, Constant1});
+ auto BV1 = B.buildBuildVector(V2S16, {Constant0, Constant1});
+
+ EXPECT_EQ(LegalizerHelper::LegalizeResult::Legalized,
+ Helper.widenScalar(*BV0, 0, V2S32));
+ EXPECT_EQ(LegalizerHelper::LegalizeResult::Legalized,
+ Helper.widenScalar(*BV1, 1, S32));
+
+ auto CheckStr = R"(
+ CHECK: [[K0:%[0-9]+]]:_(s16) = G_CONSTANT i16 1
+ CHECK-NEXT: [[K1:%[0-9]+]]:_(s16) = G_CONSTANT i16 2
+ CHECK-NEXT: [[EXT_K0_0:%[0-9]+]]:_(s32) = G_ANYEXT [[K0]]
+ CHECK-NEXT: [[EXT_K1_0:%[0-9]+]]:_(s32) = G_ANYEXT [[K1]]
+ CHECK-NEXT: [[BV0:%[0-9]+]]:_(<2 x s32>) = G_BUILD_VECTOR [[EXT_K0_0]]:_(s32), [[EXT_K1_0]]:_(s32)
+ CHECK-NEXT: [[BV0_TRUNC:%[0-9]+]]:_(<2 x s16>) = G_TRUNC [[BV0]]
+
+ CHECK: [[EXT_K0_1:%[0-9]+]]:_(s32) = G_ANYEXT [[K0]]
+ CHECK-NEXT: [[EXT_K1_1:%[0-9]+]]:_(s32) = G_ANYEXT [[K1]]
+
+ CHECK-NEXT: [[BV1:%[0-9]+]]:_(<2 x s16>) = G_BUILD_VECTOR_TRUNC [[EXT_K0_1]]:_(s32), [[EXT_K1_1]]:_(s32)
+ )";
+
+ EXPECT_TRUE(CheckMachineFunction(*MF, CheckStr)) << *MF;
+}
+
} // namespace
Index: lib/CodeGen/GlobalISel/LegalizerHelper.cpp
===================================================================
--- lib/CodeGen/GlobalISel/LegalizerHelper.cpp
+++ lib/CodeGen/GlobalISel/LegalizerHelper.cpp
@@ -1398,6 +1398,25 @@
widenScalarDst(MI, WideTy, 0);
Observer.changedInstr(MI);
return Legalized;
+ case TargetOpcode::G_BUILD_VECTOR: {
+ Observer.changingInstr(MI);
+
+ const LLT WideEltTy = TypeIdx == 1 ? WideTy : WideTy.getElementType();
+ for (int I = 1, E = MI.getNumOperands(); I != E; ++I)
+ widenScalarSrc(MI, WideEltTy, I, TargetOpcode::G_ANYEXT);
+
+ // Avoid changing the result vector type if the source element type was
+ // requested.
+ if (TypeIdx == 1) {
+ auto &TII = *MI.getMF()->getSubtarget().getInstrInfo();
+ MI.setDesc(TII.get(TargetOpcode::G_BUILD_VECTOR_TRUNC));
+ } else {
+ widenScalarDst(MI, WideTy, 0);
+ }
+
+ Observer.changedInstr(MI);
+ return Legalized;
+ }
}
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D64248.208177.patch
Type: text/x-patch
Size: 3041 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190705/a392dd80/attachment.bin>
More information about the llvm-commits
mailing list