Skip to content

Commit e76e936

Browse files
bevin-hanssonsearlmc1
authored andcommitted
[ExpandLargeFpConvert] Fix bug in int-to-fp expansion. (llvm#85370)
When deciding whether to perform rounding on the significand, the generated IR was using (width - leading zeros - 1) rather than (width - leading zeros). This is different from how the routine in compiler-rt does it: int sd = srcBits - clzSrcT(a); int e = sd - 1; if (sd > dstMantDig) { This bug means that the following code, when built on -O0: #include <stdio.h> _BitInt(233) v_1037 = 0; int main(void) { v_1037 = 18014398509481982wb; double d = v_1037; printf("d = %f\n", d); return 0; } prints "d = 9007199254740992.000000", which is incorrect. The correct result is "d = 18014398509481982.000000". (cherry picked from commit f623adb) Change-Id: Ieb9c0c786a1b781200f40e6229e69231c8fabe15
1 parent a1a82e3 commit e76e936

File tree

4 files changed

+456
-536
lines changed

4 files changed

+456
-536
lines changed

llvm/lib/CodeGen/ExpandLargeFpConvert.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@ static void expandIToFP(Instruction *IToFP) {
375375
Value *Sub2 = Builder.CreateSub(Builder.getIntN(BitWidthNew, BitWidth - 1),
376376
FloatWidth == 128 ? Call : Cast);
377377
Value *Cmp3 = Builder.CreateICmpSGT(
378-
Sub2, Builder.getIntN(BitWidthNew, FPMantissaWidth + 1));
378+
Sub1, Builder.getIntN(BitWidthNew, FPMantissaWidth + 1));
379379
Builder.CreateCondBr(Cmp3, IfThen4, IfElse);
380380

381381
// if.then4:

0 commit comments

Comments
 (0)