LLVM 24.0.0git
ValueTrackingFP.cpp
Go to the documentation of this file.
1//===- ValueTrackingFP.cpp - Floating-point value tracking ----------------===//
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 routines that help analyze properties that chains of
10// floating-point computations have.
11//
12//===----------------------------------------------------------------------===//
13
14#include "llvm/ADT/APInt.h"
15#include "llvm/ADT/ArrayRef.h"
17#include "llvm/ADT/ScopeExit.h"
18#include "llvm/ADT/StringRef.h"
24#include "llvm/IR/Argument.h"
25#include "llvm/IR/Attributes.h"
26#include "llvm/IR/BasicBlock.h"
27#include "llvm/IR/Constant.h"
29#include "llvm/IR/Constants.h"
31#include "llvm/IR/Dominators.h"
32#include "llvm/IR/Function.h"
33#include "llvm/IR/InstrTypes.h"
34#include "llvm/IR/Instruction.h"
37#include "llvm/IR/Intrinsics.h"
38#include "llvm/IR/IntrinsicsAMDGPU.h"
39#include "llvm/IR/LLVMContext.h"
40#include "llvm/IR/Metadata.h"
41#include "llvm/IR/Operator.h"
43#include "llvm/IR/Type.h"
44#include "llvm/IR/Value.h"
49#include <cassert>
50#include <optional>
51
52using namespace llvm;
53using namespace llvm::PatternMatch;
54
56 bool CondIsTrue,
57 const Instruction *CtxI,
58 KnownFPClass &KnownFromContext,
59 unsigned Depth = 0) {
60 Value *A, *B;
62 (CondIsTrue ? match(Cond, m_LogicalAnd(m_Value(A), m_Value(B)))
64 computeKnownFPClassFromCond(V, A, CondIsTrue, CtxI, KnownFromContext,
65 Depth + 1);
66 computeKnownFPClassFromCond(V, B, CondIsTrue, CtxI, KnownFromContext,
67 Depth + 1);
68 return;
69 }
71 computeKnownFPClassFromCond(V, A, !CondIsTrue, CtxI, KnownFromContext,
72 Depth + 1);
73 return;
74 }
76 Value *LHS;
77 uint64_t ClassVal = 0;
78 const APFloat *CRHS;
79 const APInt *RHS;
80 if (match(Cond, m_FCmp(Pred, m_Value(LHS), m_APFloat(CRHS)))) {
81 auto [CmpVal, MaskIfTrue, MaskIfFalse] = fcmpImpliesClass(
83 LHS != V);
84 if (CmpVal == V)
85 KnownFromContext.knownNot(~(CondIsTrue ? MaskIfTrue : MaskIfFalse));
87 m_Specific(V), m_ConstantInt(ClassVal)))) {
88 FPClassTest Mask = static_cast<FPClassTest>(ClassVal);
89 KnownFromContext.knownNot(CondIsTrue ? ~Mask : Mask);
91 m_APInt(RHS)))) {
92 bool TrueIfSigned;
93 if (!isSignBitCheck(Pred, *RHS, TrueIfSigned))
94 return;
95 if (TrueIfSigned == CondIsTrue)
96 KnownFromContext.signBitMustBeOne();
97 else
98 KnownFromContext.signBitMustBeZero();
99 }
100}
101
103 const SimplifyQuery &Q) {
104 KnownFPClass KnownFromContext;
105
106 if (Q.CC && Q.CC->AffectedValues.contains(V))
108 KnownFromContext);
109
110 if (!Q.CtxI)
111 return KnownFromContext;
112
113 if (Q.DC && Q.DT) {
114 // Handle dominating conditions.
115 for (CondBrInst *BI : Q.DC->conditionsFor(V)) {
116 Value *Cond = BI->getCondition();
117
118 BasicBlockEdge Edge0(BI->getParent(), BI->getSuccessor(0));
119 if (Q.DT->dominates(Edge0, Q.CtxI->getParent()))
120 computeKnownFPClassFromCond(V, Cond, /*CondIsTrue=*/true, Q.CtxI,
121 KnownFromContext);
122
123 BasicBlockEdge Edge1(BI->getParent(), BI->getSuccessor(1));
124 if (Q.DT->dominates(Edge1, Q.CtxI->getParent()))
125 computeKnownFPClassFromCond(V, Cond, /*CondIsTrue=*/false, Q.CtxI,
126 KnownFromContext);
127 }
128 }
129
130 if (!Q.AC)
131 return KnownFromContext;
132
133 // Try to restrict the floating-point classes based on information from
134 // assumptions.
135 for (auto &AssumeVH : Q.AC->assumptionsFor(V)) {
136 if (!AssumeVH)
137 continue;
138 CallInst *I = cast<CallInst>(AssumeVH);
139
140 assert(I->getFunction() == Q.CtxI->getParent()->getParent() &&
141 "Got assumption for the wrong function!");
142 assert(I->getIntrinsicID() == Intrinsic::assume &&
143 "must be an assume intrinsic");
144
145 if (!isValidAssumeForContext(I, Q))
146 continue;
147
148 computeKnownFPClassFromCond(V, I->getArgOperand(0),
149 /*CondIsTrue=*/true, Q.CtxI, KnownFromContext);
150 }
151
152 return KnownFromContext;
153}
154
156 Value *Arm, bool Invert,
157 const SimplifyQuery &SQ,
158 unsigned Depth) {
159
160 KnownFPClass KnownSrc;
162 /*CondIsTrue=*/!Invert, SQ.CtxI, KnownSrc,
163 Depth + 1);
164 KnownSrc = KnownSrc.unionWith(Known);
165 if (KnownSrc.isUnknown())
166 return;
167
168 if (isGuaranteedNotToBeUndef(Arm, SQ.AC, SQ.CtxI, SQ.DT, Depth + 1))
169 Known = KnownSrc;
170}
171
172void computeKnownFPClass(const Value *V, const APInt &DemandedElts,
173 FPClassTest InterestedClasses, KnownFPClass &Known,
174 const SimplifyQuery &Q, unsigned Depth);
175
177 FPClassTest InterestedClasses,
178 const SimplifyQuery &Q, unsigned Depth) {
179 auto *FVTy = dyn_cast<FixedVectorType>(V->getType());
180 APInt DemandedElts =
181 FVTy ? APInt::getAllOnes(FVTy->getNumElements()) : APInt(1, 1);
182 computeKnownFPClass(V, DemandedElts, InterestedClasses, Known, Q, Depth);
183}
184
186 const APInt &DemandedElts,
187 FPClassTest InterestedClasses,
189 const SimplifyQuery &Q,
190 unsigned Depth) {
191 if ((InterestedClasses & (KnownFPClass::OrderedLessThanZeroMask | fcNan)) ==
192 fcNone)
193 return;
194
195 KnownFPClass KnownSrc;
196 computeKnownFPClass(Op->getOperand(0), DemandedElts, InterestedClasses,
197 KnownSrc, Q, Depth + 1);
198
199 const fltSemantics &DstTy = Op->getType()->getScalarType()->getFltSemantics();
200 const fltSemantics &SrcTy =
201 Op->getOperand(0)->getType()->getScalarType()->getFltSemantics();
202
203 const auto *I = dyn_cast<Instruction>(Op);
204 const Function *F = I ? I->getFunction() : nullptr;
205 DenormalMode DstMode =
206 F ? F->getDenormalMode(DstTy) : DenormalMode::getDynamic();
207 DenormalMode SrcMode =
208 F ? F->getDenormalMode(SrcTy) : DenormalMode::getDynamic();
209
210 Known = KnownFPClass::fptrunc(KnownSrc, DstTy, SrcTy, RM, DstMode, SrcMode);
211}
212
213static void
214computeKnownFPClassForFAddSub(const Operator *Op, const APInt &DemandedElts,
215 FPClassTest InterestedClasses,
217 unsigned Depth, bool IsAdd, bool IsStrict) {
218 const Value *LHS = Op->getOperand(0);
219 const Value *RHS = Op->getOperand(1);
220
221 const RoundingMode RM =
222 IsStrict ? cast<ConstrainedFPIntrinsic>(Op)->getRoundingMode().value_or(
225
226 KnownFPClass KnownLHS, KnownRHS;
227 bool WantNegative =
228 IsAdd &&
229 (InterestedClasses & KnownFPClass::OrderedLessThanZeroMask) != fcNone;
230 bool WantNaN = (InterestedClasses & fcNan) != fcNone;
231 bool WantNegZero = (InterestedClasses & fcNegZero) != fcNone;
232 bool WantSubnormal = (InterestedClasses & fcSubnormal) != fcNone;
233
234 if (!WantNaN && !WantNegative && !WantNegZero && !WantSubnormal)
235 return;
236
237 FPClassTest InterestedSrcs = InterestedClasses;
238 if (WantNegative)
240 if (InterestedClasses & fcNan)
241 InterestedSrcs |= fcInf;
242 computeKnownFPClass(RHS, DemandedElts, InterestedSrcs, KnownRHS, Q,
243 Depth + 1);
244
245 // Special case fadd x, x, which is the canonical form of fmul x, 2.
246 bool Self = LHS == RHS &&
248 if (Self)
249 KnownLHS = KnownRHS;
250
251 if ((WantNaN && KnownRHS.isKnownNeverNaN()) ||
252 (WantNegative && KnownRHS.cannotBeOrderedLessThanZero()) || WantNegZero ||
253 WantSubnormal || !IsAdd) {
254
255 // FIXME: Context function should always be passed in separately
256 const Function *F = cast<Instruction>(Op)->getFunction();
257 const fltSemantics &FltSem =
258 Op->getType()->getScalarType()->getFltSemantics();
260 F ? F->getDenormalMode(FltSem) : DenormalMode::getDynamic();
261
262 if (Self && IsAdd) {
263 Known = KnownFPClass::fadd_self(KnownLHS, RM, Mode);
264 } else {
265 // RHS is canonically cheaper to compute. Skip inspecting the LHS if
266 // there's no point.
267
268 if (!Self) {
269 computeKnownFPClass(LHS, DemandedElts, InterestedSrcs, KnownLHS, Q,
270 Depth + 1);
271 }
272
273 if (const APFloat *CRHS; IsAdd && match(RHS, m_APFloat(CRHS))) {
274 Known = KnownFPClass::fadd(KnownLHS, *CRHS, RM, Mode);
275 return;
276 }
277
278 Known = IsAdd ? KnownFPClass::fadd(KnownLHS, KnownRHS, RM, Mode)
279 : KnownFPClass::fsub(KnownLHS, KnownRHS, RM, Mode);
280 }
281 }
282}
283
285 const APInt &DemandedElts,
286 FPClassTest InterestedClasses,
288 const SimplifyQuery &Q, unsigned Depth) {
289 const Value *LHS = Op->getOperand(0);
290 const Value *RHS = Op->getOperand(1);
291
292 FPClassTest InterestedLHS = fcNone;
293 FPClassTest InterestedRHS = fcNone;
294
295 // NaN is also generated for frem(Inf, x) and frem(x, 0.0).
296 if (InterestedClasses & fcNan) {
297 InterestedLHS |= fcNan | fcInf;
298 InterestedRHS |= fcNan | fcZero | fcSubnormal;
299 }
300
301 // The sign for frem is the same as the first operand.
302 if (InterestedClasses & (fcPosNormal | fcPosSubnormal))
303 InterestedLHS |= fcPosNormal | fcPosSubnormal;
304 if (InterestedClasses & (fcNegNormal | fcNegSubnormal))
305 InterestedLHS |= fcNegNormal | fcNegSubnormal;
306
307 // A negative zero result requires a negative finite first operand.
308 if (InterestedClasses & fcNegZero)
309 InterestedLHS |= fcNegFinite;
310
311 // A positive zero result can additionally come from a negative finite
312 // result being flushed to positive zero.
313 if (InterestedClasses & fcPosZero)
314 InterestedLHS |= fcPosFinite | fcNegNormal | fcNegSubnormal;
315
316 const Function *F = cast<Instruction>(Op)->getFunction();
318 F ? F->getDenormalMode(Op->getType()->getScalarType()->getFltSemantics())
320
321 if (LHS == RHS && isGuaranteedNotToBeUndef(LHS, Q.AC, Q.CtxI, Q.DT)) {
322 // X % X is always exactly [+-]0.0 or a NaN.
323 FPClassTest InterestedSrcs = InterestedLHS | InterestedRHS;
324 KnownFPClass KnownSrc;
325 if (InterestedSrcs != fcNone)
326 computeKnownFPClass(LHS, DemandedElts, InterestedSrcs, KnownSrc, Q,
327 Depth + 1);
329 return;
330 }
331
332 KnownFPClass KnownLHS;
333 if (InterestedLHS != fcNone)
334 computeKnownFPClass(LHS, DemandedElts, InterestedLHS, KnownLHS, Q,
335 Depth + 1);
336
337 KnownFPClass KnownRHS;
338 // RHS is only useful for refining NaN classes.
339 if (InterestedRHS != fcNone && KnownLHS.isKnownNever(fcSNan))
340 computeKnownFPClass(RHS, DemandedElts, InterestedRHS, KnownRHS, Q,
341 Depth + 1);
342
343 Known = KnownFPClass::frem(KnownLHS, KnownRHS, Mode);
344}
345
347 switch (IID) {
348 case Intrinsic::minimum:
350 case Intrinsic::maximum:
352 case Intrinsic::minimumnum:
354 case Intrinsic::maximumnum:
356 case Intrinsic::minnum:
358 case Intrinsic::maxnum:
360 default:
361 llvm_unreachable("not a floating-point min-max intrinsic");
362 }
363}
364
365/// \return true if this is a floating point value that is known to have a
366/// magnitude smaller than 1. i.e., fabs(X) <= 1.0 or is nan.
367static bool isAbsoluteValueULEOne(const Value *V) {
368 // TODO: Handle frexp
369 // TODO: Other rounding intrinsics?
370 // TODO: Try computeKnownExponentRangeFromContext
371
372 // fabs(x - floor(x)) <= 1
373 const Value *SubFloorX;
374 if (match(V, m_FSub(m_Value(SubFloorX),
376 return true;
377
380}
381
382void computeKnownFPClass(const Value *V, const APInt &DemandedElts,
383 FPClassTest InterestedClasses, KnownFPClass &Known,
384 const SimplifyQuery &Q, unsigned Depth) {
385 assert(Known.isUnknown() && "should not be called with known information");
386
387 if (!DemandedElts) {
388 // No demanded elts, better to assume we don't know anything.
389 Known.resetAll();
390 return;
391 }
392
393 assert(Depth <= MaxAnalysisRecursionDepth && "Limit Search Depth");
394
395 if (auto *CFP = dyn_cast<ConstantFP>(V)) {
396 Known = KnownFPClass(CFP->getValueAPF());
397 return;
398 }
399
401 Known.setKnownFPClasses(fcPosZero);
402 return;
403 }
404
405 if (isa<PoisonValue>(V)) {
407 return;
408 }
409
410 // Try to handle fixed width vector constants
411 auto *VFVTy = dyn_cast<FixedVectorType>(V->getType());
412 const Constant *CV = dyn_cast<Constant>(V);
413 if (VFVTy && CV) {
415
416 // For vectors, verify that each element is not NaN.
417 unsigned NumElts = VFVTy->getNumElements();
418 for (unsigned i = 0; i != NumElts; ++i) {
419 if (!DemandedElts[i])
420 continue;
421
422 Constant *Elt = CV->getAggregateElement(i);
423 if (!Elt) {
425 return;
426 }
427 if (isa<PoisonValue>(Elt))
428 continue;
429 auto *CElt = dyn_cast<ConstantFP>(Elt);
430 if (!CElt) {
432 return;
433 }
434
435 Known |= KnownFPClass(CElt->getValueAPF());
436 }
437 return;
438 }
439
440 if (const auto *CDS = dyn_cast<ConstantDataSequential>(V)) {
442 for (size_t I = 0, E = CDS->getNumElements(); I != E; ++I)
443 Known |= KnownFPClass(CDS->getElementAsAPFloat(I));
444 return;
445 }
446
447 if (const auto *CA = dyn_cast<ConstantAggregate>(V)) {
448 // TODO: Handle complex aggregates
450 for (const Use &Op : CA->operands()) {
451 auto *CFP = dyn_cast<ConstantFP>(Op.get());
452 if (!CFP) {
454 return;
455 }
456
457 Known |= KnownFPClass(CFP->getValueAPF());
458 }
459
460 return;
461 }
462
463 FPClassTest KnownNotFromFlags = fcNone;
464 if (const auto *CB = dyn_cast<CallBase>(V))
465 KnownNotFromFlags |= CB->getRetNoFPClass();
466 else if (const auto *Arg = dyn_cast<Argument>(V))
467 KnownNotFromFlags |= Arg->getNoFPClass();
468
471 if (FPOp->hasNoNaNs())
472 KnownNotFromFlags |= fcNan;
473 if (FPOp->hasNoInfs())
474 KnownNotFromFlags |= fcInf;
475 }
476
477 KnownFPClass AssumedClasses = computeKnownFPClassFromContext(V, Q);
478 KnownNotFromFlags |= ~AssumedClasses.getKnownFPClasses();
479
480 // We no longer need to find out about these bits from inputs if we can
481 // assume this from flags/attributes.
482 InterestedClasses &= ~KnownNotFromFlags;
483
484 llvm::scope_exit ClearClassesFromFlags([=, &Known] {
485 Known.knownNot(KnownNotFromFlags);
486 if (!Known.getSignBit() && AssumedClasses.getSignBit()) {
487 if (*AssumedClasses.getSignBit())
488 Known.signBitMustBeOne();
489 else
490 Known.signBitMustBeZero();
491 }
492 });
493
494 if (!Op)
495 return;
496
497 // All recursive calls that increase depth must come after this.
499 return;
500
501 const unsigned Opc = Op->getOpcode();
502 switch (Opc) {
503 case Instruction::FNeg: {
504 computeKnownFPClass(Op->getOperand(0), DemandedElts, InterestedClasses,
505 Known, Q, Depth + 1);
506 Known.fneg();
507 break;
508 }
509 case Instruction::Select: {
510 auto ComputeForArm = [&](Value *Arm, bool Invert) {
511 KnownFPClass Res;
512 computeKnownFPClass(Arm, DemandedElts, InterestedClasses, Res, Q,
513 Depth + 1);
514 adjustKnownFPClassForSelectArm(Res, Op->getOperand(0), Arm, Invert, Q,
515 Depth);
516 return Res;
517 };
518 // Only known if known in both the LHS and RHS.
519 Known =
520 ComputeForArm(Op->getOperand(1), /*Invert=*/false)
521 .intersectWith(ComputeForArm(Op->getOperand(2), /*Invert=*/true));
522 break;
523 }
524 case Instruction::Load: {
525 const MDNode *NoFPClass =
526 cast<LoadInst>(Op)->getMetadata(LLVMContext::MD_nofpclass);
527 if (!NoFPClass)
528 break;
529
530 ConstantInt *MaskVal =
532 Known.knownNot(static_cast<FPClassTest>(MaskVal->getZExtValue()));
533 break;
534 }
535 case Instruction::Call: {
536 const CallInst *II = cast<CallInst>(Op);
537 const Intrinsic::ID IID = II->getIntrinsicID();
538 switch (IID) {
539 case Intrinsic::fabs: {
540 if ((InterestedClasses & (fcNan | fcPositive)) != fcNone) {
541 // If we only care about the sign bit we don't need to inspect the
542 // operand.
543 computeKnownFPClass(II->getArgOperand(0), DemandedElts,
544 InterestedClasses, Known, Q, Depth + 1);
545 }
546
547 Known.fabs();
548 break;
549 }
550 case Intrinsic::copysign: {
551 KnownFPClass KnownSign;
552
553 computeKnownFPClass(II->getArgOperand(0), DemandedElts, InterestedClasses,
554 Known, Q, Depth + 1);
555 computeKnownFPClass(II->getArgOperand(1), DemandedElts, InterestedClasses,
556 KnownSign, Q, Depth + 1);
557 Known.copysign(KnownSign);
558 break;
559 }
560 case Intrinsic::fma:
561 case Intrinsic::fmuladd: {
562 if ((InterestedClasses & (fcNegative | fcNan)) == fcNone)
563 break;
564
565 const bool IsFMA = IID == Intrinsic::fma;
566
567 // A NaN operand always gives a NaN result, so a result known not to be
568 // NaN means the operands are not NaN. This does not work for inf:
569 // fma produces NaN when multiplying zero by infinity, or when adding two
570 // exact infinities of the opposite sign. So a result known not to be inf
571 // (e.g. from nofpclass or a dominating condition) says nothing about the
572 // operands. Only the ninf flag also applies to the operands.
573 FPClassTest KnownNotSrc = fcNone;
574 if ((KnownNotFromFlags & fcNan) == fcNan)
575 KnownNotSrc |= fcNan;
576 if (II->hasNoInfs())
577 KnownNotSrc |= fcInf;
578
579 // FIXME: This should check isGuaranteedNotToBeUndef
580 if (II->getArgOperand(0) == II->getArgOperand(1)) {
581 FPClassTest InterestedSquared = InterestedClasses;
582 FPClassTest InterestedAddend = InterestedClasses;
583 // Only fma(+inf, +inf, -inf) and fma(-inf, -inf, -inf) produce NaN when
584 // squaring.
585 if (InterestedClasses & fcQNan) {
586 InterestedSquared |= fcSNan | fcInf;
587 InterestedAddend |= fcSNan | fcNegInf;
588 }
589
590 KnownFPClass KnownSrc, KnownAddend;
591 computeKnownFPClass(II->getArgOperand(2), DemandedElts,
592 InterestedAddend, KnownAddend, Q, Depth + 1);
593 computeKnownFPClass(II->getArgOperand(0), DemandedElts,
594 InterestedSquared, KnownSrc, Q, Depth + 1);
595
596 const Function *F = II->getFunction();
597 const fltSemantics &FltSem =
598 II->getType()->getScalarType()->getFltSemantics();
600 F ? F->getDenormalMode(FltSem) : DenormalMode::getDynamic();
601
602 KnownSrc.knownNot(KnownNotSrc);
603 KnownAddend.knownNot(KnownNotSrc);
604
605 Known = IsFMA
606 ? KnownFPClass::fma_square(KnownSrc, KnownAddend, Mode)
607 : KnownFPClass::fmuladd_square(KnownSrc, KnownAddend, Mode);
608 break;
609 }
610
611 KnownFPClass KnownSrc[3];
612 for (int I = 0; I != 3; ++I) {
613 computeKnownFPClass(II->getArgOperand(I), DemandedElts,
614 InterestedClasses, KnownSrc[I], Q, Depth + 1);
615 if (KnownSrc[I].isUnknown())
616 return;
617
618 KnownSrc[I].knownNot(KnownNotSrc);
619 }
620
621 const Function *F = II->getFunction();
622 const fltSemantics &FltSem =
623 II->getType()->getScalarType()->getFltSemantics();
625 F ? F->getDenormalMode(FltSem) : DenormalMode::getDynamic();
626 Known =
627 IsFMA ? KnownFPClass::fma(KnownSrc[0], KnownSrc[1], KnownSrc[2], Mode)
628 : KnownFPClass::fmuladd(KnownSrc[0], KnownSrc[1], KnownSrc[2],
629 Mode);
630 break;
631 }
632 case Intrinsic::experimental_constrained_fadd:
633 case Intrinsic::experimental_constrained_fsub: {
635 Op, DemandedElts, InterestedClasses, Known, Q, Depth,
636 /*IsAdd=*/IID == Intrinsic::experimental_constrained_fadd,
637 /*IsStrict=*/true);
638 break;
639 }
640 case Intrinsic::experimental_constrained_frem: {
641 computeKnownFPClassForFRem(Op, DemandedElts, InterestedClasses, Known, Q,
642 Depth);
643 break;
644 }
645 case Intrinsic::sqrt:
646 case Intrinsic::experimental_constrained_sqrt: {
647 KnownFPClass KnownSrc;
648 FPClassTest InterestedSrcs = InterestedClasses;
649 if (InterestedClasses & fcQNan)
651 // Subnormals may flush to zero.
652 if (InterestedClasses & fcZero)
653 InterestedSrcs |= fcSubnormal;
654
655 computeKnownFPClass(II->getArgOperand(0), DemandedElts, InterestedSrcs,
656 KnownSrc, Q, Depth + 1);
657
659
660 bool HasNSZ = Q.IIQ.hasNoSignedZeros(II);
661 if (!HasNSZ) {
662 const Function *F = II->getFunction();
663 const fltSemantics &FltSem =
664 II->getType()->getScalarType()->getFltSemantics();
665 Mode = F ? F->getDenormalMode(FltSem) : DenormalMode::getDynamic();
666 }
667
668 Known = KnownFPClass::sqrt(KnownSrc, Mode);
669 if (HasNSZ)
670 Known.knownNot(fcNegZero);
671
672 break;
673 }
674 case Intrinsic::sin: {
675 KnownFPClass KnownSrc;
676 computeKnownFPClass(II->getArgOperand(0), DemandedElts, InterestedClasses,
677 KnownSrc, Q, Depth + 1);
678 Known = KnownFPClass::sin(KnownSrc);
679 break;
680 }
681 case Intrinsic::cos: {
682 KnownFPClass KnownSrc;
683 computeKnownFPClass(II->getArgOperand(0), DemandedElts, InterestedClasses,
684 KnownSrc, Q, Depth + 1);
685 Known = KnownFPClass::cos(KnownSrc);
686 break;
687 }
688 case Intrinsic::tan: {
689 KnownFPClass KnownSrc;
690 computeKnownFPClass(II->getArgOperand(0), DemandedElts, InterestedClasses,
691 KnownSrc, Q, Depth + 1);
692 Known = KnownFPClass::tan(KnownSrc);
693 break;
694 }
695 case Intrinsic::sinh: {
696 KnownFPClass KnownSrc;
697 computeKnownFPClass(II->getArgOperand(0), DemandedElts, InterestedClasses,
698 KnownSrc, Q, Depth + 1);
699 Known = KnownFPClass::sinh(KnownSrc);
700 break;
701 }
702 case Intrinsic::cosh: {
703 KnownFPClass KnownSrc;
704 computeKnownFPClass(II->getArgOperand(0), DemandedElts, InterestedClasses,
705 KnownSrc, Q, Depth + 1);
706 Known = KnownFPClass::cosh(KnownSrc);
707 break;
708 }
709 case Intrinsic::tanh: {
710 KnownFPClass KnownSrc;
711 computeKnownFPClass(II->getArgOperand(0), DemandedElts, InterestedClasses,
712 KnownSrc, Q, Depth + 1);
713 Known = KnownFPClass::tanh(KnownSrc);
714 break;
715 }
716 case Intrinsic::asin: {
717 KnownFPClass KnownSrc;
718 computeKnownFPClass(II->getArgOperand(0), DemandedElts, InterestedClasses,
719 KnownSrc, Q, Depth + 1);
720 Known = KnownFPClass::asin(KnownSrc);
721 break;
722 }
723 case Intrinsic::acos: {
724 KnownFPClass KnownSrc;
725 computeKnownFPClass(II->getArgOperand(0), DemandedElts, InterestedClasses,
726 KnownSrc, Q, Depth + 1);
727 Known = KnownFPClass::acos(KnownSrc);
728 break;
729 }
730 case Intrinsic::atan: {
731 KnownFPClass KnownSrc;
732 computeKnownFPClass(II->getArgOperand(0), DemandedElts, InterestedClasses,
733 KnownSrc, Q, Depth + 1);
734 Known = KnownFPClass::atan(KnownSrc);
735 break;
736 }
737 case Intrinsic::atan2: {
738 FPClassTest InterestedY = InterestedClasses;
739 FPClassTest InterestedX = InterestedClasses;
740
741 // We can rule out negative values if y cannot have a negative value.
742 if ((InterestedClasses & fcNegFinite) != fcNone)
743 InterestedY |= fcNegative;
744
745 // We can rule out positive values if y cannot have a positive value.
746 if ((InterestedClasses & fcPosFinite) != fcNone)
747 InterestedY |= fcPositive | fcNegSubnormal;
748
749 // We can rule out zero and subnormal if x cannot have a positive value.
750 if ((InterestedClasses & (fcZero | fcSubnormal)) != fcNone)
751 InterestedX |= fcPositive | fcNegSubnormal;
752
753 KnownFPClass KnownY, KnownX;
754 computeKnownFPClass(II->getArgOperand(0), DemandedElts, InterestedY,
755 KnownY, Q, Depth + 1);
756 computeKnownFPClass(II->getArgOperand(1), DemandedElts, InterestedX,
757 KnownX, Q, Depth + 1);
758
759 const Function *F = II->getFunction();
761 F ? F->getDenormalMode(
762 II->getType()->getScalarType()->getFltSemantics())
764 Known = KnownFPClass::atan2(KnownY, KnownX, Mode);
765 break;
766 }
767 case Intrinsic::maxnum:
768 case Intrinsic::minnum:
769 case Intrinsic::minimum:
770 case Intrinsic::maximum:
771 case Intrinsic::minimumnum:
772 case Intrinsic::maximumnum: {
773 KnownFPClass KnownLHS, KnownRHS;
774 computeKnownFPClass(II->getArgOperand(0), DemandedElts, InterestedClasses,
775 KnownLHS, Q, Depth + 1);
776 computeKnownFPClass(II->getArgOperand(1), DemandedElts, InterestedClasses,
777 KnownRHS, Q, Depth + 1);
778
779 const Function *F = II->getFunction();
780
782 F ? F->getDenormalMode(
783 II->getType()->getScalarType()->getFltSemantics())
785
786 Known = KnownFPClass::minMaxLike(KnownLHS, KnownRHS, getMinMaxKind(IID),
787 Mode);
788 break;
789 }
790 case Intrinsic::canonicalize: {
791 KnownFPClass KnownSrc;
792 computeKnownFPClass(II->getArgOperand(0), DemandedElts, InterestedClasses,
793 KnownSrc, Q, Depth + 1);
794
795 const Function *F = II->getFunction();
796 const fltSemantics &Flt =
797 II->getType()->getScalarType()->getFltSemantics();
799 F ? F->getDenormalMode(Flt) : DenormalMode::getDynamic();
800 Known = KnownFPClass::canonicalize(KnownSrc, Flt, Mode);
801 break;
802 }
803 case Intrinsic::vector_reduce_fmax:
804 case Intrinsic::vector_reduce_fmin:
805 case Intrinsic::vector_reduce_fmaximum:
806 case Intrinsic::vector_reduce_fminimum:
807 case Intrinsic::vector_reduce_fmaximumnum:
808 case Intrinsic::vector_reduce_fminimumnum: {
809 // reduce min/max will choose an element from one of the vector elements,
810 // so we can infer and class information that is common to all elements.
811 Known = computeKnownFPClass(II->getArgOperand(0), II->getFastMathFlags(),
812 InterestedClasses, Q, Depth + 1);
813 // Can only propagate sign if output is never NaN.
814 if (!Known.isKnownNeverNaN())
815 Known.setSignBit(std::nullopt);
816 break;
817 }
818 // reverse preserves all characteristics of the input vec's element.
819 case Intrinsic::vector_reverse:
821 II->getArgOperand(0), DemandedElts.reverseBits(),
822 II->getFastMathFlags(), InterestedClasses, Q, Depth + 1);
823 break;
824 case Intrinsic::trunc:
825 case Intrinsic::floor:
826 case Intrinsic::ceil:
827 case Intrinsic::rint:
828 case Intrinsic::nearbyint:
829 case Intrinsic::round:
830 case Intrinsic::roundeven: {
831 KnownFPClass KnownSrc;
832 FPClassTest InterestedSrcs = InterestedClasses;
833
834 // Negative round ups towards zero produce negative zero.
835 if (InterestedSrcs & fcNegFinite)
836 InterestedSrcs |= fcNegFinite;
837
838 // Negative subnormals may flush to positive zero.
839 if (InterestedSrcs & fcPosFinite)
840 InterestedSrcs |= fcPosFinite | fcNegSubnormal;
841
842 computeKnownFPClass(II->getArgOperand(0), DemandedElts, InterestedSrcs,
843 KnownSrc, Q, Depth + 1);
844
845 const Function *F = II->getFunction();
847 F ? F->getDenormalMode(
848 II->getType()->getScalarType()->getFltSemantics())
850 const bool IsMultiUnitFPType =
851 V->getType()->getScalarType()->isMultiUnitFPType();
852
853 switch (IID) {
854 case Intrinsic::trunc:
855 Known = KnownFPClass::trunc(KnownSrc, Mode);
856 break;
857 case Intrinsic::floor:
858 Known = KnownFPClass::floor(KnownSrc, IsMultiUnitFPType, Mode);
859 break;
860 case Intrinsic::ceil:
861 Known = KnownFPClass::ceil(KnownSrc, IsMultiUnitFPType, Mode);
862 break;
863 default:
864 Known =
865 KnownFPClass::roundToIntegral(KnownSrc, IsMultiUnitFPType, Mode);
866 break;
867 }
868 break;
869 }
870 case Intrinsic::exp:
871 case Intrinsic::exp2:
872 case Intrinsic::exp10:
873 case Intrinsic::amdgcn_exp2: {
874 KnownFPClass KnownSrc;
875 computeKnownFPClass(II->getArgOperand(0), DemandedElts, InterestedClasses,
876 KnownSrc, Q, Depth + 1);
877
878 Known = KnownFPClass::exp(KnownSrc);
879
880 Type *EltTy = II->getType()->getScalarType();
881 if (IID == Intrinsic::amdgcn_exp2 && EltTy->isFloatTy())
882 Known.knownNot(fcSubnormal);
883
884 break;
885 }
886 case Intrinsic::fptrunc_round: {
887 Metadata *MD = cast<MetadataAsValue>(II->getArgOperand(1))->getMetadata();
888 RoundingMode RM =
889 *convertStrToRoundingMode(cast<MDString>(MD)->getString());
890 computeKnownFPClassForFPTrunc(Op, RM, DemandedElts, InterestedClasses,
891 Known, Q, Depth);
892 break;
893 }
894 case Intrinsic::log:
895 case Intrinsic::log10:
896 case Intrinsic::log2:
897 case Intrinsic::experimental_constrained_log:
898 case Intrinsic::experimental_constrained_log10:
899 case Intrinsic::experimental_constrained_log2:
900 case Intrinsic::amdgcn_log: {
901 FPClassTest InterestedSrcs = fcNone;
902
903 // log(negative) produces NaN.
904 if ((InterestedClasses & fcNan) != fcNone)
905 InterestedSrcs |= fcNan | fcNegative;
906
907 // log(logical-zero) produces negative infinity.
908 if ((InterestedClasses & fcNegInf) != fcNone)
909 InterestedSrcs |= fcZero | fcSubnormal;
910
911 // log(x) < -0.0 if x < +1.0
912 if ((InterestedClasses & fcNegNormal) != fcNone)
913 InterestedSrcs |= fcPosSubnormal | fcPosNormal;
914
915 // log(x) >= +0.0 if x >= +1.0
916 if ((InterestedClasses & (fcPosZero | fcPosNormal)) != fcNone)
917 InterestedSrcs |= fcPosNormal;
918
919 // log(x) is positive infinity iff x is positive infinity.
920 if ((InterestedClasses & fcPosInf) != fcNone)
921 InterestedSrcs |= fcPosInf;
922
923 KnownFPClass KnownSrc;
924 if (InterestedSrcs != fcNone)
925 computeKnownFPClass(II->getArgOperand(0), DemandedElts, InterestedSrcs,
926 KnownSrc, Q, Depth + 1);
927 const Function *F = II->getFunction();
929 F ? F->getDenormalMode(
930 II->getType()->getScalarType()->getFltSemantics())
932 const bool IsMultiUnitFPType =
933 V->getType()->getScalarType()->isMultiUnitFPType();
934 Known = KnownFPClass::log(KnownSrc, Mode, IsMultiUnitFPType);
935 break;
936 }
937 case Intrinsic::pow: {
938 const bool WantNaN = (InterestedClasses & fcNan) != fcNone;
939 const bool WantNegative = (InterestedClasses & fcNegative) != fcNone;
940 if (!WantNaN && !WantNegative)
941 break;
942
943 FPClassTest InterestedLHS = fcNone;
944 FPClassTest InterestedRHS = fcNone;
945 if (WantNaN) {
946 // pow may return NaN if one of the arguments is NaN. NaN may also be
947 // produced from a negative, non-zero finite base and a non-integer
948 // exponent.
949 InterestedLHS |= fcNan | fcNegNormal | fcNegSubnormal;
950 InterestedRHS |= fcNan;
951 }
952 if (WantNegative) {
953 // A negative value is returned when a negative base is raised to an odd
954 // integer power. Only normal values can be odd integers.
955 InterestedLHS |= fcNegative;
956 InterestedRHS |= fcNormal;
957 }
958
959 KnownFPClass KnownLHS;
960 computeKnownFPClass(II->getArgOperand(0), DemandedElts, InterestedLHS,
961 KnownLHS, Q, Depth + 1);
962
963 // If the LHS is unknown, then querying the RHS is only useful for rare
964 // edge cases.
965 if (KnownLHS.isUnknown())
966 break;
967
968 KnownFPClass KnownRHS;
969 computeKnownFPClass(II->getArgOperand(1), DemandedElts, InterestedRHS,
970 KnownRHS, Q, Depth + 1);
971 Known = KnownFPClass::pow(KnownLHS, KnownRHS);
972 break;
973 }
974 case Intrinsic::powi: {
975 if ((InterestedClasses & (fcNan | fcInf | fcNegative)) == fcNone)
976 break;
977
978 // The exponent is always a scalar, even when raising a vector to a power.
979 const Value *Exp = II->getArgOperand(1);
980 KnownBits ExponentKnownBits =
981 computeKnownBits(Exp, APInt(1, 1), Q, Depth + 1);
982
983 FPClassTest InterestedSrcs = fcNone;
984 if (InterestedClasses & fcNan)
985 InterestedSrcs |= fcNan;
986 if (!ExponentKnownBits.isZero()) {
987 if (InterestedClasses & fcInf)
988 InterestedSrcs |= fcFinite | fcInf;
989 if ((InterestedClasses & fcNegative) && !ExponentKnownBits.isEven())
990 InterestedSrcs |= fcNegative;
991 }
992
993 KnownFPClass KnownSrc;
994 if (InterestedSrcs != fcNone)
995 computeKnownFPClass(II->getArgOperand(0), DemandedElts, InterestedSrcs,
996 KnownSrc, Q, Depth + 1);
997
998 Known = KnownFPClass::powi(KnownSrc, ExponentKnownBits);
999 break;
1000 }
1001 case Intrinsic::ldexp: {
1002 KnownFPClass KnownSrc;
1003 computeKnownFPClass(II->getArgOperand(0), DemandedElts, InterestedClasses,
1004 KnownSrc, Q, Depth + 1);
1005 // Can refine inf/zero handling based on the exponent operand.
1006 const FPClassTest ExpInfoMask = fcZero | fcSubnormal | fcInf;
1007
1008 const Value *ExpArg = II->getArgOperand(1);
1009 ConstantRange ExpKnownRange =
1010 ((KnownSrc.getKnownFPClasses() & ExpInfoMask) != fcNone)
1011 ? computeConstantRange(ExpArg, /*ForSigned=*/true, Q, Depth + 1)
1012 : ConstantRange::getFull(
1013 ExpArg->getType()->getScalarSizeInBits());
1014
1015 const fltSemantics &Flt =
1016 II->getType()->getScalarType()->getFltSemantics();
1017
1018 const Function *F = II->getFunction();
1020 F ? F->getDenormalMode(Flt) : DenormalMode::getDynamic();
1021
1022 Known = KnownFPClass::ldexp(KnownSrc, ExpKnownRange.getSignedMin(),
1023 ExpKnownRange.getSignedMax(), Flt, Mode);
1024 break;
1025 }
1026 case Intrinsic::arithmetic_fence: {
1027 computeKnownFPClass(II->getArgOperand(0), DemandedElts, InterestedClasses,
1028 Known, Q, Depth + 1);
1029 break;
1030 }
1031 case Intrinsic::experimental_constrained_sitofp:
1032 case Intrinsic::experimental_constrained_uitofp:
1033 // Cannot produce nan
1034 Known.knownNot(fcNan);
1035
1036 // sitofp and uitofp turn into +0.0 for zero.
1037 Known.knownNot(fcNegZero);
1038
1039 // Integers cannot be subnormal
1040 Known.knownNot(fcSubnormal);
1041
1042 if (IID == Intrinsic::experimental_constrained_uitofp)
1043 Known.signBitMustBeZero();
1044
1045 // TODO: Copy inf handling from instructions
1046 break;
1047
1048 case Intrinsic::amdgcn_fract: {
1049 Known.knownNot(fcInf);
1050
1051 if (InterestedClasses & fcNan) {
1052 KnownFPClass KnownSrc;
1053 computeKnownFPClass(II->getArgOperand(0), DemandedElts,
1054 InterestedClasses, KnownSrc, Q, Depth + 1);
1055
1056 if (KnownSrc.isKnownNeverInfOrNaN())
1057 Known.knownNot(fcNan);
1058 else if (KnownSrc.isKnownNever(fcSNan))
1059 Known.knownNot(fcSNan);
1060 }
1061
1062 break;
1063 }
1064 case Intrinsic::amdgcn_rcp: {
1065 KnownFPClass KnownSrc;
1066 computeKnownFPClass(II->getArgOperand(0), DemandedElts, InterestedClasses,
1067 KnownSrc, Q, Depth + 1);
1068
1069 Known.propagateNonNaN(KnownSrc);
1070
1071 Type *EltTy = II->getType()->getScalarType();
1072
1073 // f32 denormal always flushed.
1074 if (EltTy->isFloatTy()) {
1075 Known.knownNot(fcSubnormal);
1076 KnownSrc.knownNot(fcSubnormal);
1077 }
1078
1079 if (KnownSrc.isKnownNever(fcNegative))
1080 Known.knownNot(fcNegative);
1081 if (KnownSrc.isKnownNever(fcPositive))
1082 Known.knownNot(fcPositive);
1083
1084 if (const Function *F = II->getFunction()) {
1085 DenormalMode Mode = F->getDenormalMode(EltTy->getFltSemantics());
1086 if (KnownSrc.isKnownNeverLogicalPosZero(Mode))
1087 Known.knownNot(fcPosInf);
1088 if (KnownSrc.isKnownNeverLogicalNegZero(Mode))
1089 Known.knownNot(fcNegInf);
1090 }
1091
1092 break;
1093 }
1094 case Intrinsic::amdgcn_rsq: {
1095 KnownFPClass KnownSrc;
1096 // The only negative value that can be returned is -inf for -0 inputs.
1098
1099 computeKnownFPClass(II->getArgOperand(0), DemandedElts, InterestedClasses,
1100 KnownSrc, Q, Depth + 1);
1101
1102 // Negative -> nan
1103 if (KnownSrc.isKnownNeverNaN() && KnownSrc.cannotBeOrderedLessThanZero())
1104 Known.knownNot(fcNan);
1105 else if (KnownSrc.isKnownNever(fcSNan))
1106 Known.knownNot(fcSNan);
1107
1108 // +inf -> +0
1109 if (KnownSrc.isKnownNeverPosInfinity())
1110 Known.knownNot(fcPosZero);
1111
1112 Type *EltTy = II->getType()->getScalarType();
1113
1114 // f32 denormal always flushed.
1115 if (EltTy->isFloatTy())
1116 Known.knownNot(fcPosSubnormal);
1117
1118 if (const Function *F = II->getFunction()) {
1119 DenormalMode Mode = F->getDenormalMode(EltTy->getFltSemantics());
1120
1121 // -0 -> -inf
1122 if (KnownSrc.isKnownNeverLogicalNegZero(Mode))
1123 Known.knownNot(fcNegInf);
1124
1125 // +0 -> +inf
1126 if (KnownSrc.isKnownNeverLogicalPosZero(Mode))
1127 Known.knownNot(fcPosInf);
1128 }
1129
1130 break;
1131 }
1132 case Intrinsic::amdgcn_trig_preop: {
1133 // Always returns a value [0, 1)
1134 Known.knownNot(fcNan | fcInf | fcNegative);
1135 break;
1136 }
1137 case Intrinsic::convert_from_arbitrary_fp: {
1138 auto *MD = cast<MetadataAsValue>(II->getArgOperand(1))->getMetadata();
1139 StringRef FormatStr = cast<MDString>(MD)->getString();
1140
1141 const fltSemantics *SrcSemantics =
1143 if (!SrcSemantics)
1144 break;
1145
1146 const fltSemantics DstSemantics =
1147 II->getType()->getScalarType()->getFltSemantics();
1148
1149 if (!APFloat::semanticsHasNaN(*SrcSemantics))
1150 Known.knownNot(fcNan);
1151
1152 // fcInf can only be cleared if the source format has no Inf encoding
1153 // and the dst max exp can accommodate src max exp.
1154 if (!APFloat::semanticsHasInf(*SrcSemantics) &&
1155 APFloat::semanticsMaxExponent(*SrcSemantics) <=
1156 APFloat::semanticsMaxExponent(DstSemantics))
1157 Known.knownNot(fcInf);
1158
1159 // Check and clear all neg flags for formats that do not have signed
1160 // representation.
1161 if (!APFloat::semanticsHasSignedRepr(*SrcSemantics))
1162 Known.knownNot(fcNegative);
1163
1164 // Check if format has no zero at all (Float8E8M0FNU), or no negative
1165 // zero.
1166 if (!APFloat::semanticsHasZero(*SrcSemantics))
1167 Known.knownNot(fcZero);
1168 else if (SrcSemantics->nanEncoding == fltNanEncoding::NegativeZero)
1169 Known.knownNot(fcNegZero);
1170
1171 // If src lands normally in dest, the result can never be subnormal.
1172 if (APFloat::isRepresentableAsNormalIn(*SrcSemantics, DstSemantics))
1173 Known.knownNot(fcSubnormal);
1174 break;
1175 }
1176 default:
1177 break;
1178 }
1179
1180 break;
1181 }
1182 case Instruction::FAdd:
1183 case Instruction::FSub: {
1184 computeKnownFPClassForFAddSub(Op, DemandedElts, InterestedClasses, Known, Q,
1185 Depth, /*IsAdd=*/Opc == Instruction::FAdd,
1186 /*IsStrict=*/false);
1187 break;
1188 }
1189 case Instruction::FMul: {
1190 const Function *F = cast<Instruction>(Op)->getFunction();
1192 F ? F->getDenormalMode(
1193 Op->getType()->getScalarType()->getFltSemantics())
1195
1196 Value *LHS = Op->getOperand(0);
1197 Value *RHS = Op->getOperand(1);
1198 // X * X is always non-negative or a NaN.
1199 // FIXME: Should check isGuaranteedNotToBeUndef
1200 if (LHS == RHS) {
1201 KnownFPClass KnownSrc;
1202 computeKnownFPClass(LHS, DemandedElts, fcAllFlags, KnownSrc, Q,
1203 Depth + 1);
1204 Known = KnownFPClass::square(KnownSrc, Mode);
1205 break;
1206 }
1207
1208 KnownFPClass KnownLHS, KnownRHS;
1209
1210 const APFloat *CRHS;
1211 if (match(RHS, m_APFloat(CRHS))) {
1212 computeKnownFPClass(LHS, DemandedElts, fcAllFlags, KnownLHS, Q,
1213 Depth + 1);
1214 Known = KnownFPClass::fmul(KnownLHS, *CRHS, Mode);
1215 } else {
1216 computeKnownFPClass(RHS, DemandedElts, fcAllFlags, KnownRHS, Q,
1217 Depth + 1);
1218 // TODO: Improve accuracy in unfused FMA pattern. We can prove an
1219 // additional not-nan if the addend is known-not negative infinity if the
1220 // multiply is known-not infinity.
1221
1222 computeKnownFPClass(LHS, DemandedElts, fcAllFlags, KnownLHS, Q,
1223 Depth + 1);
1224 Known = KnownFPClass::fmul(KnownLHS, KnownRHS, Mode);
1225 }
1226
1227 /// Propgate no-infs if the other source is known smaller than one, such
1228 /// that this cannot introduce overflow.
1229 if (KnownLHS.isKnownNever(fcInf) && isAbsoluteValueULEOne(RHS))
1230 Known.knownNot(fcInf);
1231 else if (KnownRHS.isKnownNever(fcInf) && isAbsoluteValueULEOne(LHS))
1232 Known.knownNot(fcInf);
1233
1234 break;
1235 }
1236 case Instruction::FDiv: {
1237 const bool WantNan = (InterestedClasses & fcNan) != fcNone;
1238
1239 const Function *F = cast<Instruction>(Op)->getFunction();
1240 const fltSemantics &FltSem =
1241 Op->getType()->getScalarType()->getFltSemantics();
1243 F ? F->getDenormalMode(FltSem) : DenormalMode::getDynamic();
1244
1245 if (Op->getOperand(0) == Op->getOperand(1) &&
1246 isGuaranteedNotToBeUndef(Op->getOperand(0), Q.AC, Q.CtxI, Q.DT)) {
1247 // X / X is always exactly 1.0 or a NaN.
1248 Known.setKnownFPClasses(fcNan | fcPosNormal);
1249
1250 if (!WantNan)
1251 break;
1252
1253 KnownFPClass KnownSrc;
1254 computeKnownFPClass(Op->getOperand(0), DemandedElts,
1255 fcNan | fcInf | fcZero | fcSubnormal, KnownSrc, Q,
1256 Depth + 1);
1257
1258 Known = KnownFPClass::fdiv_self(KnownSrc, Mode);
1259 break;
1260 }
1261
1262 const bool WantNegative = (InterestedClasses & fcNegative) != fcNone;
1263 const bool WantPositive = (InterestedClasses & fcPositive) != fcNone;
1264 if (!WantNan && !WantNegative && !WantPositive)
1265 break;
1266
1267 KnownFPClass KnownLHS, KnownRHS;
1268 computeKnownFPClass(Op->getOperand(1), DemandedElts, fcAllFlags, KnownRHS,
1269 Q, Depth + 1);
1270
1271 bool KnowSomethingUseful =
1272 KnownRHS.isKnownNever(fcSNan) ||
1275
1276 if (KnowSomethingUseful)
1277 computeKnownFPClass(Op->getOperand(0), DemandedElts, fcAllFlags, KnownLHS,
1278 Q, Depth + 1);
1279
1280 Known = KnownFPClass::fdiv(KnownLHS, KnownRHS, Mode);
1281 break;
1282 }
1283 case Instruction::FRem: {
1284 computeKnownFPClassForFRem(Op, DemandedElts, InterestedClasses, Known, Q,
1285 Depth);
1286 break;
1287 }
1288 case Instruction::FPExt: {
1289 KnownFPClass KnownSrc;
1290 computeKnownFPClass(Op->getOperand(0), DemandedElts, InterestedClasses,
1291 KnownSrc, Q, Depth + 1);
1292
1293 const fltSemantics &DstTy =
1294 Op->getType()->getScalarType()->getFltSemantics();
1295 const fltSemantics &SrcTy =
1296 Op->getOperand(0)->getType()->getScalarType()->getFltSemantics();
1297
1298 const auto *I = dyn_cast<Instruction>(Op);
1299 const Function *F = I ? I->getFunction() : nullptr;
1300 DenormalMode DstMode =
1301 F ? F->getDenormalMode(DstTy) : DenormalMode::getDynamic();
1302 DenormalMode SrcMode =
1303 F ? F->getDenormalMode(SrcTy) : DenormalMode::getDynamic();
1304
1305 Known = KnownFPClass::fpext(KnownSrc, DstTy, SrcTy, DstMode, SrcMode);
1306 break;
1307 }
1308 case Instruction::FPTrunc: {
1310 DemandedElts, InterestedClasses, Known, Q,
1311 Depth);
1312 break;
1313 }
1314 case Instruction::SIToFP:
1315 case Instruction::UIToFP: {
1316 // Cannot produce nan
1317 Known.knownNot(fcNan);
1318
1319 // Integers cannot be subnormal
1320 Known.knownNot(fcSubnormal);
1321
1322 // sitofp and uitofp turn into +0.0 for zero.
1323 Known.knownNot(fcNegZero);
1324
1325 // UIToFP is always non-negative regardless of known bits.
1326 if (Op->getOpcode() == Instruction::UIToFP)
1327 Known.signBitMustBeZero();
1328
1329 // Only compute known bits if we can learn something useful from them.
1330 if (!(InterestedClasses & (fcPosZero | fcNormal | fcInf)))
1331 break;
1332
1333 KnownBits IntKnown =
1334 computeKnownBits(Op->getOperand(0), DemandedElts, Q, Depth + 1);
1335
1336 // If the integer is non-zero, the result cannot be +0.0
1337 if (IntKnown.isNonZero())
1338 Known.knownNot(fcPosZero);
1339
1340 if (Op->getOpcode() == Instruction::SIToFP) {
1341 // If the signed integer is known non-negative, the result is
1342 // non-negative. If the signed integer is known negative, the result is
1343 // negative.
1344 if (IntKnown.isNonNegative()) {
1345 Known.signBitMustBeZero();
1346 } else if (IntKnown.isNegative()) {
1347 Known.signBitMustBeOne();
1348 }
1349 }
1350
1351 // Guard kept for ilogb()
1352 if (InterestedClasses & fcInf) {
1353 // Get width of largest magnitude integer known.
1354 // This still works for a signed minimum value because the largest FP
1355 // value is scaled by some fraction close to 2.0 (1.0 + 0.xxxx).
1356 int IntSize = IntKnown.getBitWidth();
1357 if (Op->getOpcode() == Instruction::UIToFP)
1358 IntSize -= IntKnown.countMinLeadingZeros();
1359 else if (Op->getOpcode() == Instruction::SIToFP)
1360 IntSize -= IntKnown.countMinSignBits();
1361
1362 // If the exponent of the largest finite FP value can hold the largest
1363 // integer, the result of the cast must be finite.
1364 Type *FPTy = Op->getType()->getScalarType();
1365 if (ilogb(APFloat::getLargest(FPTy->getFltSemantics())) >= IntSize)
1366 Known.knownNot(fcInf);
1367 }
1368
1369 break;
1370 }
1371 case Instruction::ExtractElement: {
1372 // Look through extract element. If the index is non-constant or
1373 // out-of-range demand all elements, otherwise just the extracted element.
1374 const Value *Vec = Op->getOperand(0);
1375
1376 APInt DemandedVecElts;
1377 if (auto *VecTy = dyn_cast<FixedVectorType>(Vec->getType())) {
1378 unsigned NumElts = VecTy->getNumElements();
1379 DemandedVecElts = APInt::getAllOnes(NumElts);
1380 auto *CIdx = dyn_cast<ConstantInt>(Op->getOperand(1));
1381 if (CIdx && CIdx->getValue().ult(NumElts))
1382 DemandedVecElts = APInt::getOneBitSet(NumElts, CIdx->getZExtValue());
1383 } else {
1384 DemandedVecElts = APInt(1, 1);
1385 }
1386
1387 return computeKnownFPClass(Vec, DemandedVecElts, InterestedClasses, Known,
1388 Q, Depth + 1);
1389 }
1390 case Instruction::InsertElement: {
1391 if (isa<ScalableVectorType>(Op->getType()))
1392 return;
1393
1394 const Value *Vec = Op->getOperand(0);
1395 const Value *Elt = Op->getOperand(1);
1396 auto *CIdx = dyn_cast<ConstantInt>(Op->getOperand(2));
1397 unsigned NumElts = DemandedElts.getBitWidth();
1398 APInt DemandedVecElts = DemandedElts;
1399 bool NeedsElt = true;
1400 // If we know the index we are inserting to, clear it from Vec check.
1401 if (CIdx && CIdx->getValue().ult(NumElts)) {
1402 DemandedVecElts.clearBit(CIdx->getZExtValue());
1403 NeedsElt = DemandedElts[CIdx->getZExtValue()];
1404 }
1405
1406 // Do we demand the inserted element?
1407 if (NeedsElt) {
1408 computeKnownFPClass(Elt, Known, InterestedClasses, Q, Depth + 1);
1409 // If we don't know any bits, early out.
1410 if (Known.isUnknown())
1411 break;
1412 } else {
1414 }
1415
1416 // Do we need anymore elements from Vec?
1417 if (!DemandedVecElts.isZero()) {
1418 KnownFPClass Known2;
1419 computeKnownFPClass(Vec, DemandedVecElts, InterestedClasses, Known2, Q,
1420 Depth + 1);
1421 Known |= Known2;
1422 }
1423
1424 break;
1425 }
1426 case Instruction::ShuffleVector: {
1427 // Handle vector splat idiom
1428 if (Value *Splat = getSplatValue(V)) {
1429 computeKnownFPClass(Splat, Known, InterestedClasses, Q, Depth + 1);
1430 break;
1431 }
1432
1433 // For undef elements, we don't know anything about the common state of
1434 // the shuffle result.
1435 APInt DemandedLHS, DemandedRHS;
1436 auto *Shuf = dyn_cast<ShuffleVectorInst>(Op);
1437 if (!Shuf ||
1438 !getShuffleDemandedElts(Shuf, DemandedElts, DemandedLHS, DemandedRHS))
1439 return;
1440
1441 if (!!DemandedLHS) {
1442 const Value *LHS = Shuf->getOperand(0);
1443 computeKnownFPClass(LHS, DemandedLHS, InterestedClasses, Known, Q,
1444 Depth + 1);
1445
1446 // If we don't know any bits, early out.
1447 if (Known.isUnknown())
1448 break;
1449 } else {
1451 }
1452
1453 if (!!DemandedRHS) {
1454 KnownFPClass Known2;
1455 const Value *RHS = Shuf->getOperand(1);
1456 computeKnownFPClass(RHS, DemandedRHS, InterestedClasses, Known2, Q,
1457 Depth + 1);
1458 Known |= Known2;
1459 }
1460
1461 break;
1462 }
1463 case Instruction::ExtractValue: {
1464 const ExtractValueInst *Extract = cast<ExtractValueInst>(Op);
1465 ArrayRef<unsigned> Indices = Extract->getIndices();
1466 const Value *Src = Extract->getAggregateOperand();
1467 if (isa<StructType>(Src->getType()) && Indices.size() == 1) {
1468 if (const auto *II = dyn_cast<IntrinsicInst>(Src)) {
1469 switch (II->getIntrinsicID()) {
1470 case Intrinsic::frexp: {
1471 if (Indices[0] != 0)
1472 break;
1473
1474 FPClassTest InterestedSrcs = InterestedClasses;
1475
1476 // Positive subnormals and negative subnormals could become positive
1477 // zero.
1478 if (InterestedClasses & fcPosZero)
1479 InterestedSrcs |= fcSubnormal;
1480
1481 // Negative subnormals could become negative zero.
1482 if (InterestedClasses & fcNegZero)
1483 InterestedSrcs |= fcNegSubnormal;
1484
1485 if (InterestedClasses & fcPosNormal)
1486 InterestedSrcs |= fcPosSubnormal;
1487
1488 if (InterestedClasses & fcNegNormal)
1489 InterestedSrcs |= fcNegSubnormal;
1490
1491 KnownFPClass KnownSrc;
1492 computeKnownFPClass(II->getArgOperand(0), DemandedElts,
1493 InterestedSrcs, KnownSrc, Q, Depth + 1);
1494
1495 const Function *F = cast<Instruction>(Op)->getFunction();
1496 const fltSemantics &FltSem =
1497 Op->getType()->getScalarType()->getFltSemantics();
1498
1500 F ? F->getDenormalMode(FltSem) : DenormalMode::getDynamic();
1501 Known = KnownFPClass::frexp_mant(KnownSrc, Mode);
1502 return;
1503 }
1504 case Intrinsic::sincospi: {
1505 FPClassTest InterestedSrcs = InterestedClasses;
1506
1507 // Infinite inputs become NaN.
1508 if (InterestedClasses & fcNan)
1509 InterestedSrcs |= fcInf;
1510
1511 KnownFPClass KnownSrc;
1512 computeKnownFPClass(II->getArgOperand(0), DemandedElts,
1513 InterestedSrcs, KnownSrc, Q, Depth + 1);
1514
1515 const bool IsMultiUnitFPType =
1516 V->getType()->getScalarType()->isMultiUnitFPType();
1517
1518 if (Indices[0] == 0)
1519 Known = KnownFPClass::sinpi(KnownSrc, IsMultiUnitFPType);
1520 else if (Indices[0] == 1)
1521 Known = KnownFPClass::cospi(KnownSrc, IsMultiUnitFPType);
1522 return;
1523 }
1524 default:
1525 break;
1526 }
1527 }
1528 }
1529
1530 computeKnownFPClass(Src, DemandedElts, InterestedClasses, Known, Q,
1531 Depth + 1);
1532 break;
1533 }
1534 case Instruction::PHI: {
1535 const PHINode *P = cast<PHINode>(Op);
1536 // Unreachable blocks may have zero-operand PHI nodes.
1537 if (P->getNumIncomingValues() == 0)
1538 break;
1539
1540 // Otherwise take the unions of the known bit sets of the operands,
1541 // taking conservative care to avoid excessive recursion.
1542 const unsigned PhiRecursionLimit = MaxAnalysisRecursionDepth - 2;
1543
1544 if (Depth < PhiRecursionLimit) {
1545 // Skip if every incoming value references to ourself.
1546 if (isa_and_nonnull<UndefValue>(P->hasConstantValue()))
1547 break;
1548
1549 bool First = true;
1550
1551 for (const Use &U : P->operands()) {
1552 Value *IncValue;
1553 Instruction *CtxI;
1554 breakSelfRecursivePHI(&U, P, IncValue, CtxI);
1555 // Skip direct self references.
1556 if (IncValue == P)
1557 continue;
1558
1559 KnownFPClass KnownSrc;
1560 // Recurse, but cap the recursion to two levels, because we don't want
1561 // to waste time spinning around in loops. We need at least depth 2 to
1562 // detect known sign bits.
1563 computeKnownFPClass(IncValue, DemandedElts, InterestedClasses, KnownSrc,
1565 PhiRecursionLimit);
1566
1567 if (First) {
1568 Known = KnownSrc;
1569 First = false;
1570 } else {
1571 Known |= KnownSrc;
1572 }
1573
1574 if (Known.getKnownFPClasses() == fcAllFlags)
1575 break;
1576 }
1577 }
1578
1579 // Look for the case of a for loop which has a positive
1580 // initial value and is incremented by a squared value.
1581 // This will propagate sign information out of such loops.
1582 if (P->getNumIncomingValues() != 2 || Known.cannotBeOrderedLessThanZero())
1583 break;
1584 for (unsigned I = 0; I < 2; I++) {
1585 Value *RecurValue = P->getIncomingValue(1 - I);
1587 if (!II)
1588 continue;
1589 Value *R, *L, *Init;
1590 PHINode *PN;
1592 PN == P) {
1593 switch (II->getIntrinsicID()) {
1594 case Intrinsic::fma:
1595 case Intrinsic::fmuladd: {
1596 KnownFPClass KnownStart;
1597 computeKnownFPClass(Init, DemandedElts, InterestedClasses, KnownStart,
1598 Q, Depth + 1);
1599 if (KnownStart.cannotBeOrderedLessThanZero() && L == R &&
1600 isGuaranteedNotToBeUndef(L, Q.AC, Q.CtxI, Q.DT, Depth + 1))
1602 break;
1603 }
1604 }
1605 }
1606 }
1607 break;
1608 }
1609 case Instruction::BitCast: {
1610 const Value *Src;
1611 if (!match(Op, m_ElementWiseBitCast(m_Value(Src))) ||
1612 !Src->getType()->isIntOrIntVectorTy())
1613 break;
1614
1615 const Type *Ty = Op->getType();
1616
1617 Value *CastLHS, *CastRHS;
1618
1619 // Match bitcast(umax(bitcast(a), bitcast(b)))
1620 if (match(Src, m_c_MaxOrMin(m_BitCast(m_Value(CastLHS)),
1621 m_BitCast(m_Value(CastRHS)))) &&
1622 CastLHS->getType() == Ty && CastRHS->getType() == Ty) {
1623 KnownFPClass KnownLHS, KnownRHS;
1624 computeKnownFPClass(CastRHS, DemandedElts, InterestedClasses, KnownRHS, Q,
1625 Depth + 1);
1626 if (!KnownRHS.isUnknown()) {
1627 computeKnownFPClass(CastLHS, DemandedElts, InterestedClasses, KnownLHS,
1628 Q, Depth + 1);
1629 Known = KnownLHS | KnownRHS;
1630 }
1631
1632 return;
1633 }
1634
1635 const Type *EltTy = Ty->getScalarType();
1636 KnownBits Bits = computeKnownBits(Src, DemandedElts, Q, Depth + 1);
1637
1639 break;
1640 }
1641 default:
1642 break;
1643 }
1644}
1645
1647 const APInt &DemandedElts,
1648 FPClassTest InterestedClasses,
1649 const SimplifyQuery &SQ,
1650 unsigned Depth) {
1651 KnownFPClass KnownClasses;
1652 ::computeKnownFPClass(V, DemandedElts, InterestedClasses, KnownClasses, SQ,
1653 Depth);
1654 return KnownClasses;
1655}
1656
1658 FPClassTest InterestedClasses,
1659 const SimplifyQuery &SQ,
1660 unsigned Depth) {
1662 ::computeKnownFPClass(V, Known, InterestedClasses, SQ, Depth);
1663 return Known;
1664}
1665
1667 const Value *V, const DataLayout &DL, FPClassTest InterestedClasses,
1668 const TargetLibraryInfo *TLI, AssumptionCache *AC, const Instruction *CtxI,
1669 const DominatorTree *DT, bool UseInstrInfo, unsigned Depth) {
1670 return computeKnownFPClass(V, InterestedClasses,
1671 SimplifyQuery(DL, TLI, DT, AC, CtxI, UseInstrInfo),
1672 Depth);
1673}
1674
1676llvm::computeKnownFPClass(const Value *V, const APInt &DemandedElts,
1677 FastMathFlags FMF, FPClassTest InterestedClasses,
1678 const SimplifyQuery &SQ, unsigned Depth) {
1679 if (FMF.noNaNs())
1680 InterestedClasses &= ~fcNan;
1681 if (FMF.noInfs())
1682 InterestedClasses &= ~fcInf;
1683
1684 KnownFPClass Result =
1685 computeKnownFPClass(V, DemandedElts, InterestedClasses, SQ, Depth);
1686
1687 if (FMF.noNaNs())
1688 Result.setKnownFPClasses(Result.getKnownFPClasses() & ~fcNan);
1689 if (FMF.noInfs())
1690 Result.setKnownFPClasses(Result.getKnownFPClasses() & ~fcInf);
1691 return Result;
1692}
1693
1695 FPClassTest InterestedClasses,
1696 const SimplifyQuery &SQ,
1697 unsigned Depth) {
1698 auto *FVTy = dyn_cast<FixedVectorType>(V->getType());
1699 APInt DemandedElts =
1700 FVTy ? APInt::getAllOnes(FVTy->getNumElements()) : APInt(1, 1);
1701 return computeKnownFPClass(V, DemandedElts, FMF, InterestedClasses, SQ,
1702 Depth);
1703}
1704
1706 unsigned Depth) {
1708 return Known.isKnownNever(fcNegZero);
1709}
1710
1712 unsigned Depth) {
1715 return Known.cannotBeOrderedLessThanZero();
1716}
1717
1719 unsigned Depth) {
1721 return Known.isKnownNeverInfinity();
1722}
1723
1724/// Return true if the floating-point value can never contain a NaN or infinity.
1726 unsigned Depth) {
1728 return Known.isKnownNeverNaN() && Known.isKnownNeverInfinity();
1729}
1730
1731/// Return true if the floating-point scalar value is not a NaN or if the
1732/// floating-point vector value has no NaN elements. Return false if a value
1733/// could ever be NaN.
1735 unsigned Depth) {
1737 return Known.isKnownNeverNaN();
1738}
1739
1740/// Return false if we can prove that the specified FP value's sign bit is 0.
1741/// Return true if we can prove that the specified FP value's sign bit is 1.
1742/// Otherwise return std::nullopt.
1743std::optional<bool> llvm::computeKnownFPSignBit(const Value *V,
1744 const SimplifyQuery &SQ,
1745 unsigned Depth) {
1747 return Known.getSignBit();
1748}
1749
1751 auto *User = cast<Instruction>(U.getUser());
1752 if (auto *FPOp = dyn_cast<FPMathOperator>(User)) {
1753 if (FPOp->hasNoSignedZeros())
1754 return true;
1755 }
1756
1757 switch (User->getOpcode()) {
1758 case Instruction::FPToSI:
1759 case Instruction::FPToUI:
1760 return true;
1761 case Instruction::FRem:
1762 // frem(x, +-0.0) == NaN, and more generally frem(x, y) == frem(x, -y).
1763 return U.getOperandNo() == 1;
1764 case Instruction::FCmp:
1765 // fcmp treats both positive and negative zero as equal.
1766 return true;
1767 case Instruction::Call:
1768 if (auto *II = dyn_cast<IntrinsicInst>(User)) {
1769 switch (II->getIntrinsicID()) {
1770 case Intrinsic::fabs:
1771 case Intrinsic::exp:
1772 case Intrinsic::exp2:
1773 case Intrinsic::exp10:
1774 case Intrinsic::log:
1775 case Intrinsic::log2:
1776 case Intrinsic::log10:
1777 case Intrinsic::cos:
1778 case Intrinsic::acos:
1779 case Intrinsic::cosh:
1780 case Intrinsic::fptosi_sat:
1781 case Intrinsic::fptoui_sat:
1782 case Intrinsic::lround:
1783 case Intrinsic::llround:
1784 case Intrinsic::lrint:
1785 case Intrinsic::llrint:
1786 return true;
1787 case Intrinsic::copysign:
1788 return U.getOperandNo() == 0;
1789 case Intrinsic::pow:
1790 // pow(x, +-0.0) == +1.0 or NaN
1791 return U.getOperandNo() == 1;
1792 case Intrinsic::is_fpclass: {
1793 auto Test =
1794 static_cast<FPClassTest>(
1795 cast<ConstantInt>(II->getArgOperand(1))->getZExtValue()) &
1798 }
1799 default:
1800 return false;
1801 }
1802 }
1803 return false;
1804 default:
1805 return false;
1806 }
1807}
1808
1810 auto *User = cast<Instruction>(U.getUser());
1811 if (auto *FPOp = dyn_cast<FPMathOperator>(User)) {
1812 if (FPOp->hasNoNaNs())
1813 return true;
1814 }
1815
1816 switch (User->getOpcode()) {
1817 case Instruction::FPToSI:
1818 case Instruction::FPToUI:
1819 return true;
1820 // Proper FP math operations ignore the sign bit of NaN.
1821 case Instruction::FAdd:
1822 case Instruction::FSub:
1823 case Instruction::FMul:
1824 case Instruction::FDiv:
1825 case Instruction::FRem:
1826 case Instruction::FPTrunc:
1827 case Instruction::FPExt:
1828 case Instruction::FCmp:
1829 return true;
1830 // Bitwise FP operations should preserve the sign bit of NaN.
1831 case Instruction::FNeg:
1832 case Instruction::Select:
1833 case Instruction::PHI:
1834 return false;
1835 case Instruction::Ret:
1836 return User->getFunction()->getAttributes().getRetNoFPClass() &
1838 case Instruction::Call:
1839 case Instruction::Invoke: {
1840 if (auto *II = dyn_cast<IntrinsicInst>(User)) {
1841 switch (II->getIntrinsicID()) {
1842 case Intrinsic::fabs:
1843 return true;
1844 case Intrinsic::copysign:
1845 return U.getOperandNo() == 0;
1846 // Other proper FP math intrinsics ignore the sign bit of NaN.
1847 case Intrinsic::maxnum:
1848 case Intrinsic::minnum:
1849 case Intrinsic::maximum:
1850 case Intrinsic::minimum:
1851 case Intrinsic::maximumnum:
1852 case Intrinsic::minimumnum:
1853 case Intrinsic::canonicalize:
1854 case Intrinsic::fptrunc_round:
1855 case Intrinsic::fma:
1856 case Intrinsic::fmuladd:
1857 case Intrinsic::ldexp:
1858 case Intrinsic::frexp:
1859 case Intrinsic::modf:
1860 case Intrinsic::sqrt:
1861 case Intrinsic::exp:
1862 case Intrinsic::exp2:
1863 case Intrinsic::exp10:
1864 case Intrinsic::log:
1865 case Intrinsic::log2:
1866 case Intrinsic::log10:
1867 case Intrinsic::pow:
1868 case Intrinsic::powi:
1869 case Intrinsic::sin:
1870 case Intrinsic::cos:
1871 case Intrinsic::sincos:
1872 case Intrinsic::sincospi:
1873 case Intrinsic::tan:
1874 case Intrinsic::asin:
1875 case Intrinsic::acos:
1876 case Intrinsic::atan:
1877 case Intrinsic::atan2:
1878 case Intrinsic::sinh:
1879 case Intrinsic::cosh:
1880 case Intrinsic::tanh:
1881 case Intrinsic::trunc:
1882 case Intrinsic::floor:
1883 case Intrinsic::ceil:
1884 case Intrinsic::round:
1885 case Intrinsic::roundeven:
1886 case Intrinsic::nearbyint:
1887 case Intrinsic::rint:
1888 case Intrinsic::fptoui_sat:
1889 case Intrinsic::fptosi_sat:
1890 case Intrinsic::lround:
1891 case Intrinsic::llround:
1892 case Intrinsic::lrint:
1893 case Intrinsic::llrint:
1894 case Intrinsic::is_fpclass:
1895 return true;
1896 default:
1897 return false;
1898 }
1899 }
1900
1901 FPClassTest NoFPClass =
1902 cast<CallBase>(User)->getParamNoFPClass(U.getOperandNo());
1903 return NoFPClass & FPClassTest::fcNan;
1904 }
1905 default:
1906 return false;
1907 }
1908}
1909
1911 FastMathFlags FMF) {
1912 if (isa<PoisonValue>(V))
1913 return true;
1914 if (isa<UndefValue>(V))
1915 return false;
1916
1917 if (match(V, m_CheckedFp([](const APFloat &Val) { return Val.isInteger(); })))
1918 return true;
1919
1921 if (!I)
1922 return false;
1923
1924 switch (I->getOpcode()) {
1925 case Instruction::SIToFP:
1926 case Instruction::UIToFP:
1927 // TODO: Could check nofpclass(inf) on incoming argument
1928 if (FMF.noInfs())
1929 return true;
1930
1931 // Need to check int size cannot produce infinity, which computeKnownFPClass
1932 // knows how to do already.
1933 return isKnownNeverInfinity(I, SQ);
1934 case Instruction::Call: {
1935 const CallInst *CI = cast<CallInst>(I);
1936 switch (CI->getIntrinsicID()) {
1937 case Intrinsic::trunc:
1938 case Intrinsic::floor:
1939 case Intrinsic::ceil:
1940 case Intrinsic::rint:
1941 case Intrinsic::nearbyint:
1942 case Intrinsic::round:
1943 case Intrinsic::roundeven:
1944 return (FMF.noInfs() && FMF.noNaNs()) || isKnownNeverInfOrNaN(I, SQ);
1945 default:
1946 break;
1947 }
1948
1949 break;
1950 }
1951 default:
1952 break;
1953 }
1954
1955 return false;
1956}
const TargetLowering & TLI
SDValue Pred
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
uint64_t uint64_t
This file implements a class to represent arbitrary precision integral constant values and operations...
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
This file contains the simple types necessary to represent the attributes associated with functions a...
static const Function * getParent(const Value *V)
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
This file contains the declarations for the subclasses of Constant, which represent the different fla...
Utilities for dealing with flags related to floating point properties and mode controls.
#define F(x, y, z)
Definition MD5.cpp:54
#define I(x, y, z)
Definition MD5.cpp:57
This file contains the declarations for metadata subclasses.
uint64_t IntrinsicInst * II
#define P(N)
SmallVector< MachineOperand, 4 > Cond
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")))
This file defines the scope_exit class, which executes user-defined cleanup logic at scope exit.
static void computeKnownFPClassForFPTrunc(const Operator *Op, RoundingMode RM, const APInt &DemandedElts, FPClassTest InterestedClasses, KnownFPClass &Known, const SimplifyQuery &Q, unsigned Depth)
static void computeKnownFPClassFromCond(const Value *V, Value *Cond, bool CondIsTrue, const Instruction *CtxI, KnownFPClass &KnownFromContext, unsigned Depth=0)
static bool isAbsoluteValueULEOne(const Value *V)
static KnownFPClass computeKnownFPClassFromContext(const Value *V, const SimplifyQuery &Q)
static constexpr KnownFPClass::MinMaxKind getMinMaxKind(Intrinsic::ID IID)
static void computeKnownFPClassForFAddSub(const Operator *Op, const APInt &DemandedElts, FPClassTest InterestedClasses, KnownFPClass &Known, const SimplifyQuery &Q, unsigned Depth, bool IsAdd, bool IsStrict)
static void computeKnownFPClassForFRem(const Operator *Op, const APInt &DemandedElts, FPClassTest InterestedClasses, KnownFPClass &Known, const SimplifyQuery &Q, unsigned Depth)
Value * RHS
Value * LHS
static LLVM_ABI bool semanticsHasInf(const fltSemantics &)
Definition APFloat.cpp:643
static LLVM_ABI bool semanticsHasSignedRepr(const fltSemantics &)
Definition APFloat.cpp:639
static LLVM_ABI ExponentType semanticsMaxExponent(const fltSemantics &)
Definition APFloat.cpp:614
static LLVM_ABI bool semanticsHasNaN(const fltSemantics &)
Definition APFloat.cpp:647
static LLVM_ABI bool semanticsHasZero(const fltSemantics &)
Definition APFloat.cpp:635
static LLVM_ABI bool isRepresentableAsNormalIn(const fltSemantics &Src, const fltSemantics &Dst)
Definition APFloat.cpp:660
static LLVM_ABI const fltSemantics * getArbitraryFPSemantics(StringRef Format)
Returns the fltSemantics for a given arbitrary FP format string, or nullptr if invalid.
Definition APFloat.cpp:6401
static APFloat getLargest(const fltSemantics &Sem, bool Negative=false)
Returns the largest finite number in the given semantics.
Definition APFloat.h:1270
bool isInteger() const
Definition APFloat.h:1628
Class for arbitrary precision integers.
Definition APInt.h:78
static APInt getAllOnes(unsigned numBits)
Return an APInt of a specified width with all bits set.
Definition APInt.h:230
void clearBit(unsigned BitPosition)
Set a given bit to 0.
Definition APInt.h:1426
bool isZero() const
Determine if this value is zero, i.e. all bits are clear.
Definition APInt.h:376
unsigned getBitWidth() const
Return the number of bits in the APInt.
Definition APInt.h:1508
LLVM_ABI APInt reverseBits() const
Definition APInt.cpp:786
static APInt getOneBitSet(unsigned numBits, unsigned BitNo)
Return an APInt with exactly one bit set in the result.
Definition APInt.h:235
Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:40
size_t size() const
Get the array size.
Definition ArrayRef.h:141
A cache of @llvm.assume calls within a function.
MutableArrayRef< ResultElem > assumptionsFor(const Value *V)
Access the list of assumptions which affect this value.
LLVM_ABI Intrinsic::ID getIntrinsicID() const
Returns the intrinsic ID of the intrinsic called or Intrinsic::not_intrinsic if the called function i...
This class represents a function call, abstracting a target machine's calling convention.
An abstraction over a floating-point predicate, and a pack of an integer predicate with samesign info...
Conditional Branch instruction.
This is the shared class of boolean and integer constants.
Definition Constants.h:87
uint64_t getZExtValue() const
Return the constant as a 64-bit unsigned integer value after it has been zero extended as appropriate...
Definition Constants.h:168
This class represents a range of values.
LLVM_ABI APInt getSignedMin() const
Return the smallest signed value contained in the ConstantRange.
LLVM_ABI APInt getSignedMax() const
Return the largest signed value contained in the ConstantRange.
This is an important base class in LLVM.
Definition Constant.h:44
LLVM_ABI Constant * getAggregateElement(unsigned Elt) const
For aggregates (struct/array/vector) return the constant that corresponds to the specified element if...
A parsed version of the target data layout string in and methods for querying it.
Definition DataLayout.h:64
ArrayRef< CondBrInst * > conditionsFor(const Value *V) const
Access the list of branches which affect this value.
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree.
Definition Dominators.h:122
LLVM_ABI bool dominates(const BasicBlock *BB, const Use &U) const
Return true if the (end of the) basic block BB dominates the use U.
This instruction extracts a struct member or array element value from an aggregate value.
ArrayRef< unsigned > getIndices() const
Utility class for floating point operations which can have information about relaxed accuracy require...
Definition Operator.h:202
Convenience struct for specifying and reasoning about fast-math flags.
Definition FMF.h:23
bool noInfs() const
Definition FMF.h:66
bool noNaNs() const
Definition FMF.h:65
A wrapper class for inspecting calls to intrinsic functions.
bool isKnownNeverInfOrNaN() const
Return true if it's known this can never be an infinity or nan.
static LLVM_ABI KnownFPClass atan2(const KnownFPClass &LHS, const KnownFPClass &RHS, DenormalMode Mode)
Report known values for atan2.
static LLVM_ABI KnownFPClass fma(const KnownFPClass &LHS, const KnownFPClass &RHS, const KnownFPClass &Addend, DenormalMode Mode)
Report known values for fma.
static LLVM_ABI KnownFPClass sin(const KnownFPClass &Src)
Report known values for sin.
static LLVM_ABI KnownFPClass fptrunc(const KnownFPClass &KnownSrc, const fltSemantics &DstTy, const fltSemantics &SrcTy, RoundingMode RM, DenormalMode DstMode, DenormalMode SrcMode)
Propagate known class for fptrunc and fptrunc_round.
static constexpr FPClassTest OrderedLessThanZeroMask
static LLVM_ABI KnownFPClass trunc(const KnownFPClass &Src, DenormalMode Mode)
Propagate known class for trunc.
static LLVM_ABI KnownFPClass fadd(const KnownFPClass &LHS, const KnownFPClass &RHS, RoundingMode RM, DenormalMode Mode)
Report known values for fadd.
static LLVM_ABI KnownFPClass fsub(const KnownFPClass &LHS, const KnownFPClass &RHS, RoundingMode RM, DenormalMode Mode)
Report known values for fsub.
static LLVM_ABI KnownFPClass fma_square(const KnownFPClass &Squared, const KnownFPClass &Addend, DenormalMode Mode)
Report known values for fma squared, squared, addend.
KnownFPClass unionWith(const KnownFPClass &RHS) const
static LLVM_ABI KnownFPClass fadd_self(const KnownFPClass &Src, RoundingMode RM, DenormalMode Mode)
Report known values for fadd x, x.
static LLVM_ABI KnownFPClass frem(const KnownFPClass &LHS, const KnownFPClass &RHS, DenormalMode Mode)
Report known values for frem.
static LLVM_ABI KnownFPClass atan(const KnownFPClass &Src)
Report known values for atan.
static LLVM_ABI KnownFPClass ldexp(const KnownFPClass &Src, const APInt &ConstantRangeMin, const APInt &ConstantRangeMax, const fltSemantics &Flt, DenormalMode Mode)
Propagate known class for ldexp, assuming the exponent is known to be within [ConstantRangeMin,...
static LLVM_ABI KnownFPClass frexp_mant(const KnownFPClass &Src, DenormalMode Mode)
Propagate known class for mantissa component of frexp.
static LLVM_ABI KnownFPClass roundToIntegral(const KnownFPClass &Src, bool IsMultiUnitFPType, DenormalMode Mode)
Propagate known class for rounding intrinsics (rint, nearbyint, round, roundeven).
static LLVM_ABI KnownFPClass sinpi(const KnownFPClass &Src, bool IsMultiUnitFPType)
Report known values for sinpi.
static LLVM_ABI KnownFPClass fmuladd(const KnownFPClass &LHS, const KnownFPClass &RHS, const KnownFPClass &Addend, DenormalMode Mode)
Report known values for fmuladd.
static LLVM_ABI KnownFPClass ceil(const KnownFPClass &Src, bool IsMultiUnitFPType, DenormalMode Mode)
Propagate known class for ceil.
static LLVM_ABI KnownFPClass fmuladd_square(const KnownFPClass &Squared, const KnownFPClass &Addend, DenormalMode Mode)
Report known values for fmuladd squared, squared, addend.
static LLVM_ABI KnownFPClass fpext(const KnownFPClass &KnownSrc, const fltSemantics &DstTy, const fltSemantics &SrcTy, DenormalMode DstMode, DenormalMode SrcMode)
Propagate known class for fpext.
static LLVM_ABI KnownFPClass cos(const KnownFPClass &Src)
Report known values for cos.
static LLVM_ABI KnownFPClass cosh(const KnownFPClass &Src)
Report known values for cosh.
bool isUnknown() const
static LLVM_ABI KnownFPClass exp(const KnownFPClass &Src)
Report known values for exp, exp2 and exp10.
static LLVM_ABI KnownFPClass asin(const KnownFPClass &Src)
Report known values for asin.
bool isKnownNeverNaN() const
Return true if it's known this can never be a nan.
static LLVM_ABI KnownFPClass minMaxLike(const KnownFPClass &LHS, const KnownFPClass &RHS, MinMaxKind Kind, DenormalMode Mode)
void knownNot(FPClassMask RuleOut)
static LLVM_ABI KnownFPClass canonicalize(const KnownFPClass &Src, const fltSemantics &Flt, DenormalMode Mode)
Apply the canonicalize intrinsic to this value.
std::optional< bool > getSignBit() const
std::nullopt if the sign bit is unknown, true if the sign bit is definitely set or false if the sign ...
static LLVM_ABI KnownFPClass floor(const KnownFPClass &Src, bool IsMultiUnitFPType, DenormalMode Mode)
Propagate known class for floor.
FPClassTest getKnownFPClasses() const
Floating-point classes the value could be one of.
static KnownFPClass getEmpty()
static LLVM_ABI KnownFPClass cospi(const KnownFPClass &Src, bool IsMultiUnitFPType)
Report known values for cospi.
static LLVM_ABI KnownFPClass tan(const KnownFPClass &Src)
Report known values for tan.
bool cannotBeOrderedLessThanZero() const
Return true if we can prove that the analyzed floating-point value is either NaN or never less than -...
void signBitMustBeOne()
Assume the sign bit is one.
static LLVM_ABI KnownFPClass fdiv_self(const KnownFPClass &Src, DenormalMode Mode)
Report known values for fdiv x, x.
void signBitMustBeZero()
Assume the sign bit is zero.
static LLVM_ABI KnownFPClass sqrt(const KnownFPClass &Src, DenormalMode Mode=DenormalMode::getDynamic())
Propagate known class for sqrt.
LLVM_ABI bool isKnownNeverLogicalPosZero(DenormalMode Mode) const
Return true if it's known this can never be interpreted as a positive zero.
bool isKnownNever(FPClassMask Mask) const
Return true if it's known this can never be one of the mask entries.
bool isKnownNeverPosInfinity() const
Return true if it's known this can never be +infinity.
LLVM_ABI bool isKnownNeverLogicalNegZero(DenormalMode Mode) const
Return true if it's known this can never be interpreted as a negative zero.
static LLVM_ABI KnownFPClass bitcast(const fltSemantics &FltSemantics, const KnownBits &Bits)
Report known values for a bitcast into a float with provided semantics.
static LLVM_ABI KnownFPClass square(const KnownFPClass &Src, DenormalMode Mode)
static LLVM_ABI KnownFPClass acos(const KnownFPClass &Src)
Report known values for acos.
static LLVM_ABI KnownFPClass log(const KnownFPClass &Src, DenormalMode Mode, bool IsMultiUnitFPType)
Propagate known class for log/log2/log10.
static LLVM_ABI KnownFPClass frem_self(const KnownFPClass &Src, DenormalMode Mode)
Report known values for frem x, x. Valid for all rounding modes.
static LLVM_ABI KnownFPClass powi(const KnownFPClass &Src, const KnownBits &N)
Propagate known class for powi.
static LLVM_ABI KnownFPClass fdiv(const KnownFPClass &LHS, const KnownFPClass &RHS, DenormalMode Mode)
Report known values for fdiv.
static LLVM_ABI KnownFPClass fmul(const KnownFPClass &LHS, const KnownFPClass &RHS, DenormalMode Mode)
Report known values for fmul.
static LLVM_ABI KnownFPClass pow(const KnownFPClass &LHS, const KnownFPClass &RHS)
Propagate known class for pow.
static LLVM_ABI KnownFPClass sinh(const KnownFPClass &Src)
Report known values for sinh.
static LLVM_ABI KnownFPClass tanh(const KnownFPClass &Src)
Report known values for tanh.
Metadata node.
Definition Metadata.h:1087
const MDOperand & getOperand(unsigned I) const
Definition Metadata.h:1443
Root of the metadata hierarchy.
Definition Metadata.h:65
This is a utility class that provides an abstraction for the common functionality between Instruction...
Definition Operator.h:33
bool contains(ConstPtrType Ptr) const
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
Provides information about what library functions are available for the current target.
The instances of the Type class are immutable: once they are created, they are never changed.
Definition Type.h:46
bool isFloatTy() const
Return true if this is 'float', a 32-bit IEEE fp type.
Definition Type.h:155
unsigned getScalarSizeInBits() const LLVM_READONLY
If this is a vector type, return the getPrimitiveSizeInBits value for the element type.
Definition Type.h:354
Type * getScalarType() const
If this is a vector type, return the element type, otherwise return 'this'.
Definition Type.h:370
LLVM_ABI const fltSemantics & getFltSemantics() const
Definition Type.cpp:96
A Use represents the edge between a Value definition and its users.
Definition Use.h:35
LLVM Value Representation.
Definition Value.h:75
Type * getType() const
All values are typed, get the type of this value.
Definition Value.h:257
const ParentTy * getParent() const
Definition ilist_node.h:34
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
BinaryOp_match< SrcTy, SpecificConstantMatch, TargetOpcode::G_XOR, true > m_Not(const SrcTy &&Src)
Matches a register not-ed by a G_XOR.
CmpClass_match< LHS, RHS, FCmpInst > m_FCmp(CmpPredicate &Pred, const LHS &L, const RHS &R)
BinaryOp_match< LHS, RHS, Instruction::FSub > m_FSub(const LHS &L, const RHS &R)
ap_match< APInt > m_APInt(const APInt *&Res)
Match a ConstantInt or splatted ConstantVector, binding the specified pointer to the contained APInt.
bool match(Val *V, const Pattern &P)
match_deferred< Value > m_Deferred(Value *const &V)
Like m_Specific(), but works if the specific value to match is determined as part of the same match()...
specificval_ty m_Specific(const Value *V)
Match if we have a specific specified value.
ap_match< APFloat > m_APFloat(const APFloat *&Res)
Match a ConstantFP or splatted ConstantVector, binding the specified pointer to the contained APFloat...
auto m_Value()
Match an arbitrary value and ignore it.
auto m_LogicalOr()
Matches L || R where L and R are arbitrary values.
CastOperator_match< OpTy, Instruction::BitCast > m_BitCast(const OpTy &Op)
Matches BitCast.
auto m_Intrinsic(const Ts &...Ops)
Match intrinsic calls like this: m_Intrinsic<Intrinsic::fabs>(m_Value(X))
auto m_c_MaxOrMin(const LHS &L, const RHS &R)
cstfp_pred_ty< custom_checkfn< APFloat > > m_CheckedFp(function_ref< bool(const APFloat &)> CheckFn)
Match a float or vector where CheckFn(ele) for each element is true.
CmpClass_match< LHS, RHS, ICmpInst > m_ICmp(CmpPredicate &Pred, const LHS &L, const RHS &R)
auto m_LogicalAnd()
Matches L && R where L and R are arbitrary values.
ElementWiseBitCast_match< OpTy > m_ElementWiseBitCast(const OpTy &Op)
auto m_ConstantInt()
Match an arbitrary ConstantInt and ignore it.
std::enable_if_t< detail::IsValidPointer< X, Y >::value, X * > extract(Y &&MD)
Extract a Value from Metadata.
Definition Metadata.h:680
This is an optimization pass for GlobalISel generic memory operations.
LLVM_ABI KnownFPClass computeKnownFPClass(const Value *V, const APInt &DemandedElts, FPClassTest InterestedClasses, const SimplifyQuery &SQ, unsigned Depth=0)
Determine which floating-point classes are valid for V, and return them in KnownFPClass bit sets.
LLVM_ABI bool isKnownNeverInfinity(const Value *V, const SimplifyQuery &SQ, unsigned Depth=0)
Return true if the floating-point scalar value is not an infinity or if the floating-point vector val...
LLVM_ABI bool isSignBitCheck(ICmpInst::Predicate Pred, const APInt &RHS, bool &TrueIfSigned)
Given an exploded icmp instruction, return true if the comparison only checks the sign bit.
@ Known
Known to have no common set bits.
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:643
LLVM_ABI void computeKnownBits(const Value *V, KnownBits &Known, const DataLayout &DL, AssumptionCache *AC=nullptr, const Instruction *CtxI=nullptr, const DominatorTree *DT=nullptr, bool UseInstrInfo=true, unsigned Depth=0)
Determine which bits of V are known to be either zero or one and return them in the KnownZero/KnownOn...
int ilogb(const APFloat &Arg)
Returns the exponent of the internal representation of the APFloat.
Definition APFloat.h:1735
LLVM_ABI Value * getSplatValue(const Value *V)
Get splat value if the input is a splat vector or return nullptr.
bool isa_and_nonnull(const Y &Val)
Definition Casting.h:676
LLVM_ABI bool canIgnoreSignBitOfZero(const Use &U)
Return true if the sign bit of the FP value can be ignored by the user when the value is zero.
LLVM_ABI bool isGuaranteedNotToBeUndef(const Value *V, AssumptionCache *AC=nullptr, const Instruction *CtxI=nullptr, const DominatorTree *DT=nullptr, unsigned Depth=0)
Returns true if V cannot be undef, but may be poison.
std::tuple< Value *, FPClassTest, FPClassTest > fcmpImpliesClass(CmpInst::Predicate Pred, const Function &F, Value *LHS, FPClassTest RHSClass, bool LookThroughSrc=true)
LLVM_ABI bool isValidAssumeForContext(const Instruction *I, const Instruction *CtxI, const DominatorTree *DT=nullptr, bool AllowEphemerals=false)
Return true if it is valid to use the assumptions provided by an assume intrinsic,...
auto dyn_cast_or_null(const Y &Val)
Definition Casting.h:753
LLVM_ABI bool getShuffleDemandedElts(int SrcWidth, ArrayRef< int > Mask, const APInt &DemandedElts, APInt &DemandedLHS, APInt &DemandedRHS, bool AllowUndefElts=false)
Transform a shuffle mask's output demanded element mask into demanded element masks for the 2 operand...
constexpr unsigned MaxAnalysisRecursionDepth
FPOp
The floating-point operations supported by the folding helpers.
Definition FPFold.h:25
FPClassTest
Floating-point class tests, supported by 'is_fpclass' intrinsic.
LLVM_ABI bool cannotBeNegativeZero(const Value *V, const SimplifyQuery &SQ, unsigned Depth=0)
Return true if we can prove that the specified FP value is never equal to -0.0.
LLVM_ABI void adjustKnownFPClassForSelectArm(KnownFPClass &Known, Value *Cond, Value *Arm, bool Invert, const SimplifyQuery &Q, unsigned Depth=0)
Adjust Known for the given select Arm to include information from the select Cond.
LLVM_ABI bool matchSimpleTernaryIntrinsicRecurrence(const IntrinsicInst *I, PHINode *&P, Value *&Init, Value *&OtherOp0, Value *&OtherOp1)
Attempt to match a simple value-accumulating recurrence of the form: llvm.intrinsic....
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
Definition Casting.h:547
@ First
Helpers to iterate all locations in the MemoryEffectsBase class.
Definition ModRef.h:74
DWARFExpression::Operation Op
RoundingMode
Rounding mode.
@ NearestTiesToEven
roundTiesToEven.
@ Dynamic
Denotes mode unknown at compile time.
LLVM_ABI bool isKnownNeverInfOrNaN(const Value *V, const SimplifyQuery &SQ, unsigned Depth=0)
Return true if the floating-point value can never contain a NaN or infinity.
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:559
LLVM_ABI bool isKnownNeverNaN(const Value *V, const SimplifyQuery &SQ, unsigned Depth=0)
Return true if the floating-point scalar value is not a NaN or if the floating-point vector value has...
LLVM_ABI std::optional< RoundingMode > convertStrToRoundingMode(StringRef)
Returns a valid RoundingMode enumerator when given a string that is valid as input in constrained int...
Definition FPEnv.cpp:25
LLVM_ABI bool isKnownIntegral(const Value *V, const SimplifyQuery &SQ, FastMathFlags FMF)
Return true if the floating-point value V is known to be an integer value.
LLVM_ABI bool cannotBeOrderedLessThanZero(const Value *V, const SimplifyQuery &SQ, unsigned Depth=0)
Return true if we can prove that the specified FP value is either NaN or never less than -0....
LLVM_ABI void breakSelfRecursivePHI(const Use *U, const PHINode *PHI, Value *&ValOut, Instruction *&CtxIOut, const PHINode **PhiOut=nullptr)
Choose the value to analyze for the incoming use U of PHI, avoiding recursion back into PHI.
LLVM_ABI std::optional< bool > computeKnownFPSignBit(const Value *V, const SimplifyQuery &SQ, unsigned Depth=0)
Return false if we can prove that the specified FP value's sign bit is 0.
LLVM_ABI bool canIgnoreSignBitOfNaN(const Use &U)
Return true if the sign bit of the FP value can be ignored by the user when the value is NaN.
LLVM_ABI ConstantRange computeConstantRange(const Value *V, bool ForSigned, const SimplifyQuery &SQ, unsigned Depth=0)
Determine the possible constant range of an integer or vector of integer value.
SmallPtrSet< Value *, 4 > AffectedValues
Represent subnormal handling kind for floating point instruction inputs and outputs.
static constexpr DenormalMode getDynamic()
bool hasNoSignedZeros(const InstT *Op) const
unsigned countMinSignBits() const
Returns the number of times the sign bit is replicated into the other bits.
Definition KnownBits.h:269
bool isNonNegative() const
Returns true if this value is known to be non-negative.
Definition KnownBits.h:106
bool isZero() const
Returns true if value is all zero.
Definition KnownBits.h:78
unsigned getBitWidth() const
Get the bit width of this value.
Definition KnownBits.h:44
bool isNonZero() const
Returns true if this value is known to be non-zero.
Definition KnownBits.h:109
bool isEven() const
Return if the value is known even (the low bit is 0).
Definition KnownBits.h:162
unsigned countMinLeadingZeros() const
Returns the minimum number of leading zero bits.
Definition KnownBits.h:262
bool isNegative() const
Returns true if this value is known to be negative.
Definition KnownBits.h:103
SimplifyQuery getWithoutCondContext() const
const DominatorTree * DT
SimplifyQuery getWithInstruction(const Instruction *I) const
AssumptionCache * AC
const DomConditionCache * DC
const Instruction * CtxI
const InstrInfoQuery IIQ
const CondContext * CC
fltNanEncoding nanEncoding
Definition APFloat.h:1066