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 // FIXME: This should check isGuaranteedNotToBeUndef
568 if (II->getArgOperand(0) == II->getArgOperand(1)) {
569 FPClassTest InterestedSquared = InterestedClasses;
570 FPClassTest InterestedAddend = InterestedClasses;
571 // Only fma(+inf, +inf, -inf) and fma(-inf, -inf, -inf) produce NaN when
572 // squaring.
573 if (InterestedClasses & fcQNan) {
574 InterestedSquared |= fcSNan | fcInf;
575 InterestedAddend |= fcSNan | fcNegInf;
576 }
577
578 KnownFPClass KnownSrc, KnownAddend;
579 computeKnownFPClass(II->getArgOperand(2), DemandedElts,
580 InterestedAddend, KnownAddend, Q, Depth + 1);
581 computeKnownFPClass(II->getArgOperand(0), DemandedElts,
582 InterestedSquared, KnownSrc, Q, Depth + 1);
583
584 const Function *F = II->getFunction();
585 const fltSemantics &FltSem =
586 II->getType()->getScalarType()->getFltSemantics();
588 F ? F->getDenormalMode(FltSem) : DenormalMode::getDynamic();
589
590 if ((KnownNotFromFlags & fcNan) == fcNan) {
591 KnownSrc.knownNot(fcNan);
592 KnownAddend.knownNot(fcNan);
593 }
594
595 if ((KnownNotFromFlags & fcInf) == fcInf) {
596 KnownSrc.knownNot(fcInf);
597 KnownAddend.knownNot(fcInf);
598 }
599
600 Known = IsFMA
601 ? KnownFPClass::fma_square(KnownSrc, KnownAddend, Mode)
602 : KnownFPClass::fmuladd_square(KnownSrc, KnownAddend, Mode);
603 break;
604 }
605
606 KnownFPClass KnownSrc[3];
607 for (int I = 0; I != 3; ++I) {
608 computeKnownFPClass(II->getArgOperand(I), DemandedElts,
609 InterestedClasses, KnownSrc[I], Q, Depth + 1);
610 if (KnownSrc[I].isUnknown())
611 return;
612
613 if ((KnownNotFromFlags & fcNan) == fcNan)
614 KnownSrc[I].knownNot(fcNan);
615 if ((KnownNotFromFlags & fcInf) == fcInf)
616 KnownSrc[I].knownNot(fcInf);
617 }
618
619 const Function *F = II->getFunction();
620 const fltSemantics &FltSem =
621 II->getType()->getScalarType()->getFltSemantics();
623 F ? F->getDenormalMode(FltSem) : DenormalMode::getDynamic();
624 Known =
625 IsFMA ? KnownFPClass::fma(KnownSrc[0], KnownSrc[1], KnownSrc[2], Mode)
626 : KnownFPClass::fmuladd(KnownSrc[0], KnownSrc[1], KnownSrc[2],
627 Mode);
628 break;
629 }
630 case Intrinsic::experimental_constrained_fadd:
631 case Intrinsic::experimental_constrained_fsub: {
633 Op, DemandedElts, InterestedClasses, Known, Q, Depth,
634 /*IsAdd=*/IID == Intrinsic::experimental_constrained_fadd,
635 /*IsStrict=*/true);
636 break;
637 }
638 case Intrinsic::experimental_constrained_frem: {
639 computeKnownFPClassForFRem(Op, DemandedElts, InterestedClasses, Known, Q,
640 Depth);
641 break;
642 }
643 case Intrinsic::sqrt:
644 case Intrinsic::experimental_constrained_sqrt: {
645 KnownFPClass KnownSrc;
646 FPClassTest InterestedSrcs = InterestedClasses;
647 if (InterestedClasses & fcQNan)
649 // Subnormals may flush to zero.
650 if (InterestedClasses & fcZero)
651 InterestedSrcs |= fcSubnormal;
652
653 computeKnownFPClass(II->getArgOperand(0), DemandedElts, InterestedSrcs,
654 KnownSrc, Q, Depth + 1);
655
657
658 bool HasNSZ = Q.IIQ.hasNoSignedZeros(II);
659 if (!HasNSZ) {
660 const Function *F = II->getFunction();
661 const fltSemantics &FltSem =
662 II->getType()->getScalarType()->getFltSemantics();
663 Mode = F ? F->getDenormalMode(FltSem) : DenormalMode::getDynamic();
664 }
665
666 Known = KnownFPClass::sqrt(KnownSrc, Mode);
667 if (HasNSZ)
668 Known.knownNot(fcNegZero);
669
670 break;
671 }
672 case Intrinsic::sin: {
673 KnownFPClass KnownSrc;
674 computeKnownFPClass(II->getArgOperand(0), DemandedElts, InterestedClasses,
675 KnownSrc, Q, Depth + 1);
676 Known = KnownFPClass::sin(KnownSrc);
677 break;
678 }
679 case Intrinsic::cos: {
680 KnownFPClass KnownSrc;
681 computeKnownFPClass(II->getArgOperand(0), DemandedElts, InterestedClasses,
682 KnownSrc, Q, Depth + 1);
683 Known = KnownFPClass::cos(KnownSrc);
684 break;
685 }
686 case Intrinsic::tan: {
687 KnownFPClass KnownSrc;
688 computeKnownFPClass(II->getArgOperand(0), DemandedElts, InterestedClasses,
689 KnownSrc, Q, Depth + 1);
690 Known = KnownFPClass::tan(KnownSrc);
691 break;
692 }
693 case Intrinsic::sinh: {
694 KnownFPClass KnownSrc;
695 computeKnownFPClass(II->getArgOperand(0), DemandedElts, InterestedClasses,
696 KnownSrc, Q, Depth + 1);
697 Known = KnownFPClass::sinh(KnownSrc);
698 break;
699 }
700 case Intrinsic::cosh: {
701 KnownFPClass KnownSrc;
702 computeKnownFPClass(II->getArgOperand(0), DemandedElts, InterestedClasses,
703 KnownSrc, Q, Depth + 1);
704 Known = KnownFPClass::cosh(KnownSrc);
705 break;
706 }
707 case Intrinsic::tanh: {
708 KnownFPClass KnownSrc;
709 computeKnownFPClass(II->getArgOperand(0), DemandedElts, InterestedClasses,
710 KnownSrc, Q, Depth + 1);
711 Known = KnownFPClass::tanh(KnownSrc);
712 break;
713 }
714 case Intrinsic::asin: {
715 KnownFPClass KnownSrc;
716 computeKnownFPClass(II->getArgOperand(0), DemandedElts, InterestedClasses,
717 KnownSrc, Q, Depth + 1);
718 Known = KnownFPClass::asin(KnownSrc);
719 break;
720 }
721 case Intrinsic::acos: {
722 KnownFPClass KnownSrc;
723 computeKnownFPClass(II->getArgOperand(0), DemandedElts, InterestedClasses,
724 KnownSrc, Q, Depth + 1);
725 Known = KnownFPClass::acos(KnownSrc);
726 break;
727 }
728 case Intrinsic::atan: {
729 KnownFPClass KnownSrc;
730 computeKnownFPClass(II->getArgOperand(0), DemandedElts, InterestedClasses,
731 KnownSrc, Q, Depth + 1);
732 Known = KnownFPClass::atan(KnownSrc);
733 break;
734 }
735 case Intrinsic::atan2: {
736 FPClassTest InterestedY = InterestedClasses;
737 FPClassTest InterestedX = InterestedClasses;
738
739 // We can rule out negative values if y cannot have a negative value.
740 if ((InterestedClasses & fcNegFinite) != fcNone)
741 InterestedY |= fcNegative;
742
743 // We can rule out positive values if y cannot have a positive value.
744 if ((InterestedClasses & fcPosFinite) != fcNone)
745 InterestedY |= fcPositive | fcNegSubnormal;
746
747 // We can rule out zero and subnormal if x cannot have a positive value.
748 if ((InterestedClasses & (fcZero | fcSubnormal)) != fcNone)
749 InterestedX |= fcPositive | fcNegSubnormal;
750
751 KnownFPClass KnownY, KnownX;
752 computeKnownFPClass(II->getArgOperand(0), DemandedElts, InterestedY,
753 KnownY, Q, Depth + 1);
754 computeKnownFPClass(II->getArgOperand(1), DemandedElts, InterestedX,
755 KnownX, Q, Depth + 1);
756
757 const Function *F = II->getFunction();
759 F ? F->getDenormalMode(
760 II->getType()->getScalarType()->getFltSemantics())
762 Known = KnownFPClass::atan2(KnownY, KnownX, Mode);
763 break;
764 }
765 case Intrinsic::maxnum:
766 case Intrinsic::minnum:
767 case Intrinsic::minimum:
768 case Intrinsic::maximum:
769 case Intrinsic::minimumnum:
770 case Intrinsic::maximumnum: {
771 KnownFPClass KnownLHS, KnownRHS;
772 computeKnownFPClass(II->getArgOperand(0), DemandedElts, InterestedClasses,
773 KnownLHS, Q, Depth + 1);
774 computeKnownFPClass(II->getArgOperand(1), DemandedElts, InterestedClasses,
775 KnownRHS, Q, Depth + 1);
776
777 const Function *F = II->getFunction();
778
780 F ? F->getDenormalMode(
781 II->getType()->getScalarType()->getFltSemantics())
783
784 Known = KnownFPClass::minMaxLike(KnownLHS, KnownRHS, getMinMaxKind(IID),
785 Mode);
786 break;
787 }
788 case Intrinsic::canonicalize: {
789 KnownFPClass KnownSrc;
790 computeKnownFPClass(II->getArgOperand(0), DemandedElts, InterestedClasses,
791 KnownSrc, Q, Depth + 1);
792
793 const Function *F = II->getFunction();
794 const fltSemantics &Flt =
795 II->getType()->getScalarType()->getFltSemantics();
797 F ? F->getDenormalMode(Flt) : DenormalMode::getDynamic();
798 Known = KnownFPClass::canonicalize(KnownSrc, Flt, Mode);
799 break;
800 }
801 case Intrinsic::vector_reduce_fmax:
802 case Intrinsic::vector_reduce_fmin:
803 case Intrinsic::vector_reduce_fmaximum:
804 case Intrinsic::vector_reduce_fminimum:
805 case Intrinsic::vector_reduce_fmaximumnum:
806 case Intrinsic::vector_reduce_fminimumnum: {
807 // reduce min/max will choose an element from one of the vector elements,
808 // so we can infer and class information that is common to all elements.
809 Known = computeKnownFPClass(II->getArgOperand(0), II->getFastMathFlags(),
810 InterestedClasses, Q, Depth + 1);
811 // Can only propagate sign if output is never NaN.
812 if (!Known.isKnownNeverNaN())
813 Known.setSignBit(std::nullopt);
814 break;
815 }
816 // reverse preserves all characteristics of the input vec's element.
817 case Intrinsic::vector_reverse:
819 II->getArgOperand(0), DemandedElts.reverseBits(),
820 II->getFastMathFlags(), InterestedClasses, Q, Depth + 1);
821 break;
822 case Intrinsic::trunc:
823 case Intrinsic::floor:
824 case Intrinsic::ceil:
825 case Intrinsic::rint:
826 case Intrinsic::nearbyint:
827 case Intrinsic::round:
828 case Intrinsic::roundeven: {
829 KnownFPClass KnownSrc;
830 FPClassTest InterestedSrcs = InterestedClasses;
831
832 // Negative round ups towards zero produce negative zero.
833 if (InterestedSrcs & fcNegFinite)
834 InterestedSrcs |= fcNegFinite;
835
836 // Negative subnormals may flush to positive zero.
837 if (InterestedSrcs & fcPosFinite)
838 InterestedSrcs |= fcPosFinite | fcNegSubnormal;
839
840 computeKnownFPClass(II->getArgOperand(0), DemandedElts, InterestedSrcs,
841 KnownSrc, Q, Depth + 1);
842
843 const Function *F = II->getFunction();
845 F ? F->getDenormalMode(
846 II->getType()->getScalarType()->getFltSemantics())
848 const bool IsMultiUnitFPType =
849 V->getType()->getScalarType()->isMultiUnitFPType();
850
851 switch (IID) {
852 case Intrinsic::trunc:
853 Known = KnownFPClass::trunc(KnownSrc, Mode);
854 break;
855 case Intrinsic::floor:
856 Known = KnownFPClass::floor(KnownSrc, IsMultiUnitFPType, Mode);
857 break;
858 case Intrinsic::ceil:
859 Known = KnownFPClass::ceil(KnownSrc, IsMultiUnitFPType, Mode);
860 break;
861 default:
862 Known =
863 KnownFPClass::roundToIntegral(KnownSrc, IsMultiUnitFPType, Mode);
864 break;
865 }
866 break;
867 }
868 case Intrinsic::exp:
869 case Intrinsic::exp2:
870 case Intrinsic::exp10:
871 case Intrinsic::amdgcn_exp2: {
872 KnownFPClass KnownSrc;
873 computeKnownFPClass(II->getArgOperand(0), DemandedElts, InterestedClasses,
874 KnownSrc, Q, Depth + 1);
875
876 Known = KnownFPClass::exp(KnownSrc);
877
878 Type *EltTy = II->getType()->getScalarType();
879 if (IID == Intrinsic::amdgcn_exp2 && EltTy->isFloatTy())
880 Known.knownNot(fcSubnormal);
881
882 break;
883 }
884 case Intrinsic::fptrunc_round: {
885 Metadata *MD = cast<MetadataAsValue>(II->getArgOperand(1))->getMetadata();
886 RoundingMode RM =
887 *convertStrToRoundingMode(cast<MDString>(MD)->getString());
888 computeKnownFPClassForFPTrunc(Op, RM, DemandedElts, InterestedClasses,
889 Known, Q, Depth);
890 break;
891 }
892 case Intrinsic::log:
893 case Intrinsic::log10:
894 case Intrinsic::log2:
895 case Intrinsic::experimental_constrained_log:
896 case Intrinsic::experimental_constrained_log10:
897 case Intrinsic::experimental_constrained_log2:
898 case Intrinsic::amdgcn_log: {
899 FPClassTest InterestedSrcs = fcNone;
900
901 // log(negative) produces NaN.
902 if ((InterestedClasses & fcNan) != fcNone)
903 InterestedSrcs |= fcNan | fcNegative;
904
905 // log(logical-zero) produces negative infinity.
906 if ((InterestedClasses & fcNegInf) != fcNone)
907 InterestedSrcs |= fcZero | fcSubnormal;
908
909 // log(x) < -0.0 if x < +1.0
910 if ((InterestedClasses & fcNegNormal) != fcNone)
911 InterestedSrcs |= fcPosSubnormal | fcPosNormal;
912
913 // log(x) >= +0.0 if x >= +1.0
914 if ((InterestedClasses & (fcPosZero | fcPosNormal)) != fcNone)
915 InterestedSrcs |= fcPosNormal;
916
917 // log(x) is positive infinity iff x is positive infinity.
918 if ((InterestedClasses & fcPosInf) != fcNone)
919 InterestedSrcs |= fcPosInf;
920
921 KnownFPClass KnownSrc;
922 if (InterestedSrcs != fcNone)
923 computeKnownFPClass(II->getArgOperand(0), DemandedElts, InterestedSrcs,
924 KnownSrc, Q, Depth + 1);
925 const Function *F = II->getFunction();
927 F ? F->getDenormalMode(
928 II->getType()->getScalarType()->getFltSemantics())
930 const bool IsMultiUnitFPType =
931 V->getType()->getScalarType()->isMultiUnitFPType();
932 Known = KnownFPClass::log(KnownSrc, Mode, IsMultiUnitFPType);
933 break;
934 }
935 case Intrinsic::pow: {
936 const bool WantNaN = (InterestedClasses & fcNan) != fcNone;
937 const bool WantNegative = (InterestedClasses & fcNegative) != fcNone;
938 if (!WantNaN && !WantNegative)
939 break;
940
941 FPClassTest InterestedLHS = fcNone;
942 FPClassTest InterestedRHS = fcNone;
943 if (WantNaN) {
944 // pow may return NaN if one of the arguments is NaN. NaN may also be
945 // produced from a negative, non-zero finite base and a non-integer
946 // exponent.
947 InterestedLHS |= fcNan | fcNegNormal | fcNegSubnormal;
948 InterestedRHS |= fcNan;
949 }
950 if (WantNegative) {
951 // A negative value is returned when a negative base is raised to an odd
952 // integer power. Only normal values can be odd integers.
953 InterestedLHS |= fcNegative;
954 InterestedRHS |= fcNormal;
955 }
956
957 KnownFPClass KnownLHS;
958 computeKnownFPClass(II->getArgOperand(0), DemandedElts, InterestedLHS,
959 KnownLHS, Q, Depth + 1);
960
961 // If the LHS is unknown, then querying the RHS is only useful for rare
962 // edge cases.
963 if (KnownLHS.isUnknown())
964 break;
965
966 KnownFPClass KnownRHS;
967 computeKnownFPClass(II->getArgOperand(1), DemandedElts, InterestedRHS,
968 KnownRHS, Q, Depth + 1);
969 Known = KnownFPClass::pow(KnownLHS, KnownRHS);
970 break;
971 }
972 case Intrinsic::powi: {
973 if ((InterestedClasses & (fcNan | fcInf | fcNegative)) == fcNone)
974 break;
975
976 // The exponent is always a scalar, even when raising a vector to a power.
977 const Value *Exp = II->getArgOperand(1);
978 KnownBits ExponentKnownBits =
979 computeKnownBits(Exp, APInt(1, 1), Q, Depth + 1);
980
981 FPClassTest InterestedSrcs = fcNone;
982 if (InterestedClasses & fcNan)
983 InterestedSrcs |= fcNan;
984 if (!ExponentKnownBits.isZero()) {
985 if (InterestedClasses & fcInf)
986 InterestedSrcs |= fcFinite | fcInf;
987 if ((InterestedClasses & fcNegative) && !ExponentKnownBits.isEven())
988 InterestedSrcs |= fcNegative;
989 }
990
991 KnownFPClass KnownSrc;
992 if (InterestedSrcs != fcNone)
993 computeKnownFPClass(II->getArgOperand(0), DemandedElts, InterestedSrcs,
994 KnownSrc, Q, Depth + 1);
995
996 Known = KnownFPClass::powi(KnownSrc, ExponentKnownBits);
997 break;
998 }
999 case Intrinsic::ldexp: {
1000 KnownFPClass KnownSrc;
1001 computeKnownFPClass(II->getArgOperand(0), DemandedElts, InterestedClasses,
1002 KnownSrc, Q, Depth + 1);
1003 // Can refine inf/zero handling based on the exponent operand.
1004 const FPClassTest ExpInfoMask = fcZero | fcSubnormal | fcInf;
1005
1006 const Value *ExpArg = II->getArgOperand(1);
1007 ConstantRange ExpKnownRange =
1008 ((KnownSrc.getKnownFPClasses() & ExpInfoMask) != fcNone)
1009 ? computeConstantRange(ExpArg, /*ForSigned=*/true, Q, Depth + 1)
1010 : ConstantRange::getFull(
1011 ExpArg->getType()->getScalarSizeInBits());
1012
1013 const fltSemantics &Flt =
1014 II->getType()->getScalarType()->getFltSemantics();
1015
1016 const Function *F = II->getFunction();
1018 F ? F->getDenormalMode(Flt) : DenormalMode::getDynamic();
1019
1020 Known = KnownFPClass::ldexp(KnownSrc, ExpKnownRange.getSignedMin(),
1021 ExpKnownRange.getSignedMax(), Flt, Mode);
1022 break;
1023 }
1024 case Intrinsic::arithmetic_fence: {
1025 computeKnownFPClass(II->getArgOperand(0), DemandedElts, InterestedClasses,
1026 Known, Q, Depth + 1);
1027 break;
1028 }
1029 case Intrinsic::experimental_constrained_sitofp:
1030 case Intrinsic::experimental_constrained_uitofp:
1031 // Cannot produce nan
1032 Known.knownNot(fcNan);
1033
1034 // sitofp and uitofp turn into +0.0 for zero.
1035 Known.knownNot(fcNegZero);
1036
1037 // Integers cannot be subnormal
1038 Known.knownNot(fcSubnormal);
1039
1040 if (IID == Intrinsic::experimental_constrained_uitofp)
1041 Known.signBitMustBeZero();
1042
1043 // TODO: Copy inf handling from instructions
1044 break;
1045
1046 case Intrinsic::amdgcn_fract: {
1047 Known.knownNot(fcInf);
1048
1049 if (InterestedClasses & fcNan) {
1050 KnownFPClass KnownSrc;
1051 computeKnownFPClass(II->getArgOperand(0), DemandedElts,
1052 InterestedClasses, KnownSrc, Q, Depth + 1);
1053
1054 if (KnownSrc.isKnownNeverInfOrNaN())
1055 Known.knownNot(fcNan);
1056 else if (KnownSrc.isKnownNever(fcSNan))
1057 Known.knownNot(fcSNan);
1058 }
1059
1060 break;
1061 }
1062 case Intrinsic::amdgcn_rcp: {
1063 KnownFPClass KnownSrc;
1064 computeKnownFPClass(II->getArgOperand(0), DemandedElts, InterestedClasses,
1065 KnownSrc, Q, Depth + 1);
1066
1067 Known.propagateNonNaN(KnownSrc);
1068
1069 Type *EltTy = II->getType()->getScalarType();
1070
1071 // f32 denormal always flushed.
1072 if (EltTy->isFloatTy()) {
1073 Known.knownNot(fcSubnormal);
1074 KnownSrc.knownNot(fcSubnormal);
1075 }
1076
1077 if (KnownSrc.isKnownNever(fcNegative))
1078 Known.knownNot(fcNegative);
1079 if (KnownSrc.isKnownNever(fcPositive))
1080 Known.knownNot(fcPositive);
1081
1082 if (const Function *F = II->getFunction()) {
1083 DenormalMode Mode = F->getDenormalMode(EltTy->getFltSemantics());
1084 if (KnownSrc.isKnownNeverLogicalPosZero(Mode))
1085 Known.knownNot(fcPosInf);
1086 if (KnownSrc.isKnownNeverLogicalNegZero(Mode))
1087 Known.knownNot(fcNegInf);
1088 }
1089
1090 break;
1091 }
1092 case Intrinsic::amdgcn_rsq: {
1093 KnownFPClass KnownSrc;
1094 // The only negative value that can be returned is -inf for -0 inputs.
1096
1097 computeKnownFPClass(II->getArgOperand(0), DemandedElts, InterestedClasses,
1098 KnownSrc, Q, Depth + 1);
1099
1100 // Negative -> nan
1101 if (KnownSrc.isKnownNeverNaN() && KnownSrc.cannotBeOrderedLessThanZero())
1102 Known.knownNot(fcNan);
1103 else if (KnownSrc.isKnownNever(fcSNan))
1104 Known.knownNot(fcSNan);
1105
1106 // +inf -> +0
1107 if (KnownSrc.isKnownNeverPosInfinity())
1108 Known.knownNot(fcPosZero);
1109
1110 Type *EltTy = II->getType()->getScalarType();
1111
1112 // f32 denormal always flushed.
1113 if (EltTy->isFloatTy())
1114 Known.knownNot(fcPosSubnormal);
1115
1116 if (const Function *F = II->getFunction()) {
1117 DenormalMode Mode = F->getDenormalMode(EltTy->getFltSemantics());
1118
1119 // -0 -> -inf
1120 if (KnownSrc.isKnownNeverLogicalNegZero(Mode))
1121 Known.knownNot(fcNegInf);
1122
1123 // +0 -> +inf
1124 if (KnownSrc.isKnownNeverLogicalPosZero(Mode))
1125 Known.knownNot(fcPosInf);
1126 }
1127
1128 break;
1129 }
1130 case Intrinsic::amdgcn_trig_preop: {
1131 // Always returns a value [0, 1)
1132 Known.knownNot(fcNan | fcInf | fcNegative);
1133 break;
1134 }
1135 case Intrinsic::convert_from_arbitrary_fp: {
1136 auto *MD = cast<MetadataAsValue>(II->getArgOperand(1))->getMetadata();
1137 StringRef FormatStr = cast<MDString>(MD)->getString();
1138
1139 const fltSemantics *SrcSemantics =
1141 if (!SrcSemantics)
1142 break;
1143
1144 const fltSemantics DstSemantics =
1145 II->getType()->getScalarType()->getFltSemantics();
1146
1147 if (!APFloat::semanticsHasNaN(*SrcSemantics))
1148 Known.knownNot(fcNan);
1149
1150 // fcInf can only be cleared if the source format has no Inf encoding
1151 // and the dst max exp can accommodate src max exp.
1152 if (!APFloat::semanticsHasInf(*SrcSemantics) &&
1153 APFloat::semanticsMaxExponent(*SrcSemantics) <=
1154 APFloat::semanticsMaxExponent(DstSemantics))
1155 Known.knownNot(fcInf);
1156
1157 // Check and clear all neg flags for formats that do not have signed
1158 // representation.
1159 if (!APFloat::semanticsHasSignedRepr(*SrcSemantics))
1160 Known.knownNot(fcNegative);
1161
1162 // Check if format has no zero at all (Float8E8M0FNU), or no negative
1163 // zero.
1164 if (!APFloat::semanticsHasZero(*SrcSemantics))
1165 Known.knownNot(fcZero);
1166 else if (SrcSemantics->nanEncoding == fltNanEncoding::NegativeZero)
1167 Known.knownNot(fcNegZero);
1168
1169 // If src lands normally in dest, the result can never be subnormal.
1170 if (APFloat::isRepresentableAsNormalIn(*SrcSemantics, DstSemantics))
1171 Known.knownNot(fcSubnormal);
1172 break;
1173 }
1174 default:
1175 break;
1176 }
1177
1178 break;
1179 }
1180 case Instruction::FAdd:
1181 case Instruction::FSub: {
1182 computeKnownFPClassForFAddSub(Op, DemandedElts, InterestedClasses, Known, Q,
1183 Depth, /*IsAdd=*/Opc == Instruction::FAdd,
1184 /*IsStrict=*/false);
1185 break;
1186 }
1187 case Instruction::FMul: {
1188 const Function *F = cast<Instruction>(Op)->getFunction();
1190 F ? F->getDenormalMode(
1191 Op->getType()->getScalarType()->getFltSemantics())
1193
1194 Value *LHS = Op->getOperand(0);
1195 Value *RHS = Op->getOperand(1);
1196 // X * X is always non-negative or a NaN.
1197 // FIXME: Should check isGuaranteedNotToBeUndef
1198 if (LHS == RHS) {
1199 KnownFPClass KnownSrc;
1200 computeKnownFPClass(LHS, DemandedElts, fcAllFlags, KnownSrc, Q,
1201 Depth + 1);
1202 Known = KnownFPClass::square(KnownSrc, Mode);
1203 break;
1204 }
1205
1206 KnownFPClass KnownLHS, KnownRHS;
1207
1208 const APFloat *CRHS;
1209 if (match(RHS, m_APFloat(CRHS))) {
1210 computeKnownFPClass(LHS, DemandedElts, fcAllFlags, KnownLHS, Q,
1211 Depth + 1);
1212 Known = KnownFPClass::fmul(KnownLHS, *CRHS, Mode);
1213 } else {
1214 computeKnownFPClass(RHS, DemandedElts, fcAllFlags, KnownRHS, Q,
1215 Depth + 1);
1216 // TODO: Improve accuracy in unfused FMA pattern. We can prove an
1217 // additional not-nan if the addend is known-not negative infinity if the
1218 // multiply is known-not infinity.
1219
1220 computeKnownFPClass(LHS, DemandedElts, fcAllFlags, KnownLHS, Q,
1221 Depth + 1);
1222 Known = KnownFPClass::fmul(KnownLHS, KnownRHS, Mode);
1223 }
1224
1225 /// Propgate no-infs if the other source is known smaller than one, such
1226 /// that this cannot introduce overflow.
1227 if (KnownLHS.isKnownNever(fcInf) && isAbsoluteValueULEOne(RHS))
1228 Known.knownNot(fcInf);
1229 else if (KnownRHS.isKnownNever(fcInf) && isAbsoluteValueULEOne(LHS))
1230 Known.knownNot(fcInf);
1231
1232 break;
1233 }
1234 case Instruction::FDiv: {
1235 const bool WantNan = (InterestedClasses & fcNan) != fcNone;
1236
1237 const Function *F = cast<Instruction>(Op)->getFunction();
1238 const fltSemantics &FltSem =
1239 Op->getType()->getScalarType()->getFltSemantics();
1241 F ? F->getDenormalMode(FltSem) : DenormalMode::getDynamic();
1242
1243 if (Op->getOperand(0) == Op->getOperand(1) &&
1244 isGuaranteedNotToBeUndef(Op->getOperand(0), Q.AC, Q.CtxI, Q.DT)) {
1245 // X / X is always exactly 1.0 or a NaN.
1246 Known.setKnownFPClasses(fcNan | fcPosNormal);
1247
1248 if (!WantNan)
1249 break;
1250
1251 KnownFPClass KnownSrc;
1252 computeKnownFPClass(Op->getOperand(0), DemandedElts,
1253 fcNan | fcInf | fcZero | fcSubnormal, KnownSrc, Q,
1254 Depth + 1);
1255
1256 Known = KnownFPClass::fdiv_self(KnownSrc, Mode);
1257 break;
1258 }
1259
1260 const bool WantNegative = (InterestedClasses & fcNegative) != fcNone;
1261 const bool WantPositive = (InterestedClasses & fcPositive) != fcNone;
1262 if (!WantNan && !WantNegative && !WantPositive)
1263 break;
1264
1265 KnownFPClass KnownLHS, KnownRHS;
1266 computeKnownFPClass(Op->getOperand(1), DemandedElts, fcAllFlags, KnownRHS,
1267 Q, Depth + 1);
1268
1269 bool KnowSomethingUseful =
1270 KnownRHS.isKnownNever(fcSNan) ||
1273
1274 if (KnowSomethingUseful)
1275 computeKnownFPClass(Op->getOperand(0), DemandedElts, fcAllFlags, KnownLHS,
1276 Q, Depth + 1);
1277
1278 Known = KnownFPClass::fdiv(KnownLHS, KnownRHS, Mode);
1279 break;
1280 }
1281 case Instruction::FRem: {
1282 computeKnownFPClassForFRem(Op, DemandedElts, InterestedClasses, Known, Q,
1283 Depth);
1284 break;
1285 }
1286 case Instruction::FPExt: {
1287 KnownFPClass KnownSrc;
1288 computeKnownFPClass(Op->getOperand(0), DemandedElts, InterestedClasses,
1289 KnownSrc, Q, Depth + 1);
1290
1291 const fltSemantics &DstTy =
1292 Op->getType()->getScalarType()->getFltSemantics();
1293 const fltSemantics &SrcTy =
1294 Op->getOperand(0)->getType()->getScalarType()->getFltSemantics();
1295
1296 const auto *I = dyn_cast<Instruction>(Op);
1297 const Function *F = I ? I->getFunction() : nullptr;
1298 DenormalMode DstMode =
1299 F ? F->getDenormalMode(DstTy) : DenormalMode::getDynamic();
1300 DenormalMode SrcMode =
1301 F ? F->getDenormalMode(SrcTy) : DenormalMode::getDynamic();
1302
1303 Known = KnownFPClass::fpext(KnownSrc, DstTy, SrcTy, DstMode, SrcMode);
1304 break;
1305 }
1306 case Instruction::FPTrunc: {
1308 DemandedElts, InterestedClasses, Known, Q,
1309 Depth);
1310 break;
1311 }
1312 case Instruction::SIToFP:
1313 case Instruction::UIToFP: {
1314 // Cannot produce nan
1315 Known.knownNot(fcNan);
1316
1317 // Integers cannot be subnormal
1318 Known.knownNot(fcSubnormal);
1319
1320 // sitofp and uitofp turn into +0.0 for zero.
1321 Known.knownNot(fcNegZero);
1322
1323 // UIToFP is always non-negative regardless of known bits.
1324 if (Op->getOpcode() == Instruction::UIToFP)
1325 Known.signBitMustBeZero();
1326
1327 // Only compute known bits if we can learn something useful from them.
1328 if (!(InterestedClasses & (fcPosZero | fcNormal | fcInf)))
1329 break;
1330
1331 KnownBits IntKnown =
1332 computeKnownBits(Op->getOperand(0), DemandedElts, Q, Depth + 1);
1333
1334 // If the integer is non-zero, the result cannot be +0.0
1335 if (IntKnown.isNonZero())
1336 Known.knownNot(fcPosZero);
1337
1338 if (Op->getOpcode() == Instruction::SIToFP) {
1339 // If the signed integer is known non-negative, the result is
1340 // non-negative. If the signed integer is known negative, the result is
1341 // negative.
1342 if (IntKnown.isNonNegative()) {
1343 Known.signBitMustBeZero();
1344 } else if (IntKnown.isNegative()) {
1345 Known.signBitMustBeOne();
1346 }
1347 }
1348
1349 // Guard kept for ilogb()
1350 if (InterestedClasses & fcInf) {
1351 // Get width of largest magnitude integer known.
1352 // This still works for a signed minimum value because the largest FP
1353 // value is scaled by some fraction close to 2.0 (1.0 + 0.xxxx).
1354 int IntSize = IntKnown.getBitWidth();
1355 if (Op->getOpcode() == Instruction::UIToFP)
1356 IntSize -= IntKnown.countMinLeadingZeros();
1357 else if (Op->getOpcode() == Instruction::SIToFP)
1358 IntSize -= IntKnown.countMinSignBits();
1359
1360 // If the exponent of the largest finite FP value can hold the largest
1361 // integer, the result of the cast must be finite.
1362 Type *FPTy = Op->getType()->getScalarType();
1363 if (ilogb(APFloat::getLargest(FPTy->getFltSemantics())) >= IntSize)
1364 Known.knownNot(fcInf);
1365 }
1366
1367 break;
1368 }
1369 case Instruction::ExtractElement: {
1370 // Look through extract element. If the index is non-constant or
1371 // out-of-range demand all elements, otherwise just the extracted element.
1372 const Value *Vec = Op->getOperand(0);
1373
1374 APInt DemandedVecElts;
1375 if (auto *VecTy = dyn_cast<FixedVectorType>(Vec->getType())) {
1376 unsigned NumElts = VecTy->getNumElements();
1377 DemandedVecElts = APInt::getAllOnes(NumElts);
1378 auto *CIdx = dyn_cast<ConstantInt>(Op->getOperand(1));
1379 if (CIdx && CIdx->getValue().ult(NumElts))
1380 DemandedVecElts = APInt::getOneBitSet(NumElts, CIdx->getZExtValue());
1381 } else {
1382 DemandedVecElts = APInt(1, 1);
1383 }
1384
1385 return computeKnownFPClass(Vec, DemandedVecElts, InterestedClasses, Known,
1386 Q, Depth + 1);
1387 }
1388 case Instruction::InsertElement: {
1389 if (isa<ScalableVectorType>(Op->getType()))
1390 return;
1391
1392 const Value *Vec = Op->getOperand(0);
1393 const Value *Elt = Op->getOperand(1);
1394 auto *CIdx = dyn_cast<ConstantInt>(Op->getOperand(2));
1395 unsigned NumElts = DemandedElts.getBitWidth();
1396 APInt DemandedVecElts = DemandedElts;
1397 bool NeedsElt = true;
1398 // If we know the index we are inserting to, clear it from Vec check.
1399 if (CIdx && CIdx->getValue().ult(NumElts)) {
1400 DemandedVecElts.clearBit(CIdx->getZExtValue());
1401 NeedsElt = DemandedElts[CIdx->getZExtValue()];
1402 }
1403
1404 // Do we demand the inserted element?
1405 if (NeedsElt) {
1406 computeKnownFPClass(Elt, Known, InterestedClasses, Q, Depth + 1);
1407 // If we don't know any bits, early out.
1408 if (Known.isUnknown())
1409 break;
1410 } else {
1412 }
1413
1414 // Do we need anymore elements from Vec?
1415 if (!DemandedVecElts.isZero()) {
1416 KnownFPClass Known2;
1417 computeKnownFPClass(Vec, DemandedVecElts, InterestedClasses, Known2, Q,
1418 Depth + 1);
1419 Known |= Known2;
1420 }
1421
1422 break;
1423 }
1424 case Instruction::ShuffleVector: {
1425 // Handle vector splat idiom
1426 if (Value *Splat = getSplatValue(V)) {
1427 computeKnownFPClass(Splat, Known, InterestedClasses, Q, Depth + 1);
1428 break;
1429 }
1430
1431 // For undef elements, we don't know anything about the common state of
1432 // the shuffle result.
1433 APInt DemandedLHS, DemandedRHS;
1434 auto *Shuf = dyn_cast<ShuffleVectorInst>(Op);
1435 if (!Shuf ||
1436 !getShuffleDemandedElts(Shuf, DemandedElts, DemandedLHS, DemandedRHS))
1437 return;
1438
1439 if (!!DemandedLHS) {
1440 const Value *LHS = Shuf->getOperand(0);
1441 computeKnownFPClass(LHS, DemandedLHS, InterestedClasses, Known, Q,
1442 Depth + 1);
1443
1444 // If we don't know any bits, early out.
1445 if (Known.isUnknown())
1446 break;
1447 } else {
1449 }
1450
1451 if (!!DemandedRHS) {
1452 KnownFPClass Known2;
1453 const Value *RHS = Shuf->getOperand(1);
1454 computeKnownFPClass(RHS, DemandedRHS, InterestedClasses, Known2, Q,
1455 Depth + 1);
1456 Known |= Known2;
1457 }
1458
1459 break;
1460 }
1461 case Instruction::ExtractValue: {
1462 const ExtractValueInst *Extract = cast<ExtractValueInst>(Op);
1463 ArrayRef<unsigned> Indices = Extract->getIndices();
1464 const Value *Src = Extract->getAggregateOperand();
1465 if (isa<StructType>(Src->getType()) && Indices.size() == 1) {
1466 if (const auto *II = dyn_cast<IntrinsicInst>(Src)) {
1467 switch (II->getIntrinsicID()) {
1468 case Intrinsic::frexp: {
1469 if (Indices[0] != 0)
1470 break;
1471
1472 FPClassTest InterestedSrcs = InterestedClasses;
1473
1474 // Positive subnormals and negative subnormals could become positive
1475 // zero.
1476 if (InterestedClasses & fcPosZero)
1477 InterestedSrcs |= fcSubnormal;
1478
1479 // Negative subnormals could become negative zero.
1480 if (InterestedClasses & fcNegZero)
1481 InterestedSrcs |= fcNegSubnormal;
1482
1483 if (InterestedClasses & fcPosNormal)
1484 InterestedSrcs |= fcPosSubnormal;
1485
1486 if (InterestedClasses & fcNegNormal)
1487 InterestedSrcs |= fcNegSubnormal;
1488
1489 KnownFPClass KnownSrc;
1490 computeKnownFPClass(II->getArgOperand(0), DemandedElts,
1491 InterestedSrcs, KnownSrc, Q, Depth + 1);
1492
1493 const Function *F = cast<Instruction>(Op)->getFunction();
1494 const fltSemantics &FltSem =
1495 Op->getType()->getScalarType()->getFltSemantics();
1496
1498 F ? F->getDenormalMode(FltSem) : DenormalMode::getDynamic();
1499 Known = KnownFPClass::frexp_mant(KnownSrc, Mode);
1500 return;
1501 }
1502 case Intrinsic::sincospi: {
1503 FPClassTest InterestedSrcs = InterestedClasses;
1504
1505 // Infinite inputs become NaN.
1506 if (InterestedClasses & fcNan)
1507 InterestedSrcs |= fcInf;
1508
1509 KnownFPClass KnownSrc;
1510 computeKnownFPClass(II->getArgOperand(0), DemandedElts,
1511 InterestedSrcs, KnownSrc, Q, Depth + 1);
1512
1513 const bool IsMultiUnitFPType =
1514 V->getType()->getScalarType()->isMultiUnitFPType();
1515
1516 if (Indices[0] == 0)
1517 Known = KnownFPClass::sinpi(KnownSrc, IsMultiUnitFPType);
1518 else if (Indices[0] == 1)
1519 Known = KnownFPClass::cospi(KnownSrc, IsMultiUnitFPType);
1520 return;
1521 }
1522 default:
1523 break;
1524 }
1525 }
1526 }
1527
1528 computeKnownFPClass(Src, DemandedElts, InterestedClasses, Known, Q,
1529 Depth + 1);
1530 break;
1531 }
1532 case Instruction::PHI: {
1533 const PHINode *P = cast<PHINode>(Op);
1534 // Unreachable blocks may have zero-operand PHI nodes.
1535 if (P->getNumIncomingValues() == 0)
1536 break;
1537
1538 // Otherwise take the unions of the known bit sets of the operands,
1539 // taking conservative care to avoid excessive recursion.
1540 const unsigned PhiRecursionLimit = MaxAnalysisRecursionDepth - 2;
1541
1542 if (Depth < PhiRecursionLimit) {
1543 // Skip if every incoming value references to ourself.
1544 if (isa_and_nonnull<UndefValue>(P->hasConstantValue()))
1545 break;
1546
1547 bool First = true;
1548
1549 for (const Use &U : P->operands()) {
1550 Value *IncValue;
1551 Instruction *CtxI;
1552 breakSelfRecursivePHI(&U, P, IncValue, CtxI);
1553 // Skip direct self references.
1554 if (IncValue == P)
1555 continue;
1556
1557 KnownFPClass KnownSrc;
1558 // Recurse, but cap the recursion to two levels, because we don't want
1559 // to waste time spinning around in loops. We need at least depth 2 to
1560 // detect known sign bits.
1561 computeKnownFPClass(IncValue, DemandedElts, InterestedClasses, KnownSrc,
1563 PhiRecursionLimit);
1564
1565 if (First) {
1566 Known = KnownSrc;
1567 First = false;
1568 } else {
1569 Known |= KnownSrc;
1570 }
1571
1572 if (Known.getKnownFPClasses() == fcAllFlags)
1573 break;
1574 }
1575 }
1576
1577 // Look for the case of a for loop which has a positive
1578 // initial value and is incremented by a squared value.
1579 // This will propagate sign information out of such loops.
1580 if (P->getNumIncomingValues() != 2 || Known.cannotBeOrderedLessThanZero())
1581 break;
1582 for (unsigned I = 0; I < 2; I++) {
1583 Value *RecurValue = P->getIncomingValue(1 - I);
1585 if (!II)
1586 continue;
1587 Value *R, *L, *Init;
1588 PHINode *PN;
1590 PN == P) {
1591 switch (II->getIntrinsicID()) {
1592 case Intrinsic::fma:
1593 case Intrinsic::fmuladd: {
1594 KnownFPClass KnownStart;
1595 computeKnownFPClass(Init, DemandedElts, InterestedClasses, KnownStart,
1596 Q, Depth + 1);
1597 if (KnownStart.cannotBeOrderedLessThanZero() && L == R &&
1598 isGuaranteedNotToBeUndef(L, Q.AC, Q.CtxI, Q.DT, Depth + 1))
1600 break;
1601 }
1602 }
1603 }
1604 }
1605 break;
1606 }
1607 case Instruction::BitCast: {
1608 const Value *Src;
1609 if (!match(Op, m_ElementWiseBitCast(m_Value(Src))) ||
1610 !Src->getType()->isIntOrIntVectorTy())
1611 break;
1612
1613 const Type *Ty = Op->getType();
1614
1615 Value *CastLHS, *CastRHS;
1616
1617 // Match bitcast(umax(bitcast(a), bitcast(b)))
1618 if (match(Src, m_c_MaxOrMin(m_BitCast(m_Value(CastLHS)),
1619 m_BitCast(m_Value(CastRHS)))) &&
1620 CastLHS->getType() == Ty && CastRHS->getType() == Ty) {
1621 KnownFPClass KnownLHS, KnownRHS;
1622 computeKnownFPClass(CastRHS, DemandedElts, InterestedClasses, KnownRHS, Q,
1623 Depth + 1);
1624 if (!KnownRHS.isUnknown()) {
1625 computeKnownFPClass(CastLHS, DemandedElts, InterestedClasses, KnownLHS,
1626 Q, Depth + 1);
1627 Known = KnownLHS | KnownRHS;
1628 }
1629
1630 return;
1631 }
1632
1633 const Type *EltTy = Ty->getScalarType();
1634 KnownBits Bits = computeKnownBits(Src, DemandedElts, Q, Depth + 1);
1635
1637 break;
1638 }
1639 default:
1640 break;
1641 }
1642}
1643
1645 const APInt &DemandedElts,
1646 FPClassTest InterestedClasses,
1647 const SimplifyQuery &SQ,
1648 unsigned Depth) {
1649 KnownFPClass KnownClasses;
1650 ::computeKnownFPClass(V, DemandedElts, InterestedClasses, KnownClasses, SQ,
1651 Depth);
1652 return KnownClasses;
1653}
1654
1656 FPClassTest InterestedClasses,
1657 const SimplifyQuery &SQ,
1658 unsigned Depth) {
1660 ::computeKnownFPClass(V, Known, InterestedClasses, SQ, Depth);
1661 return Known;
1662}
1663
1665 const Value *V, const DataLayout &DL, FPClassTest InterestedClasses,
1666 const TargetLibraryInfo *TLI, AssumptionCache *AC, const Instruction *CtxI,
1667 const DominatorTree *DT, bool UseInstrInfo, unsigned Depth) {
1668 return computeKnownFPClass(V, InterestedClasses,
1669 SimplifyQuery(DL, TLI, DT, AC, CtxI, UseInstrInfo),
1670 Depth);
1671}
1672
1674llvm::computeKnownFPClass(const Value *V, const APInt &DemandedElts,
1675 FastMathFlags FMF, FPClassTest InterestedClasses,
1676 const SimplifyQuery &SQ, unsigned Depth) {
1677 if (FMF.noNaNs())
1678 InterestedClasses &= ~fcNan;
1679 if (FMF.noInfs())
1680 InterestedClasses &= ~fcInf;
1681
1682 KnownFPClass Result =
1683 computeKnownFPClass(V, DemandedElts, InterestedClasses, SQ, Depth);
1684
1685 if (FMF.noNaNs())
1686 Result.setKnownFPClasses(Result.getKnownFPClasses() & ~fcNan);
1687 if (FMF.noInfs())
1688 Result.setKnownFPClasses(Result.getKnownFPClasses() & ~fcInf);
1689 return Result;
1690}
1691
1693 FPClassTest InterestedClasses,
1694 const SimplifyQuery &SQ,
1695 unsigned Depth) {
1696 auto *FVTy = dyn_cast<FixedVectorType>(V->getType());
1697 APInt DemandedElts =
1698 FVTy ? APInt::getAllOnes(FVTy->getNumElements()) : APInt(1, 1);
1699 return computeKnownFPClass(V, DemandedElts, FMF, InterestedClasses, SQ,
1700 Depth);
1701}
1702
1704 unsigned Depth) {
1706 return Known.isKnownNever(fcNegZero);
1707}
1708
1710 unsigned Depth) {
1713 return Known.cannotBeOrderedLessThanZero();
1714}
1715
1717 unsigned Depth) {
1719 return Known.isKnownNeverInfinity();
1720}
1721
1722/// Return true if the floating-point value can never contain a NaN or infinity.
1724 unsigned Depth) {
1726 return Known.isKnownNeverNaN() && Known.isKnownNeverInfinity();
1727}
1728
1729/// Return true if the floating-point scalar value is not a NaN or if the
1730/// floating-point vector value has no NaN elements. Return false if a value
1731/// could ever be NaN.
1733 unsigned Depth) {
1735 return Known.isKnownNeverNaN();
1736}
1737
1738/// Return false if we can prove that the specified FP value's sign bit is 0.
1739/// Return true if we can prove that the specified FP value's sign bit is 1.
1740/// Otherwise return std::nullopt.
1741std::optional<bool> llvm::computeKnownFPSignBit(const Value *V,
1742 const SimplifyQuery &SQ,
1743 unsigned Depth) {
1745 return Known.getSignBit();
1746}
1747
1749 auto *User = cast<Instruction>(U.getUser());
1750 if (auto *FPOp = dyn_cast<FPMathOperator>(User)) {
1751 if (FPOp->hasNoSignedZeros())
1752 return true;
1753 }
1754
1755 switch (User->getOpcode()) {
1756 case Instruction::FPToSI:
1757 case Instruction::FPToUI:
1758 return true;
1759 case Instruction::FRem:
1760 // frem(x, +-0.0) == NaN, and more generally frem(x, y) == frem(x, -y).
1761 return U.getOperandNo() == 1;
1762 case Instruction::FCmp:
1763 // fcmp treats both positive and negative zero as equal.
1764 return true;
1765 case Instruction::Call:
1766 if (auto *II = dyn_cast<IntrinsicInst>(User)) {
1767 switch (II->getIntrinsicID()) {
1768 case Intrinsic::fabs:
1769 case Intrinsic::exp:
1770 case Intrinsic::exp2:
1771 case Intrinsic::exp10:
1772 case Intrinsic::log:
1773 case Intrinsic::log2:
1774 case Intrinsic::log10:
1775 case Intrinsic::cos:
1776 case Intrinsic::acos:
1777 case Intrinsic::cosh:
1778 case Intrinsic::fptosi_sat:
1779 case Intrinsic::fptoui_sat:
1780 case Intrinsic::lround:
1781 case Intrinsic::llround:
1782 case Intrinsic::lrint:
1783 case Intrinsic::llrint:
1784 return true;
1785 case Intrinsic::copysign:
1786 return U.getOperandNo() == 0;
1787 case Intrinsic::pow:
1788 // pow(x, +-0.0) == +1.0 or NaN
1789 return U.getOperandNo() == 1;
1790 case Intrinsic::is_fpclass: {
1791 auto Test =
1792 static_cast<FPClassTest>(
1793 cast<ConstantInt>(II->getArgOperand(1))->getZExtValue()) &
1796 }
1797 default:
1798 return false;
1799 }
1800 }
1801 return false;
1802 default:
1803 return false;
1804 }
1805}
1806
1808 auto *User = cast<Instruction>(U.getUser());
1809 if (auto *FPOp = dyn_cast<FPMathOperator>(User)) {
1810 if (FPOp->hasNoNaNs())
1811 return true;
1812 }
1813
1814 switch (User->getOpcode()) {
1815 case Instruction::FPToSI:
1816 case Instruction::FPToUI:
1817 return true;
1818 // Proper FP math operations ignore the sign bit of NaN.
1819 case Instruction::FAdd:
1820 case Instruction::FSub:
1821 case Instruction::FMul:
1822 case Instruction::FDiv:
1823 case Instruction::FRem:
1824 case Instruction::FPTrunc:
1825 case Instruction::FPExt:
1826 case Instruction::FCmp:
1827 return true;
1828 // Bitwise FP operations should preserve the sign bit of NaN.
1829 case Instruction::FNeg:
1830 case Instruction::Select:
1831 case Instruction::PHI:
1832 return false;
1833 case Instruction::Ret:
1834 return User->getFunction()->getAttributes().getRetNoFPClass() &
1836 case Instruction::Call:
1837 case Instruction::Invoke: {
1838 if (auto *II = dyn_cast<IntrinsicInst>(User)) {
1839 switch (II->getIntrinsicID()) {
1840 case Intrinsic::fabs:
1841 return true;
1842 case Intrinsic::copysign:
1843 return U.getOperandNo() == 0;
1844 // Other proper FP math intrinsics ignore the sign bit of NaN.
1845 case Intrinsic::maxnum:
1846 case Intrinsic::minnum:
1847 case Intrinsic::maximum:
1848 case Intrinsic::minimum:
1849 case Intrinsic::maximumnum:
1850 case Intrinsic::minimumnum:
1851 case Intrinsic::canonicalize:
1852 case Intrinsic::fptrunc_round:
1853 case Intrinsic::fma:
1854 case Intrinsic::fmuladd:
1855 case Intrinsic::ldexp:
1856 case Intrinsic::frexp:
1857 case Intrinsic::modf:
1858 case Intrinsic::sqrt:
1859 case Intrinsic::exp:
1860 case Intrinsic::exp2:
1861 case Intrinsic::exp10:
1862 case Intrinsic::log:
1863 case Intrinsic::log2:
1864 case Intrinsic::log10:
1865 case Intrinsic::pow:
1866 case Intrinsic::powi:
1867 case Intrinsic::sin:
1868 case Intrinsic::cos:
1869 case Intrinsic::sincos:
1870 case Intrinsic::sincospi:
1871 case Intrinsic::tan:
1872 case Intrinsic::asin:
1873 case Intrinsic::acos:
1874 case Intrinsic::atan:
1875 case Intrinsic::atan2:
1876 case Intrinsic::sinh:
1877 case Intrinsic::cosh:
1878 case Intrinsic::tanh:
1879 case Intrinsic::trunc:
1880 case Intrinsic::floor:
1881 case Intrinsic::ceil:
1882 case Intrinsic::round:
1883 case Intrinsic::roundeven:
1884 case Intrinsic::nearbyint:
1885 case Intrinsic::rint:
1886 case Intrinsic::fptoui_sat:
1887 case Intrinsic::fptosi_sat:
1888 case Intrinsic::lround:
1889 case Intrinsic::llround:
1890 case Intrinsic::lrint:
1891 case Intrinsic::llrint:
1892 case Intrinsic::is_fpclass:
1893 return true;
1894 default:
1895 return false;
1896 }
1897 }
1898
1899 FPClassTest NoFPClass =
1900 cast<CallBase>(User)->getParamNoFPClass(U.getOperandNo());
1901 return NoFPClass & FPClassTest::fcNan;
1902 }
1903 default:
1904 return false;
1905 }
1906}
1907
1909 FastMathFlags FMF) {
1910 if (isa<PoisonValue>(V))
1911 return true;
1912 if (isa<UndefValue>(V))
1913 return false;
1914
1915 if (match(V, m_CheckedFp([](const APFloat &Val) { return Val.isInteger(); })))
1916 return true;
1917
1919 if (!I)
1920 return false;
1921
1922 switch (I->getOpcode()) {
1923 case Instruction::SIToFP:
1924 case Instruction::UIToFP:
1925 // TODO: Could check nofpclass(inf) on incoming argument
1926 if (FMF.noInfs())
1927 return true;
1928
1929 // Need to check int size cannot produce infinity, which computeKnownFPClass
1930 // knows how to do already.
1931 return isKnownNeverInfinity(I, SQ);
1932 case Instruction::Call: {
1933 const CallInst *CI = cast<CallInst>(I);
1934 switch (CI->getIntrinsicID()) {
1935 case Intrinsic::trunc:
1936 case Intrinsic::floor:
1937 case Intrinsic::ceil:
1938 case Intrinsic::rint:
1939 case Intrinsic::nearbyint:
1940 case Intrinsic::round:
1941 case Intrinsic::roundeven:
1942 return (FMF.noInfs() && FMF.noNaNs()) || isKnownNeverInfOrNaN(I, SQ);
1943 default:
1944 break;
1945 }
1946
1947 break;
1948 }
1949 default:
1950 break;
1951 }
1952
1953 return false;
1954}
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