File tree Expand file tree Collapse file tree 2 files changed +26
-4
lines changed
test/Transforms/Float2Int Expand file tree Collapse file tree 2 files changed +26
-4
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 1+ ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 6
2+ ; RUN: opt -S -passes=float2int < %s | FileCheck %s
3+
4+ ; Make sure that we don't demote constant floating-point values when
5+ ; it cannot be represented by target integer type.
6+
7+ define i1 @pr167627 () {
8+ ; CHECK-LABEL: define i1 @pr167627() {
9+ ; CHECK-NEXT: [[ENTRY:.*:]]
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]]
13+ ;
14+ entry:
15+ %fadd = fadd float 0xC5AAD8ABE0000000 , 0xC57E819700000000
16+ %cmp = fcmp one float %fadd , 0 .000000e+00
17+ ret i1 %cmp
18+ }
You can’t perform that action at this time.
0 commit comments