Skip to content

Commit 56c091e

Browse files
[LLVM][IR] Use splat syntax when printing ConstantExpr based splats. (#116856)
This brings the printing of scalable vector constant splats inline with their fixed length counterparts.
1 parent bdd10d9 commit 56c091e

File tree

145 files changed

+1290
-1271
lines changed

Some content is hidden

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

145 files changed

+1290
-1271
lines changed

clang/test/CodeGen/AArch64/sve-vector-bitwise-ops.c

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -260,80 +260,80 @@ svuint64_t xor_u64(svuint64_t a, svuint64_t b) {
260260

261261
// CHECK-LABEL: @neg_bool(
262262
// CHECK-NEXT: entry:
263-
// CHECK-NEXT: [[NEG:%.*]] = xor <vscale x 16 x i1> [[A:%.*]], shufflevector (<vscale x 16 x i1> insertelement (<vscale x 16 x i1> poison, i1 true, i64 0), <vscale x 16 x i1> poison, <vscale x 16 x i32> zeroinitializer)
264-
// CHECK-NEXT: ret <vscale x 16 x i1> [[NEG]]
263+
// CHECK-NEXT: [[NOT:%.*]] = xor <vscale x 16 x i1> [[A:%.*]], splat (i1 true)
264+
// CHECK-NEXT: ret <vscale x 16 x i1> [[NOT]]
265265
//
266266
svbool_t neg_bool(svbool_t a) {
267267
return ~a;
268268
}
269269

270270
// CHECK-LABEL: @neg_i8(
271271
// CHECK-NEXT: entry:
272-
// CHECK-NEXT: [[NEG:%.*]] = xor <vscale x 16 x i8> [[A:%.*]], shufflevector (<vscale x 16 x i8> insertelement (<vscale x 16 x i8> poison, i8 -1, i64 0), <vscale x 16 x i8> poison, <vscale x 16 x i32> zeroinitializer)
273-
// CHECK-NEXT: ret <vscale x 16 x i8> [[NEG]]
272+
// CHECK-NEXT: [[NOT:%.*]] = xor <vscale x 16 x i8> [[A:%.*]], splat (i8 -1)
273+
// CHECK-NEXT: ret <vscale x 16 x i8> [[NOT]]
274274
//
275275
svint8_t neg_i8(svint8_t a) {
276276
return ~a;
277277
}
278278

279279
// CHECK-LABEL: @neg_i16(
280280
// CHECK-NEXT: entry:
281-
// CHECK-NEXT: [[NEG:%.*]] = xor <vscale x 8 x i16> [[A:%.*]], shufflevector (<vscale x 8 x i16> insertelement (<vscale x 8 x i16> poison, i16 -1, i64 0), <vscale x 8 x i16> poison, <vscale x 8 x i32> zeroinitializer)
282-
// CHECK-NEXT: ret <vscale x 8 x i16> [[NEG]]
281+
// CHECK-NEXT: [[NOT:%.*]] = xor <vscale x 8 x i16> [[A:%.*]], splat (i16 -1)
282+
// CHECK-NEXT: ret <vscale x 8 x i16> [[NOT]]
283283
//
284284
svint16_t neg_i16(svint16_t a) {
285285
return ~a;
286286
}
287287

288288
// CHECK-LABEL: @neg_i32(
289289
// CHECK-NEXT: entry:
290-
// CHECK-NEXT: [[NEG:%.*]] = xor <vscale x 4 x i32> [[A:%.*]], shufflevector (<vscale x 4 x i32> insertelement (<vscale x 4 x i32> poison, i32 -1, i64 0), <vscale x 4 x i32> poison, <vscale x 4 x i32> zeroinitializer)
291-
// CHECK-NEXT: ret <vscale x 4 x i32> [[NEG]]
290+
// CHECK-NEXT: [[NOT:%.*]] = xor <vscale x 4 x i32> [[A:%.*]], splat (i32 -1)
291+
// CHECK-NEXT: ret <vscale x 4 x i32> [[NOT]]
292292
//
293293
svint32_t neg_i32(svint32_t a) {
294294
return ~a;
295295
}
296296

297297
// CHECK-LABEL: @neg_i64(
298298
// CHECK-NEXT: entry:
299-
// CHECK-NEXT: [[NEG:%.*]] = xor <vscale x 2 x i64> [[A:%.*]], shufflevector (<vscale x 2 x i64> insertelement (<vscale x 2 x i64> poison, i64 -1, i64 0), <vscale x 2 x i64> poison, <vscale x 2 x i32> zeroinitializer)
300-
// CHECK-NEXT: ret <vscale x 2 x i64> [[NEG]]
299+
// CHECK-NEXT: [[NOT:%.*]] = xor <vscale x 2 x i64> [[A:%.*]], splat (i64 -1)
300+
// CHECK-NEXT: ret <vscale x 2 x i64> [[NOT]]
301301
//
302302
svint64_t neg_i64(svint64_t a) {
303303
return ~a;
304304
}
305305

306306
// CHECK-LABEL: @neg_u8(
307307
// CHECK-NEXT: entry:
308-
// CHECK-NEXT: [[NEG:%.*]] = xor <vscale x 16 x i8> [[A:%.*]], shufflevector (<vscale x 16 x i8> insertelement (<vscale x 16 x i8> poison, i8 -1, i64 0), <vscale x 16 x i8> poison, <vscale x 16 x i32> zeroinitializer)
309-
// CHECK-NEXT: ret <vscale x 16 x i8> [[NEG]]
308+
// CHECK-NEXT: [[NOT:%.*]] = xor <vscale x 16 x i8> [[A:%.*]], splat (i8 -1)
309+
// CHECK-NEXT: ret <vscale x 16 x i8> [[NOT]]
310310
//
311311
svuint8_t neg_u8(svuint8_t a) {
312312
return ~a;
313313
}
314314

315315
// CHECK-LABEL: @neg_u16(
316316
// CHECK-NEXT: entry:
317-
// CHECK-NEXT: [[NEG:%.*]] = xor <vscale x 8 x i16> [[A:%.*]], shufflevector (<vscale x 8 x i16> insertelement (<vscale x 8 x i16> poison, i16 -1, i64 0), <vscale x 8 x i16> poison, <vscale x 8 x i32> zeroinitializer)
318-
// CHECK-NEXT: ret <vscale x 8 x i16> [[NEG]]
317+
// CHECK-NEXT: [[NOT:%.*]] = xor <vscale x 8 x i16> [[A:%.*]], splat (i16 -1)
318+
// CHECK-NEXT: ret <vscale x 8 x i16> [[NOT]]
319319
//
320320
svuint16_t neg_u16(svuint16_t a) {
321321
return ~a;
322322
}
323323

324324
// CHECK-LABEL: @neg_u32(
325325
// CHECK-NEXT: entry:
326-
// CHECK-NEXT: [[NEG:%.*]] = xor <vscale x 4 x i32> [[A:%.*]], shufflevector (<vscale x 4 x i32> insertelement (<vscale x 4 x i32> poison, i32 -1, i64 0), <vscale x 4 x i32> poison, <vscale x 4 x i32> zeroinitializer)
327-
// CHECK-NEXT: ret <vscale x 4 x i32> [[NEG]]
326+
// CHECK-NEXT: [[NOT:%.*]] = xor <vscale x 4 x i32> [[A:%.*]], splat (i32 -1)
327+
// CHECK-NEXT: ret <vscale x 4 x i32> [[NOT]]
328328
//
329329
svuint32_t neg_u32(svuint32_t a) {
330330
return ~a;
331331
}
332332

333333
// CHECK-LABEL: @neg_u64(
334334
// CHECK-NEXT: entry:
335-
// CHECK-NEXT: [[NEG:%.*]] = xor <vscale x 2 x i64> [[A:%.*]], shufflevector (<vscale x 2 x i64> insertelement (<vscale x 2 x i64> poison, i64 -1, i64 0), <vscale x 2 x i64> poison, <vscale x 2 x i32> zeroinitializer)
336-
// CHECK-NEXT: ret <vscale x 2 x i64> [[NEG]]
335+
// CHECK-NEXT: [[NOT:%.*]] = xor <vscale x 2 x i64> [[A:%.*]], splat (i64 -1)
336+
// CHECK-NEXT: ret <vscale x 2 x i64> [[NOT]]
337337
//
338338
svuint64_t neg_u64(svuint64_t a) {
339339
return ~a;

clang/test/CodeGenCXX/aarch64-sve-vector-conditional-op.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -164,10 +164,10 @@ svint32_t cond_i32_splat(svint32_t a) {
164164

165165
// CHECK-LABEL: @_Z14cond_u32_splatu12__SVUint32_t(
166166
// CHECK-NEXT: entry:
167-
// CHECK-NEXT: [[CMP:%.*]] = icmp ult <vscale x 4 x i32> [[A:%.*]], shufflevector (<vscale x 4 x i32> insertelement (<vscale x 4 x i32> poison, i32 1, i64 0), <vscale x 4 x i32> poison, <vscale x 4 x i32> zeroinitializer)
167+
// CHECK-NEXT: [[CMP:%.*]] = icmp ult <vscale x 4 x i32> [[A:%.*]], splat (i32 1)
168168
// CHECK-NEXT: [[CONV:%.*]] = zext <vscale x 4 x i1> [[CMP]] to <vscale x 4 x i32>
169169
// CHECK-NEXT: [[VECTOR_COND:%.*]] = icmp ne <vscale x 4 x i32> [[CONV]], zeroinitializer
170-
// CHECK-NEXT: [[VECTOR_SELECT:%.*]] = select <vscale x 4 x i1> [[VECTOR_COND]], <vscale x 4 x i32> [[A]], <vscale x 4 x i32> shufflevector (<vscale x 4 x i32> insertelement (<vscale x 4 x i32> poison, i32 1, i64 0), <vscale x 4 x i32> poison, <vscale x 4 x i32> zeroinitializer)
170+
// CHECK-NEXT: [[VECTOR_SELECT:%.*]] = select <vscale x 4 x i1> [[VECTOR_COND]], <vscale x 4 x i32> [[A]], <vscale x 4 x i32> splat (i32 1)
171171
// CHECK-NEXT: ret <vscale x 4 x i32> [[VECTOR_SELECT]]
172172
//
173173
svuint32_t cond_u32_splat(svuint32_t a) {
@@ -188,10 +188,10 @@ svint64_t cond_i64_splat(svint64_t a) {
188188

189189
// CHECK-LABEL: @_Z14cond_u64_splatu12__SVUint64_t(
190190
// CHECK-NEXT: entry:
191-
// CHECK-NEXT: [[CMP:%.*]] = icmp ult <vscale x 2 x i64> [[A:%.*]], shufflevector (<vscale x 2 x i64> insertelement (<vscale x 2 x i64> poison, i64 1, i64 0), <vscale x 2 x i64> poison, <vscale x 2 x i32> zeroinitializer)
191+
// CHECK-NEXT: [[CMP:%.*]] = icmp ult <vscale x 2 x i64> [[A:%.*]], splat (i64 1)
192192
// CHECK-NEXT: [[CONV:%.*]] = zext <vscale x 2 x i1> [[CMP]] to <vscale x 2 x i64>
193193
// CHECK-NEXT: [[VECTOR_COND:%.*]] = icmp ne <vscale x 2 x i64> [[CONV]], zeroinitializer
194-
// CHECK-NEXT: [[VECTOR_SELECT:%.*]] = select <vscale x 2 x i1> [[VECTOR_COND]], <vscale x 2 x i64> [[A]], <vscale x 2 x i64> shufflevector (<vscale x 2 x i64> insertelement (<vscale x 2 x i64> poison, i64 1, i64 0), <vscale x 2 x i64> poison, <vscale x 2 x i32> zeroinitializer)
194+
// CHECK-NEXT: [[VECTOR_SELECT:%.*]] = select <vscale x 2 x i1> [[VECTOR_COND]], <vscale x 2 x i64> [[A]], <vscale x 2 x i64> splat (i64 1)
195195
// CHECK-NEXT: ret <vscale x 2 x i64> [[VECTOR_SELECT]]
196196
//
197197
svuint64_t cond_u64_splat(svuint64_t a) {

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 << " (";

llvm/test/Assembler/constant-splat.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,13 @@ define <4 x i32> @ret_fixed_lenth_vector_splat_i32() {
5151
}
5252

5353
define void @add_fixed_lenth_vector_splat_double(<vscale x 2 x double> %a) {
54-
; CHECK: %add = fadd <vscale x 2 x double> %a, shufflevector (<vscale x 2 x double> insertelement (<vscale x 2 x double> poison, double 5.700000e+00, i64 0), <vscale x 2 x double> poison, <vscale x 2 x i32> zeroinitializer)
54+
; CHECK: %add = fadd <vscale x 2 x double> %a, splat (double 5.700000e+00)
5555
%add = fadd <vscale x 2 x double> %a, splat (double 5.700000e+00)
5656
ret void
5757
}
5858

5959
define <vscale x 4 x i32> @ret_scalable_vector_splat_i32() {
60-
; CHECK: ret <vscale x 4 x i32> shufflevector (<vscale x 4 x i32> insertelement (<vscale x 4 x i32> poison, i32 78, i64 0), <vscale x 4 x i32> poison, <vscale x 4 x i32> zeroinitializer)
60+
; CHECK: ret <vscale x 4 x i32> splat (i32 78)
6161
ret <vscale x 4 x i32> splat (i32 78)
6262
}
6363

llvm/test/Bitcode/vscale-shuffle.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
; RUN: verify-uselistorder < %s
33

44
define void @f() {
5-
%l = call <vscale x 16 x i8> @l(<vscale x 16 x i1> shufflevector (<vscale x 16 x i1> insertelement (<vscale x 16 x i1> undef, i1 true, i32 0), <vscale x 16 x i1> undef, <vscale x 16 x i32> zeroinitializer))
6-
%i = add <vscale x 2 x i64> undef, shufflevector (<vscale x 2 x i64> insertelement (<vscale x 2 x i64> undef, i64 1, i32 0), <vscale x 2 x i64> undef, <vscale x 2 x i32> zeroinitializer)
5+
%l = call <vscale x 16 x i8> @l(<vscale x 16 x i1> splat (i1 true))
6+
%i = add <vscale x 2 x i64> undef, splat (i64 1)
77
unreachable
88
}
99

0 commit comments

Comments
 (0)