Skip to content

Commit bee588e

Browse files
[LLVM][IR] Use splat syntax when printing ConstantDataVector.
1 parent f314e12 commit bee588e

File tree

830 files changed

+14676
-14003
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

830 files changed

+14676
-14003
lines changed

llvm/lib/IR/AsmWriter.cpp

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,11 @@
8989

9090
using namespace llvm;
9191

92+
namespace llvm {
93+
extern cl::opt<bool> UseConstantIntForFixedLengthSplat;
94+
extern cl::opt<bool> UseConstantFPForFixedLengthSplat;
95+
} // namespace llvm
96+
9297
// Make virtual table appear in this compilation unit.
9398
AssemblyAnnotationWriter::~AssemblyAnnotationWriter() = default;
9499

@@ -1687,6 +1692,46 @@ static void WriteConstantInternal(raw_ostream &Out, const Constant *CV,
16871692
return;
16881693
}
16891694

1695+
// When in the mode where Constant{Int,FP} do not support vector types the
1696+
// "splat(Ty val)" syntax is interpreted as a ConstantDataVector. Maintaining
1697+
// this association when outputiing the IR will significantly reduce the
1698+
// output changes when in the mode where Constant{Int,FP} do support vector
1699+
// types. In turn this should make it easier to spot difference in output
1700+
// when switching between the modes. Once the transition is complete this
1701+
// code will be removed.
1702+
if (const ConstantDataVector *CDV = dyn_cast<ConstantDataVector>(CV)) {
1703+
if (auto *SplatVal = CDV->getSplatValue()) {
1704+
Type* EltTy = SplatVal->getType();
1705+
1706+
if (EltTy->isIntegerTy() && !UseConstantIntForFixedLengthSplat) {
1707+
if (const ConstantInt *CI = dyn_cast<ConstantInt>(SplatVal)) {
1708+
Out << "splat (";
1709+
WriterCtx.TypePrinter->print(EltTy, Out);
1710+
Out << " ";
1711+
1712+
if (EltTy->isIntegerTy(1))
1713+
Out << (CI->getZExtValue() ? "true" : "false");
1714+
else
1715+
Out << CI->getValue();
1716+
1717+
Out << ")";
1718+
return;
1719+
}
1720+
}
1721+
1722+
if (EltTy->isFloatingPointTy() && !UseConstantFPForFixedLengthSplat) {
1723+
if (const ConstantFP *CFP = dyn_cast<ConstantFP>(SplatVal)) {
1724+
Out << "splat (";
1725+
WriterCtx.TypePrinter->print(EltTy, Out);
1726+
Out << " ";
1727+
WriteAPFloatInternal(Out, CFP->getValueAPF());
1728+
Out << ")";
1729+
return;
1730+
}
1731+
}
1732+
}
1733+
}
1734+
16901735
if (isa<ConstantVector>(CV) || isa<ConstantDataVector>(CV)) {
16911736
auto *CVVTy = cast<FixedVectorType>(CV->getType());
16921737
Type *ETy = CVVTy->getElementType();

llvm/lib/IR/Constants.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,14 @@ using namespace llvm;
3636
using namespace PatternMatch;
3737

3838
// As set of temporary options to help migrate how splats are represented.
39-
static cl::opt<bool> UseConstantIntForFixedLengthSplat(
39+
namespace llvm {
40+
cl::opt<bool> UseConstantIntForFixedLengthSplat(
4041
"use-constant-int-for-fixed-length-splat", cl::init(false), cl::Hidden,
4142
cl::desc("Use ConstantInt's native fixed-length vector splat support."));
42-
static cl::opt<bool> UseConstantFPForFixedLengthSplat(
43+
cl::opt<bool> UseConstantFPForFixedLengthSplat(
4344
"use-constant-fp-for-fixed-length-splat", cl::init(false), cl::Hidden,
4445
cl::desc("Use ConstantFP's native fixed-length vector splat support."));
46+
}
4547
static cl::opt<bool> UseConstantIntForScalableSplat(
4648
"use-constant-int-for-scalable-splat", cl::init(false), cl::Hidden,
4749
cl::desc("Use ConstantInt's native scalable vector splat support."));

llvm/test/Analysis/CostModel/AArch64/arith-fp.ll

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -70,15 +70,15 @@ define i32 @fsub(i32 %arg) {
7070
define i32 @fneg_idiom(i32 %arg) {
7171
; CHECK-LABEL: 'fneg_idiom'
7272
; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %F16 = fsub half 0xH8000, undef
73-
; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %V4F16 = fsub <4 x half> <half 0xH8000, half 0xH8000, half 0xH8000, half 0xH8000>, undef
74-
; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %V8F16 = fsub <8 x half> <half 0xH8000, half 0xH8000, half 0xH8000, half 0xH8000, half 0xH8000, half 0xH8000, half 0xH8000, half 0xH8000>, undef
73+
; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %V4F16 = fsub <4 x half> splat (half 0xH8000), undef
74+
; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %V8F16 = fsub <8 x half> splat (half 0xH8000), undef
7575
; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %F32 = fsub float -0.000000e+00, undef
76-
; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %V2F32 = fsub <2 x float> <float -0.000000e+00, float -0.000000e+00>, undef
77-
; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %V4F32 = fsub <4 x float> <float -0.000000e+00, float -0.000000e+00, float -0.000000e+00, float -0.000000e+00>, undef
78-
; CHECK-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %V8F32 = fsub <8 x float> <float -0.000000e+00, float -0.000000e+00, float -0.000000e+00, float -0.000000e+00, float -0.000000e+00, float -0.000000e+00, float -0.000000e+00, float -0.000000e+00>, undef
76+
; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %V2F32 = fsub <2 x float> splat (float -0.000000e+00), undef
77+
; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %V4F32 = fsub <4 x float> splat (float -0.000000e+00), undef
78+
; CHECK-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %V8F32 = fsub <8 x float> splat (float -0.000000e+00), undef
7979
; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %F64 = fsub double -0.000000e+00, undef
80-
; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %V2F64 = fsub <2 x double> <double -0.000000e+00, double -0.000000e+00>, undef
81-
; CHECK-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %V4F64 = fsub <4 x double> <double -0.000000e+00, double -0.000000e+00, double -0.000000e+00, double -0.000000e+00>, undef
80+
; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %V2F64 = fsub <2 x double> splat (double -0.000000e+00), undef
81+
; CHECK-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %V4F64 = fsub <4 x double> splat (double -0.000000e+00), undef
8282
; CHECK-NEXT: Cost Model: Found an estimated cost of 0 for instruction: ret i32 undef
8383
;
8484
%F16 = fsub half -0.0, undef

llvm/test/Analysis/CostModel/AArch64/arith-widening.ll

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2091,11 +2091,11 @@ define void @extmulv16(<16 x i8> %i8, <16 x i16> %i16, <16 x i32> %i32, <16 x i6
20912091
define void @extmul_const(<8 x i8> %i8, <8 x i16> %i16, <8 x i32> %i32, <8 x i64> %i64) {
20922092
; CHECK-LABEL: 'extmul_const'
20932093
; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %sl1_8_16 = sext <8 x i8> %i8 to <8 x i16>
2094-
; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %asl_8_16 = mul <8 x i16> %sl1_8_16, <i16 10, i16 10, i16 10, i16 10, i16 10, i16 10, i16 10, i16 10>
2094+
; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %asl_8_16 = mul <8 x i16> %sl1_8_16, splat (i16 10)
20952095
; CHECK-NEXT: Cost Model: Found an estimated cost of 0 for instruction: %zl1_8_16 = zext <8 x i8> %i8 to <8 x i16>
2096-
; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %azl_8_16 = mul <8 x i16> %zl1_8_16, <i16 10, i16 10, i16 10, i16 10, i16 10, i16 10, i16 10, i16 10>
2096+
; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %azl_8_16 = mul <8 x i16> %zl1_8_16, splat (i16 10)
20972097
; CHECK-NEXT: Cost Model: Found an estimated cost of 0 for instruction: %zl1_8_16b = zext <8 x i8> %i8 to <8 x i16>
2098-
; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %and = and <8 x i16> %sl1_8_16, <i16 255, i16 255, i16 255, i16 255, i16 255, i16 255, i16 255, i16 255>
2098+
; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %and = and <8 x i16> %sl1_8_16, splat (i16 255)
20992099
; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %aal_8_16 = mul <8 x i16> %zl1_8_16b, %and
21002100
; CHECK-NEXT: Cost Model: Found an estimated cost of 0 for instruction: ret void
21012101
;

0 commit comments

Comments
 (0)