Skip to content

Commit abae161

Browse files
committed
[AIE2] Support broadcast_to_v16accfloat and broadcast_to_v16float
These "frontend intrinsics" were not properly supported and would crash the compiler if used. They now use __builtin_aiev2_vbroadcast32_I512 and are eventually selected to a VBCST_32 instruction. There is already an ISel test for this. See aie2/GlobalISel/inst-select-vbcst.mir.
1 parent ebbc1af commit abae161

File tree

4 files changed

+21
-9
lines changed

4 files changed

+21
-9
lines changed

clang/include/clang/Basic/BuiltinsAIE.def

-1
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,6 @@ BUILTIN(__builtin_aiev2_vbroadcast64_I512, "V16iV2i", "nc")
272272
BUILTIN(__builtin_aiev2_vbroadcast_bf16_bf512, "V32yy", "nc")
273273
BUILTIN(__builtin_aiev2_vbroadcast_bf32_bf512, "V32yV2y", "nc")
274274
BUILTIN(__builtin_aiev2_vbroadcast_bf64_bf512, "V32yV4y", "nc")
275-
BUILTIN(__builtin_aiev2_vbroadcastfloat_I512, "V16ff", "nc")
276275
BUILTIN(__builtin_aiev2_vbroadcast_zero_acc1024, "V16m", "nc")
277276
//scl2vec::broadcast_elem
278277
BUILTIN(__builtin_aiev2_vextract_broadcast8_I512, "V64cV64ci", "nc")

clang/lib/Headers/aiev2_scl2vec.h

+6-4
Original file line numberDiff line numberDiff line change
@@ -521,13 +521,15 @@ broadcast_to_v32bfloat16(v4bfloat16 b) {
521521

522522
INTRINSIC(v16accfloat)
523523
broadcast_to_v16accfloat(float b) {
524-
return __builtin_aiev2_vbroadcastfloat_I512(b);
524+
int as_int = __builtin_bit_cast(int, b);
525+
return __builtin_aiev2_vbroadcast32_I512(as_int);
525526
}
526527

527-
#if 0
528528
INTRINSIC(v16float)
529-
broadcast_to_v16float (float b) { return __builtin_aiev2_vbroadcast32_I512(b); }
530-
#endif
529+
broadcast_to_v16float(float b) {
530+
int as_int = __builtin_bit_cast(int, b);
531+
return __builtin_aiev2_vbroadcast32_I512(as_int);
532+
}
531533

532534
INTRINSIC(v32bfloat16)
533535
broadcast_zero_to_v32bfloat16() { return broadcast_to_v32bfloat16(0); }

clang/test/CodeGen/aie/aie2/aie2-scl2vec-intrinsic.cpp

+15-3
Original file line numberDiff line numberDiff line change
@@ -1162,14 +1162,26 @@ v16accfloat test_shift(v16accfloat a, v16accfloat b, int shift_by) {
11621162

11631163
// CHECK-LABEL: @_Z29test_broadcast_to_v16accfloatf(
11641164
// CHECK-NEXT: entry:
1165-
// CHECK-NEXT: [[TMP0:%.*]] = tail call <16 x float> @llvm.aie2.vbroadcastfloat.I512(float [[B:%.*]])
1166-
// CHECK-NEXT: [[TMP1:%.*]] = bitcast <16 x float> [[TMP0]] to <8 x i64>
1167-
// CHECK-NEXT: ret <8 x i64> [[TMP1]]
1165+
// CHECK-NEXT: [[TMP0:%.*]] = bitcast float [[B:%.*]] to i32
1166+
// CHECK-NEXT: [[TMP1:%.*]] = tail call <16 x i32> @llvm.aie2.vbroadcast32.I512(i32 [[TMP0]])
1167+
// CHECK-NEXT: [[TMP2:%.*]] = bitcast <16 x i32> [[TMP1]] to <8 x i64>
1168+
// CHECK-NEXT: ret <8 x i64> [[TMP2]]
11681169
//
11691170
v16accfloat test_broadcast_to_v16accfloat (float b) {
11701171
return broadcast_to_v16accfloat(b);
11711172
}
11721173

1174+
// CHECK-LABEL: @_Z26test_broadcast_to_v16floatf(
1175+
// CHECK-NEXT: entry:
1176+
// CHECK-NEXT: [[TMP0:%.*]] = bitcast float [[B:%.*]] to i32
1177+
// CHECK-NEXT: [[TMP1:%.*]] = tail call <16 x i32> @llvm.aie2.vbroadcast32.I512(i32 [[TMP0]])
1178+
// CHECK-NEXT: [[TMP2:%.*]] = bitcast <16 x i32> [[TMP1]] to <16 x float>
1179+
// CHECK-NEXT: ret <16 x float> [[TMP2]]
1180+
//
1181+
v16float test_broadcast_to_v16float (float b) {
1182+
return broadcast_to_v16float(b);
1183+
}
1184+
11731185
// CHECK-LABEL: @_Z11test_shiftxDv32_u6__bf16S_ii(
11741186
// CHECK-NEXT: entry:
11751187
// CHECK-NEXT: [[TMP0:%.*]] = tail call noundef <32 x bfloat> @llvm.aie2.vshift.bf512.bf512(<32 x bfloat> [[A:%.*]], <32 x bfloat> [[B:%.*]], i32 [[STEP:%.*]], i32 [[SHIFT:%.*]])

llvm/include/llvm/IR/IntrinsicsAIE2.td

-1
Original file line numberDiff line numberDiff line change
@@ -721,7 +721,6 @@ def int_aie2_vbroadcast64_I512 : ClangBuiltin<"__builtin_aiev2_vbroadcast64_I512
721721
def int_aie2_vbroadcast16_bf512 : ClangBuiltin<"__builtin_aiev2_vbroadcast_bf16_bf512">, AIEV2VBCST16bf512;
722722
def int_aie2_vbroadcast32_bf512 : ClangBuiltin<"__builtin_aiev2_vbroadcast_bf32_bf512">, AIEV2VBCST32bf512;
723723
def int_aie2_vbroadcast64_bf512 : ClangBuiltin<"__builtin_aiev2_vbroadcast_bf64_bf512">, AIEV2VBCST64bf512;
724-
def int_aie2_vbroadcastfloat_I512 : ClangBuiltin<"__builtin_aiev2_vbroadcastfloat_I512">, AIEV2VBCSTF32I512;
725724
def int_aie2_vbroadcast_zero_acc1024 : ClangBuiltin<"__builtin_aiev2_vbroadcast_zero_acc1024">, AIEV2VCLRACC1024;
726725
//scl2vec::broadcast_elem
727726
def int_aie2_vextract_broadcast8_I512 : ClangBuiltin<"__builtin_aiev2_vextract_broadcast8_I512">, AIEV2VEXTBCST8I512;

0 commit comments

Comments
 (0)