Skip to content

Commit

Permalink
[X86] printConstant - add ConstantVector handling
Browse files Browse the repository at this point in the history
  • Loading branch information
RKSimon committed Jan 22, 2024
1 parent e302950 commit 27eb8d5
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
28 changes: 17 additions & 11 deletions llvm/lib/Target/X86/X86MCInstLower.cpp
Expand Up @@ -1536,6 +1536,15 @@ static void printConstant(const Constant *COp, unsigned BitWidth,
else
CS << "?";
}
} else if (auto *CV = dyn_cast<ConstantVector>(COp)) {
unsigned EltBits = CV->getType()->getScalarSizeInBits();
unsigned E = std::min(BitWidth / EltBits, CV->getNumOperands());
assert((BitWidth % EltBits) == 0 && "Element size mismatch");
for (unsigned I = 0; I != E; ++I) {
if (I != 0)
CS << ",";
printConstant(CV->getOperand(I), EltBits, CS, PrintZero);
}
} else {
CS << "?";
}
Expand All @@ -1550,18 +1559,15 @@ static void printZeroUpperMove(const MachineInstr *MI, MCStreamer &OutStreamer,
CS << X86ATTInstPrinter::getRegisterName(DstOp.getReg()) << " = ";

if (auto *C = X86::getConstantFromPool(*MI, 1)) {
if (isa<ConstantInt>(C) || isa<ConstantFP>(C) ||
isa<ConstantDataSequential>(C)) {
CS << "[";
printConstant(C, SclWidth, CS);
for (int I = 1, E = VecWidth / SclWidth; I < E; ++I) {
CS << ",";
printConstant(C, SclWidth, CS, true);
}
CS << "]";
OutStreamer.AddComment(CS.str());
return; // early-out
CS << "[";
printConstant(C, SclWidth, CS);
for (int I = 1, E = VecWidth / SclWidth; I < E; ++I) {
CS << ",";
printConstant(C, SclWidth, CS, true);
}
CS << "]";
OutStreamer.AddComment(CS.str());
return; // early-out
}

// We didn't find a constant load, fallback to a shuffle mask decode.
Expand Down
2 changes: 1 addition & 1 deletion llvm/test/CodeGen/X86/widen_shuffle-1.ll
Expand Up @@ -105,7 +105,7 @@ define void @shuf5(ptr %p) nounwind {
; X86-LABEL: shuf5:
; X86: # %bb.0:
; X86-NEXT: movl {{[0-9]+}}(%esp), %eax
; X86-NEXT: movsd {{.*#+}} xmm0 = mem[0],zero
; X86-NEXT: movsd {{.*#+}} xmm0 = [33,33,33,33,33,33,33,33,0,0,0,0,0,0,0,0]
; X86-NEXT: movsd %xmm0, (%eax)
; X86-NEXT: retl
;
Expand Down

0 comments on commit 27eb8d5

Please sign in to comment.