Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove reinterpret_cast. #260

Open
wants to merge 2 commits into
base: aie-public
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 16 additions & 17 deletions clang/lib/Headers/aie2p_scl2vec.h
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ INTRINSIC(v16uint32) upd_elem(v16uint32 v, int idx, v2uint32 b) {
}
#endif
INTRINSIC(v16float) upd_elem(v16float v, int idx, float b) {
return vector_insert(v, idx, __builtin_bit_cast(int, b));
return vector_insert(v, idx, b);
}
INTRINSIC(v32bfloat16) upd_elem(v32bfloat16 v, int idx, v2bfloat16 b) {
return __builtin_aie2p_vinsert_bf32_bf512(v, idx, b);
Expand Down Expand Up @@ -380,7 +380,7 @@ INTRINSIC(v16float) insert(v16float v, int idx, float b) {
}
#endif
INTRINSIC(v16float) insert(v16float v, int idx, float b) {
return vector_insert(v, idx, __builtin_bit_cast(int, b));
return vector_insert(v, idx, b);
}
INTRINSIC(v32bfloat16) insert(v32bfloat16 v, int idx, bfloat16 b) {
return vector_insert(v, idx, b);
Expand Down Expand Up @@ -796,21 +796,21 @@ ext_mask64(v16uint32 v, int idx, int sign) DIAGNOSE_EXT_IDX {
INTRINSIC(bfloat16)
ext_elem(v32bfloat16 v, int idx, int sign) DIAGNOSE_EXT_IDX {

int elem = vector_extract((v32int16)v, idx, sign);
return *reinterpret_cast<bfloat16 *>(&elem);
short elem = vector_extract((v32int16)v, idx, sign);
return __builtin_bit_cast(bfloat16, elem);
}

INTRINSIC(float)
ext_elem(v16float v, int idx, int sign) DIAGNOSE_EXT_IDX {
return (float)vector_extract((v16int32)v, idx, sign);
return vector_extract(v, idx, sign);
}

INTRINSIC(v2float)
ext_v2float(v16float v, int idx, int sign) DIAGNOSE_EXT_IDX {

int elem1 = vector_extract((v16int32)v, idx, sign);
int elem2 = vector_extract((v16int32)v, idx + 1, sign);
v2float val{(float)elem1, (float)elem2};
float elem1 = vector_extract(v, idx, sign);
float elem2 = vector_extract(v, idx + 1, sign);
v2float val{elem1, elem2};
return val;
}

Expand All @@ -836,14 +836,14 @@ INTRINSIC(v2bfloat16)
ext_v2bfloat16(v32bfloat16 v, int idx, int sign) DIAGNOSE_EXT_IDX {

int elem = vector_extract((v16int32)v, idx, sign);
return *reinterpret_cast<v2bfloat16 *>(&elem);
return __builtin_bit_cast(v2bfloat16, elem);
}

INTRINSIC(v4bfloat16)
ext_v4bfloat16(v32bfloat16 v, int idx, int sign) DIAGNOSE_EXT_IDX {

v2int32 elem = vector_extract64((v16int32)v, idx, sign);
return *reinterpret_cast<v4bfloat16 *>(&elem);
return __builtin_bit_cast(v4bfloat16, elem);
}

INTRINSIC(v2int4)
Expand Down Expand Up @@ -994,8 +994,7 @@ extract_v4bfloat16(v32bfloat16 v, int idx, int sign) DIAGNOSE_EXT_IDX {
}

INTRINSIC(float) extract_elem(v16float v, int idx, int sign) DIAGNOSE_EXT_IDX {
int elem = vector_extract(v, idx, sign);
return *reinterpret_cast<float *>(&elem);
return vector_extract(v, idx, sign);
}

#if 0
Expand Down Expand Up @@ -1389,8 +1388,8 @@ broadcast_bfloat16(bfloat16 b) { return b - v32bfloat16{0}; }

INTRINSIC(v16float)
broadcast_float(float b) {
int as_int = *reinterpret_cast<int *>(&b);
return broadcast_s32(as_int);
int as_int = __builtin_bit_cast(int, b);
return __builtin_bit_cast(v16float, broadcast_s32(as_int));
}

#if 0
Expand Down Expand Up @@ -1430,7 +1429,7 @@ INTRINSIC(v32int16)
broadcast_to_v32int16(short b) { return b - v32int16{0}; }

INTRINSIC(v32int16)
broadcast_to_v32int16(v2int16 b) { return broadcast_u32((int)b); }
broadcast_to_v32int16(v2int16 b) { return broadcast_s32((int)b); }

INTRINSIC(v32int16)
broadcast_to_v32int16(v4int16 b) { return vector_broadcast64((v2int32)b); }
Expand All @@ -1439,7 +1438,7 @@ INTRINSIC(v16int32)
broadcast_to_v16int32(int b) { return b - v16int32{0}; }

INTRINSIC(v16int32)
broadcast_to_v16int32(mask64 b) { return vector_broadcast64((v2uint32)b); }
broadcast_to_v16int32(mask64 b) { return vector_broadcast64((v2int32)b); }

INTRINSIC(v16int32)
broadcast_to_v16int32(v2int32 b) { return vector_broadcast64(b); }
Expand Down Expand Up @@ -1510,7 +1509,7 @@ broadcast_to_v32bfloat16(v4bfloat16 b) {
INTRINSIC(v16accfloat)
broadcast_to_v16accfloat(float b) {
int as_int = __builtin_bit_cast(int, b);
return broadcast_s32(as_int);
return __builtin_bit_cast(v16accfloat, broadcast_s32(as_int));
}

INTRINSIC(v16accfloat)
Expand Down
8 changes: 2 additions & 6 deletions clang/test/CodeGen/aie/aie-scl2vec-intrinsic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2102,9 +2102,7 @@ unsigned int test_extract_elem(v16uint32 v, int idx, int sign) {
// AIE2P-SAME: <16 x float> noundef [[V:%.*]], i32 noundef [[IDX:%.*]], i32 noundef [[SIGN:%.*]]) local_unnamed_addr #[[ATTR1]] {
// AIE2P-NEXT: entry:
// AIE2P-NEXT: [[VECEXT_I_I:%.*]] = extractelement <16 x float> [[V]], i32 [[IDX]]
// AIE2P-NEXT: [[CONV_I:%.*]] = fptosi float [[VECEXT_I_I]] to i32
// AIE2P-NEXT: [[TMP0:%.*]] = bitcast i32 [[CONV_I]] to float
// AIE2P-NEXT: ret float [[TMP0]]
// AIE2P-NEXT: ret float [[VECEXT_I_I]]
//
float test_extract_elem_float(v16float v, int idx, int sign) {
return extract_elem(v, idx, sign);
Expand Down Expand Up @@ -2671,9 +2669,7 @@ v4bfloat16 test_extract_v4bfloat16(v32bfloat16 v, int idx, int sign) {
// AIE2P-LABEL: define dso_local noundef <16 x float> @_Z11test_insertDv16_fif(
// AIE2P-SAME: <16 x float> noundef [[V:%.*]], i32 noundef [[IDX:%.*]], float noundef [[B:%.*]]) local_unnamed_addr #[[ATTR1]] {
// AIE2P-NEXT: entry:
// AIE2P-NEXT: [[TMP0:%.*]] = bitcast float [[B]] to i32
// AIE2P-NEXT: [[CONV_I_I:%.*]] = sitofp i32 [[TMP0]] to float
// AIE2P-NEXT: [[VECINS_I_I:%.*]] = insertelement <16 x float> [[V]], float [[CONV_I_I]], i32 [[IDX]]
// AIE2P-NEXT: [[VECINS_I_I:%.*]] = insertelement <16 x float> [[V]], float [[B]], i32 [[IDX]]
// AIE2P-NEXT: ret <16 x float> [[VECINS_I_I]]
//
v16float test_insert(v16float v, int idx, float b) {
Expand Down
53 changes: 19 additions & 34 deletions clang/test/CodeGen/aie/aie2p/aie2p-scl2vec-intrinsic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -360,9 +360,7 @@ v16int32 test_broadcast_elem_128(v16int32 a, int b){
// AIE2P-LABEL: define dso_local noundef <16 x float> @_Z13test_upd_elemDv16_fif(
// AIE2P-SAME: <16 x float> noundef [[V:%.*]], i32 noundef [[IDX:%.*]], float noundef [[B:%.*]]) local_unnamed_addr #[[ATTR0]] {
// AIE2P-NEXT: entry:
// AIE2P-NEXT: [[TMP0:%.*]] = bitcast float [[B]] to i32
// AIE2P-NEXT: [[CONV_I_I:%.*]] = sitofp i32 [[TMP0]] to float
// AIE2P-NEXT: [[VECINS_I_I:%.*]] = insertelement <16 x float> [[V]], float [[CONV_I_I]], i32 [[IDX]]
// AIE2P-NEXT: [[VECINS_I_I:%.*]] = insertelement <16 x float> [[V]], float [[B]], i32 [[IDX]]
// AIE2P-NEXT: ret <16 x float> [[VECINS_I_I]]
//
v16float test_upd_elem(v16float v, int idx, float b) {
Expand Down Expand Up @@ -440,10 +438,8 @@ v16int32 test_broadcast_elem_128(v16int32 a, int b){
// AIE2P-LABEL: define dso_local noundef float @_Z13test_ext_elemDv16_fii(
// AIE2P-SAME: <16 x float> noundef [[A:%.*]], i32 noundef [[B:%.*]], i32 noundef [[C:%.*]]) local_unnamed_addr #[[ATTR0]] {
// AIE2P-NEXT: entry:
// AIE2P-NEXT: [[TMP0:%.*]] = bitcast <16 x float> [[A]] to <16 x i32>
// AIE2P-NEXT: [[VECEXT_I_I:%.*]] = extractelement <16 x i32> [[TMP0]], i32 [[B]]
// AIE2P-NEXT: [[CONV_I:%.*]] = sitofp i32 [[VECEXT_I_I]] to float
// AIE2P-NEXT: ret float [[CONV_I]]
// AIE2P-NEXT: [[VECEXT_I_I:%.*]] = extractelement <16 x float> [[A]], i32 [[B]]
// AIE2P-NEXT: ret float [[VECEXT_I_I]]
//
float test_ext_elem(v16float a, int b, int c){
return ext_elem(a, b, c);
Expand All @@ -452,15 +448,12 @@ v16int32 test_broadcast_elem_128(v16int32 a, int b){
// AIE2P-LABEL: define dso_local noundef <2 x float> @_Z16test_ext_v2floatDv16_fii(
// AIE2P-SAME: <16 x float> noundef [[A:%.*]], i32 noundef [[B:%.*]], i32 noundef [[C:%.*]]) local_unnamed_addr #[[ATTR0]] {
// AIE2P-NEXT: entry:
// AIE2P-NEXT: [[TMP0:%.*]] = bitcast <16 x float> [[A]] to <16 x i32>
// AIE2P-NEXT: [[VECEXT_I_I:%.*]] = extractelement <16 x i32> [[TMP0]], i32 [[B]]
// AIE2P-NEXT: [[VECEXT_I_I:%.*]] = extractelement <16 x float> [[A]], i32 [[B]]
// AIE2P-NEXT: [[ADD_I:%.*]] = add nsw i32 [[B]], 1
// AIE2P-NEXT: [[VECEXT_I7_I:%.*]] = extractelement <16 x i32> [[TMP0]], i32 [[ADD_I]]
// AIE2P-NEXT: [[CONV_I:%.*]] = sitofp i32 [[VECEXT_I_I]] to float
// AIE2P-NEXT: [[VECINIT_I:%.*]] = insertelement <2 x float> poison, float [[CONV_I]], i64 0
// AIE2P-NEXT: [[CONV2_I:%.*]] = sitofp i32 [[VECEXT_I7_I]] to float
// AIE2P-NEXT: [[VECINIT3_I:%.*]] = insertelement <2 x float> [[VECINIT_I]], float [[CONV2_I]], i64 1
// AIE2P-NEXT: ret <2 x float> [[VECINIT3_I]]
// AIE2P-NEXT: [[VECEXT_I6_I:%.*]] = extractelement <16 x float> [[A]], i32 [[ADD_I]]
// AIE2P-NEXT: [[VECINIT_I:%.*]] = insertelement <2 x float> poison, float [[VECEXT_I_I]], i64 0
// AIE2P-NEXT: [[VECINIT2_I:%.*]] = insertelement <2 x float> [[VECINIT_I]], float [[VECEXT_I6_I]], i64 1
// AIE2P-NEXT: ret <2 x float> [[VECINIT2_I]]
//
v2float test_ext_v2float(v16float a, int b, int c){
return ext_v2float(a, b, c);
Expand All @@ -470,9 +463,7 @@ v16int32 test_broadcast_elem_128(v16int32 a, int b){
// AIE2P-SAME: <16 x float> noundef [[A:%.*]], i32 noundef [[B:%.*]], i32 noundef [[C:%.*]]) local_unnamed_addr #[[ATTR0]] {
// AIE2P-NEXT: entry:
// AIE2P-NEXT: [[VECEXT_I_I:%.*]] = extractelement <16 x float> [[A]], i32 [[B]]
// AIE2P-NEXT: [[CONV_I:%.*]] = fptosi float [[VECEXT_I_I]] to i32
// AIE2P-NEXT: [[TMP0:%.*]] = bitcast i32 [[CONV_I]] to float
// AIE2P-NEXT: ret float [[TMP0]]
// AIE2P-NEXT: ret float [[VECEXT_I_I]]
//
float test_extract_elem(v16float a, int b, int c){
return extract_elem(a, b, c);
Expand All @@ -481,15 +472,12 @@ float test_extract_elem(v16float a, int b, int c){
// AIE2P-LABEL: define dso_local noundef <2 x float> @_Z20test_extract_v2floatDv16_fii(
// AIE2P-SAME: <16 x float> noundef [[A:%.*]], i32 noundef [[B:%.*]], i32 noundef [[C:%.*]]) local_unnamed_addr #[[ATTR0]] {
// AIE2P-NEXT: entry:
// AIE2P-NEXT: [[TMP0:%.*]] = bitcast <16 x float> [[A]] to <16 x i32>
// AIE2P-NEXT: [[VECEXT_I_I_I:%.*]] = extractelement <16 x i32> [[TMP0]], i32 [[B]]
// AIE2P-NEXT: [[VECEXT_I_I_I:%.*]] = extractelement <16 x float> [[A]], i32 [[B]]
// AIE2P-NEXT: [[ADD_I_I:%.*]] = add nsw i32 [[B]], 1
// AIE2P-NEXT: [[VECEXT_I7_I_I:%.*]] = extractelement <16 x i32> [[TMP0]], i32 [[ADD_I_I]]
// AIE2P-NEXT: [[CONV_I_I:%.*]] = sitofp i32 [[VECEXT_I_I_I]] to float
// AIE2P-NEXT: [[VECINIT_I_I:%.*]] = insertelement <2 x float> poison, float [[CONV_I_I]], i64 0
// AIE2P-NEXT: [[CONV2_I_I:%.*]] = sitofp i32 [[VECEXT_I7_I_I]] to float
// AIE2P-NEXT: [[VECINIT3_I_I:%.*]] = insertelement <2 x float> [[VECINIT_I_I]], float [[CONV2_I_I]], i64 1
// AIE2P-NEXT: ret <2 x float> [[VECINIT3_I_I]]
// AIE2P-NEXT: [[VECEXT_I6_I_I:%.*]] = extractelement <16 x float> [[A]], i32 [[ADD_I_I]]
// AIE2P-NEXT: [[VECINIT_I_I:%.*]] = insertelement <2 x float> poison, float [[VECEXT_I_I_I]], i64 0
// AIE2P-NEXT: [[VECINIT2_I_I:%.*]] = insertelement <2 x float> [[VECINIT_I_I]], float [[VECEXT_I6_I_I]], i64 1
// AIE2P-NEXT: ret <2 x float> [[VECINIT2_I_I]]
//
v2float test_extract_v2float(v16float a, int b, int c){
return extract_v2float(a, b, c);
Expand All @@ -498,15 +486,12 @@ v2float test_extract_v2float(v16float a, int b, int c){
// AIE2P-LABEL: define dso_local noundef <2 x float> @_Z20test_extract_v2floatDv16_fi(
// AIE2P-SAME: <16 x float> noundef [[A:%.*]], i32 noundef [[B:%.*]]) local_unnamed_addr #[[ATTR0]] {
// AIE2P-NEXT: entry:
// AIE2P-NEXT: [[TMP0:%.*]] = bitcast <16 x float> [[A]] to <16 x i32>
// AIE2P-NEXT: [[VECEXT_I_I_I_I:%.*]] = extractelement <16 x i32> [[TMP0]], i32 [[B]]
// AIE2P-NEXT: [[VECEXT_I_I_I_I:%.*]] = extractelement <16 x float> [[A]], i32 [[B]]
// AIE2P-NEXT: [[ADD_I_I_I:%.*]] = add nsw i32 [[B]], 1
// AIE2P-NEXT: [[VECEXT_I7_I_I_I:%.*]] = extractelement <16 x i32> [[TMP0]], i32 [[ADD_I_I_I]]
// AIE2P-NEXT: [[CONV_I_I_I:%.*]] = sitofp i32 [[VECEXT_I_I_I_I]] to float
// AIE2P-NEXT: [[VECINIT_I_I_I:%.*]] = insertelement <2 x float> poison, float [[CONV_I_I_I]], i64 0
// AIE2P-NEXT: [[CONV2_I_I_I:%.*]] = sitofp i32 [[VECEXT_I7_I_I_I]] to float
// AIE2P-NEXT: [[VECINIT3_I_I_I:%.*]] = insertelement <2 x float> [[VECINIT_I_I_I]], float [[CONV2_I_I_I]], i64 1
// AIE2P-NEXT: ret <2 x float> [[VECINIT3_I_I_I]]
// AIE2P-NEXT: [[VECEXT_I6_I_I_I:%.*]] = extractelement <16 x float> [[A]], i32 [[ADD_I_I_I]]
// AIE2P-NEXT: [[VECINIT_I_I_I:%.*]] = insertelement <2 x float> poison, float [[VECEXT_I_I_I_I]], i64 0
// AIE2P-NEXT: [[VECINIT2_I_I_I:%.*]] = insertelement <2 x float> [[VECINIT_I_I_I]], float [[VECEXT_I6_I_I_I]], i64 1
// AIE2P-NEXT: ret <2 x float> [[VECINIT2_I_I_I]]
//
v2float test_extract_v2float(v16float a, int b){
return extract_v2float(a, b);
Expand Down
Loading