ADT: Replace FPClassTest fabs with inverse_fabs and unknown_sign (#66390)

This commit is contained in:
Matt Arsenault 2023-09-14 19:46:53 +03:00 committed by GitHub
parent 0d0ab7600f
commit 07acfe3a4d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 21 additions and 4 deletions

View File

@ -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 different 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);

View File

@ -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.

View File

@ -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);
}