Skip to content

Commit a258894

Browse files
committed
Fix convertBFloatAPFloatToAPInt for NaN/Inf values
Bfloat type has an 8-bit exponent so the exponent of NaN/Inf numbers must be 0xff instead of 0x1f. This is probably a copy-paste mistake from the half float type. Reviewed By: lattner Differential Revision: https://reviews.llvm.org/D81302
1 parent f39e12a commit a258894

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

llvm/lib/Support/APFloat.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -3278,11 +3278,11 @@ APInt IEEEFloat::convertBFloatAPFloatToAPInt() const {
32783278
myexponent = 0;
32793279
mysignificand = 0;
32803280
} else if (category == fcInfinity) {
3281-
myexponent = 0x1f;
3281+
myexponent = 0xff;
32823282
mysignificand = 0;
32833283
} else {
32843284
assert(category == fcNaN && "Unknown category!");
3285-
myexponent = 0x1f;
3285+
myexponent = 0xff;
32863286
mysignificand = (uint32_t)*significandParts();
32873287
}
32883288

llvm/test/Assembler/bfloat.ll

+24
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,27 @@ define float @check_bfloat_convert() {
3636
; OPT: 0x4191A00000000000
3737
ret float %tmp
3838
}
39+
40+
; ASSEM-DISASS-LABEL @snan_bfloat
41+
define bfloat @snan_bfloat() {
42+
; ASSEM-DISASS: ret bfloat 0xR7F81
43+
ret bfloat 0xR7F81
44+
}
45+
46+
; ASSEM-DISASS-LABEL @qnan_bfloat
47+
define bfloat @qnan_bfloat() {
48+
; ASSEM-DISASS: ret bfloat 0xR7FC0
49+
ret bfloat 0xR7FC0
50+
}
51+
52+
; ASSEM-DISASS-LABEL @pos_inf_bfloat
53+
define bfloat @pos_inf_bfloat() {
54+
; ASSEM-DISASS: ret bfloat 0xR7F80
55+
ret bfloat 0xR7F80
56+
}
57+
58+
; ASSEM-DISASS-LABEL @neg_inf_bfloat
59+
define bfloat @neg_inf_bfloat() {
60+
; ASSEM-DISASS: ret bfloat 0xRFF80
61+
ret bfloat 0xRFF80
62+
}

0 commit comments

Comments
 (0)