Skip to content

Commit 13c9a8a

Browse files
[LLVM][IR] Use splat syntax when printing Constant[Data]Vector.
1 parent 5bb3480 commit 13c9a8a

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

llvm/lib/IR/AsmWriter.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1690,6 +1690,23 @@ static void WriteConstantInternal(raw_ostream &Out, const Constant *CV,
16901690
if (isa<ConstantVector>(CV) || isa<ConstantDataVector>(CV)) {
16911691
auto *CVVTy = cast<FixedVectorType>(CV->getType());
16921692
Type *ETy = CVVTy->getElementType();
1693+
1694+
// Use the same shorthand for splat vector (i.e. "splat(Ty val)") as is
1695+
// permitted on IR input to reduce the output changes when enabling
1696+
// UseConstant{Int,FP}ForFixedLengthSplat.
1697+
// TODO: Remove this block when the UseConstant{Int,FP}ForFixedLengthSplat
1698+
// options are removed.
1699+
if (auto *SplatVal = CV->getSplatValue()) {
1700+
if (isa<ConstantInt>(SplatVal) || isa<ConstantFP>(SplatVal)) {
1701+
Out << "splat (";
1702+
WriterCtx.TypePrinter->print(ETy, Out);
1703+
Out << " ";
1704+
WriteAsOperandInternal(Out, SplatVal, WriterCtx);
1705+
Out << ")";
1706+
return;
1707+
}
1708+
}
1709+
16931710
Out << '<';
16941711
WriterCtx.TypePrinter->print(ETy, Out);
16951712
Out << ' ';

0 commit comments

Comments
 (0)