Skip to content

[clang][CodeGen] fix UB in aarch64 bfloat16 scalar conversion #89062

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

Merged
merged 2 commits into from
Apr 29, 2024
Merged
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
2 changes: 1 addition & 1 deletion clang/include/clang/Basic/arm_neon.td
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ def OP_VCVT_BF16_F32_HI_A32
(call "vget_low", $p0))>;

def OP_CVT_F32_BF16
: Op<(bitcast "R", (op "<<", (bitcast "int32_t", $p0),
: Op<(bitcast "R", (op "<<", (cast "int32_t", (bitcast "int16_t", $p0)),
(literal "int32_t", "16")))>;

//===----------------------------------------------------------------------===//
Expand Down
9 changes: 5 additions & 4 deletions clang/test/CodeGen/arm-bf16-convert-intrinsics.c
Original file line number Diff line number Diff line change
Expand Up @@ -426,11 +426,12 @@ bfloat16_t test_vcvth_bf16_f32(float32_t a) {
// CHECK-NEXT: [[__REINT_I:%.*]] = alloca bfloat, align 2
// CHECK-NEXT: [[__REINT1_I:%.*]] = alloca i32, align 4
// CHECK-NEXT: store bfloat [[A:%.*]], ptr [[__REINT_I]], align 2
// CHECK-NEXT: [[TMP1:%.*]] = load i32, ptr [[__REINT_I]], align 2
// CHECK-NEXT: [[SHL_I:%.*]] = shl i32 [[TMP1]], 16
// CHECK-NEXT: [[TMP0:%.*]] = load i16, ptr [[__REINT_I]], align 2
// CHECK-NEXT: [[CONV_I:%.*]] = sext i16 [[TMP0]] to i32
// CHECK-NEXT: [[SHL_I:%.*]] = shl i32 [[CONV_I]], 16
// CHECK-NEXT: store i32 [[SHL_I]], ptr [[__REINT1_I]], align 4
// CHECK-NEXT: [[TMP3:%.*]] = load float, ptr [[__REINT1_I]], align 4
// CHECK-NEXT: ret float [[TMP3]]
// CHECK-NEXT: [[TMP1:%.*]] = load float, ptr [[__REINT1_I]], align 4
// CHECK-NEXT: ret float [[TMP1]]
//
float32_t test_vcvtah_f32_bf16(bfloat16_t a) {
return vcvtah_f32_bf16(a);
Expand Down