Skip to content

Commit 5e85860

Browse files
[LLVM][IR] Use splat syntax when printing Constant[Data]Vector.
1 parent 9a1a8f3 commit 5e85860

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

0 commit comments

Comments
 (0)