[PATCH] D56835: GlobalISel: Make buildConstant handle vectors
Matt Arsenault via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Jan 17 02:17:52 PST 2019
arsenm created this revision.
arsenm added reviewers: aditya_nandakumar, aemerson.
Herald added subscribers: kristof.beyls, rovka, wdng.
Produce a splat build_vector similar to how
SelectionDAG::getConstant does.
https://reviews.llvm.org/D56835
Files:
include/llvm/Support/LowLevelTypeImpl.h
lib/CodeGen/GlobalISel/MachineIRBuilder.cpp
Index: lib/CodeGen/GlobalISel/MachineIRBuilder.cpp
===================================================================
--- lib/CodeGen/GlobalISel/MachineIRBuilder.cpp
+++ lib/CodeGen/GlobalISel/MachineIRBuilder.cpp
@@ -244,11 +244,28 @@
MachineInstrBuilder MachineIRBuilder::buildConstant(const DstOp &Res,
const ConstantInt &Val) {
LLT Ty = Res.getLLTTy(*getMRI());
+ LLT EltTy = Ty.getScalarType();
const ConstantInt *NewVal = &Val;
- if (Ty.getScalarSizeInBits() != Val.getBitWidth())
- NewVal = ConstantInt::get(getMF().getFunction().getContext(),
- Val.getValue().sextOrTrunc(Ty.getSizeInBits()));
+ if (EltTy.getSizeInBits() != Val.getBitWidth()) {
+ NewVal = ConstantInt::get(
+ getMF().getFunction().getContext(),
+ Val.getValue().sextOrTrunc(EltTy.getSizeInBits()));
+ }
+
+ if (Ty.isVector()) {
+ unsigned EltReg = getMRI()->createGenericVirtualRegister(EltTy);
+ buildInstr(TargetOpcode::G_CONSTANT)
+ .addDef(EltReg)
+ .addCImm(NewVal);
+
+ auto MIB = buildInstr(TargetOpcode::G_BUILD_VECTOR);
+ Res.addDefToMIB(*getMRI(), MIB);
+
+ for (unsigned I = 0, E = Ty.getNumElements(); I != E; ++I)
+ MIB.addUse(EltReg);
+ return MIB;
+ }
auto MIB = buildInstr(TargetOpcode::G_CONSTANT);
Res.addDefToMIB(*getMRI(), MIB);
@@ -266,7 +283,24 @@
MachineInstrBuilder MachineIRBuilder::buildFConstant(const DstOp &Res,
const ConstantFP &Val) {
- assert(!Res.getLLTTy(*getMRI()).isPointer() && "invalid operand type");
+ LLT Ty = Res.getLLTTy(*getMRI());
+
+ assert(!Ty.isPointer() && "invalid operand type");
+
+ if (Ty.isVector()) {
+ unsigned EltReg
+ = getMRI()->createGenericVirtualRegister(Ty.getElementType());
+ buildInstr(TargetOpcode::G_FCONSTANT)
+ .addDef(EltReg)
+ .addFPImm(&Val);
+
+ auto MIB = buildInstr(TargetOpcode::G_BUILD_VECTOR);
+ Res.addDefToMIB(*getMRI(), MIB);
+
+ for (unsigned I = 0, E = Ty.getNumElements(); I != E; ++I)
+ MIB.addUse(EltReg);
+ return MIB;
+ }
auto MIB = buildInstr(TargetOpcode::G_FCONSTANT);
Res.addDefToMIB(*getMRI(), MIB);
Index: include/llvm/Support/LowLevelTypeImpl.h
===================================================================
--- include/llvm/Support/LowLevelTypeImpl.h
+++ include/llvm/Support/LowLevelTypeImpl.h
@@ -104,6 +104,10 @@
return getScalarSizeInBits() * getNumElements();
}
+ LLT getScalarType() const {
+ return isVector() ? getElementType() : *this;
+ }
+
unsigned getScalarSizeInBits() const {
assert(RawData != 0 && "Invalid Type");
if (!IsVector) {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D56835.182232.patch
Type: text/x-patch
Size: 2716 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190117/0b5a1d51/attachment.bin>
More information about the llvm-commits
mailing list