[llvm] 07acfe3 - ADT: Replace FPClassTest fabs with inverse_fabs and unknown_sign (#66390)
via llvm-commits
llvm-commits at lists.llvm.org
Thu Sep 14 09:46:57 PDT 2023
Author: Matt Arsenault
Date: 2023-09-14T19:46:53+03:00
New Revision: 07acfe3a4d473fccbb2b027cc8c77aec25d1dbe3
URL: https://github.com/llvm/llvm-project/commit/07acfe3a4d473fccbb2b027cc8c77aec25d1dbe3
DIFF: https://github.com/llvm/llvm-project/commit/07acfe3a4d473fccbb2b027cc8c77aec25d1dbe3.diff
LOG: ADT: Replace FPClassTest fabs with inverse_fabs and unknown_sign (#66390)
Added:
Modified:
llvm/include/llvm/ADT/FloatingPointMode.h
llvm/lib/Support/FloatingPointMode.cpp
llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/ADT/FloatingPointMode.h b/llvm/include/llvm/ADT/FloatingPointMode.h
index d80a811fd447a78..468de085d1bede4 100644
--- a/llvm/include/llvm/ADT/FloatingPointMode.h
+++ b/llvm/include/llvm/ADT/FloatingPointMode.h
@@ -269,8 +269,12 @@ LLVM_DECLARE_ENUM_AS_BITMASK(FPClassTest, /* LargestValue */ fcPosInf);
/// Return the test mask which returns true if the value's sign bit is flipped.
FPClassTest fneg(FPClassTest Mask);
-/// Return the test mask which returns true if the value's sign bit is cleared.
-FPClassTest fabs(FPClassTest Mask);
+/// Return the test mask which returns true after fabs is applied to the value.
+FPClassTest inverse_fabs(FPClassTest Mask);
+
+/// Return the test mask which returns true if the value could have the same set
+/// of classes, but with a
diff erent sign.
+FPClassTest unknown_sign(FPClassTest Mask);
/// Write a human readable form of \p Mask to \p OS
raw_ostream &operator<<(raw_ostream &OS, FPClassTest Mask);
diff --git a/llvm/lib/Support/FloatingPointMode.cpp b/llvm/lib/Support/FloatingPointMode.cpp
index 9543884ff46edd5..5a2836eb8243422 100644
--- a/llvm/lib/Support/FloatingPointMode.cpp
+++ b/llvm/lib/Support/FloatingPointMode.cpp
@@ -32,7 +32,7 @@ FPClassTest llvm::fneg(FPClassTest Mask) {
return NewMask;
}
-FPClassTest llvm::fabs(FPClassTest Mask) {
+FPClassTest llvm::inverse_fabs(FPClassTest Mask) {
FPClassTest NewMask = Mask & fcNan;
if (Mask & fcPosZero)
NewMask |= fcZero;
@@ -45,6 +45,19 @@ FPClassTest llvm::fabs(FPClassTest Mask) {
return NewMask;
}
+FPClassTest llvm::unknown_sign(FPClassTest Mask) {
+ FPClassTest NewMask = Mask & fcNan;
+ if (Mask & fcZero)
+ NewMask |= fcZero;
+ if (Mask & fcSubnormal)
+ NewMask |= fcSubnormal;
+ if (Mask & fcNormal)
+ NewMask |= fcNormal;
+ if (Mask & fcInf)
+ NewMask |= fcInf;
+ return NewMask;
+}
+
// Every bitfield has a unique name and one or more aliasing names that cover
// multiple bits. Names should be listed in order of preference, with higher
// popcounts listed first.
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
index 17cfd90ac209392..c6100f24b0507de 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
@@ -899,7 +899,7 @@ Instruction *InstCombinerImpl::foldIntrinsicIsFPClass(IntrinsicInst &II) {
Value *FAbsSrc;
if (match(Src0, m_FAbs(m_Value(FAbsSrc)))) {
- II.setArgOperand(1, ConstantInt::get(Src1->getType(), fabs(Mask)));
+ II.setArgOperand(1, ConstantInt::get(Src1->getType(), inverse_fabs(Mask)));
return replaceOperand(II, 0, FAbsSrc);
}
More information about the llvm-commits
mailing list