Skip to content

Commit 87869e4

Browse files
committed
[ConstantFPRange] Fix abs(nan)
1 parent cc99daa commit 87869e4

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

llvm/lib/IR/ConstantFPRange.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@ ConstantFPRange ConstantFPRange::unionWith(const ConstantFPRange &CR) const {
393393
}
394394

395395
ConstantFPRange ConstantFPRange::abs() const {
396-
if (isEmptySet())
396+
if (isNaNOnly())
397397
return *this;
398398
// Check if the range is all non-negative or all non-positive.
399399
if (Lower.isNegative() == Upper.isNegative()) {

llvm/unittests/IR/ConstantFPRangeTest.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -779,6 +779,7 @@ TEST_F(ConstantFPRangeTest, abs) {
779779
EXPECT_EQ(NegInf.abs(), PosInf);
780780
EXPECT_EQ(Some.abs(), SomePos);
781781
EXPECT_EQ(SomeNeg.abs(), SomePos);
782+
EXPECT_EQ(NaN.abs(), NaN);
782783
EXPECT_EQ(ConstantFPRange::getNonNaN(APFloat(-2.0), APFloat(3.0)).abs(),
783784
ConstantFPRange::getNonNaN(APFloat(0.0), APFloat(3.0)));
784785
EXPECT_EQ(ConstantFPRange::getNonNaN(APFloat(-3.0), APFloat(2.0)).abs(),
@@ -794,6 +795,7 @@ TEST_F(ConstantFPRangeTest, negate) {
794795
EXPECT_EQ(Some.negate(), Some);
795796
EXPECT_EQ(SomePos.negate(), SomeNeg);
796797
EXPECT_EQ(SomeNeg.negate(), SomePos);
798+
EXPECT_EQ(NaN.negate(), NaN);
797799
EXPECT_EQ(ConstantFPRange::getNonNaN(APFloat(-2.0), APFloat(3.0)).negate(),
798800
ConstantFPRange::getNonNaN(APFloat(-3.0), APFloat(2.0)));
799801
EXPECT_EQ(ConstantFPRange::getNonNaN(APFloat(-3.0), APFloat(2.0)).negate(),

0 commit comments

Comments
 (0)