File tree Expand file tree Collapse file tree 2 files changed +11
-5
lines changed
test/Transforms/Float2Int Expand file tree Collapse file tree 2 files changed +11
-5
lines changed Original file line number Diff line number Diff line change @@ -237,10 +237,14 @@ std::optional<ConstantRange> Float2IntPass::calcRange(Instruction *I) {
237237 // OK, it's representable. Now get it.
238238 APSInt Int (MaxIntegerBW+1 , false );
239239 bool Exact;
240- CF->getValueAPF ().convertToInteger (Int,
241- APFloat::rmNearestTiesToEven,
242- &Exact);
243- OpRanges.push_back (ConstantRange (Int));
240+ APFloat::opStatus Status = CF->getValueAPF ().convertToInteger (
241+ Int, APFloat::rmNearestTiesToEven, &Exact);
242+ // Although the round above is loseless, we still need to check if the
243+ // floating-point value can be represented in the integer type.
244+ if (Status == APFloat::opOK || Status == APFloat::opInexact)
245+ OpRanges.push_back (ConstantRange (Int));
246+ else
247+ return badRange ();
244248 } else {
245249 llvm_unreachable (" Should have already marked this as badRange!" );
246250 }
Original file line number Diff line number Diff line change 77define i1 @pr167627 () {
88; CHECK-LABEL: define i1 @pr167627() {
99; CHECK-NEXT: [[ENTRY:.*:]]
10- ; CHECK-NEXT: ret i1 false
10+ ; CHECK-NEXT: [[FADD:%.*]] = fadd float 0xC5AAD8ABE0000000, 0xC57E819700000000
11+ ; CHECK-NEXT: [[CMP:%.*]] = fcmp one float [[FADD]], 0.000000e+00
12+ ; CHECK-NEXT: ret i1 [[CMP]]
1113;
1214entry:
1315 %fadd = fadd float 0xC5AAD8ABE0000000 , 0xC57E819700000000
You can’t perform that action at this time.
0 commit comments