[llvm] 1a5eead - [X86] Add printZeroUpperMove constant/shuffle comments helper. NFC.
Simon Pilgrim via llvm-commits
llvm-commits at lists.llvm.org
Mon Jan 22 03:45:10 PST 2024
Author: Simon Pilgrim
Date: 2024-01-22T11:44:51Z
New Revision: 1a5eeade161beddf9c8b2fabad56af3081cd3629
URL: https://github.com/llvm/llvm-project/commit/1a5eeade161beddf9c8b2fabad56af3081cd3629
DIFF: https://github.com/llvm/llvm-project/commit/1a5eeade161beddf9c8b2fabad56af3081cd3629.diff
LOG: [X86] Add printZeroUpperMove constant/shuffle comments helper. NFC.
Pull out helper instead of repeating switch cases.
Added:
Modified:
llvm/lib/Target/X86/X86MCInstLower.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Target/X86/X86MCInstLower.cpp b/llvm/lib/Target/X86/X86MCInstLower.cpp
index 6e8e5123369973..53a81fde12c821 100644
--- a/llvm/lib/Target/X86/X86MCInstLower.cpp
+++ b/llvm/lib/Target/X86/X86MCInstLower.cpp
@@ -1536,6 +1536,52 @@ static void printConstant(const Constant *COp, unsigned BitWidth,
}
}
+static void printZeroUpperMove(const MachineInstr *MI, MCStreamer &OutStreamer,
+ int SclWidth, int VecWidth,
+ const char *ShuffleComment) {
+ assert(MI->getNumOperands() >= (1 + X86::AddrNumOperands) &&
+ "Unexpected number of operands!");
+
+ std::string Comment;
+ raw_string_ostream CS(Comment);
+ const MachineOperand &DstOp = MI->getOperand(0);
+ CS << X86ATTInstPrinter::getRegisterName(DstOp.getReg()) << " = ";
+
+ if (auto *C =
+ X86::getConstantFromPool(*MI, MI->getOperand(1 + X86::AddrDisp))) {
+ int CstEltSize = C->getType()->getScalarSizeInBits();
+ if (SclWidth == CstEltSize) {
+ if (auto *CI = dyn_cast<ConstantInt>(C)) {
+ CS << "[";
+ printConstant(CI->getValue(), CS);
+ for (int I = 1, E = VecWidth / SclWidth; I < E; ++I) {
+ CS << ",0";
+ }
+ CS << "]";
+ OutStreamer.AddComment(CS.str());
+ return; // early-out
+ }
+
+ if (auto *CF = dyn_cast<ConstantFP>(C)) {
+ CS << "[";
+ printConstant(CF->getValue(), CS);
+ APFloat ZeroFP = APFloat::getZero(CF->getValue().getSemantics());
+ for (int I = 1, E = VecWidth / SclWidth; I < E; ++I) {
+ CS << ",";
+ printConstant(ZeroFP, CS);
+ }
+ CS << "]";
+ OutStreamer.AddComment(CS.str());
+ return; // early-out
+ }
+ }
+ }
+
+ // We didn't find a constant load, fallback to a shuffle mask decode.
+ CS << ShuffleComment;
+ OutStreamer.AddComment(CS.str());
+}
+
void X86AsmPrinter::EmitSEHInstruction(const MachineInstr *MI) {
assert(MF->hasWinCFI() && "SEH_ instruction in function without WinCFI?");
assert((getSubtarget().isOSWindows() || TM.getTargetTriple().isUEFI()) &&
@@ -1807,94 +1853,28 @@ static void addConstantComments(const MachineInstr *MI,
}
case X86::MOVSDrm:
- case X86::MOVSSrm:
case X86::VMOVSDrm:
- case X86::VMOVSSrm:
case X86::VMOVSDZrm:
- case X86::VMOVSSZrm:
case X86::MOVSDrm_alt:
- case X86::MOVSSrm_alt:
case X86::VMOVSDrm_alt:
- case X86::VMOVSSrm_alt:
case X86::VMOVSDZrm_alt:
- case X86::VMOVSSZrm_alt:
- case X86::MOVDI2PDIrm:
case X86::MOVQI2PQIrm:
- case X86::VMOVDI2PDIrm:
case X86::VMOVQI2PQIrm:
- case X86::VMOVDI2PDIZrm:
- case X86::VMOVQI2PQIZrm: {
- assert(MI->getNumOperands() >= (1 + X86::AddrNumOperands) &&
- "Unexpected number of operands!");
- int SclWidth = 32;
- int VecWidth = 128;
-
- switch (MI->getOpcode()) {
- default:
- llvm_unreachable("Invalid opcode");
- case X86::MOVSDrm:
- case X86::VMOVSDrm:
- case X86::VMOVSDZrm:
- case X86::MOVSDrm_alt:
- case X86::VMOVSDrm_alt:
- case X86::VMOVSDZrm_alt:
- case X86::MOVQI2PQIrm:
- case X86::VMOVQI2PQIrm:
- case X86::VMOVQI2PQIZrm:
- SclWidth = 64;
- VecWidth = 128;
+ case X86::VMOVQI2PQIZrm:
+ printZeroUpperMove(MI, OutStreamer, 64, 128, "mem[0],zero");
break;
- case X86::MOVSSrm:
- case X86::VMOVSSrm:
- case X86::VMOVSSZrm:
- case X86::MOVSSrm_alt:
- case X86::VMOVSSrm_alt:
- case X86::VMOVSSZrm_alt:
- case X86::MOVDI2PDIrm:
- case X86::VMOVDI2PDIrm:
- case X86::VMOVDI2PDIZrm:
- SclWidth = 32;
- VecWidth = 128;
- break;
- }
- std::string Comment;
- raw_string_ostream CS(Comment);
- const MachineOperand &DstOp = MI->getOperand(0);
- CS << X86ATTInstPrinter::getRegisterName(DstOp.getReg()) << " = ";
- if (auto *C =
- X86::getConstantFromPool(*MI, MI->getOperand(1 + X86::AddrDisp))) {
- if ((unsigned)SclWidth == C->getType()->getScalarSizeInBits()) {
- if (auto *CI = dyn_cast<ConstantInt>(C)) {
- CS << "[";
- printConstant(CI->getValue(), CS);
- for (int I = 1, E = VecWidth / SclWidth; I < E; ++I) {
- CS << ",0";
- }
- CS << "]";
- OutStreamer.AddComment(CS.str());
- break; // early-out
- }
- if (auto *CF = dyn_cast<ConstantFP>(C)) {
- CS << "[";
- printConstant(CF->getValue(), CS);
- APFloat ZeroFP = APFloat::getZero(CF->getValue().getSemantics());
- for (int I = 1, E = VecWidth / SclWidth; I < E; ++I) {
- CS << ",";
- printConstant(ZeroFP, CS);
- }
- CS << "]";
- OutStreamer.AddComment(CS.str());
- break; // early-out
- }
- }
- }
-
- // We didn't find a constant load, fallback to a shuffle mask decode.
- CS << (SclWidth == 32 ? "mem[0],zero,zero,zero" : "mem[0],zero");
- OutStreamer.AddComment(CS.str());
+ case X86::MOVSSrm:
+ case X86::VMOVSSrm:
+ case X86::VMOVSSZrm:
+ case X86::MOVSSrm_alt:
+ case X86::VMOVSSrm_alt:
+ case X86::VMOVSSZrm_alt:
+ case X86::MOVDI2PDIrm:
+ case X86::VMOVDI2PDIrm:
+ case X86::VMOVDI2PDIZrm:
+ printZeroUpperMove(MI, OutStreamer, 32, 128, "mem[0],zero,zero,zero");
break;
- }
#define MOV_CASE(Prefix, Suffix) \
case X86::Prefix##MOVAPD##Suffix##rm: \
More information about the llvm-commits
mailing list