Skip to content

Commit 034972c

Browse files
[LLVM][IR] Use splat syntax when printing ConstantExpr based splats.
1 parent c25c6c3 commit 034972c

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

llvm/lib/IR/AsmWriter.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1741,6 +1741,24 @@ static void WriteConstantInternal(raw_ostream &Out, const Constant *CV,
17411741
}
17421742

17431743
if (const ConstantExpr *CE = dyn_cast<ConstantExpr>(CV)) {
1744+
// Use the same shorthand for splat vector (i.e. "splat(Ty val)") as is
1745+
// permitted on IR input to reduce the output changes when enabling
1746+
// UseConstant{Int,FP}ForScalableSplat.
1747+
// TODO: Remove this block when the UseConstant{Int,FP}ForScalableSplat
1748+
// options are removed.
1749+
if (CE->getOpcode() == Instruction::ShuffleVector) {
1750+
if (auto *SplatVal = CE->getSplatValue()) {
1751+
if (isa<ConstantInt>(SplatVal) || isa<ConstantFP>(SplatVal)) {
1752+
Out << "splat (";
1753+
WriterCtx.TypePrinter->print(SplatVal->getType(), Out);
1754+
Out << ' ';
1755+
WriteAsOperandInternal(Out, SplatVal, WriterCtx);
1756+
Out << ')';
1757+
return;
1758+
}
1759+
}
1760+
}
1761+
17441762
Out << CE->getOpcodeName();
17451763
WriteOptimizationInfo(Out, CE);
17461764
Out << " (";

0 commit comments

Comments
 (0)