Skip to content

Commit 14c3018

Browse files
[ExpandLargeFpConvert] Fix incorrect values in fp-to-int conversion. (#86514)
The IR for a double-to-i129 conversion looks like this in one of the blocks in compiler-rt: %cmp5.i = icmp ult i16 %3, -129, !dbg !24 But in ExpandLargeFpConvert, it looks like: %13 = icmp ult i129 %12, 4294967167, !dbg !19 ExpandLargeFpConvert is wrong; the value should have been signed before negating, but instead we get a very large unsigned value. Another value in the same pass also has this issue.
1 parent 6a6f9bf commit 14c3018

File tree

4 files changed

+218
-225
lines changed

4 files changed

+218
-225
lines changed

llvm/lib/CodeGen/ExpandLargeFpConvert.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -175,9 +175,10 @@ static void expandFPToI(Instruction *FPToI) {
175175
// if.end:
176176
Builder.SetInsertPoint(IfEnd);
177177
Value *Add1 = Builder.CreateAdd(
178-
And2, ConstantInt::getSigned(IntTy, -int64_t(ExponentBias + BitWidth)));
179-
Value *Cmp3 =
180-
Builder.CreateICmpULT(Add1, ConstantInt::getSigned(IntTy, -BitWidth));
178+
And2, ConstantInt::getSigned(
179+
IntTy, -static_cast<int64_t>(ExponentBias + BitWidth)));
180+
Value *Cmp3 = Builder.CreateICmpULT(
181+
Add1, ConstantInt::getSigned(IntTy, -static_cast<int64_t>(BitWidth)));
181182
Builder.CreateCondBr(Cmp3, IfThen5, IfEnd9);
182183

183184
// if.then5:
@@ -203,8 +204,8 @@ static void expandFPToI(Instruction *FPToI) {
203204
// if.else:
204205
Builder.SetInsertPoint(IfElse);
205206
Value *Sub15 = Builder.CreateAdd(
206-
And2,
207-
ConstantInt::getSigned(IntTy, -(ExponentBias + FPMantissaWidth)));
207+
And2, ConstantInt::getSigned(
208+
IntTy, -static_cast<int64_t>(ExponentBias + FPMantissaWidth)));
208209
Value *Shl = Builder.CreateShl(Or, Sub15);
209210
Value *Mul16 = Builder.CreateMul(Shl, Sign);
210211
Builder.CreateBr(End);

0 commit comments

Comments
 (0)