LLVM 22.0.0git
KnownFPClass.h
Go to the documentation of this file.
1//===- llvm/Support/KnownFPClass.h - Stores known fpclass -------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file contains a class for representing known fpclasses used by
10// computeKnownFPClass.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef LLVM_SUPPORT_KNOWNFPCLASS_H
15#define LLVM_SUPPORT_KNOWNFPCLASS_H
16
19#include <optional>
20
21namespace llvm {
22
24 /// Floating-point classes the value could be one of.
26
27 /// std::nullopt if the sign bit is unknown, true if the sign bit is
28 /// definitely set or false if the sign bit is definitely unset.
29 std::optional<bool> SignBit;
30
32 return KnownFPClasses == Other.KnownFPClasses && SignBit == Other.SignBit;
33 }
34
35 /// Return true if it's known this can never be one of the mask entries.
36 bool isKnownNever(FPClassTest Mask) const {
37 return (KnownFPClasses & Mask) == fcNone;
38 }
39
40 bool isKnownAlways(FPClassTest Mask) const { return isKnownNever(~Mask); }
41
42 bool isUnknown() const { return KnownFPClasses == fcAllFlags && !SignBit; }
43
44 /// Return true if it's known this can never be a nan.
45 bool isKnownNeverNaN() const { return isKnownNever(fcNan); }
46
47 /// Return true if it's known this must always be a nan.
48 bool isKnownAlwaysNaN() const { return isKnownAlways(fcNan); }
49
50 /// Return true if it's known this can never be an infinity.
51 bool isKnownNeverInfinity() const { return isKnownNever(fcInf); }
52
53 /// Return true if it's known this can never be +infinity.
55
56 /// Return true if it's known this can never be -infinity.
58
59 /// Return true if it's known this can never be a subnormal
61
62 /// Return true if it's known this can never be a positive subnormal
64
65 /// Return true if it's known this can never be a negative subnormal
67
68 /// Return true if it's known this can never be a zero. This means a literal
69 /// [+-]0, and does not include denormal inputs implicitly treated as [+-]0.
70 bool isKnownNeverZero() const { return isKnownNever(fcZero); }
71
72 /// Return true if it's known this can never be a literal positive zero.
73 bool isKnownNeverPosZero() const { return isKnownNever(fcPosZero); }
74
75 /// Return true if it's known this can never be a negative zero. This means a
76 /// literal -0 and does not include denormal inputs implicitly treated as -0.
77 bool isKnownNeverNegZero() const { return isKnownNever(fcNegZero); }
78
79 /// Return true if it's know this can never be interpreted as a zero. This
80 /// extends isKnownNeverZero to cover the case where the assumed
81 /// floating-point mode for the function interprets denormals as zero.
83
84 /// Return true if it's know this can never be interpreted as a negative zero.
86
87 /// Return true if it's know this can never be interpreted as a positive zero.
89
94
95 /// Return true if we can prove that the analyzed floating-point value is
96 /// either NaN or never less than -0.0.
97 ///
98 /// NaN --> true
99 /// +0 --> true
100 /// -0 --> true
101 /// x > +0 --> true
102 /// x < -0 --> false
105 }
106
107 /// Return true if we can prove that the analyzed floating-point value is
108 /// either NaN or never greater than -0.0.
109 /// NaN --> true
110 /// +0 --> true
111 /// -0 --> true
112 /// x > +0 --> false
113 /// x < -0 --> true
116 }
117
119 KnownFPClasses = KnownFPClasses | RHS.KnownFPClasses;
120
121 if (SignBit != RHS.SignBit)
122 SignBit = std::nullopt;
123 return *this;
124 }
125
126 void knownNot(FPClassTest RuleOut) {
127 KnownFPClasses = KnownFPClasses & ~RuleOut;
128 if (isKnownNever(fcNan) && !SignBit) {
130 SignBit = false;
131 else if (isKnownNever(fcPositive))
132 SignBit = true;
133 }
134 }
135
136 void fneg() {
138 if (SignBit)
139 SignBit = !*SignBit;
140 }
141
142 void fabs() {
145
148
151
154
156 }
157
158 /// Return true if the sign bit must be 0, ignoring the sign of nans.
160
161 /// Assume the sign bit is zero.
164 SignBit = false;
165 }
166
167 /// Assume the sign bit is one.
170 SignBit = true;
171 }
172
173 void copysign(const KnownFPClass &Sign) {
174 // Don't know anything about the sign of the source. Expand the possible set
175 // to its opposite sign pair.
182 if (KnownFPClasses & fcInf)
184
185 // Sign bit is exactly preserved even for nans.
186 SignBit = Sign.SignBit;
187
188 // Clear sign bits based on the input sign mask.
189 if (Sign.isKnownNever(fcPositive | fcNan) || (SignBit && *SignBit))
191 if (Sign.isKnownNever(fcNegative | fcNan) || (SignBit && !*SignBit))
193 }
194
195 // Propagate knowledge that a non-NaN source implies the result can also not
196 // be a NaN. For unconstrained operations, signaling nans are not guaranteed
197 // to be quieted but cannot be introduced.
198 void propagateNaN(const KnownFPClass &Src, bool PreserveSign = false) {
199 if (Src.isKnownNever(fcNan)) {
201 if (PreserveSign)
202 SignBit = Src.SignBit;
203 } else if (Src.isKnownNever(fcSNan))
205 }
206
207 /// Propagate knowledge from a source value that could be a denormal or
208 /// zero. We have to be conservative since output flushing is not guaranteed,
209 /// so known-never-zero may not hold.
210 ///
211 /// This assumes a copy-like operation and will replace any currently known
212 /// information.
214
215 /// Report known classes if \p Src is evaluated through a potentially
216 /// canonicalizing operation. We can assume signaling nans will not be
217 /// introduced, but cannot assume a denormal will be flushed under FTZ/DAZ.
218 ///
219 /// This assumes a copy-like operation and will replace any currently known
220 /// information.
223
224 void resetAll() { *this = KnownFPClass(); }
225};
226
228 LHS |= RHS;
229 return LHS;
230}
231
233 RHS |= LHS;
234 return std::move(RHS);
235}
236
237} // namespace llvm
238
239#endif
#define LLVM_ABI
Definition: Compiler.h:213
Utilities for dealing with flags related to floating point properties and mode controls.
static cl::opt< RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode > Mode("regalloc-enable-advisor", cl::Hidden, cl::init(RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode::Default), cl::desc("Enable regalloc advisor mode"), cl::values(clEnumValN(RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode::Default, "default", "Default"), clEnumValN(RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode::Release, "release", "precompiled"), clEnumValN(RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode::Development, "development", "for training")))
Value * RHS
Value * LHS
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
LLVM_ABI FPClassTest fneg(FPClassTest Mask)
Return the test mask which returns true if the value's sign bit is flipped.
FPClassTest
Floating-point class tests, supported by 'is_fpclass' intrinsic.
@ Other
Any other memory.
APInt operator|(APInt a, const APInt &b)
Definition: APInt.h:2143
Represent subnormal handling kind for floating point instruction inputs and outputs.
bool isKnownAlwaysNaN() const
Return true if it's known this must always be a nan.
Definition: KnownFPClass.h:48
FPClassTest KnownFPClasses
Floating-point classes the value could be one of.
Definition: KnownFPClass.h:25
bool isKnownNeverInfinity() const
Return true if it's known this can never be an infinity.
Definition: KnownFPClass.h:51
bool cannotBeOrderedGreaterThanZero() const
Return true if we can prove that the analyzed floating-point value is either NaN or never greater tha...
Definition: KnownFPClass.h:114
static constexpr FPClassTest OrderedGreaterThanZeroMask
Definition: KnownFPClass.h:92
static constexpr FPClassTest OrderedLessThanZeroMask
Definition: KnownFPClass.h:90
void knownNot(FPClassTest RuleOut)
Definition: KnownFPClass.h:126
bool isKnownNeverZero() const
Return true if it's known this can never be a zero.
Definition: KnownFPClass.h:70
void copysign(const KnownFPClass &Sign)
Definition: KnownFPClass.h:173
bool isKnownNeverSubnormal() const
Return true if it's known this can never be a subnormal.
Definition: KnownFPClass.h:60
bool isKnownAlways(FPClassTest Mask) const
Definition: KnownFPClass.h:40
LLVM_ABI bool isKnownNeverLogicalZero(DenormalMode Mode) const
Return true if it's know this can never be interpreted as a zero.
LLVM_ABI void propagateDenormal(const KnownFPClass &Src, DenormalMode Mode)
Propagate knowledge from a source value that could be a denormal or zero.
KnownFPClass & operator|=(const KnownFPClass &RHS)
Definition: KnownFPClass.h:118
bool isUnknown() const
Definition: KnownFPClass.h:42
bool isKnownNeverNegInfinity() const
Return true if it's known this can never be -infinity.
Definition: KnownFPClass.h:57
bool isKnownNeverNegSubnormal() const
Return true if it's known this can never be a negative subnormal.
Definition: KnownFPClass.h:66
bool isKnownNeverPosZero() const
Return true if it's known this can never be a literal positive zero.
Definition: KnownFPClass.h:73
std::optional< bool > SignBit
std::nullopt if the sign bit is unknown, true if the sign bit is definitely set or false if the sign ...
Definition: KnownFPClass.h:29
bool isKnownNeverNaN() const
Return true if it's known this can never be a nan.
Definition: KnownFPClass.h:45
bool isKnownNever(FPClassTest Mask) const
Return true if it's known this can never be one of the mask entries.
Definition: KnownFPClass.h:36
bool isKnownNeverNegZero() const
Return true if it's known this can never be a negative zero.
Definition: KnownFPClass.h:77
void propagateNaN(const KnownFPClass &Src, bool PreserveSign=false)
Definition: KnownFPClass.h:198
bool cannotBeOrderedLessThanZero() const
Return true if we can prove that the analyzed floating-point value is either NaN or never less than -...
Definition: KnownFPClass.h:103
void signBitMustBeOne()
Assume the sign bit is one.
Definition: KnownFPClass.h:168
LLVM_ABI void propagateCanonicalizingSrc(const KnownFPClass &Src, DenormalMode Mode)
Report known classes if Src is evaluated through a potentially canonicalizing operation.
void signBitMustBeZero()
Assume the sign bit is zero.
Definition: KnownFPClass.h:162
LLVM_ABI bool isKnownNeverLogicalPosZero(DenormalMode Mode) const
Return true if it's know this can never be interpreted as a positive zero.
bool isKnownNeverPosInfinity() const
Return true if it's known this can never be +infinity.
Definition: KnownFPClass.h:54
LLVM_ABI bool isKnownNeverLogicalNegZero(DenormalMode Mode) const
Return true if it's know this can never be interpreted as a negative zero.
bool operator==(KnownFPClass Other) const
Definition: KnownFPClass.h:31
bool signBitIsZeroOrNaN() const
Return true if the sign bit must be 0, ignoring the sign of nans.
Definition: KnownFPClass.h:159
bool isKnownNeverPosSubnormal() const
Return true if it's known this can never be a positive subnormal.
Definition: KnownFPClass.h:63