[PATCH] D37184: [X86] Add constant pool decoding to more instructions
Sanjay Patel via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Mar 20 07:52:42 PDT 2018
spatel added a comment.
This is a good improvement, but can we make the splats even less of an eye chart (let me know if you see any problems with this):
Index: lib/Target/X86/X86MCInstLower.cpp
===================================================================
--- lib/Target/X86/X86MCInstLower.cpp (revision 327978)
+++ lib/Target/X86/X86MCInstLower.cpp (working copy)
@@ -1447,6 +1447,81 @@
}
}
+static void printConstantPoolOp(MCStreamer &OutStreamer,
+ const MachineInstr *MI,
+ StringRef Op, unsigned EltSize,
+ bool EOL) {
+ if (!OutStreamer.isVerboseAsm())
+ return;
+
+ const MCInstrDesc &Desc = MI->getDesc();
+ int MemOperand = X86II::getOperandBias(Desc) +
+ X86II::getMemoryOperandNo(Desc.TSFlags);
+ const MachineOperand &MemOp = MI->getOperand(MemOperand + 3);
+
+ auto *C = getConstantFromPool(*MI, MemOp);
+ if (!C)
+ return;
+
+ SmallVector<uint64_t, 16> Vec;
+ APInt UndefElts;
+ if (!extractConstantMask(C, EltSize, UndefElts, Vec))
+ return;
+
+ const MachineOperand &DstOp = MI->getOperand(0);
+ const MachineOperand &SrcOp = MI->getOperand(Desc.getNumDefs());
+
+ std::string Comment;
+ raw_string_ostream CS(Comment);
+
+ CS << X86ATTInstPrinter::getRegisterName(DstOp.getReg());
+ CS << " = ";
+ CS << X86ATTInstPrinter::getRegisterName(SrcOp.getReg());
+ CS << Op << "[";
+
+ // Try to print the minimal splat constant. The vector constant returned by
+ // extractConstantMask may have wider elements than the element type of the
+ // actual mask constant.
+ Type *CTy = C->getType();
+ unsigned VecNumElts = Vec.size();
+ if (CTy->isVectorTy() && CTy->getVectorNumElements() > VecNumElts) {
+ if (auto *SplatC = dyn_cast_or_null<ConstantInt>(C->getSplatValue())) {
+ uint64_t SplatVal = SplatC->getZExtValue();
+ CS << format_hex(SplatVal, CTy->getScalarSizeInBits() / 4 + 2);
+ CS << " splat]";
+ OutStreamer.AddComment(CS.str(), EOL);
+ return;
+ }
+ }
+
+ // Print the mask
+ bool IsSplat = true;
+ for (unsigned i = 1; i < VecNumElts; ++i) {
+ if (Vec[0] != Vec[i]) {
+ IsSplat = false;
+ break;
+ }
+ }
+
+ for (unsigned i = 0; i < VecNumElts; ++i) {
+ if (i != 0)
+ CS << ",";
+ if (UndefElts[i])
+ CS << 'u';
+ else
+ CS << format_hex(Vec[i], EltSize / 4 + 2);
+
+ if (IsSplat) {
+ CS << " splat";
+ break;
+ }
+ }
+
+ CS << "]";
+
+ OutStreamer.AddComment(CS.str(), EOL);
+}
+
void X86AsmPrinter::EmitInstruction(const MachineInstr *MI) {
X86MCInstLower MCInstLowering(*MF, *this);
const X86RegisterInfo *RI = MF->getSubtarget<X86Subtarget>().getRegisterInfo();
Repository:
rL LLVM
https://reviews.llvm.org/D37184
More information about the llvm-commits
mailing list