LLVM 24.0.0git
GISelValueTracking.cpp
Go to the documentation of this file.
1//===- lib/CodeGen/GlobalISel/GISelValueTracking.cpp --------------*- C++
2//*-===//
3//
4// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5// See https://llvm.org/LICENSE.txt for license information.
6// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7//
8//===----------------------------------------------------------------------===//
9//
10/// Provides analysis for querying information about KnownBits during GISel
11/// passes.
12//
13//===----------------------------------------------------------------------===//
15#include "llvm/ADT/APFloat.h"
17#include "llvm/ADT/ScopeExit.h"
35#include "llvm/IR/FMF.h"
41
42#define DEBUG_TYPE "gisel-known-bits"
43
44using namespace llvm;
45using namespace MIPatternMatch;
46
48
50 "Analysis for ComputingKnownBits", false, true)
51
53 : MF(MF), MRI(MF.getRegInfo()), TL(*MF.getSubtarget().getTargetLowering()),
54 DL(MF.getFunction().getDataLayout()), MaxDepth(MaxDepth) {}
55
57 const MachineInstr *MI = MRI.getVRegDef(R);
58 switch (MI->getOpcode()) {
59 case TargetOpcode::COPY:
60 return computeKnownAlignment(MI->getOperand(1).getReg(), Depth);
61 case TargetOpcode::G_ASSERT_ALIGN: {
62 // TODO: Min with source
63 return Align(MI->getOperand(2).getImm());
64 }
65 case TargetOpcode::G_FRAME_INDEX: {
66 int FrameIdx = MI->getOperand(1).getIndex();
67 return MF.getFrameInfo().getObjectAlign(FrameIdx);
68 }
69 case TargetOpcode::G_INTRINSIC:
70 case TargetOpcode::G_INTRINSIC_W_SIDE_EFFECTS:
71 case TargetOpcode::G_INTRINSIC_CONVERGENT:
72 case TargetOpcode::G_INTRINSIC_CONVERGENT_W_SIDE_EFFECTS:
73 default:
74 return TL.computeKnownAlignForTargetInstr(*this, R, MRI, Depth + 1);
75 }
76}
77
79 assert(MI.getNumExplicitDefs() == 1 &&
80 "expected single return generic instruction");
81 return getKnownBits(MI.getOperand(0).getReg());
82}
83
85 const LLT Ty = MRI.getType(R);
86 // Since the number of lanes in a scalable vector is unknown at compile time,
87 // we track one bit which is implicitly broadcast to all lanes. This means
88 // that all lanes in a scalable vector are considered demanded.
89 APInt DemandedElts =
90 Ty.isFixedVector() ? APInt::getAllOnes(Ty.getNumElements()) : APInt(1, 1);
91 return getKnownBits(R, DemandedElts);
92}
93
95 const APInt &DemandedElts,
96 unsigned Depth) {
98 computeKnownBitsImpl(R, Known, DemandedElts, Depth);
99 return Known;
100}
101
103 LLT Ty = MRI.getType(R);
104 unsigned BitWidth = Ty.getScalarSizeInBits();
106}
107
109 LLT Ty = MRI.getType(R);
110 const APInt ScalarDemandedElts(1, 1);
111 APInt DemandedElts = Ty.isFixedVector()
112 ? APInt::getAllOnes(Ty.getNumElements())
113 : ScalarDemandedElts;
114 return isKnownNeverZero(R, DemandedElts, Depth);
115}
116
118 unsigned Depth) {
119 if (Depth >= getMaxDepth())
120 return false;
121
122 const APInt ScalarDemandedElts(1, 1);
123 MachineInstr &MI = *MRI.getVRegDef(R);
124
125 switch (MI.getOpcode()) {
126 default:
127 break;
128
129 case TargetOpcode::G_BUILD_VECTOR: {
130 for (const auto &[I, MO] : enumerate(drop_begin(MI.operands()))) {
131 if (!DemandedElts[I])
132 continue;
133 if (!isKnownNeverZero(MO.getReg(), ScalarDemandedElts, Depth + 1))
134 return false;
135 }
136 return true;
137 }
138
139 case TargetOpcode::G_EXTRACT_VECTOR_ELT: {
141 Register InVec = Extract.getVectorReg();
142 LLT VecTy = MRI.getType(InVec);
143 if (VecTy.isScalableVector())
144 break;
145 unsigned NumSrcElts = VecTy.getNumElements();
146 // An out-of-range constant index produces poison. Keep all lanes demanded,
147 // which is poison-safe and matches SelectionDAG's conservative behavior.
148 APInt DemandedSrcElts = APInt::getAllOnes(NumSrcElts);
149 if (auto Idx = getIConstantVRegVal(Extract.getIndexReg(), MRI)) {
150 if (Idx->ult(NumSrcElts))
151 DemandedSrcElts = APInt::getOneBitSet(NumSrcElts, Idx->getZExtValue());
152 }
153 return isKnownNeverZero(InVec, DemandedSrcElts, Depth + 1);
154 }
155
156 case TargetOpcode::G_SHUFFLE_VECTOR: {
158 LLT SrcTy = MRI.getType(Shuf.getSrc1Reg());
159 if (SrcTy.isScalableVector())
160 break;
161 APInt DemandedLHS, DemandedRHS;
162 if (!getShuffleDemandedElts(SrcTy.getNumElements(), Shuf.getMask(),
163 DemandedElts, DemandedLHS, DemandedRHS))
164 break;
165 if (!DemandedLHS.isZero() &&
166 !isKnownNeverZero(Shuf.getSrc1Reg(), DemandedLHS, Depth + 1))
167 return false;
168 if (!DemandedRHS.isZero() &&
169 !isKnownNeverZero(Shuf.getSrc2Reg(), DemandedRHS, Depth + 1))
170 return false;
171 return true;
172 }
173
174 case TargetOpcode::G_OR:
175 return isKnownNeverZero(MI.getOperand(1).getReg(), DemandedElts,
176 Depth + 1) ||
177 isKnownNeverZero(MI.getOperand(2).getReg(), DemandedElts, Depth + 1);
178
179 case TargetOpcode::G_SELECT:
180 return isKnownNeverZero(MI.getOperand(2).getReg(), DemandedElts,
181 Depth + 1) &&
182 isKnownNeverZero(MI.getOperand(3).getReg(), DemandedElts, Depth + 1);
183
184 case TargetOpcode::G_SHL: {
185 Register LHSReg = MI.getOperand(1).getReg();
186 if (MI.getFlag(MachineInstr::NoSWrap) || MI.getFlag(MachineInstr::NoUWrap))
187 return isKnownNeverZero(LHSReg, DemandedElts, Depth + 1);
188 KnownBits ValKnown = getKnownBits(LHSReg, DemandedElts, Depth + 1);
189 if (ValKnown.One[0])
190 return true;
191 APInt MaxCnt =
192 getKnownBits(MI.getOperand(2).getReg(), DemandedElts, Depth + 1)
193 .getMaxValue();
194 if (MaxCnt.ult(ValKnown.getBitWidth()) &&
195 !ValKnown.One.shl(MaxCnt).isZero())
196 return true;
197 break;
198 }
199 }
200
201 // Pass through this frame's Depth (not Depth+1) because we have not recursed
202 // into a child MI here: the fallback queries KnownBits for the same R.
203 return getKnownBits(R, DemandedElts, Depth).isNonZero();
204}
205
209
213
214[[maybe_unused]] static void
215dumpResult(const MachineInstr &MI, const KnownBits &Known, unsigned Depth) {
216 dbgs() << "[" << Depth << "] Compute known bits: " << MI << "[" << Depth
217 << "] Computed for: " << MI << "[" << Depth << "] Known: 0x"
218 << toString(Known.Zero | Known.One, 16, false) << "\n"
219 << "[" << Depth << "] Zero: 0x" << toString(Known.Zero, 16, false)
220 << "\n"
221 << "[" << Depth << "] One: 0x" << toString(Known.One, 16, false)
222 << "\n";
223}
224
225/// Compute known bits for the intersection of \p Src0 and \p Src1
226void GISelValueTracking::computeKnownBitsMin(Register Src0, Register Src1,
228 const APInt &DemandedElts,
229 unsigned Depth) {
230 // Test src1 first, since we canonicalize simpler expressions to the RHS.
231 computeKnownBitsImpl(Src1, Known, DemandedElts, Depth);
232
233 // If we don't know any bits, early out.
234 if (Known.isUnknown())
235 return;
236
237 KnownBits Known2;
238 computeKnownBitsImpl(Src0, Known2, DemandedElts, Depth);
239
240 // Only known if known in both the LHS and RHS.
241 Known = Known.intersectWith(Known2);
242}
243
244// Bitfield extract is computed as (Src >> Offset) & Mask, where Mask is
245// created using Width. Use this function when the inputs are KnownBits
246// objects. TODO: Move this KnownBits.h if this is usable in more cases.
247static KnownBits extractBits(unsigned BitWidth, const KnownBits &SrcOpKnown,
248 const KnownBits &OffsetKnown,
249 const KnownBits &WidthKnown) {
250 KnownBits Mask(BitWidth);
251 Mask.Zero = APInt::getBitsSetFrom(
253 Mask.One = APInt::getLowBitsSet(
255 return KnownBits::lshr(SrcOpKnown, OffsetKnown) & Mask;
256}
257
259 const APInt &DemandedElts,
260 unsigned Depth) {
261 MachineInstr &MI = *MRI.getVRegDef(R);
262 unsigned Opcode = MI.getOpcode();
263 LLT DstTy = MRI.getType(R);
264
265 // Handle the case where this is called on a register that does not have a
266 // type constraint. For example, it may be post-ISel or this target might not
267 // preserve the type when early-selecting instructions.
268 if (!DstTy.isValid()) {
269 Known = KnownBits();
270 return;
271 }
272
273#ifndef NDEBUG
274 if (DstTy.isFixedVector()) {
275 assert(
276 DstTy.getNumElements() == DemandedElts.getBitWidth() &&
277 "DemandedElt width should equal the fixed vector number of elements");
278 } else {
279 assert(DemandedElts.getBitWidth() == 1 && DemandedElts == APInt(1, 1) &&
280 "DemandedElt width should be 1 for scalars or scalable vectors");
281 }
282#endif
283
284 unsigned BitWidth = DstTy.getScalarSizeInBits();
285 Known = KnownBits(BitWidth); // Don't know anything
286
287 // Depth may get bigger than max depth if it gets passed to a different
288 // GISelValueTracking object.
289 // This may happen when say a generic part uses a GISelValueTracking object
290 // with some max depth, but then we hit TL.computeKnownBitsForTargetInstr
291 // which creates a new GISelValueTracking object with a different and smaller
292 // depth. If we just check for equality, we would never exit if the depth
293 // that is passed down to the target specific GISelValueTracking object is
294 // already bigger than its max depth.
295 if (Depth >= getMaxDepth())
296 return;
297
298 if (!DemandedElts)
299 return; // No demanded elts, better to assume we don't know anything.
300
301 KnownBits Known2;
302
303 switch (Opcode) {
304 default:
305 TL.computeKnownBitsForTargetInstr(*this, R, Known, DemandedElts, MRI,
306 Depth);
307 break;
308 case TargetOpcode::G_BUILD_VECTOR: {
309 // Collect the known bits that are shared by every demanded vector element.
310 Known.Zero.setAllBits();
311 Known.One.setAllBits();
312 for (const auto &[I, MO] : enumerate(drop_begin(MI.operands()))) {
313 if (!DemandedElts[I])
314 continue;
315
316 computeKnownBitsImpl(MO.getReg(), Known2, APInt(1, 1), Depth + 1);
317
318 // Known bits are the values that are shared by every demanded element.
319 Known = Known.intersectWith(Known2);
320
321 // If we don't know any bits, early out.
322 if (Known.isUnknown())
323 break;
324 }
325 break;
326 }
327 case TargetOpcode::G_SPLAT_VECTOR: {
328 computeKnownBitsImpl(MI.getOperand(1).getReg(), Known, APInt(1, 1),
329 Depth + 1);
330 // Implicitly truncate the bits to match the official semantics of
331 // G_SPLAT_VECTOR.
332 Known = Known.trunc(BitWidth);
333 break;
334 }
335 case TargetOpcode::COPY:
336 case TargetOpcode::G_PHI:
337 case TargetOpcode::PHI: {
340 // Destination registers should not have subregisters at this
341 // point of the pipeline, otherwise the main live-range will be
342 // defined more than once, which is against SSA.
343 assert(MI.getOperand(0).getSubReg() == 0 && "Is this code in SSA?");
344 // PHI's operand are a mix of registers and basic blocks interleaved.
345 // We only care about the register ones.
346 for (unsigned Idx = 1; Idx < MI.getNumOperands(); Idx += 2) {
347 const MachineOperand &Src = MI.getOperand(Idx);
348 Register SrcReg = Src.getReg();
349 LLT SrcTy = MRI.getType(SrcReg);
350 // Look through trivial copies and phis but don't look through trivial
351 // copies or phis of the form `%1:(s32) = OP %0:gpr32`, known-bits
352 // analysis is currently unable to determine the bit width of a
353 // register class.
354 //
355 // We can't use NoSubRegister by name as it's defined by each target but
356 // it's always defined to be 0 by tablegen.
357 if (SrcReg.isVirtual() && Src.getSubReg() == 0 /*NoSubRegister*/ &&
358 SrcTy.isValid()) {
359 APInt NowDemandedElts;
360 if (!SrcTy.isFixedVector()) {
361 NowDemandedElts = APInt(1, 1);
362 } else if (DstTy.isFixedVector() &&
363 SrcTy.getNumElements() == DstTy.getNumElements()) {
364 NowDemandedElts = DemandedElts;
365 } else {
366 NowDemandedElts = APInt::getAllOnes(SrcTy.getNumElements());
367 }
368
369 // For COPYs we don't do anything, don't increase the depth.
370 computeKnownBitsImpl(SrcReg, Known2, NowDemandedElts,
371 Depth + (Opcode != TargetOpcode::COPY));
372 Known2 = Known2.anyextOrTrunc(BitWidth);
373 Known = Known.intersectWith(Known2);
374 // If we reach a point where we don't know anything
375 // just stop looking through the operands.
376 if (Known.isUnknown())
377 break;
378 } else {
379 // We know nothing.
381 break;
382 }
383 }
384 break;
385 }
386 case TargetOpcode::G_STEP_VECTOR: {
387 APInt Step = MI.getOperand(1).getCImm()->getValue();
388
389 if (Step.isPowerOf2())
390 Known.Zero.setLowBits(Step.logBase2());
391
393 break;
394
395 const APInt MinNumElts =
398 bool Overflow;
399 const APInt MaxNumElts = getVScaleRange(&F, BitWidth)
401 .umul_ov(MinNumElts, Overflow);
402 if (Overflow)
403 break;
404 const APInt MaxValue = (MaxNumElts - 1).umul_ov(Step, Overflow);
405 if (Overflow)
406 break;
407 Known.Zero.setHighBits(MaxValue.countl_zero());
408 break;
409 }
410 case TargetOpcode::G_CONSTANT: {
411 Known = KnownBits::makeConstant(MI.getOperand(1).getCImm()->getValue());
412 break;
413 }
414 case TargetOpcode::G_FRAME_INDEX: {
415 int FrameIdx = MI.getOperand(1).getIndex();
416 TL.computeKnownBitsForStackObjectPointer(
417 Known, MF, MF.getFrameInfo().getObjectAlign(FrameIdx));
418 break;
419 }
420 case TargetOpcode::G_SUB: {
421 computeKnownBitsImpl(MI.getOperand(1).getReg(), Known, DemandedElts,
422 Depth + 1);
423 computeKnownBitsImpl(MI.getOperand(2).getReg(), Known2, DemandedElts,
424 Depth + 1);
426 MI.getFlag(MachineInstr::NoUWrap));
427 break;
428 }
429 case TargetOpcode::G_XOR: {
430 computeKnownBitsImpl(MI.getOperand(2).getReg(), Known, DemandedElts,
431 Depth + 1);
432 computeKnownBitsImpl(MI.getOperand(1).getReg(), Known2, DemandedElts,
433 Depth + 1);
434
435 Known ^= Known2;
436 break;
437 }
438 case TargetOpcode::G_PTR_ADD: {
439 if (DstTy.isVector())
440 break;
441 // G_PTR_ADD is like G_ADD. FIXME: Is this true for all targets?
442 LLT Ty = MRI.getType(MI.getOperand(1).getReg());
443 if (DL.isNonIntegralAddressSpace(Ty.getAddressSpace()))
444 break;
445 [[fallthrough]];
446 }
447 case TargetOpcode::G_ADD: {
448 computeKnownBitsImpl(MI.getOperand(1).getReg(), Known, DemandedElts,
449 Depth + 1);
450 computeKnownBitsImpl(MI.getOperand(2).getReg(), Known2, DemandedElts,
451 Depth + 1);
452 Known = KnownBits::add(Known, Known2);
453 break;
454 }
455 case TargetOpcode::G_AND: {
456 // If either the LHS or the RHS are Zero, the result is zero.
457 computeKnownBitsImpl(MI.getOperand(2).getReg(), Known, DemandedElts,
458 Depth + 1);
459 computeKnownBitsImpl(MI.getOperand(1).getReg(), Known2, DemandedElts,
460 Depth + 1);
461
462 Known &= Known2;
463 break;
464 }
465 case TargetOpcode::G_OR: {
466 // If either the LHS or the RHS are Zero, the result is zero.
467 computeKnownBitsImpl(MI.getOperand(2).getReg(), Known, DemandedElts,
468 Depth + 1);
469 computeKnownBitsImpl(MI.getOperand(1).getReg(), Known2, DemandedElts,
470 Depth + 1);
471
472 Known |= Known2;
473 break;
474 }
475 case TargetOpcode::G_MUL: {
476 computeKnownBitsImpl(MI.getOperand(2).getReg(), Known, DemandedElts,
477 Depth + 1);
478 computeKnownBitsImpl(MI.getOperand(1).getReg(), Known2, DemandedElts,
479 Depth + 1);
480 Known = KnownBits::mul(Known, Known2);
481 break;
482 }
483 case TargetOpcode::G_UMULH: {
484 computeKnownBitsImpl(MI.getOperand(2).getReg(), Known, DemandedElts,
485 Depth + 1);
486 computeKnownBitsImpl(MI.getOperand(1).getReg(), Known2, DemandedElts,
487 Depth + 1);
488 Known = KnownBits::mulhu(Known, Known2);
489 break;
490 }
491 case TargetOpcode::G_SMULH: {
492 computeKnownBitsImpl(MI.getOperand(2).getReg(), Known, DemandedElts,
493 Depth + 1);
494 computeKnownBitsImpl(MI.getOperand(1).getReg(), Known2, DemandedElts,
495 Depth + 1);
496 Known = KnownBits::mulhs(Known, Known2);
497 break;
498 }
499 case TargetOpcode::G_UAVGFLOOR: {
500 computeKnownBitsImpl(MI.getOperand(1).getReg(), Known, DemandedElts,
501 Depth + 1);
502 computeKnownBitsImpl(MI.getOperand(2).getReg(), Known2, DemandedElts,
503 Depth + 1);
505 break;
506 }
507 case TargetOpcode::G_UAVGCEIL: {
508 computeKnownBitsImpl(MI.getOperand(1).getReg(), Known, DemandedElts,
509 Depth + 1);
510 computeKnownBitsImpl(MI.getOperand(2).getReg(), Known2, DemandedElts,
511 Depth + 1);
513 break;
514 }
515 case TargetOpcode::G_SAVGFLOOR: {
516 computeKnownBitsImpl(MI.getOperand(1).getReg(), Known, DemandedElts,
517 Depth + 1);
518 computeKnownBitsImpl(MI.getOperand(2).getReg(), Known2, DemandedElts,
519 Depth + 1);
521 break;
522 }
523 case TargetOpcode::G_SAVGCEIL: {
524 computeKnownBitsImpl(MI.getOperand(1).getReg(), Known, DemandedElts,
525 Depth + 1);
526 computeKnownBitsImpl(MI.getOperand(2).getReg(), Known2, DemandedElts,
527 Depth + 1);
529 break;
530 }
531 case TargetOpcode::G_ABDU: {
532 computeKnownBitsImpl(MI.getOperand(2).getReg(), Known, DemandedElts,
533 Depth + 1);
534 computeKnownBitsImpl(MI.getOperand(1).getReg(), Known2, DemandedElts,
535 Depth + 1);
536 Known = KnownBits::abdu(Known, Known2);
537 break;
538 }
539 case TargetOpcode::G_ABDS: {
540 computeKnownBitsImpl(MI.getOperand(2).getReg(), Known, DemandedElts,
541 Depth + 1);
542 computeKnownBitsImpl(MI.getOperand(1).getReg(), Known2, DemandedElts,
543 Depth + 1);
544 Known = KnownBits::abds(Known, Known2);
545
546 unsigned SignBits1 =
547 computeNumSignBits(MI.getOperand(2).getReg(), DemandedElts, Depth + 1);
548 if (SignBits1 == 1) {
549 break;
550 }
551 unsigned SignBits0 =
552 computeNumSignBits(MI.getOperand(1).getReg(), DemandedElts, Depth + 1);
553
554 Known.Zero.setHighBits(std::min(SignBits0, SignBits1) - 1);
555 break;
556 }
557 case TargetOpcode::G_SADDSAT: {
558 computeKnownBitsImpl(MI.getOperand(1).getReg(), Known, DemandedElts,
559 Depth + 1);
560 computeKnownBitsImpl(MI.getOperand(2).getReg(), Known2, DemandedElts,
561 Depth + 1);
563 break;
564 }
565 case TargetOpcode::G_UADDSAT: {
566 computeKnownBitsImpl(MI.getOperand(1).getReg(), Known, DemandedElts,
567 Depth + 1);
568 computeKnownBitsImpl(MI.getOperand(2).getReg(), Known2, DemandedElts,
569 Depth + 1);
571 break;
572 }
573 case TargetOpcode::G_SSUBSAT: {
574 computeKnownBitsImpl(MI.getOperand(1).getReg(), Known, DemandedElts,
575 Depth + 1);
576 computeKnownBitsImpl(MI.getOperand(2).getReg(), Known2, DemandedElts,
577 Depth + 1);
579 break;
580 }
581 case TargetOpcode::G_USUBSAT: {
582 computeKnownBitsImpl(MI.getOperand(1).getReg(), Known, DemandedElts,
583 Depth + 1);
584 computeKnownBitsImpl(MI.getOperand(2).getReg(), Known2, DemandedElts,
585 Depth + 1);
587 break;
588 }
589 case TargetOpcode::G_UDIV: {
590 computeKnownBitsImpl(MI.getOperand(1).getReg(), Known, DemandedElts,
591 Depth + 1);
592 computeKnownBitsImpl(MI.getOperand(2).getReg(), Known2, DemandedElts,
593 Depth + 1);
594 Known = KnownBits::udiv(Known, Known2,
596 break;
597 }
598 case TargetOpcode::G_SDIV: {
599 computeKnownBitsImpl(MI.getOperand(1).getReg(), Known, DemandedElts,
600 Depth + 1);
601 computeKnownBitsImpl(MI.getOperand(2).getReg(), Known2, DemandedElts,
602 Depth + 1);
603 Known = KnownBits::sdiv(Known, Known2,
605 break;
606 }
607 case TargetOpcode::G_UREM: {
608 KnownBits LHSKnown(Known.getBitWidth());
609 KnownBits RHSKnown(Known.getBitWidth());
610
611 computeKnownBitsImpl(MI.getOperand(1).getReg(), LHSKnown, DemandedElts,
612 Depth + 1);
613 computeKnownBitsImpl(MI.getOperand(2).getReg(), RHSKnown, DemandedElts,
614 Depth + 1);
615
616 Known = KnownBits::urem(LHSKnown, RHSKnown);
617 break;
618 }
619 case TargetOpcode::G_SREM: {
620 KnownBits LHSKnown(Known.getBitWidth());
621 KnownBits RHSKnown(Known.getBitWidth());
622
623 computeKnownBitsImpl(MI.getOperand(1).getReg(), LHSKnown, DemandedElts,
624 Depth + 1);
625 computeKnownBitsImpl(MI.getOperand(2).getReg(), RHSKnown, DemandedElts,
626 Depth + 1);
627
628 Known = KnownBits::srem(LHSKnown, RHSKnown);
629 break;
630 }
631 case TargetOpcode::G_SELECT: {
632 computeKnownBitsMin(MI.getOperand(2).getReg(), MI.getOperand(3).getReg(),
633 Known, DemandedElts, Depth + 1);
634 break;
635 }
636 case TargetOpcode::G_SMIN: {
637 // TODO: Handle clamp pattern with number of sign bits
638 KnownBits KnownRHS;
639 computeKnownBitsImpl(MI.getOperand(1).getReg(), Known, DemandedElts,
640 Depth + 1);
641 computeKnownBitsImpl(MI.getOperand(2).getReg(), KnownRHS, DemandedElts,
642 Depth + 1);
643 Known = KnownBits::smin(Known, KnownRHS);
644 break;
645 }
646 case TargetOpcode::G_SMAX: {
647 // TODO: Handle clamp pattern with number of sign bits
648 KnownBits KnownRHS;
649 computeKnownBitsImpl(MI.getOperand(1).getReg(), Known, DemandedElts,
650 Depth + 1);
651 computeKnownBitsImpl(MI.getOperand(2).getReg(), KnownRHS, DemandedElts,
652 Depth + 1);
653 Known = KnownBits::smax(Known, KnownRHS);
654 break;
655 }
656 case TargetOpcode::G_UMIN: {
657 KnownBits KnownRHS;
658 computeKnownBitsImpl(MI.getOperand(1).getReg(), Known, DemandedElts,
659 Depth + 1);
660 computeKnownBitsImpl(MI.getOperand(2).getReg(), KnownRHS, DemandedElts,
661 Depth + 1);
662 Known = KnownBits::umin(Known, KnownRHS);
663 break;
664 }
665 case TargetOpcode::G_UMAX: {
666 KnownBits KnownRHS;
667 computeKnownBitsImpl(MI.getOperand(1).getReg(), Known, DemandedElts,
668 Depth + 1);
669 computeKnownBitsImpl(MI.getOperand(2).getReg(), KnownRHS, DemandedElts,
670 Depth + 1);
671 Known = KnownBits::umax(Known, KnownRHS);
672 break;
673 }
674 case TargetOpcode::G_FCMP:
675 case TargetOpcode::G_ICMP: {
676 if (DstTy.isVector())
677 break;
678 if (TL.getBooleanContents(DstTy.isVector(),
679 Opcode == TargetOpcode::G_FCMP) ==
681 BitWidth > 1)
682 Known.Zero.setBitsFrom(1);
683 break;
684 }
685 case TargetOpcode::G_SEXT: {
686 computeKnownBitsImpl(MI.getOperand(1).getReg(), Known, DemandedElts,
687 Depth + 1);
688 // If the sign bit is known to be zero or one, then sext will extend
689 // it to the top bits, else it will just zext.
690 Known = Known.sext(BitWidth);
691 break;
692 }
693 case TargetOpcode::G_ASSERT_SEXT:
694 case TargetOpcode::G_SEXT_INREG: {
695 computeKnownBitsImpl(MI.getOperand(1).getReg(), Known, DemandedElts,
696 Depth + 1);
697 Known = Known.sextInReg(MI.getOperand(2).getImm());
698 break;
699 }
700 case TargetOpcode::G_ANYEXT: {
701 computeKnownBitsImpl(MI.getOperand(1).getReg(), Known, DemandedElts,
702 Depth + 1);
703 Known = Known.anyext(BitWidth);
704 break;
705 }
706 case TargetOpcode::G_LOAD: {
707 const MachineMemOperand *MMO = *MI.memoperands_begin();
708 KnownBits KnownRange(MMO->getMemoryType().getScalarSizeInBits());
709 if (const MDNode *Ranges = MMO->getRanges())
710 computeKnownBitsFromRangeMetadata(*Ranges, KnownRange);
711 Known = KnownRange.anyext(Known.getBitWidth());
712 break;
713 }
714 case TargetOpcode::G_SEXTLOAD:
715 case TargetOpcode::G_ZEXTLOAD: {
716 if (DstTy.isVector())
717 break;
718 const MachineMemOperand *MMO = *MI.memoperands_begin();
719 KnownBits KnownRange(MMO->getMemoryType().getScalarSizeInBits());
720 if (const MDNode *Ranges = MMO->getRanges())
721 computeKnownBitsFromRangeMetadata(*Ranges, KnownRange);
722 Known = Opcode == TargetOpcode::G_SEXTLOAD
723 ? KnownRange.sext(Known.getBitWidth())
724 : KnownRange.zext(Known.getBitWidth());
725 break;
726 }
727 case TargetOpcode::G_ASHR: {
728 KnownBits LHSKnown, RHSKnown;
729 computeKnownBitsImpl(MI.getOperand(1).getReg(), LHSKnown, DemandedElts,
730 Depth + 1);
731 computeKnownBitsImpl(MI.getOperand(2).getReg(), RHSKnown, DemandedElts,
732 Depth + 1);
733 Known = KnownBits::ashr(LHSKnown, RHSKnown);
734 break;
735 }
736 case TargetOpcode::G_LSHR: {
737 KnownBits LHSKnown, RHSKnown;
738 computeKnownBitsImpl(MI.getOperand(1).getReg(), LHSKnown, DemandedElts,
739 Depth + 1);
740 computeKnownBitsImpl(MI.getOperand(2).getReg(), RHSKnown, DemandedElts,
741 Depth + 1);
742 Known = KnownBits::lshr(LHSKnown, RHSKnown);
743 break;
744 }
745 case TargetOpcode::G_SHL: {
746 KnownBits LHSKnown, RHSKnown;
747 computeKnownBitsImpl(MI.getOperand(1).getReg(), LHSKnown, DemandedElts,
748 Depth + 1);
749 computeKnownBitsImpl(MI.getOperand(2).getReg(), RHSKnown, DemandedElts,
750 Depth + 1);
751 Known = KnownBits::shl(LHSKnown, RHSKnown);
752 break;
753 }
754 case TargetOpcode::G_ROTL:
755 case TargetOpcode::G_ROTR: {
756 auto MaybeAmtOp =
757 isConstantOrConstantSplatVector(MI.getOperand(2).getReg(), MRI);
758 if (!MaybeAmtOp)
759 break;
760
761 Register SrcReg = MI.getOperand(1).getReg();
762 computeKnownBitsImpl(SrcReg, Known, DemandedElts, Depth + 1);
763
764 unsigned Amt = MaybeAmtOp->urem(BitWidth);
765
766 // Canonicalize to ROTR.
767 if (Opcode == TargetOpcode::G_ROTL)
768 Amt = BitWidth - Amt;
769
770 Known.Zero = Known.Zero.rotr(Amt);
771 Known.One = Known.One.rotr(Amt);
772 break;
773 }
774 case TargetOpcode::G_FSHL:
775 case TargetOpcode::G_FSHR: {
776 auto MaybeAmtOp =
777 isConstantOrConstantSplatVector(MI.getOperand(3).getReg(), MRI);
778 if (!MaybeAmtOp)
779 break;
780
781 const APInt Amt = *MaybeAmtOp;
782 computeKnownBitsImpl(MI.getOperand(1).getReg(), Known, DemandedElts,
783 Depth + 1);
784 computeKnownBitsImpl(MI.getOperand(2).getReg(), Known2, DemandedElts,
785 Depth + 1);
786 Known = Opcode == TargetOpcode::G_FSHL
787 ? KnownBits::fshl(Known, Known2, Amt)
788 : KnownBits::fshr(Known, Known2, Amt);
789 break;
790 }
791 case TargetOpcode::G_INTTOPTR:
792 case TargetOpcode::G_PTRTOINT:
793 if (DstTy.isVector())
794 break;
795 // Fall through and handle them the same as zext/trunc.
796 [[fallthrough]];
797 case TargetOpcode::G_ZEXT:
798 case TargetOpcode::G_TRUNC: {
799 Register SrcReg = MI.getOperand(1).getReg();
800 computeKnownBitsImpl(SrcReg, Known, DemandedElts, Depth + 1);
801 Known = Known.zextOrTrunc(BitWidth);
802 break;
803 }
804 case TargetOpcode::G_ASSERT_ZEXT: {
805 Register SrcReg = MI.getOperand(1).getReg();
806 computeKnownBitsImpl(SrcReg, Known, DemandedElts, Depth + 1);
807
808 unsigned SrcBitWidth = MI.getOperand(2).getImm();
809 assert(SrcBitWidth && "SrcBitWidth can't be zero");
810 APInt InMask = APInt::getLowBitsSet(BitWidth, SrcBitWidth);
811 Known.Zero |= (~InMask);
812 Known.One &= (~Known.Zero);
813 break;
814 }
815 case TargetOpcode::G_ASSERT_ALIGN: {
816 int64_t LogOfAlign = Log2_64(MI.getOperand(2).getImm());
817
818 // TODO: Should use maximum with source
819 // If a node is guaranteed to be aligned, set low zero bits accordingly as
820 // well as clearing one bits.
821 Known.Zero.setLowBits(LogOfAlign);
822 Known.One.clearLowBits(LogOfAlign);
823 break;
824 }
825 case TargetOpcode::G_MERGE_VALUES: {
826 unsigned NumOps = MI.getNumOperands();
827 unsigned OpSize = MRI.getType(MI.getOperand(1).getReg()).getSizeInBits();
828
829 for (unsigned I = 0; I != NumOps - 1; ++I) {
830 KnownBits SrcOpKnown;
831 computeKnownBitsImpl(MI.getOperand(I + 1).getReg(), SrcOpKnown,
832 DemandedElts, Depth + 1);
833 Known.insertBits(SrcOpKnown, I * OpSize);
834 }
835 break;
836 }
837 case TargetOpcode::G_UNMERGE_VALUES: {
838 unsigned NumOps = MI.getNumOperands();
839 Register SrcReg = MI.getOperand(NumOps - 1).getReg();
840 LLT SrcTy = MRI.getType(SrcReg);
841
842 if (SrcTy.isVector() && SrcTy.getScalarType() != DstTy.getScalarType())
843 return; // TODO: Handle vector->subelement unmerges
844
845 // Figure out the result operand index
846 unsigned DstIdx = 0;
847 for (; DstIdx != NumOps - 1 && MI.getOperand(DstIdx).getReg() != R;
848 ++DstIdx)
849 ;
850
851 APInt SubDemandedElts = DemandedElts;
852 if (SrcTy.isVector()) {
853 unsigned DstLanes = DstTy.isVector() ? DstTy.getNumElements() : 1;
854 SubDemandedElts =
855 DemandedElts.zext(SrcTy.getNumElements()).shl(DstIdx * DstLanes);
856 }
857
858 KnownBits SrcOpKnown;
859 computeKnownBitsImpl(SrcReg, SrcOpKnown, SubDemandedElts, Depth + 1);
860
861 if (SrcTy.isVector())
862 Known = std::move(SrcOpKnown);
863 else
864 Known = SrcOpKnown.extractBits(BitWidth, BitWidth * DstIdx);
865 break;
866 }
867 case TargetOpcode::G_BSWAP: {
868 Register SrcReg = MI.getOperand(1).getReg();
869 computeKnownBitsImpl(SrcReg, Known, DemandedElts, Depth + 1);
870 Known = Known.byteSwap();
871 break;
872 }
873 case TargetOpcode::G_BITREVERSE: {
874 Register SrcReg = MI.getOperand(1).getReg();
875 computeKnownBitsImpl(SrcReg, Known, DemandedElts, Depth + 1);
876 Known = Known.reverseBits();
877 break;
878 }
879 case TargetOpcode::G_CTPOP: {
880 computeKnownBitsImpl(MI.getOperand(1).getReg(), Known2, DemandedElts,
881 Depth + 1);
882 // We can bound the space the count needs. Also, bits known to be zero
883 // can't contribute to the population.
884 unsigned BitsPossiblySet = Known2.countMaxPopulation();
885 unsigned LowBits = llvm::bit_width(BitsPossiblySet);
886 Known.Zero.setBitsFrom(LowBits);
887 // TODO: we could bound Known.One using the lower bound on the number of
888 // bits which might be set provided by popcnt KnownOne2.
889 break;
890 }
891 case TargetOpcode::G_UBFX: {
892 KnownBits SrcOpKnown, OffsetKnown, WidthKnown;
893 computeKnownBitsImpl(MI.getOperand(1).getReg(), SrcOpKnown, DemandedElts,
894 Depth + 1);
895 computeKnownBitsImpl(MI.getOperand(2).getReg(), OffsetKnown, DemandedElts,
896 Depth + 1);
897 computeKnownBitsImpl(MI.getOperand(3).getReg(), WidthKnown, DemandedElts,
898 Depth + 1);
899 Known = extractBits(BitWidth, SrcOpKnown, OffsetKnown, WidthKnown);
900 break;
901 }
902 case TargetOpcode::G_SBFX: {
903 KnownBits SrcOpKnown, OffsetKnown, WidthKnown;
904 computeKnownBitsImpl(MI.getOperand(1).getReg(), SrcOpKnown, DemandedElts,
905 Depth + 1);
906 computeKnownBitsImpl(MI.getOperand(2).getReg(), OffsetKnown, DemandedElts,
907 Depth + 1);
908 computeKnownBitsImpl(MI.getOperand(3).getReg(), WidthKnown, DemandedElts,
909 Depth + 1);
910 OffsetKnown = OffsetKnown.sext(BitWidth);
911 WidthKnown = WidthKnown.sext(BitWidth);
912 Known = extractBits(BitWidth, SrcOpKnown, OffsetKnown, WidthKnown);
913 // Sign extend the extracted value using shift left and arithmetic shift
914 // right.
916 KnownBits ShiftKnown = KnownBits::sub(ExtKnown, WidthKnown);
917 Known = KnownBits::ashr(KnownBits::shl(Known, ShiftKnown), ShiftKnown);
918 break;
919 }
920 case TargetOpcode::G_UADDO:
921 case TargetOpcode::G_UADDE:
922 case TargetOpcode::G_SADDO:
923 case TargetOpcode::G_SADDE: {
924 if (MI.getOperand(1).getReg() == R) {
925 // If we know the result of a compare has the top bits zero, use this
926 // info.
927 if (TL.getBooleanContents(DstTy.isVector(), false) ==
929 BitWidth > 1)
930 Known.Zero.setBitsFrom(1);
931 break;
932 }
933
934 assert(MI.getOperand(0).getReg() == R &&
935 "We only compute knownbits for the sum here.");
936 // With [US]ADDE, a carry bit may be added in.
937 KnownBits Carry(1);
938 if (Opcode == TargetOpcode::G_UADDE || Opcode == TargetOpcode::G_SADDE) {
939 computeKnownBitsImpl(MI.getOperand(4).getReg(), Carry, DemandedElts,
940 Depth + 1);
941 // Carry has bit width 1
942 Carry = Carry.trunc(1);
943 } else {
944 Carry.setAllZero();
945 }
946
947 computeKnownBitsImpl(MI.getOperand(2).getReg(), Known, DemandedElts,
948 Depth + 1);
949 computeKnownBitsImpl(MI.getOperand(3).getReg(), Known2, DemandedElts,
950 Depth + 1);
951 Known = KnownBits::computeForAddCarry(Known, Known2, Carry);
952 break;
953 }
954 case TargetOpcode::G_USUBO:
955 case TargetOpcode::G_USUBE:
956 case TargetOpcode::G_SSUBO:
957 case TargetOpcode::G_SSUBE:
958 case TargetOpcode::G_UMULO:
959 case TargetOpcode::G_SMULO: {
960 if (MI.getOperand(1).getReg() == R) {
961 // If we know the result of a compare has the top bits zero, use this
962 // info.
963 if (TL.getBooleanContents(DstTy.isVector(), false) ==
965 BitWidth > 1)
966 Known.Zero.setBitsFrom(1);
967 }
968 break;
969 }
970 case TargetOpcode::G_CTTZ:
971 case TargetOpcode::G_CTTZ_ZERO_POISON: {
972 KnownBits SrcOpKnown;
973 computeKnownBitsImpl(MI.getOperand(1).getReg(), SrcOpKnown, DemandedElts,
974 Depth + 1);
975 // If we have a known 1, its position is our upper bound
976 unsigned PossibleTZ = SrcOpKnown.countMaxTrailingZeros();
977 unsigned LowBits = llvm::bit_width(PossibleTZ);
978 Known.Zero.setBitsFrom(LowBits);
979 break;
980 }
981 case TargetOpcode::G_CTLZ:
982 case TargetOpcode::G_CTLZ_ZERO_POISON: {
983 KnownBits SrcOpKnown;
984 computeKnownBitsImpl(MI.getOperand(1).getReg(), SrcOpKnown, DemandedElts,
985 Depth + 1);
986 // If we have a known 1, its position is our upper bound.
987 unsigned PossibleLZ = SrcOpKnown.countMaxLeadingZeros();
988 unsigned LowBits = llvm::bit_width(PossibleLZ);
989 Known.Zero.setBitsFrom(LowBits);
990 break;
991 }
992 case TargetOpcode::G_CTLS: {
993 Register Reg = MI.getOperand(1).getReg();
994 unsigned MinRedundantSignBits = computeNumSignBits(Reg, Depth + 1) - 1;
995
996 unsigned MaxUpperRedundantSignBits = MRI.getType(Reg).getScalarSizeInBits();
997
998 ConstantRange Range(APInt(BitWidth, MinRedundantSignBits),
999 APInt(BitWidth, MaxUpperRedundantSignBits));
1000
1001 Known = Range.toKnownBits();
1002 break;
1003 }
1004 case TargetOpcode::G_EXTRACT_VECTOR_ELT: {
1006 Register InVec = Extract.getVectorReg();
1007 Register EltNo = Extract.getIndexReg();
1008
1009 auto ConstEltNo = getIConstantVRegVal(EltNo, MRI);
1010
1011 LLT VecVT = MRI.getType(InVec);
1012 // computeKnownBits not yet implemented for scalable vectors.
1013 if (VecVT.isScalableVector())
1014 break;
1015
1016 const unsigned EltBitWidth = VecVT.getScalarSizeInBits();
1017 const unsigned NumSrcElts = VecVT.getNumElements();
1018 // A return type different from the vector's element type may lead to
1019 // issues with pattern selection. Bail out to avoid that.
1020 if (BitWidth > EltBitWidth)
1021 break;
1022
1023 Known.Zero.setAllBits();
1024 Known.One.setAllBits();
1025
1026 // If we know the element index, just demand that vector element, else for
1027 // an unknown element index, ignore DemandedElts and demand them all.
1028 APInt DemandedSrcElts = APInt::getAllOnes(NumSrcElts);
1029 if (ConstEltNo && ConstEltNo->ult(NumSrcElts))
1030 DemandedSrcElts =
1031 APInt::getOneBitSet(NumSrcElts, ConstEltNo->getZExtValue());
1032
1033 computeKnownBitsImpl(InVec, Known, DemandedSrcElts, Depth + 1);
1034 break;
1035 }
1036 case TargetOpcode::G_INSERT_VECTOR_ELT: {
1038 Register InVec = Insert.getVectorReg();
1039 Register InVal = Insert.getElementReg();
1040 Register EltNo = Insert.getIndexReg();
1041 LLT VecVT = MRI.getType(InVec);
1042
1043 if (VecVT.isScalableVector())
1044 break;
1045
1046 auto ConstEltNo = getIConstantVRegVal(EltNo, MRI);
1047 unsigned NumElts = VecVT.getNumElements();
1048
1049 bool DemandedVal = true;
1050 APInt DemandedVecElts = DemandedElts;
1051 if (ConstEltNo && ConstEltNo->ult(NumElts)) {
1052 unsigned EltIdx = ConstEltNo->getZExtValue();
1053 DemandedVal = !!DemandedElts[EltIdx];
1054 DemandedVecElts.clearBit(EltIdx);
1055 }
1056 Known.setAllConflict();
1057 if (DemandedVal) {
1058 computeKnownBitsImpl(InVal, Known2, APInt(1, 1), Depth + 1);
1059 Known = Known.intersectWith(Known2.zextOrTrunc(BitWidth));
1060 }
1061 if (!!DemandedVecElts) {
1062 computeKnownBitsImpl(InVec, Known2, DemandedVecElts, Depth + 1);
1063 Known = Known.intersectWith(Known2);
1064 }
1065 break;
1066 }
1067 case TargetOpcode::G_SHUFFLE_VECTOR: {
1068 APInt DemandedLHS, DemandedRHS;
1069 // Collect the known bits that are shared by every vector element referenced
1070 // by the shuffle.
1071 unsigned NumElts = MRI.getType(MI.getOperand(1).getReg()).getNumElements();
1072 if (!getShuffleDemandedElts(NumElts, MI.getOperand(3).getShuffleMask(),
1073 DemandedElts, DemandedLHS, DemandedRHS))
1074 break;
1075
1076 // Known bits are the values that are shared by every demanded element.
1077 Known.Zero.setAllBits();
1078 Known.One.setAllBits();
1079 if (!!DemandedLHS) {
1080 computeKnownBitsImpl(MI.getOperand(1).getReg(), Known2, DemandedLHS,
1081 Depth + 1);
1082 Known = Known.intersectWith(Known2);
1083 }
1084 // If we don't know any bits, early out.
1085 if (Known.isUnknown())
1086 break;
1087 if (!!DemandedRHS) {
1088 computeKnownBitsImpl(MI.getOperand(2).getReg(), Known2, DemandedRHS,
1089 Depth + 1);
1090 Known = Known.intersectWith(Known2);
1091 }
1092 break;
1093 }
1094 case TargetOpcode::G_CONCAT_VECTORS: {
1095 if (MRI.getType(MI.getOperand(0).getReg()).isScalableVector())
1096 break;
1097 // Split DemandedElts and test each of the demanded subvectors.
1098 Known.Zero.setAllBits();
1099 Known.One.setAllBits();
1100 unsigned NumSubVectorElts =
1101 MRI.getType(MI.getOperand(1).getReg()).getNumElements();
1102
1103 for (const auto &[I, MO] : enumerate(drop_begin(MI.operands()))) {
1104 APInt DemandedSub =
1105 DemandedElts.extractBits(NumSubVectorElts, I * NumSubVectorElts);
1106 if (!!DemandedSub) {
1107 computeKnownBitsImpl(MO.getReg(), Known2, DemandedSub, Depth + 1);
1108
1109 Known = Known.intersectWith(Known2);
1110 }
1111 // If we don't know any bits, early out.
1112 if (Known.isUnknown())
1113 break;
1114 }
1115 break;
1116 }
1117 case TargetOpcode::G_ABS: {
1118 Register SrcReg = MI.getOperand(1).getReg();
1119 computeKnownBitsImpl(SrcReg, Known, DemandedElts, Depth + 1);
1120 Known = Known.abs();
1121 Known.Zero.setHighBits(computeNumSignBits(SrcReg, DemandedElts, Depth + 1) -
1122 1);
1123 break;
1124 }
1125 }
1126
1128}
1129
1130void GISelValueTracking::computeKnownFPClass(Register R, KnownFPClass &Known,
1131 FPClassTest InterestedClasses,
1132 unsigned Depth) {
1133 LLT Ty = MRI.getType(R);
1134 APInt DemandedElts =
1135 Ty.isFixedVector() ? APInt::getAllOnes(Ty.getNumElements()) : APInt(1, 1);
1136 computeKnownFPClass(R, DemandedElts, InterestedClasses, Known, Depth);
1137}
1138
1139/// Return true if this value is known to be the fractional part x - floor(x),
1140/// which lies in [0, 1). This implies the value cannot introduce overflow in a
1141/// fmul when the other operand is known finite.
1143 using namespace MIPatternMatch;
1144 Register SubX;
1145 return mi_match(R, MRI, m_GFSub(m_Reg(SubX), m_GFFloor(m_DeferredReg(SubX))));
1146}
1147
1148void GISelValueTracking::computeKnownFPClassForFPTrunc(
1149 const MachineInstr &MI, const APInt &DemandedElts,
1150 FPClassTest InterestedClasses, KnownFPClass &Known, unsigned Depth) {
1151 if ((InterestedClasses & (KnownFPClass::OrderedLessThanZeroMask | fcNan)) ==
1152 fcNone)
1153 return;
1154
1155 Register Val = MI.getOperand(1).getReg();
1156 KnownFPClass KnownSrc;
1157 computeKnownFPClass(Val, DemandedElts, InterestedClasses, KnownSrc,
1158 Depth + 1);
1159 Known = KnownFPClass::fptrunc(KnownSrc);
1160}
1161
1162void GISelValueTracking::computeKnownFPClass(Register R,
1163 const APInt &DemandedElts,
1164 FPClassTest InterestedClasses,
1166 unsigned Depth) {
1167 assert(Known.isUnknown() && "should not be called with known information");
1168
1169 if (!DemandedElts) {
1170 // No demanded elts, better to assume we don't know anything.
1171 Known.resetAll();
1172 return;
1173 }
1174
1175 assert(Depth <= MaxAnalysisRecursionDepth && "Limit Search Depth");
1176
1177 MachineInstr &MI = *MRI.getVRegDef(R);
1178 unsigned Opcode = MI.getOpcode();
1179 LLT DstTy = MRI.getType(R);
1180
1181 if (!DstTy.isValid()) {
1182 Known.resetAll();
1183 return;
1184 }
1185
1186 if (auto Cst = GFConstant::getConstant(R, MRI)) {
1187 switch (Cst->getKind()) {
1189 auto APF = Cst->getScalarValue();
1190 Known.KnownFPClasses = APF.classify();
1191 Known.SignBit = APF.isNegative();
1192 break;
1193 }
1195 Known.KnownFPClasses = fcNone;
1196 bool SignBitAllZero = true;
1197 bool SignBitAllOne = true;
1198
1199 for (auto C : *Cst) {
1200 Known.KnownFPClasses |= C.classify();
1201 if (C.isNegative())
1202 SignBitAllZero = false;
1203 else
1204 SignBitAllOne = false;
1205 }
1206
1207 if (SignBitAllOne != SignBitAllZero)
1208 Known.SignBit = SignBitAllOne;
1209
1210 break;
1211 }
1213 Known.resetAll();
1214 break;
1215 }
1216 }
1217
1218 return;
1219 }
1220
1221 FPClassTest KnownNotFromFlags = fcNone;
1223 KnownNotFromFlags |= fcNan;
1225 KnownNotFromFlags |= fcInf;
1226
1227 // We no longer need to find out about these bits from inputs if we can
1228 // assume this from flags/attributes.
1229 InterestedClasses &= ~KnownNotFromFlags;
1230
1231 llvm::scope_exit ClearClassesFromFlags(
1232 [=, &Known] { Known.knownNot(KnownNotFromFlags); });
1233
1234 // All recursive calls that increase depth must come after this.
1236 return;
1237
1238 const MachineFunction *MF = MI.getMF();
1239
1240 switch (Opcode) {
1241 default:
1242 TL.computeKnownFPClassForTargetInstr(*this, R, Known, DemandedElts, MRI,
1243 Depth);
1244 break;
1245 case TargetOpcode::G_FNEG: {
1246 Register Val = MI.getOperand(1).getReg();
1247 computeKnownFPClass(Val, DemandedElts, InterestedClasses, Known, Depth + 1);
1248 Known.fneg();
1249 break;
1250 }
1251 case TargetOpcode::G_SELECT: {
1252 GSelect &SelMI = cast<GSelect>(MI);
1253 Register Cond = SelMI.getCondReg();
1254 Register LHS = SelMI.getTrueReg();
1255 Register RHS = SelMI.getFalseReg();
1256
1257 FPClassTest FilterLHS = fcAllFlags;
1258 FPClassTest FilterRHS = fcAllFlags;
1259
1260 Register TestedValue;
1261 FPClassTest MaskIfTrue = fcAllFlags;
1262 FPClassTest MaskIfFalse = fcAllFlags;
1263 FPClassTest ClassVal = fcNone;
1264
1265 CmpInst::Predicate Pred;
1266 Register CmpLHS, CmpRHS;
1267 if (mi_match(Cond, MRI,
1268 m_GFCmp(m_Pred(Pred), m_Reg(CmpLHS), m_Reg(CmpRHS)))) {
1269 // If the select filters out a value based on the class, it no longer
1270 // participates in the class of the result
1271
1272 // TODO: In some degenerate cases we can infer something if we try again
1273 // without looking through sign operations.
1274 bool LookThroughFAbsFNeg = CmpLHS != LHS && CmpLHS != RHS;
1275 std::tie(TestedValue, MaskIfTrue, MaskIfFalse) =
1276 fcmpImpliesClass(Pred, *MF, CmpLHS, CmpRHS, LookThroughFAbsFNeg);
1277 } else if (mi_match(
1278 Cond, MRI,
1279 m_GIsFPClass(m_Reg(TestedValue), m_FPClassTest(ClassVal)))) {
1280 FPClassTest TestedMask = ClassVal;
1281 MaskIfTrue = TestedMask;
1282 MaskIfFalse = ~TestedMask;
1283 }
1284
1285 if (TestedValue == LHS) {
1286 // match !isnan(x) ? x : y
1287 FilterLHS = MaskIfTrue;
1288 } else if (TestedValue == RHS) { // && IsExactClass
1289 // match !isnan(x) ? y : x
1290 FilterRHS = MaskIfFalse;
1291 }
1292
1293 KnownFPClass Known2;
1294 computeKnownFPClass(LHS, DemandedElts, InterestedClasses & FilterLHS, Known,
1295 Depth + 1);
1296 Known.KnownFPClasses &= FilterLHS;
1297
1298 computeKnownFPClass(RHS, DemandedElts, InterestedClasses & FilterRHS,
1299 Known2, Depth + 1);
1300 Known2.KnownFPClasses &= FilterRHS;
1301
1302 Known |= Known2;
1303 break;
1304 }
1305 case TargetOpcode::G_FCOPYSIGN: {
1306 Register Magnitude = MI.getOperand(1).getReg();
1307 Register Sign = MI.getOperand(2).getReg();
1308
1309 KnownFPClass KnownSign;
1310
1311 computeKnownFPClass(Magnitude, DemandedElts, InterestedClasses, Known,
1312 Depth + 1);
1313 computeKnownFPClass(Sign, DemandedElts, InterestedClasses, KnownSign,
1314 Depth + 1);
1315 Known.copysign(KnownSign);
1316 break;
1317 }
1318 case TargetOpcode::G_FMA:
1319 case TargetOpcode::G_STRICT_FMA:
1320 case TargetOpcode::G_FMAD: {
1321 if ((InterestedClasses & fcNegative) == fcNone)
1322 break;
1323
1324 Register A = MI.getOperand(1).getReg();
1325 Register B = MI.getOperand(2).getReg();
1326 Register C = MI.getOperand(3).getReg();
1327
1328 DenormalMode Mode =
1329 MF->getDenormalMode(getFltSemanticForLLT(DstTy.getScalarType()));
1330
1331 if (A == B && isGuaranteedNotToBeUndef(A, MRI, Depth + 1)) {
1332 // x * x + y
1333 KnownFPClass KnownSrc, KnownAddend;
1334 computeKnownFPClass(C, DemandedElts, InterestedClasses, KnownAddend,
1335 Depth + 1);
1336 computeKnownFPClass(A, DemandedElts, InterestedClasses, KnownSrc,
1337 Depth + 1);
1338 if (KnownNotFromFlags) {
1339 KnownSrc.knownNot(KnownNotFromFlags);
1340 KnownAddend.knownNot(KnownNotFromFlags);
1341 }
1342 Known = KnownFPClass::fma_square(KnownSrc, KnownAddend, Mode);
1343 } else {
1344 KnownFPClass KnownSrc[3];
1345 computeKnownFPClass(A, DemandedElts, InterestedClasses, KnownSrc[0],
1346 Depth + 1);
1347 if (KnownSrc[0].isUnknown())
1348 break;
1349 computeKnownFPClass(B, DemandedElts, InterestedClasses, KnownSrc[1],
1350 Depth + 1);
1351 if (KnownSrc[1].isUnknown())
1352 break;
1353 computeKnownFPClass(C, DemandedElts, InterestedClasses, KnownSrc[2],
1354 Depth + 1);
1355 if (KnownSrc[2].isUnknown())
1356 break;
1357 if (KnownNotFromFlags) {
1358 KnownSrc[0].knownNot(KnownNotFromFlags);
1359 KnownSrc[1].knownNot(KnownNotFromFlags);
1360 KnownSrc[2].knownNot(KnownNotFromFlags);
1361 }
1362 Known = KnownFPClass::fma(KnownSrc[0], KnownSrc[1], KnownSrc[2], Mode);
1363 }
1364 break;
1365 }
1366 case TargetOpcode::G_FSQRT:
1367 case TargetOpcode::G_STRICT_FSQRT: {
1368 KnownFPClass KnownSrc;
1369 FPClassTest InterestedSrcs = InterestedClasses;
1370 if (InterestedClasses & fcNan)
1371 InterestedSrcs |= KnownFPClass::OrderedLessThanZeroMask;
1372
1373 Register Val = MI.getOperand(1).getReg();
1374 computeKnownFPClass(Val, DemandedElts, InterestedSrcs, KnownSrc, Depth + 1);
1375
1376 DenormalMode Mode =
1377 MF->getDenormalMode(getFltSemanticForLLT(DstTy.getScalarType()));
1378 Known = KnownFPClass::sqrt(KnownSrc, Mode);
1379 if (MI.getFlag(MachineInstr::MIFlag::FmNsz))
1380 Known.knownNot(fcNegZero);
1381 break;
1382 }
1383 case TargetOpcode::G_FABS: {
1384 if ((InterestedClasses & (fcNan | fcPositive)) != fcNone) {
1385 Register Val = MI.getOperand(1).getReg();
1386 // If we only care about the sign bit we don't need to inspect the
1387 // operand.
1388 computeKnownFPClass(Val, DemandedElts, InterestedClasses, Known,
1389 Depth + 1);
1390 }
1391 Known.fabs();
1392 break;
1393 }
1394 case TargetOpcode::G_FATAN2: {
1395 Register Y = MI.getOperand(1).getReg();
1396 Register X = MI.getOperand(2).getReg();
1397 KnownFPClass KnownY, KnownX;
1398 computeKnownFPClass(Y, DemandedElts, InterestedClasses, KnownY, Depth + 1);
1399 computeKnownFPClass(X, DemandedElts, InterestedClasses, KnownX, Depth + 1);
1400 Known = KnownFPClass::atan2(KnownY, KnownX);
1401 break;
1402 }
1403 case TargetOpcode::G_FSINH: {
1404 Register Val = MI.getOperand(1).getReg();
1405 KnownFPClass KnownSrc;
1406 computeKnownFPClass(Val, DemandedElts, InterestedClasses, KnownSrc,
1407 Depth + 1);
1408 Known = KnownFPClass::sinh(KnownSrc);
1409 break;
1410 }
1411 case TargetOpcode::G_FCOSH: {
1412 Register Val = MI.getOperand(1).getReg();
1413 KnownFPClass KnownSrc;
1414 computeKnownFPClass(Val, DemandedElts, InterestedClasses, KnownSrc,
1415 Depth + 1);
1416 Known = KnownFPClass::cosh(KnownSrc);
1417 break;
1418 }
1419 case TargetOpcode::G_FTANH: {
1420 Register Val = MI.getOperand(1).getReg();
1421 KnownFPClass KnownSrc;
1422 computeKnownFPClass(Val, DemandedElts, InterestedClasses, KnownSrc,
1423 Depth + 1);
1424 Known = KnownFPClass::tanh(KnownSrc);
1425 break;
1426 }
1427 case TargetOpcode::G_FASIN: {
1428 Register Val = MI.getOperand(1).getReg();
1429 KnownFPClass KnownSrc;
1430 computeKnownFPClass(Val, DemandedElts, InterestedClasses, KnownSrc,
1431 Depth + 1);
1432 Known = KnownFPClass::asin(KnownSrc);
1433 break;
1434 }
1435 case TargetOpcode::G_FACOS: {
1436 Register Val = MI.getOperand(1).getReg();
1437 KnownFPClass KnownSrc;
1438 computeKnownFPClass(Val, DemandedElts, InterestedClasses, KnownSrc,
1439 Depth + 1);
1440 Known = KnownFPClass::acos(KnownSrc);
1441 break;
1442 }
1443 case TargetOpcode::G_FATAN: {
1444 Register Val = MI.getOperand(1).getReg();
1445 KnownFPClass KnownSrc;
1446 computeKnownFPClass(Val, DemandedElts, InterestedClasses, KnownSrc,
1447 Depth + 1);
1448 Known = KnownFPClass::atan(KnownSrc);
1449 break;
1450 }
1451 case TargetOpcode::G_FTAN: {
1452 Register Val = MI.getOperand(1).getReg();
1453 KnownFPClass KnownSrc;
1454 computeKnownFPClass(Val, DemandedElts, InterestedClasses, KnownSrc,
1455 Depth + 1);
1456 Known = KnownFPClass::tan(KnownSrc);
1457 break;
1458 }
1459 case TargetOpcode::G_FSIN:
1460 case TargetOpcode::G_FCOS: {
1461 // Return NaN on infinite inputs.
1462 Register Val = MI.getOperand(1).getReg();
1463 KnownFPClass KnownSrc;
1464 computeKnownFPClass(Val, DemandedElts, InterestedClasses, KnownSrc,
1465 Depth + 1);
1466 Known = Opcode == TargetOpcode::G_FCOS ? KnownFPClass::cos(KnownSrc)
1467 : KnownFPClass::sin(KnownSrc);
1468 break;
1469 }
1470 case TargetOpcode::G_FSINCOS: {
1471 // Operand layout: (sin_dst, cos_dst, src)
1472 Register Src = MI.getOperand(2).getReg();
1473 KnownFPClass KnownSrc;
1474 computeKnownFPClass(Src, DemandedElts, InterestedClasses, KnownSrc,
1475 Depth + 1);
1476 if (R == MI.getOperand(0).getReg())
1477 Known = KnownFPClass::sin(KnownSrc);
1478 else
1479 Known = KnownFPClass::cos(KnownSrc);
1480 break;
1481 }
1482 case TargetOpcode::G_FMAXNUM:
1483 case TargetOpcode::G_FMINNUM:
1484 case TargetOpcode::G_FMINNUM_IEEE:
1485 case TargetOpcode::G_FMAXIMUM:
1486 case TargetOpcode::G_FMINIMUM:
1487 case TargetOpcode::G_FMAXNUM_IEEE:
1488 case TargetOpcode::G_FMAXIMUMNUM:
1489 case TargetOpcode::G_FMINIMUMNUM: {
1490 Register LHS = MI.getOperand(1).getReg();
1491 Register RHS = MI.getOperand(2).getReg();
1492 KnownFPClass KnownLHS, KnownRHS;
1493
1494 computeKnownFPClass(LHS, DemandedElts, InterestedClasses, KnownLHS,
1495 Depth + 1);
1496 computeKnownFPClass(RHS, DemandedElts, InterestedClasses, KnownRHS,
1497 Depth + 1);
1498
1500 switch (Opcode) {
1501 case TargetOpcode::G_FMINIMUM:
1503 break;
1504 case TargetOpcode::G_FMAXIMUM:
1506 break;
1507 case TargetOpcode::G_FMINIMUMNUM:
1509 break;
1510 case TargetOpcode::G_FMAXIMUMNUM:
1512 break;
1513 case TargetOpcode::G_FMINNUM:
1514 case TargetOpcode::G_FMINNUM_IEEE:
1516 break;
1517 case TargetOpcode::G_FMAXNUM:
1518 case TargetOpcode::G_FMAXNUM_IEEE:
1520 break;
1521 default:
1522 llvm_unreachable("unhandled min/max opcode");
1523 }
1524
1525 DenormalMode Mode =
1526 MF->getDenormalMode(getFltSemanticForLLT(DstTy.getScalarType()));
1527 Known = KnownFPClass::minMaxLike(KnownLHS, KnownRHS, Kind, Mode);
1528 break;
1529 }
1530 case TargetOpcode::G_FCANONICALIZE: {
1531 Register Val = MI.getOperand(1).getReg();
1532 KnownFPClass KnownSrc;
1533 computeKnownFPClass(Val, DemandedElts, InterestedClasses, KnownSrc,
1534 Depth + 1);
1535
1536 LLT Ty = MRI.getType(Val).getScalarType();
1537 const fltSemantics &FPType = getFltSemanticForLLT(Ty);
1538 DenormalMode DenormMode = MF->getDenormalMode(FPType);
1539 Known = KnownFPClass::canonicalize(KnownSrc, DenormMode);
1540 break;
1541 }
1542 case TargetOpcode::G_VECREDUCE_FMAX:
1543 case TargetOpcode::G_VECREDUCE_FMIN:
1544 case TargetOpcode::G_VECREDUCE_FMAXIMUM:
1545 case TargetOpcode::G_VECREDUCE_FMINIMUM: {
1546 Register Val = MI.getOperand(1).getReg();
1547 // reduce min/max will choose an element from one of the vector elements,
1548 // so we can infer and class information that is common to all elements.
1549
1550 Known =
1551 computeKnownFPClass(Val, MI.getFlags(), InterestedClasses, Depth + 1);
1552 // Can only propagate sign if output is never NaN.
1553 if (!Known.isKnownNeverNaN())
1554 Known.SignBit.reset();
1555 break;
1556 }
1557 case TargetOpcode::G_FFLOOR:
1558 case TargetOpcode::G_FCEIL:
1559 case TargetOpcode::G_FRINT:
1560 case TargetOpcode::G_FNEARBYINT:
1561 case TargetOpcode::G_INTRINSIC_FPTRUNC_ROUND:
1562 case TargetOpcode::G_INTRINSIC_ROUND:
1563 case TargetOpcode::G_INTRINSIC_ROUNDEVEN:
1564 case TargetOpcode::G_INTRINSIC_TRUNC: {
1565 Register Val = MI.getOperand(1).getReg();
1566 KnownFPClass KnownSrc;
1567 FPClassTest InterestedSrcs = InterestedClasses;
1568 if (InterestedSrcs & fcPosFinite)
1569 InterestedSrcs |= fcPosFinite;
1570 if (InterestedSrcs & fcNegFinite)
1571 InterestedSrcs |= fcNegFinite;
1572 computeKnownFPClass(Val, DemandedElts, InterestedSrcs, KnownSrc, Depth + 1);
1573
1574 // TODO: handle multi unit FPTypes once LLT FPInfo lands
1575 bool IsTrunc = Opcode == TargetOpcode::G_INTRINSIC_TRUNC;
1576 Known = KnownFPClass::roundToIntegral(KnownSrc, IsTrunc,
1577 /*IsMultiUnitFPType=*/false);
1578 break;
1579 }
1580 case TargetOpcode::G_FEXP:
1581 case TargetOpcode::G_FEXP2:
1582 case TargetOpcode::G_FEXP10: {
1583 Register Val = MI.getOperand(1).getReg();
1584 KnownFPClass KnownSrc;
1585 computeKnownFPClass(Val, DemandedElts, InterestedClasses, KnownSrc,
1586 Depth + 1);
1587 Known = KnownFPClass::exp(KnownSrc);
1588 break;
1589 }
1590 case TargetOpcode::G_FLOG:
1591 case TargetOpcode::G_FLOG2:
1592 case TargetOpcode::G_FLOG10: {
1593 // log(+inf) -> +inf
1594 // log([+-]0.0) -> -inf
1595 // log(-inf) -> nan
1596 // log(-x) -> nan
1597 if ((InterestedClasses & (fcNan | fcInf)) == fcNone)
1598 break;
1599
1600 FPClassTest InterestedSrcs = InterestedClasses;
1601 if ((InterestedClasses & fcNegInf) != fcNone)
1602 InterestedSrcs |= fcZero | fcSubnormal;
1603 if ((InterestedClasses & fcNan) != fcNone)
1604 InterestedSrcs |= fcNan | fcNegative;
1605
1606 Register Val = MI.getOperand(1).getReg();
1607 KnownFPClass KnownSrc;
1608 computeKnownFPClass(Val, DemandedElts, InterestedSrcs, KnownSrc, Depth + 1);
1609
1610 LLT Ty = MRI.getType(Val).getScalarType();
1611 const fltSemantics &FltSem = getFltSemanticForLLT(Ty);
1612 DenormalMode Mode = MF->getDenormalMode(FltSem);
1613 Known = KnownFPClass::log(KnownSrc, Mode);
1614 break;
1615 }
1616 case TargetOpcode::G_FPOWI: {
1617 if ((InterestedClasses & (fcNan | fcInf | fcNegative)) == fcNone)
1618 break;
1619
1620 Register Exp = MI.getOperand(2).getReg();
1621 LLT ExpTy = MRI.getType(Exp);
1622 KnownBits ExponentKnownBits = getKnownBits(
1623 Exp, ExpTy.isVector() ? DemandedElts : APInt(1, 1), Depth + 1);
1624
1625 FPClassTest InterestedSrcs = fcNone;
1626 if (InterestedClasses & fcNan)
1627 InterestedSrcs |= fcNan;
1628 if (!ExponentKnownBits.isZero()) {
1629 if (InterestedClasses & fcInf)
1630 InterestedSrcs |= fcFinite | fcInf;
1631 if ((InterestedClasses & fcNegative) && !ExponentKnownBits.isEven())
1632 InterestedSrcs |= fcNegative;
1633 }
1634
1635 KnownFPClass KnownSrc;
1636 if (InterestedSrcs != fcNone) {
1637 Register Val = MI.getOperand(1).getReg();
1638 computeKnownFPClass(Val, DemandedElts, InterestedSrcs, KnownSrc,
1639 Depth + 1);
1640 }
1641
1642 Known = KnownFPClass::powi(KnownSrc, ExponentKnownBits);
1643 break;
1644 }
1645 case TargetOpcode::G_FLDEXP:
1646 case TargetOpcode::G_STRICT_FLDEXP: {
1647 Register Val = MI.getOperand(1).getReg();
1648 KnownFPClass KnownSrc;
1649 computeKnownFPClass(Val, DemandedElts, InterestedClasses, KnownSrc,
1650 Depth + 1);
1651
1652 // Can refine inf/zero handling based on the exponent operand.
1653 const FPClassTest ExpInfoMask = fcZero | fcSubnormal | fcInf;
1654 KnownBits ExpBits;
1655 if ((KnownSrc.KnownFPClasses & ExpInfoMask) != fcNone) {
1656 Register ExpReg = MI.getOperand(2).getReg();
1657 LLT ExpTy = MRI.getType(ExpReg);
1658 ExpBits = getKnownBits(
1659 ExpReg, ExpTy.isVector() ? DemandedElts : APInt(1, 1), Depth + 1);
1660 }
1661
1662 LLT ScalarTy = DstTy.getScalarType();
1663 const fltSemantics &Flt = getFltSemanticForLLT(ScalarTy);
1664 DenormalMode Mode = MF->getDenormalMode(Flt);
1665 Known = KnownFPClass::ldexp(KnownSrc, ExpBits, Flt, Mode);
1666 break;
1667 }
1668 case TargetOpcode::G_FADD:
1669 case TargetOpcode::G_STRICT_FADD:
1670 case TargetOpcode::G_FSUB:
1671 case TargetOpcode::G_STRICT_FSUB: {
1672 Register LHS = MI.getOperand(1).getReg();
1673 Register RHS = MI.getOperand(2).getReg();
1674 bool IsAdd = (Opcode == TargetOpcode::G_FADD ||
1675 Opcode == TargetOpcode::G_STRICT_FADD);
1676 bool WantNegative =
1677 IsAdd &&
1678 (InterestedClasses & KnownFPClass::OrderedLessThanZeroMask) != fcNone;
1679 bool WantNaN = (InterestedClasses & fcNan) != fcNone;
1680 bool WantNegZero = (InterestedClasses & fcNegZero) != fcNone;
1681
1682 if (!WantNaN && !WantNegative && !WantNegZero) {
1683 break;
1684 }
1685
1686 DenormalMode Mode =
1687 MF->getDenormalMode(getFltSemanticForLLT(DstTy.getScalarType()));
1688
1689 FPClassTest InterestedSrcs = InterestedClasses;
1690 if (WantNegative)
1691 InterestedSrcs |= KnownFPClass::OrderedLessThanZeroMask;
1692 if (InterestedClasses & fcNan)
1693 InterestedSrcs |= fcInf;
1694
1695 // Special case fadd x, x (canonical form of fmul x, 2).
1696 if (IsAdd && LHS == RHS && isGuaranteedNotToBeUndef(LHS, MRI, Depth + 1)) {
1697 KnownFPClass KnownSelf;
1698 computeKnownFPClass(LHS, DemandedElts, InterestedSrcs, KnownSelf,
1699 Depth + 1);
1700 Known = KnownFPClass::fadd_self(KnownSelf, Mode);
1701 break;
1702 }
1703
1704 KnownFPClass KnownLHS, KnownRHS;
1705 computeKnownFPClass(RHS, DemandedElts, InterestedSrcs, KnownRHS, Depth + 1);
1706
1707 if ((WantNaN && KnownRHS.isKnownNeverNaN()) ||
1708 (WantNegative && KnownRHS.cannotBeOrderedLessThanZero()) ||
1709 WantNegZero || !IsAdd) {
1710 // RHS is canonically cheaper to compute. Skip inspecting the LHS if
1711 // there's no point.
1712 computeKnownFPClass(LHS, DemandedElts, InterestedSrcs, KnownLHS,
1713 Depth + 1);
1714 }
1715
1716 if (IsAdd)
1717 Known = KnownFPClass::fadd(KnownLHS, KnownRHS, Mode);
1718 else
1719 Known = KnownFPClass::fsub(KnownLHS, KnownRHS, Mode);
1720 break;
1721 }
1722 case TargetOpcode::G_FMUL:
1723 case TargetOpcode::G_STRICT_FMUL: {
1724 Register LHS = MI.getOperand(1).getReg();
1725 Register RHS = MI.getOperand(2).getReg();
1726 DenormalMode Mode =
1727 MF->getDenormalMode(getFltSemanticForLLT(DstTy.getScalarType()));
1728
1729 // X * X is always non-negative or a NaN (use square() for precision).
1730 if (LHS == RHS && isGuaranteedNotToBeUndef(LHS, MRI, Depth + 1)) {
1731 KnownFPClass KnownSrc;
1732 computeKnownFPClass(LHS, DemandedElts, fcAllFlags, KnownSrc, Depth + 1);
1733 Known = KnownFPClass::square(KnownSrc, Mode);
1734 } else {
1735 // If RHS is a scalar constant, use the more precise APFloat overload.
1736 auto RHSCst = GFConstant::getConstant(RHS, MRI);
1737 if (RHSCst && RHSCst->getKind() == GFConstant::GFConstantKind::Scalar) {
1738 KnownFPClass KnownLHS;
1739 computeKnownFPClass(LHS, DemandedElts, fcAllFlags, KnownLHS, Depth + 1);
1740 Known = KnownFPClass::fmul(KnownLHS, RHSCst->getScalarValue(), Mode);
1741 } else {
1742 KnownFPClass KnownLHS, KnownRHS;
1743 computeKnownFPClass(RHS, DemandedElts, fcAllFlags, KnownRHS, Depth + 1);
1744 computeKnownFPClass(LHS, DemandedElts, fcAllFlags, KnownLHS, Depth + 1);
1745 Known = KnownFPClass::fmul(KnownLHS, KnownRHS, Mode);
1746
1747 // If one operand is known |x| <= 1 and the other is finite, the
1748 // product cannot overflow to infinity.
1749 if (KnownLHS.isKnownNever(fcInf) && isAbsoluteValueULEOne(RHS, MRI))
1750 Known.knownNot(fcInf);
1751 else if (KnownRHS.isKnownNever(fcInf) &&
1753 Known.knownNot(fcInf);
1754 }
1755 }
1756 break;
1757 }
1758 case TargetOpcode::G_FDIV:
1759 case TargetOpcode::G_FREM: {
1760 Register LHS = MI.getOperand(1).getReg();
1761 Register RHS = MI.getOperand(2).getReg();
1762
1763 if (Opcode == TargetOpcode::G_FREM)
1764 Known.knownNot(fcInf);
1765
1766 DenormalMode Mode =
1767 MF->getDenormalMode(getFltSemanticForLLT(DstTy.getScalarType()));
1768
1769 if (LHS == RHS && isGuaranteedNotToBeUndef(LHS, MRI, Depth + 1)) {
1770 if (Opcode == TargetOpcode::G_FDIV) {
1771 const bool WantNan = (InterestedClasses & fcNan) != fcNone;
1772 if (!WantNan) {
1773 // X / X is always exactly 1.0 or a NaN.
1774 Known.KnownFPClasses = fcPosNormal | fcNan;
1775 break;
1776 }
1777 KnownFPClass KnownSrc;
1778 computeKnownFPClass(LHS, DemandedElts,
1779 fcNan | fcInf | fcZero | fcSubnormal, KnownSrc,
1780 Depth + 1);
1781 Known = KnownFPClass::fdiv_self(KnownSrc, Mode);
1782 } else {
1783 const bool WantNan = (InterestedClasses & fcNan) != fcNone;
1784 if (!WantNan) {
1785 // X % X is always exactly [+-]0.0 or a NaN.
1786 Known.KnownFPClasses = fcZero | fcNan;
1787 break;
1788 }
1789 KnownFPClass KnownSrc;
1790 computeKnownFPClass(LHS, DemandedElts,
1791 fcNan | fcInf | fcZero | fcSubnormal, KnownSrc,
1792 Depth + 1);
1793 Known = KnownFPClass::frem_self(KnownSrc, Mode);
1794 }
1795 break;
1796 }
1797
1798 const bool WantNan = (InterestedClasses & fcNan) != fcNone;
1799 const bool WantNegative = (InterestedClasses & fcNegative) != fcNone;
1800 const bool WantPositive = Opcode == TargetOpcode::G_FREM &&
1801 (InterestedClasses & fcPositive) != fcNone;
1802 if (!WantNan && !WantNegative && !WantPositive) {
1803 break;
1804 }
1805
1806 KnownFPClass KnownLHS, KnownRHS;
1807
1808 computeKnownFPClass(RHS, DemandedElts, fcNan | fcInf | fcZero | fcNegative,
1809 KnownRHS, Depth + 1);
1810
1811 bool KnowSomethingUseful = KnownRHS.isKnownNeverNaN() ||
1812 KnownRHS.isKnownNever(fcNegative) ||
1813 KnownRHS.isKnownNever(fcPositive);
1814
1815 if (KnowSomethingUseful || WantPositive) {
1816 computeKnownFPClass(LHS, DemandedElts, fcAllFlags, KnownLHS, Depth + 1);
1817 }
1818
1819 if (Opcode == TargetOpcode::G_FDIV) {
1820 Known = KnownFPClass::fdiv(KnownLHS, KnownRHS, Mode);
1821 } else {
1822 // Inf REM x and x REM 0 produce NaN.
1823 if (KnownLHS.isKnownNeverNaN() && KnownRHS.isKnownNeverNaN() &&
1824 KnownLHS.isKnownNeverInfinity() &&
1825 KnownRHS.isKnownNeverLogicalZero(Mode)) {
1826 Known.knownNot(fcNan);
1827 }
1828
1829 // The sign for frem is the same as the first operand.
1830 if (KnownLHS.cannotBeOrderedLessThanZero())
1832 if (KnownLHS.cannotBeOrderedGreaterThanZero())
1834
1835 // See if we can be more aggressive about the sign of 0.
1836 if (KnownLHS.isKnownNever(fcNegative))
1837 Known.knownNot(fcNegative);
1838 if (KnownLHS.isKnownNever(fcPositive))
1839 Known.knownNot(fcPositive);
1840 }
1841 break;
1842 }
1843 case TargetOpcode::G_FFREXP: {
1844 // Only handle the mantissa output (operand 0); the exponent is an integer.
1845 if (R != MI.getOperand(0).getReg())
1846 break;
1847 Register Src = MI.getOperand(2).getReg();
1848 KnownFPClass KnownSrc;
1849 computeKnownFPClass(Src, DemandedElts, InterestedClasses, KnownSrc,
1850 Depth + 1);
1851 DenormalMode Mode =
1852 MF->getDenormalMode(getFltSemanticForLLT(DstTy.getScalarType()));
1853 Known = KnownFPClass::frexp_mant(KnownSrc, Mode);
1854 break;
1855 }
1856 case TargetOpcode::G_FPEXT: {
1857 Register Src = MI.getOperand(1).getReg();
1858 KnownFPClass KnownSrc;
1859 computeKnownFPClass(Src, DemandedElts, InterestedClasses, KnownSrc,
1860 Depth + 1);
1861
1862 LLT DstScalarTy = DstTy.getScalarType();
1863 const fltSemantics &DstSem = getFltSemanticForLLT(DstScalarTy);
1864 LLT SrcTy = MRI.getType(Src).getScalarType();
1865 const fltSemantics &SrcSem = getFltSemanticForLLT(SrcTy);
1866
1867 Known = KnownFPClass::fpext(KnownSrc, DstSem, SrcSem);
1868 break;
1869 }
1870 case TargetOpcode::G_FPTRUNC: {
1871 computeKnownFPClassForFPTrunc(MI, DemandedElts, InterestedClasses, Known,
1872 Depth);
1873 break;
1874 }
1875 case TargetOpcode::G_SITOFP:
1876 case TargetOpcode::G_UITOFP: {
1877 // Cannot produce nan
1878 Known.knownNot(fcNan);
1879
1880 // Integers cannot be subnormal
1881 Known.knownNot(fcSubnormal);
1882
1883 // sitofp and uitofp turn into +0.0 for zero.
1884 Known.knownNot(fcNegZero);
1885
1886 // UIToFP is always non-negative regardless of known bits.
1887 if (Opcode == TargetOpcode::G_UITOFP)
1888 Known.signBitMustBeZero();
1889
1890 // Only compute known bits if we can learn something useful from them.
1891 if (!(InterestedClasses & (fcPosZero | fcNormal | fcInf)))
1892 break;
1893
1894 Register Val = MI.getOperand(1).getReg();
1895 LLT Ty = MRI.getType(Val);
1896 KnownBits IntKnown = getKnownBits(
1897 Val, Ty.isVector() ? DemandedElts : APInt(1, 1), Depth + 1);
1898
1899 // If the integer is non-zero, the result cannot be +0.0.
1900 if (IntKnown.isNonZero())
1901 Known.knownNot(fcPosZero);
1902
1903 if (Opcode == TargetOpcode::G_SITOFP) {
1904 // If the signed integer is known non-negative, the result is
1905 // non-negative. If the signed integer is known negative, the result is
1906 // negative.
1907 if (IntKnown.isNonNegative())
1908 Known.signBitMustBeZero();
1909 else if (IntKnown.isNegative())
1910 Known.signBitMustBeOne();
1911 }
1912
1913 if (InterestedClasses & fcInf) {
1914 LLT FPTy = DstTy.getScalarType();
1915 const fltSemantics &FltSem = getFltSemanticForLLT(FPTy);
1916
1917 // Compute the effective integer width after removing known-zero leading
1918 // bits, to check if the result can overflow to infinity.
1919 int IntSize = IntKnown.getBitWidth();
1920 if (Opcode == TargetOpcode::G_UITOFP)
1921 IntSize -= IntKnown.countMinLeadingZeros();
1922 else
1923 IntSize -= IntKnown.countMinSignBits();
1924
1925 // If the exponent of the largest finite FP value can hold the largest
1926 // integer, the result of the cast must be finite.
1927 if (ilogb(APFloat::getLargest(FltSem)) >= IntSize)
1928 Known.knownNot(fcInf);
1929 }
1930
1931 break;
1932 }
1933 // case TargetOpcode::G_MERGE_VALUES:
1934 case TargetOpcode::G_BUILD_VECTOR:
1935 case TargetOpcode::G_CONCAT_VECTORS: {
1936 GMergeLikeInstr &Merge = cast<GMergeLikeInstr>(MI);
1937
1938 if (!DstTy.isFixedVector())
1939 break;
1940
1941 bool First = true;
1942 for (unsigned Idx = 0; Idx < Merge.getNumSources(); ++Idx) {
1943 // We know the index we are inserting to, so clear it from Vec check.
1944 bool NeedsElt = DemandedElts[Idx];
1945
1946 // Do we demand the inserted element?
1947 if (NeedsElt) {
1948 Register Src = Merge.getSourceReg(Idx);
1949 if (First) {
1950 computeKnownFPClass(Src, Known, InterestedClasses, Depth + 1);
1951 First = false;
1952 } else {
1953 KnownFPClass Known2;
1954 computeKnownFPClass(Src, Known2, InterestedClasses, Depth + 1);
1955 Known |= Known2;
1956 }
1957
1958 // If we don't know any bits, early out.
1959 if (Known.isUnknown())
1960 break;
1961 }
1962 }
1963
1964 break;
1965 }
1966 case TargetOpcode::G_EXTRACT_VECTOR_ELT: {
1967 // Look through extract element. If the index is non-constant or
1968 // out-of-range demand all elements, otherwise just the extracted
1969 // element.
1970 GExtractVectorElement &Extract = cast<GExtractVectorElement>(MI);
1971 Register Vec = Extract.getVectorReg();
1972 Register Idx = Extract.getIndexReg();
1973
1974 auto CIdx = getIConstantVRegVal(Idx, MRI);
1975
1976 LLT VecTy = MRI.getType(Vec);
1977
1978 if (VecTy.isFixedVector()) {
1979 unsigned NumElts = VecTy.getNumElements();
1980 APInt DemandedVecElts = APInt::getAllOnes(NumElts);
1981 if (CIdx && CIdx->ult(NumElts))
1982 DemandedVecElts = APInt::getOneBitSet(NumElts, CIdx->getZExtValue());
1983 return computeKnownFPClass(Vec, DemandedVecElts, InterestedClasses, Known,
1984 Depth + 1);
1985 }
1986
1987 break;
1988 }
1989 case TargetOpcode::G_INSERT_VECTOR_ELT: {
1990 GInsertVectorElement &Insert = cast<GInsertVectorElement>(MI);
1991 Register Vec = Insert.getVectorReg();
1992 Register Elt = Insert.getElementReg();
1993 Register Idx = Insert.getIndexReg();
1994
1995 LLT VecTy = MRI.getType(Vec);
1996
1997 if (VecTy.isScalableVector())
1998 return;
1999
2000 auto CIdx = getIConstantVRegVal(Idx, MRI);
2001
2002 unsigned NumElts = DemandedElts.getBitWidth();
2003 APInt DemandedVecElts = DemandedElts;
2004 bool NeedsElt = true;
2005 // If we know the index we are inserting to, clear it from Vec check.
2006 if (CIdx && CIdx->ult(NumElts)) {
2007 DemandedVecElts.clearBit(CIdx->getZExtValue());
2008 NeedsElt = DemandedElts[CIdx->getZExtValue()];
2009 }
2010
2011 // Do we demand the inserted element?
2012 if (NeedsElt) {
2013 computeKnownFPClass(Elt, Known, InterestedClasses, Depth + 1);
2014 // If we don't know any bits, early out.
2015 if (Known.isUnknown())
2016 break;
2017 } else {
2018 Known.KnownFPClasses = fcNone;
2019 }
2020
2021 // Do we need anymore elements from Vec?
2022 if (!DemandedVecElts.isZero()) {
2023 KnownFPClass Known2;
2024 computeKnownFPClass(Vec, DemandedVecElts, InterestedClasses, Known2,
2025 Depth + 1);
2026 Known |= Known2;
2027 }
2028
2029 break;
2030 }
2031 case TargetOpcode::G_SHUFFLE_VECTOR: {
2032 // For undef elements, we don't know anything about the common state of
2033 // the shuffle result.
2034 GShuffleVector &Shuf = cast<GShuffleVector>(MI);
2035 APInt DemandedLHS, DemandedRHS;
2036 if (DstTy.isScalableVector()) {
2037 assert(DemandedElts == APInt(1, 1));
2038 DemandedLHS = DemandedRHS = DemandedElts;
2039 } else {
2040 unsigned NumElts = MRI.getType(Shuf.getSrc1Reg()).getNumElements();
2041 if (!llvm::getShuffleDemandedElts(NumElts, Shuf.getMask(), DemandedElts,
2042 DemandedLHS, DemandedRHS)) {
2043 Known.resetAll();
2044 return;
2045 }
2046 }
2047
2048 if (!!DemandedLHS) {
2049 Register LHS = Shuf.getSrc1Reg();
2050 computeKnownFPClass(LHS, DemandedLHS, InterestedClasses, Known,
2051 Depth + 1);
2052
2053 // If we don't know any bits, early out.
2054 if (Known.isUnknown())
2055 break;
2056 } else {
2057 Known.KnownFPClasses = fcNone;
2058 }
2059
2060 if (!!DemandedRHS) {
2061 KnownFPClass Known2;
2062 Register RHS = Shuf.getSrc2Reg();
2063 computeKnownFPClass(RHS, DemandedRHS, InterestedClasses, Known2,
2064 Depth + 1);
2065 Known |= Known2;
2066 }
2067 break;
2068 }
2069 case TargetOpcode::G_PHI: {
2070 // Cap PHI recursion below the global limit to avoid spending the entire
2071 // budget chasing loop back-edges (matches ValueTracking's
2072 // PhiRecursionLimit).
2074 break;
2075 // PHI's operands are a mix of registers and basic blocks interleaved.
2076 // We only care about the register ones.
2077 bool First = true;
2078 for (unsigned Idx = 1; Idx < MI.getNumOperands(); Idx += 2) {
2079 const MachineOperand &Src = MI.getOperand(Idx);
2080 Register SrcReg = Src.getReg();
2081 if (First) {
2082 computeKnownFPClass(SrcReg, DemandedElts, InterestedClasses, Known,
2083 Depth + 1);
2084 First = false;
2085 } else {
2086 KnownFPClass Known2;
2087 computeKnownFPClass(SrcReg, DemandedElts, InterestedClasses, Known2,
2088 Depth + 1);
2089 Known = Known.intersectWith(Known2);
2090 }
2091 if (Known.isUnknown())
2092 break;
2093 }
2094 break;
2095 }
2096 case TargetOpcode::COPY: {
2097 Register Src = MI.getOperand(1).getReg();
2098
2099 if (!Src.isVirtual())
2100 return;
2101
2102 computeKnownFPClass(Src, DemandedElts, InterestedClasses, Known, Depth + 1);
2103 break;
2104 }
2105 }
2106}
2107
2109GISelValueTracking::computeKnownFPClass(Register R, const APInt &DemandedElts,
2110 FPClassTest InterestedClasses,
2111 unsigned Depth) {
2112 KnownFPClass KnownClasses;
2113 computeKnownFPClass(R, DemandedElts, InterestedClasses, KnownClasses, Depth);
2114 return KnownClasses;
2115}
2116
2117KnownFPClass GISelValueTracking::computeKnownFPClass(
2118 Register R, FPClassTest InterestedClasses, unsigned Depth) {
2120 computeKnownFPClass(R, Known, InterestedClasses, Depth);
2121 return Known;
2122}
2123
2124KnownFPClass GISelValueTracking::computeKnownFPClass(
2125 Register R, const APInt &DemandedElts, uint32_t Flags,
2126 FPClassTest InterestedClasses, unsigned Depth) {
2128 InterestedClasses &= ~fcNan;
2130 InterestedClasses &= ~fcInf;
2131
2132 KnownFPClass Result =
2133 computeKnownFPClass(R, DemandedElts, InterestedClasses, Depth);
2134
2136 Result.KnownFPClasses &= ~fcNan;
2138 Result.KnownFPClasses &= ~fcInf;
2139 return Result;
2140}
2141
2142KnownFPClass GISelValueTracking::computeKnownFPClass(
2143 Register R, uint32_t Flags, FPClassTest InterestedClasses, unsigned Depth) {
2144 LLT Ty = MRI.getType(R);
2145 APInt DemandedElts =
2146 Ty.isFixedVector() ? APInt::getAllOnes(Ty.getNumElements()) : APInt(1, 1);
2147 return computeKnownFPClass(R, DemandedElts, Flags, InterestedClasses, Depth);
2148}
2149
2151 const MachineInstr *DefMI = MRI.getVRegDef(Val);
2152 if (!DefMI)
2153 return false;
2154
2155 if (DefMI->getFlag(MachineInstr::FmNoNans))
2156 return true;
2157
2158 // IEEE 754 arithmetic operations always quiet signaling NaNs. Short-circuit
2159 // the value-tracking analysis for the SNaN-only case: if the defining op is
2160 // known to quiet sNaN, the output can never be an sNaN.
2161 if (SNaN) {
2162 switch (DefMI->getOpcode()) {
2163 default:
2164 break;
2165 case TargetOpcode::G_FADD:
2166 case TargetOpcode::G_STRICT_FADD:
2167 case TargetOpcode::G_FSUB:
2168 case TargetOpcode::G_STRICT_FSUB:
2169 case TargetOpcode::G_FMUL:
2170 case TargetOpcode::G_STRICT_FMUL:
2171 case TargetOpcode::G_FDIV:
2172 case TargetOpcode::G_FREM:
2173 case TargetOpcode::G_FMA:
2174 case TargetOpcode::G_STRICT_FMA:
2175 case TargetOpcode::G_FMAD:
2176 case TargetOpcode::G_FSQRT:
2177 case TargetOpcode::G_STRICT_FSQRT:
2178 // Note: G_FABS and G_FNEG are bit-manipulation ops that preserve sNaN
2179 // exactly (LLVM LangRef: "never change anything except possibly the sign
2180 // bit"). They must NOT be listed here.
2181 case TargetOpcode::G_FSIN:
2182 case TargetOpcode::G_FCOS:
2183 case TargetOpcode::G_FSINCOS:
2184 case TargetOpcode::G_FTAN:
2185 case TargetOpcode::G_FASIN:
2186 case TargetOpcode::G_FACOS:
2187 case TargetOpcode::G_FATAN:
2188 case TargetOpcode::G_FATAN2:
2189 case TargetOpcode::G_FSINH:
2190 case TargetOpcode::G_FCOSH:
2191 case TargetOpcode::G_FTANH:
2192 case TargetOpcode::G_FEXP:
2193 case TargetOpcode::G_FEXP2:
2194 case TargetOpcode::G_FEXP10:
2195 case TargetOpcode::G_FLOG:
2196 case TargetOpcode::G_FLOG2:
2197 case TargetOpcode::G_FLOG10:
2198 case TargetOpcode::G_FPOWI:
2199 case TargetOpcode::G_FLDEXP:
2200 case TargetOpcode::G_STRICT_FLDEXP:
2201 case TargetOpcode::G_FFREXP:
2202 case TargetOpcode::G_INTRINSIC_TRUNC:
2203 case TargetOpcode::G_INTRINSIC_ROUND:
2204 case TargetOpcode::G_INTRINSIC_ROUNDEVEN:
2205 case TargetOpcode::G_FFLOOR:
2206 case TargetOpcode::G_FCEIL:
2207 case TargetOpcode::G_FRINT:
2208 case TargetOpcode::G_FNEARBYINT:
2209 case TargetOpcode::G_FPEXT:
2210 case TargetOpcode::G_FPTRUNC:
2211 case TargetOpcode::G_FCANONICALIZE:
2212 case TargetOpcode::G_FMINNUM:
2213 case TargetOpcode::G_FMAXNUM:
2214 case TargetOpcode::G_FMINNUM_IEEE:
2215 case TargetOpcode::G_FMAXNUM_IEEE:
2216 case TargetOpcode::G_FMINIMUM:
2217 case TargetOpcode::G_FMAXIMUM:
2218 case TargetOpcode::G_FMINIMUMNUM:
2219 case TargetOpcode::G_FMAXIMUMNUM:
2220 return true;
2221 }
2222 }
2223
2224 KnownFPClass FPClass = computeKnownFPClass(Val, SNaN ? fcSNan : fcNan);
2225
2226 if (SNaN)
2227 return FPClass.isKnownNever(fcSNan);
2228
2229 return FPClass.isKnownNeverNaN();
2230}
2231
2232/// Compute number of sign bits for the intersection of \p Src0 and \p Src1
2233unsigned GISelValueTracking::computeNumSignBitsMin(Register Src0, Register Src1,
2234 const APInt &DemandedElts,
2235 unsigned Depth) {
2236 // Test src1 first, since we canonicalize simpler expressions to the RHS.
2237 unsigned Src1SignBits = computeNumSignBits(Src1, DemandedElts, Depth);
2238 if (Src1SignBits == 1)
2239 return 1;
2240 return std::min(computeNumSignBits(Src0, DemandedElts, Depth), Src1SignBits);
2241}
2242
2243/// Compute the known number of sign bits with attached range metadata in the
2244/// memory operand. If this is an extending load, accounts for the behavior of
2245/// the high bits.
2247 unsigned TyBits) {
2248 const MDNode *Ranges = Ld->getRanges();
2249 if (!Ranges)
2250 return 1;
2251
2253 if (TyBits > CR.getBitWidth()) {
2254 switch (Ld->getOpcode()) {
2255 case TargetOpcode::G_SEXTLOAD:
2256 CR = CR.signExtend(TyBits);
2257 break;
2258 case TargetOpcode::G_ZEXTLOAD:
2259 CR = CR.zeroExtend(TyBits);
2260 break;
2261 default:
2262 break;
2263 }
2264 }
2265
2266 return std::min(CR.getSignedMin().getNumSignBits(),
2268}
2269
2271 const APInt &DemandedElts,
2272 unsigned Depth) {
2273 MachineInstr &MI = *MRI.getVRegDef(R);
2274 unsigned Opcode = MI.getOpcode();
2275
2276 if (Opcode == TargetOpcode::G_CONSTANT)
2277 return MI.getOperand(1).getCImm()->getValue().getNumSignBits();
2278
2279 if (Depth == getMaxDepth())
2280 return 1;
2281
2282 if (!DemandedElts)
2283 return 1; // No demanded elts, better to assume we don't know anything.
2284
2285 LLT DstTy = MRI.getType(R);
2286 const unsigned TyBits = DstTy.getScalarSizeInBits();
2287
2288 // Handle the case where this is called on a register that does not have a
2289 // type constraint. This is unlikely to occur except by looking through copies
2290 // but it is possible for the initial register being queried to be in this
2291 // state.
2292 if (!DstTy.isValid())
2293 return 1;
2294
2295 unsigned FirstAnswer = 1;
2296 switch (Opcode) {
2297 case TargetOpcode::COPY: {
2298 MachineOperand &Src = MI.getOperand(1);
2299 if (Src.getReg().isVirtual() && Src.getSubReg() == 0 &&
2300 MRI.getType(Src.getReg()).isValid()) {
2301 // Don't increment Depth for this one since we didn't do any work.
2302 return computeNumSignBits(Src.getReg(), DemandedElts, Depth);
2303 }
2304
2305 return 1;
2306 }
2307 case TargetOpcode::G_SEXT: {
2308 Register Src = MI.getOperand(1).getReg();
2309 LLT SrcTy = MRI.getType(Src);
2310 unsigned Tmp = DstTy.getScalarSizeInBits() - SrcTy.getScalarSizeInBits();
2311 return computeNumSignBits(Src, DemandedElts, Depth + 1) + Tmp;
2312 }
2313 case TargetOpcode::G_ASSERT_SEXT:
2314 case TargetOpcode::G_SEXT_INREG: {
2315 // Max of the input and what this extends.
2316 Register Src = MI.getOperand(1).getReg();
2317 unsigned SrcBits = MI.getOperand(2).getImm();
2318 unsigned InRegBits = TyBits - SrcBits + 1;
2319 return std::max(computeNumSignBits(Src, DemandedElts, Depth + 1),
2320 InRegBits);
2321 }
2322 case TargetOpcode::G_LOAD: {
2323 GLoad *Ld = cast<GLoad>(&MI);
2324 if (DemandedElts != 1 || !getDataLayout().isLittleEndian())
2325 break;
2326
2327 return computeNumSignBitsFromRangeMetadata(Ld, TyBits);
2328 }
2329 case TargetOpcode::G_SEXTLOAD: {
2331
2332 // FIXME: We need an in-memory type representation.
2333 if (DstTy.isVector())
2334 return 1;
2335
2336 unsigned NumBits = computeNumSignBitsFromRangeMetadata(Ld, TyBits);
2337 if (NumBits != 1)
2338 return NumBits;
2339
2340 // e.g. i16->i32 = '17' bits known.
2341 const MachineMemOperand *MMO = *MI.memoperands_begin();
2342 return TyBits - MMO->getSizeInBits().getValue() + 1;
2343 }
2344 case TargetOpcode::G_ZEXTLOAD: {
2346
2347 // FIXME: We need an in-memory type representation.
2348 if (DstTy.isVector())
2349 return 1;
2350
2351 unsigned NumBits = computeNumSignBitsFromRangeMetadata(Ld, TyBits);
2352 if (NumBits != 1)
2353 return NumBits;
2354
2355 // e.g. i16->i32 = '16' bits known.
2356 const MachineMemOperand *MMO = *MI.memoperands_begin();
2357 return TyBits - MMO->getSizeInBits().getValue();
2358 }
2359 case TargetOpcode::G_AND:
2360 case TargetOpcode::G_OR:
2361 case TargetOpcode::G_XOR: {
2362 Register Src1 = MI.getOperand(1).getReg();
2363 unsigned Src1NumSignBits =
2364 computeNumSignBits(Src1, DemandedElts, Depth + 1);
2365 if (Src1NumSignBits != 1) {
2366 Register Src2 = MI.getOperand(2).getReg();
2367 unsigned Src2NumSignBits =
2368 computeNumSignBits(Src2, DemandedElts, Depth + 1);
2369 FirstAnswer = std::min(Src1NumSignBits, Src2NumSignBits);
2370 }
2371 break;
2372 }
2373 case TargetOpcode::G_ASHR: {
2374 Register Src1 = MI.getOperand(1).getReg();
2375 Register Src2 = MI.getOperand(2).getReg();
2376 FirstAnswer = computeNumSignBits(Src1, DemandedElts, Depth + 1);
2377 if (auto C = getValidMinimumShiftAmount(Src2, DemandedElts, Depth + 1))
2378 FirstAnswer = std::min<uint64_t>(FirstAnswer + *C, TyBits);
2379 break;
2380 }
2381 case TargetOpcode::G_SHL: {
2382 Register Src1 = MI.getOperand(1).getReg();
2383 Register Src2 = MI.getOperand(2).getReg();
2384 if (std::optional<ConstantRange> ShAmtRange =
2385 getValidShiftAmountRange(Src2, DemandedElts, Depth + 1)) {
2386 uint64_t MaxShAmt = ShAmtRange->getUnsignedMax().getZExtValue();
2387 uint64_t MinShAmt = ShAmtRange->getUnsignedMin().getZExtValue();
2388
2389 MachineInstr &ExtMI = *MRI.getVRegDef(Src1);
2390 unsigned ExtOpc = ExtMI.getOpcode();
2391
2392 // Try to look through ZERO/SIGN/ANY_EXTEND. If all extended bits are
2393 // shifted out, then we can compute the number of sign bits for the
2394 // operand being extended. A future improvement could be to pass along the
2395 // "shifted left by" information in the recursive calls to
2396 // ComputeKnownSignBits. Allowing us to handle this more generically.
2397 if (ExtOpc == TargetOpcode::G_SEXT || ExtOpc == TargetOpcode::G_ZEXT ||
2398 ExtOpc == TargetOpcode::G_ANYEXT) {
2399 LLT ExtTy = MRI.getType(Src1);
2400 Register Extendee = ExtMI.getOperand(1).getReg();
2401 LLT ExtendeeTy = MRI.getType(Extendee);
2402 uint64_t SizeDiff =
2403 ExtTy.getScalarSizeInBits() - ExtendeeTy.getScalarSizeInBits();
2404
2405 if (SizeDiff <= MinShAmt) {
2406 unsigned Tmp =
2407 SizeDiff + computeNumSignBits(Extendee, DemandedElts, Depth + 1);
2408 if (MaxShAmt < Tmp)
2409 return Tmp - MaxShAmt;
2410 }
2411 }
2412 // shl destroys sign bits, ensure it doesn't shift out all sign bits.
2413 unsigned Tmp = computeNumSignBits(Src1, DemandedElts, Depth + 1);
2414 if (MaxShAmt < Tmp)
2415 return Tmp - MaxShAmt;
2416 }
2417 break;
2418 }
2419 case TargetOpcode::G_SREM: {
2420 // The sign bit is the LHS's sign bit, except when the result of the
2421 // remainder is zero. The magnitude of the result should be less than or
2422 // equal to the magnitude of the LHS. Therefore, the result should have
2423 // at least as many sign bits as the left hand side.
2424 Register Src = MI.getOperand(1).getReg();
2425 return computeNumSignBits(Src, DemandedElts, Depth + 1);
2426 }
2427 case TargetOpcode::G_TRUNC: {
2428 Register Src = MI.getOperand(1).getReg();
2429 LLT SrcTy = MRI.getType(Src);
2430
2431 // Check if the sign bits of source go down as far as the truncated value.
2432 unsigned DstTyBits = DstTy.getScalarSizeInBits();
2433 unsigned NumSrcBits = SrcTy.getScalarSizeInBits();
2434 unsigned NumSrcSignBits = computeNumSignBits(Src, DemandedElts, Depth + 1);
2435 if (NumSrcSignBits > (NumSrcBits - DstTyBits))
2436 return NumSrcSignBits - (NumSrcBits - DstTyBits);
2437 break;
2438 }
2439 case TargetOpcode::G_SELECT: {
2440 return computeNumSignBitsMin(MI.getOperand(2).getReg(),
2441 MI.getOperand(3).getReg(), DemandedElts,
2442 Depth + 1);
2443 }
2444 case TargetOpcode::G_SMIN:
2445 case TargetOpcode::G_SMAX:
2446 case TargetOpcode::G_UMIN:
2447 case TargetOpcode::G_UMAX:
2448 // TODO: Handle clamp pattern with number of sign bits for SMIN/SMAX.
2449 return computeNumSignBitsMin(MI.getOperand(1).getReg(),
2450 MI.getOperand(2).getReg(), DemandedElts,
2451 Depth + 1);
2452 case TargetOpcode::G_SADDO:
2453 case TargetOpcode::G_SADDE:
2454 case TargetOpcode::G_UADDO:
2455 case TargetOpcode::G_UADDE:
2456 case TargetOpcode::G_SSUBO:
2457 case TargetOpcode::G_SSUBE:
2458 case TargetOpcode::G_USUBO:
2459 case TargetOpcode::G_USUBE:
2460 case TargetOpcode::G_SMULO:
2461 case TargetOpcode::G_UMULO: {
2462 // If compares returns 0/-1, all bits are sign bits.
2463 // We know that we have an integer-based boolean since these operations
2464 // are only available for integer.
2465 if (MI.getOperand(1).getReg() == R) {
2466 if (TL.getBooleanContents(DstTy.isVector(), false) ==
2468 return TyBits;
2469 }
2470
2471 break;
2472 }
2473 case TargetOpcode::G_SUB: {
2474 Register Src2 = MI.getOperand(2).getReg();
2475 unsigned Src2NumSignBits =
2476 computeNumSignBits(Src2, DemandedElts, Depth + 1);
2477 if (Src2NumSignBits == 1)
2478 return 1; // Early out.
2479
2480 // Handle NEG.
2481 Register Src1 = MI.getOperand(1).getReg();
2482 KnownBits Known1 = getKnownBits(Src1, DemandedElts, Depth);
2483 if (Known1.isZero()) {
2484 KnownBits Known2 = getKnownBits(Src2, DemandedElts, Depth);
2485 // If the input is known to be 0 or 1, the output is 0/-1, which is all
2486 // sign bits set.
2487 if ((Known2.Zero | 1).isAllOnes())
2488 return TyBits;
2489
2490 // If the input is known to be positive (the sign bit is known clear),
2491 // the output of the NEG has, at worst, the same number of sign bits as
2492 // the input.
2493 if (Known2.isNonNegative()) {
2494 FirstAnswer = Src2NumSignBits;
2495 break;
2496 }
2497
2498 // Otherwise, we treat this like a SUB.
2499 }
2500
2501 unsigned Src1NumSignBits =
2502 computeNumSignBits(Src1, DemandedElts, Depth + 1);
2503 if (Src1NumSignBits == 1)
2504 return 1; // Early Out.
2505
2506 // Sub can have at most one carry bit. Thus we know that the output
2507 // is, at worst, one more bit than the inputs.
2508 FirstAnswer = std::min(Src1NumSignBits, Src2NumSignBits) - 1;
2509 break;
2510 }
2511 case TargetOpcode::G_ADD: {
2512 Register Src2 = MI.getOperand(2).getReg();
2513 unsigned Src2NumSignBits =
2514 computeNumSignBits(Src2, DemandedElts, Depth + 1);
2515 if (Src2NumSignBits <= 2)
2516 return 1; // Early out.
2517
2518 Register Src1 = MI.getOperand(1).getReg();
2519 unsigned Src1NumSignBits =
2520 computeNumSignBits(Src1, DemandedElts, Depth + 1);
2521 if (Src1NumSignBits == 1)
2522 return 1; // Early Out.
2523
2524 // Special case decrementing a value (ADD X, -1):
2525 KnownBits Known2 = getKnownBits(Src2, DemandedElts, Depth);
2526 if (Known2.isAllOnes()) {
2527 KnownBits Known1 = getKnownBits(Src1, DemandedElts, Depth);
2528 // If the input is known to be 0 or 1, the output is 0/-1, which is all
2529 // sign bits set.
2530 if ((Known1.Zero | 1).isAllOnes())
2531 return TyBits;
2532
2533 // If we are subtracting one from a positive number, there is no carry
2534 // out of the result.
2535 if (Known1.isNonNegative()) {
2536 FirstAnswer = Src1NumSignBits;
2537 break;
2538 }
2539
2540 // Otherwise, we treat this like an ADD.
2541 }
2542
2543 // Add can have at most one carry bit. Thus we know that the output
2544 // is, at worst, one more bit than the inputs.
2545 FirstAnswer = std::min(Src1NumSignBits, Src2NumSignBits) - 1;
2546 break;
2547 }
2548 case TargetOpcode::G_FCMP:
2549 case TargetOpcode::G_ICMP: {
2550 bool IsFP = Opcode == TargetOpcode::G_FCMP;
2551 if (TyBits == 1)
2552 break;
2553 auto BC = TL.getBooleanContents(DstTy.isVector(), IsFP);
2555 return TyBits; // All bits are sign bits.
2557 return TyBits - 1; // Every always-zero bit is a sign bit.
2558 break;
2559 }
2560 case TargetOpcode::G_BUILD_VECTOR: {
2561 // Collect the known bits that are shared by every demanded vector element.
2562 FirstAnswer = TyBits;
2563 APInt SingleDemandedElt(1, 1);
2564 for (const auto &[I, MO] : enumerate(drop_begin(MI.operands()))) {
2565 if (!DemandedElts[I])
2566 continue;
2567
2568 unsigned Tmp2 =
2569 computeNumSignBits(MO.getReg(), SingleDemandedElt, Depth + 1);
2570 FirstAnswer = std::min(FirstAnswer, Tmp2);
2571
2572 // If we don't know any bits, early out.
2573 if (FirstAnswer == 1)
2574 break;
2575 }
2576 break;
2577 }
2578 case TargetOpcode::G_CONCAT_VECTORS: {
2579 if (MRI.getType(MI.getOperand(0).getReg()).isScalableVector())
2580 break;
2581 FirstAnswer = TyBits;
2582 // Determine the minimum number of sign bits across all demanded
2583 // elts of the input vectors. Early out if the result is already 1.
2584 unsigned NumSubVectorElts =
2585 MRI.getType(MI.getOperand(1).getReg()).getNumElements();
2586 for (const auto &[I, MO] : enumerate(drop_begin(MI.operands()))) {
2587 APInt DemandedSub =
2588 DemandedElts.extractBits(NumSubVectorElts, I * NumSubVectorElts);
2589 if (!DemandedSub)
2590 continue;
2591 unsigned Tmp2 = computeNumSignBits(MO.getReg(), DemandedSub, Depth + 1);
2592
2593 FirstAnswer = std::min(FirstAnswer, Tmp2);
2594
2595 // If we don't know any bits, early out.
2596 if (FirstAnswer == 1)
2597 break;
2598 }
2599 break;
2600 }
2601 case TargetOpcode::G_SHUFFLE_VECTOR: {
2602 // Collect the minimum number of sign bits that are shared by every vector
2603 // element referenced by the shuffle.
2604 APInt DemandedLHS, DemandedRHS;
2605 Register Src1 = MI.getOperand(1).getReg();
2606 unsigned NumElts = MRI.getType(Src1).getNumElements();
2607 if (!getShuffleDemandedElts(NumElts, MI.getOperand(3).getShuffleMask(),
2608 DemandedElts, DemandedLHS, DemandedRHS))
2609 return 1;
2610
2611 if (!!DemandedLHS)
2612 FirstAnswer = computeNumSignBits(Src1, DemandedLHS, Depth + 1);
2613 // If we don't know anything, early out and try computeKnownBits fall-back.
2614 if (FirstAnswer == 1)
2615 break;
2616 if (!!DemandedRHS) {
2617 unsigned Tmp2 =
2618 computeNumSignBits(MI.getOperand(2).getReg(), DemandedRHS, Depth + 1);
2619 FirstAnswer = std::min(FirstAnswer, Tmp2);
2620 }
2621 break;
2622 }
2623 case TargetOpcode::G_SPLAT_VECTOR: {
2624 // Check if the sign bits of source go down as far as the truncated value.
2625 Register Src = MI.getOperand(1).getReg();
2626 unsigned NumSrcSignBits = computeNumSignBits(Src, APInt(1, 1), Depth + 1);
2627 unsigned NumSrcBits = MRI.getType(Src).getSizeInBits();
2628 if (NumSrcSignBits > (NumSrcBits - TyBits))
2629 return NumSrcSignBits - (NumSrcBits - TyBits);
2630 break;
2631 }
2632 case TargetOpcode::G_INTRINSIC:
2633 case TargetOpcode::G_INTRINSIC_W_SIDE_EFFECTS:
2634 case TargetOpcode::G_INTRINSIC_CONVERGENT:
2635 case TargetOpcode::G_INTRINSIC_CONVERGENT_W_SIDE_EFFECTS:
2636 default: {
2637 unsigned NumBits =
2638 TL.computeNumSignBitsForTargetInstr(*this, R, DemandedElts, MRI, Depth);
2639 if (NumBits > 1)
2640 FirstAnswer = std::max(FirstAnswer, NumBits);
2641 break;
2642 }
2643 }
2644
2645 // Finally, if we can prove that the top bits of the result are 0's or 1's,
2646 // use this information.
2647 KnownBits Known = getKnownBits(R, DemandedElts, Depth);
2648 return std::max(FirstAnswer, Known.countMinSignBits());
2649}
2650
2652 LLT Ty = MRI.getType(R);
2653 APInt DemandedElts =
2654 Ty.isFixedVector() ? APInt::getAllOnes(Ty.getNumElements()) : APInt(1, 1);
2655 return computeNumSignBits(R, DemandedElts, Depth);
2656}
2657
2659 Register R, const APInt &DemandedElts, unsigned Depth) {
2660 // Shifting more than the bitwidth is not valid.
2661 MachineInstr &MI = *MRI.getVRegDef(R);
2662 unsigned Opcode = MI.getOpcode();
2663
2664 LLT Ty = MRI.getType(R);
2665 unsigned BitWidth = Ty.getScalarSizeInBits();
2666
2667 if (Opcode == TargetOpcode::G_CONSTANT) {
2668 const APInt &ShAmt = MI.getOperand(1).getCImm()->getValue();
2669 if (ShAmt.uge(BitWidth))
2670 return std::nullopt;
2671 return ConstantRange(ShAmt);
2672 }
2673
2674 if (Opcode == TargetOpcode::G_BUILD_VECTOR) {
2675 const APInt *MinAmt = nullptr, *MaxAmt = nullptr;
2676 for (unsigned I = 0, E = MI.getNumOperands() - 1; I != E; ++I) {
2677 if (!DemandedElts[I])
2678 continue;
2679 MachineInstr *Op = MRI.getVRegDef(MI.getOperand(I + 1).getReg());
2680 if (Op->getOpcode() != TargetOpcode::G_CONSTANT) {
2681 MinAmt = MaxAmt = nullptr;
2682 break;
2683 }
2684
2685 const APInt &ShAmt = Op->getOperand(1).getCImm()->getValue();
2686 if (ShAmt.uge(BitWidth))
2687 return std::nullopt;
2688 if (!MinAmt || MinAmt->ugt(ShAmt))
2689 MinAmt = &ShAmt;
2690 if (!MaxAmt || MaxAmt->ult(ShAmt))
2691 MaxAmt = &ShAmt;
2692 }
2693 assert(((!MinAmt && !MaxAmt) || (MinAmt && MaxAmt)) &&
2694 "Failed to find matching min/max shift amounts");
2695 if (MinAmt && MaxAmt)
2696 return ConstantRange(*MinAmt, *MaxAmt + 1);
2697 }
2698
2699 // Use computeKnownBits to find a hidden constant/knownbits (usually type
2700 // legalized). e.g. Hidden behind multiple bitcasts/build_vector/casts etc.
2701 KnownBits KnownAmt = getKnownBits(R, DemandedElts, Depth);
2702 if (KnownAmt.getMaxValue().ult(BitWidth))
2703 return ConstantRange::fromKnownBits(KnownAmt, /*IsSigned=*/false);
2704
2705 return std::nullopt;
2706}
2707
2709 Register R, const APInt &DemandedElts, unsigned Depth) {
2710 if (std::optional<ConstantRange> AmtRange =
2711 getValidShiftAmountRange(R, DemandedElts, Depth))
2712 return AmtRange->getUnsignedMin().getZExtValue();
2713 return std::nullopt;
2714}
2715
2721
2726
2728 if (!Info) {
2729 unsigned MaxDepth =
2731 Info = std::make_unique<GISelValueTracking>(MF, MaxDepth);
2732 }
2733 return *Info;
2734}
2735
2736AnalysisKey GISelValueTrackingAnalysis::Key;
2737
2741 unsigned MaxDepth =
2743 return Result(MF, MaxDepth);
2744}
2745
2749 auto &VTA = MFAM.getResult<GISelValueTrackingAnalysis>(MF);
2750 const auto &MRI = MF.getRegInfo();
2751 OS << "name: ";
2752 MF.getFunction().printAsOperand(OS, /*PrintType=*/false);
2753 OS << '\n';
2754
2755 for (MachineBasicBlock &BB : MF) {
2756 for (MachineInstr &MI : BB) {
2757 for (MachineOperand &MO : MI.defs()) {
2758 if (!MO.isReg() || MO.getReg().isPhysical())
2759 continue;
2760 Register Reg = MO.getReg();
2761 if (!MRI.getType(Reg).isValid())
2762 continue;
2763 KnownBits Known = VTA.getKnownBits(Reg);
2764 unsigned SignedBits = VTA.computeNumSignBits(Reg);
2765 bool IsKnownNeverZero = VTA.isKnownNeverZero(Reg);
2766 OS << " " << MO << " KnownBits:" << Known << " SignBits:" << SignedBits
2767 << " IsKnownNeverZero:" << IsKnownNeverZero << '\n';
2768 };
2769 }
2770 }
2771 return PreservedAnalyses::all();
2772}
MachineInstrBuilder MachineInstrBuilder & DefMI
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
This file declares a class to represent arbitrary precision floating point values and provide a varie...
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
#define X(NUM, ENUM, NAME)
Definition ELF.h:856
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
Utilities for dealing with flags related to floating point properties and mode controls.
static void dumpResult(const MachineInstr &MI, const KnownBits &Known, unsigned Depth)
static unsigned computeNumSignBitsFromRangeMetadata(const GAnyLoad *Ld, unsigned TyBits)
Compute the known number of sign bits with attached range metadata in the memory operand.
Provides analysis for querying information about KnownBits during GISel passes.
#define DEBUG_TYPE
Declares convenience wrapper classes for interpreting MachineInstr instances as specific generic oper...
IRTranslator LLVM IR MI
const size_t AbstractManglingParser< Derived, Alloc >::NumOps
Implement a low-level type suitable for MachineInstr level instruction selection.
#define F(x, y, z)
Definition MD5.cpp:54
#define I(x, y, z)
Definition MD5.cpp:57
Contains matchers for matching SSA Machine Instructions.
Promote Memory to Register
Definition Mem2Reg.cpp:110
static MCRegister getReg(const MCDisassembler *D, unsigned RC, unsigned RegNo)
ConstantRange Range(APInt(BitWidth, Low), APInt(BitWidth, High))
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
Definition PassSupport.h:56
R600 Clause Merge
const SmallVectorImpl< MachineOperand > & 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")))
static uint64_t umul_ov(uint64_t i, uint64_t j, bool &Overflow)
This file defines the scope_exit class, which executes user-defined cleanup logic at scope exit.
This file contains some functions that are useful when dealing with strings.
#define LLVM_DEBUG(...)
Definition Debug.h:119
static TableGen::Emitter::Opt Y("gen-skeleton-entry", EmitSkeleton, "Generate example skeleton entry")
This file describes how to lower LLVM code to machine code.
static bool isAbsoluteValueULEOne(const Value *V)
static Function * getFunction(FunctionType *Ty, const Twine &Name, Module *M)
Value * RHS
Value * LHS
static APFloat getLargest(const fltSemantics &Sem, bool Negative=false)
Returns the largest finite number in the given semantics.
Definition APFloat.h:1234
Class for arbitrary precision integers.
Definition APInt.h:78
LLVM_ABI APInt umul_ov(const APInt &RHS, bool &Overflow) const
Definition APInt.cpp:2006
static APInt getAllOnes(unsigned numBits)
Return an APInt of a specified width with all bits set.
Definition APInt.h:235
void clearBit(unsigned BitPosition)
Set a given bit to 0.
Definition APInt.h:1431
LLVM_ABI APInt zext(unsigned width) const
Zero extend to a new width.
Definition APInt.cpp:1055
static APInt getSignMask(unsigned BitWidth)
Get the SignMask for a specific bit width.
Definition APInt.h:230
bool ugt(const APInt &RHS) const
Unsigned greater than comparison.
Definition APInt.h:1191
bool isZero() const
Determine if this value is zero, i.e. all bits are clear.
Definition APInt.h:381
unsigned getBitWidth() const
Return the number of bits in the APInt.
Definition APInt.h:1513
bool ult(const APInt &RHS) const
Unsigned less than comparison.
Definition APInt.h:1120
unsigned getNumSignBits() const
Computes the number of leading bits of this APInt that are equal to its sign bit.
Definition APInt.h:1653
unsigned countl_zero() const
The APInt version of std::countl_zero.
Definition APInt.h:1623
unsigned logBase2() const
Definition APInt.h:1786
uint64_t getLimitedValue(uint64_t Limit=UINT64_MAX) const
If this value is smaller than the specified limit, return it, otherwise return the limit value.
Definition APInt.h:476
APInt shl(unsigned shiftAmt) const
Left-shift function.
Definition APInt.h:880
bool isPowerOf2() const
Check if this APInt's value is a power of two greater than zero.
Definition APInt.h:441
static APInt getLowBitsSet(unsigned numBits, unsigned loBitsSet)
Constructs an APInt value that has the bottom loBitsSet bits set.
Definition APInt.h:307
LLVM_ABI APInt extractBits(unsigned numBits, unsigned bitPosition) const
Return an APInt with the extracted bits [bitPosition,bitPosition+numBits).
Definition APInt.cpp:483
static APInt getBitsSetFrom(unsigned numBits, unsigned loBit)
Constructs an APInt value that has a contiguous range of bits set.
Definition APInt.h:287
static APInt getOneBitSet(unsigned numBits, unsigned BitNo)
Return an APInt with exactly one bit set in the result.
Definition APInt.h:240
bool uge(const APInt &RHS) const
Unsigned greater or equal comparison.
Definition APInt.h:1230
PassT::Result & getResult(IRUnitT &IR, ExtraArgTs... ExtraArgs)
Get the result of an analysis pass for a given IR unit.
Represent the analysis usage information of a pass.
void setPreservesAll()
Set by analyses that do not transform their input at all.
Predicate
This enumeration lists the possible predicates for CmpInst subclasses.
Definition InstrTypes.h:740
This class represents a range of values.
static LLVM_ABI ConstantRange fromKnownBits(const KnownBits &Known, bool IsSigned)
Initialize a range based on a known bits constraint.
LLVM_ABI ConstantRange zeroExtend(uint32_t BitWidth) const
Return a new range in the specified integer type, which must be strictly larger than the current type...
LLVM_ABI APInt getSignedMin() const
Return the smallest signed value contained in the ConstantRange.
LLVM_ABI ConstantRange signExtend(uint32_t BitWidth) const
Return a new range in the specified integer type, which must be strictly larger than the current type...
LLVM_ABI APInt getUnsignedMax() const
Return the largest unsigned value contained in the ConstantRange.
LLVM_ABI APInt getSignedMax() const
Return the largest signed value contained in the ConstantRange.
uint32_t getBitWidth() const
Get the bit width of this ConstantRange.
Represents any generic load, including sign/zero extending variants.
const MDNode * getRanges() const
Returns the Ranges that describes the dereference.
Represents an extract vector element.
static LLVM_ABI std::optional< GFConstant > getConstant(Register Const, const MachineRegisterInfo &MRI)
Definition Utils.cpp:2037
To use KnownBitsInfo analysis in a pass, KnownBitsInfo &Info = getAnalysis<GISelValueTrackingInfoAnal...
GISelValueTracking & get(MachineFunction &MF)
bool runOnMachineFunction(MachineFunction &MF) override
runOnMachineFunction - This method must be overloaded to perform the desired machine code transformat...
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - This function should be overriden by passes that need analysis information to do t...
LLVM_ABI Result run(MachineFunction &MF, MachineFunctionAnalysisManager &MFAM)
LLVM_ABI PreservedAnalyses run(MachineFunction &MF, MachineFunctionAnalysisManager &MFAM)
KnownBits getKnownBits(Register R)
Align computeKnownAlignment(Register R, unsigned Depth=0)
std::optional< ConstantRange > getValidShiftAmountRange(Register R, const APInt &DemandedElts, unsigned Depth)
If a G_SHL/G_ASHR/G_LSHR node with shift operand R has shift amounts that are all less than the eleme...
bool maskedValueIsZero(Register Val, const APInt &Mask)
std::optional< uint64_t > getValidMinimumShiftAmount(Register R, const APInt &DemandedElts, unsigned Depth=0)
If a G_SHL/G_ASHR/G_LSHR node with shift operand R has shift amounts that are all less than the eleme...
const DataLayout & getDataLayout() const
unsigned computeNumSignBits(Register R, const APInt &DemandedElts, unsigned Depth=0)
const MachineFunction & getMachineFunction() const
bool isKnownNeverNaN(Register Val, bool SNaN=false)
Returns true if Val can be assumed to never be a NaN.
void computeKnownBitsImpl(Register R, KnownBits &Known, const APInt &DemandedElts, unsigned Depth=0)
bool isKnownNeverZero(Register R, unsigned Depth=0)
Return true if the value defined by R is provably never zero.
Represents an insert vector element.
Represents a G_LOAD.
Represents a G_SEXTLOAD.
Register getCondReg() const
Register getFalseReg() const
Register getTrueReg() const
Represents a G_SHUFFLE_VECTOR.
ArrayRef< int > getMask() const
Represents a G_ZEXTLOAD.
constexpr bool isScalableVector() const
Returns true if the LLT is a scalable vector.
constexpr unsigned getScalarSizeInBits() const
LLT getScalarType() const
constexpr bool isValid() const
constexpr uint16_t getNumElements() const
Returns the number of elements in a vector LLT.
constexpr bool isVector() const
constexpr ElementCount getElementCount() const
constexpr bool isFixedVector() const
Returns true if the LLT is a fixed vector.
TypeSize getValue() const
Metadata node.
Definition Metadata.h:1069
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
Function & getFunction()
Return the LLVM function that this machine code represents.
const TargetMachine & getTarget() const
getTarget - Return the target machine this machine code is compiled with
Representation of each machine instruction.
unsigned getOpcode() const
Returns the opcode of this MachineInstr.
const MachineOperand & getOperand(unsigned i) const
A description of a memory reference used in the backend.
LLT getMemoryType() const
Return the memory type of the memory reference.
const MDNode * getRanges() const
Return the range tag for the memory reference.
LocationSize getSizeInBits() const
Return the size in bits of the memory reference.
MachineOperand class - Representation of each machine instruction operand.
Register getReg() const
getReg - Returns the register number.
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
LLT getType(Register Reg) const
Get the low-level type of Reg or LLT{} if Reg is not a generic (target independent) virtual register.
A set of analyses that are preserved following a run of a transformation pass.
Definition Analysis.h:112
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
Definition Analysis.h:118
Wrapper class representing virtual and physical registers.
Definition Register.h:20
constexpr bool isVirtual() const
Return true if the specified register number is in the virtual register namespace.
Definition Register.h:79
CodeGenOptLevel getOptLevel() const
Returns the optimization level: None, Less, Default, or Aggressive.
LLVM_ABI void printAsOperand(raw_ostream &O, bool PrintType=true, const Module *M=nullptr) const
Print the name of this Value out to the specified raw_ostream.
constexpr ScalarTy getKnownMinValue() const
Returns the minimum value this quantity can represent.
Definition TypeSize.h:165
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
operand_type_match m_Reg()
UnaryOp_match< SrcTy, TargetOpcode::G_FFLOOR > m_GFFloor(const SrcTy &Src)
operand_type_match m_Pred()
bind_ty< FPClassTest > m_FPClassTest(FPClassTest &T)
deferred_ty< Register > m_DeferredReg(Register &R)
Similar to m_SpecificReg/Type, but the specific value to match originated from an earlier sub-pattern...
BinaryOp_match< LHS, RHS, TargetOpcode::G_FSUB, false > m_GFSub(const LHS &L, const RHS &R)
bool mi_match(Reg R, const MachineRegisterInfo &MRI, Pattern &&P)
ClassifyOp_match< LHS, Test, TargetOpcode::G_IS_FPCLASS > m_GIsFPClass(const LHS &L, const Test &T)
Matches the register and immediate used in a fpclass test G_IS_FPCLASS val, 96.
CompareOp_match< Pred, LHS, RHS, TargetOpcode::G_FCMP > m_GFCmp(const Pred &P, const LHS &L, const RHS &R)
This is an optimization pass for GlobalISel generic memory operations.
auto drop_begin(T &&RangeOrContainer, size_t N=1)
Return a range covering RangeOrContainer with the first N elements excluded.
Definition STLExtras.h:315
LLVM_ABI std::optional< APInt > isConstantOrConstantSplatVector(Register Def, const MachineRegisterInfo &MRI)
Determines if Def defines a constant integer or a splat vector of constant integers.
Definition Utils.cpp:1517
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 std::optional< APInt > getIConstantVRegVal(Register VReg, const MachineRegisterInfo &MRI)
If VReg is defined by a G_CONSTANT, return the corresponding value.
Definition Utils.cpp:297
@ Known
Known to have no common set bits.
auto enumerate(FirstRange &&First, RestRanges &&...Rest)
Given two or more input ranges, returns a new range whose values are tuples (A, B,...
Definition STLExtras.h:2554
LLVM_ABI const llvm::fltSemantics & getFltSemanticForLLT(LLT Ty)
Get the appropriate floating point arithmetic semantic based on the bit size of the given scalar LLT.
scope_exit(Callable) -> scope_exit< Callable >
int bit_width(T Value)
Returns the number of bits needed to represent Value if Value is nonzero.
Definition bit.h:325
constexpr bool isUIntN(unsigned N, uint64_t x)
Checks if an unsigned integer fits into the given (dynamic) bit width.
Definition MathExtras.h:244
AnalysisManager< MachineFunction > MachineFunctionAnalysisManager
int ilogb(const APFloat &Arg)
Returns the exponent of the internal representation of the APFloat.
Definition APFloat.h:1684
unsigned Log2_64(uint64_t Value)
Return the floor log base 2 of the specified value, -1 if the value is zero.
Definition MathExtras.h:338
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.
LLVM_ABI ConstantRange getConstantRangeFromMetadata(const MDNode &RangeMD)
Parse out a conservative ConstantRange from !range metadata.
std::tuple< Value *, FPClassTest, FPClassTest > fcmpImpliesClass(CmpInst::Predicate Pred, const Function &F, Value *LHS, FPClassTest RHSClass, bool LookThroughSrc=true)
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
FPClassTest
Floating-point class tests, supported by 'is_fpclass' intrinsic.
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition Debug.cpp:209
LLVM_ABI ConstantRange getVScaleRange(const Function *F, unsigned BitWidth)
Determine the possible constant range of vscale with the given bit width, based on the vscale_range f...
@ First
Helpers to iterate all locations in the MemoryEffectsBase class.
Definition ModRef.h:74
DWARFExpression::Operation Op
std::string toString(const APInt &I, unsigned Radix, bool Signed, bool formatAsCLiteral=false, bool UpperCase=true, bool InsertSeparators=false)
constexpr unsigned BitWidth
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:559
static uint32_t extractBits(uint64_t Val, uint32_t Hi, uint32_t Lo)
LLVM_ABI void computeKnownBitsFromRangeMetadata(const MDNode &Ranges, KnownBits &Known)
Compute known bits from the range metadata.
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition Alignment.h:39
A special type used by analysis passes to provide an address that identifies that particular analysis...
Definition Analysis.h:29
static KnownBits makeConstant(const APInt &C)
Create known bits from a known constant.
Definition KnownBits.h:315
static LLVM_ABI KnownBits sadd_sat(const KnownBits &LHS, const KnownBits &RHS)
Compute knownbits resulting from llvm.sadd.sat(LHS, RHS)
KnownBits anyextOrTrunc(unsigned BitWidth) const
Return known bits for an "any" extension or truncation of the value we're tracking.
Definition KnownBits.h:190
static LLVM_ABI KnownBits mulhu(const KnownBits &LHS, const KnownBits &RHS)
Compute known bits from zero-extended multiply-hi.
unsigned countMinSignBits() const
Returns the number of times the sign bit is replicated into the other bits.
Definition KnownBits.h:269
static LLVM_ABI KnownBits smax(const KnownBits &LHS, const KnownBits &RHS)
Compute known bits for smax(LHS, RHS).
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
static LLVM_ABI KnownBits usub_sat(const KnownBits &LHS, const KnownBits &RHS)
Compute knownbits resulting from llvm.usub.sat(LHS, RHS)
static LLVM_ABI KnownBits ashr(const KnownBits &LHS, const KnownBits &RHS, bool ShAmtNonZero=false, bool Exact=false)
Compute known bits for ashr(LHS, RHS).
static LLVM_ABI KnownBits ssub_sat(const KnownBits &LHS, const KnownBits &RHS)
Compute knownbits resulting from llvm.ssub.sat(LHS, RHS)
static LLVM_ABI KnownBits urem(const KnownBits &LHS, const KnownBits &RHS)
Compute known bits for urem(LHS, RHS).
unsigned countMaxTrailingZeros() const
Returns the maximum number of trailing zero bits possible.
Definition KnownBits.h:288
KnownBits trunc(unsigned BitWidth) const
Return known bits for a truncation of the value we're tracking.
Definition KnownBits.h:165
static LLVM_ABI KnownBits fshl(const KnownBits &LHS, const KnownBits &RHS, const APInt &Amt)
Compute known bits for fshl(LHS, RHS, Amt).
unsigned countMaxPopulation() const
Returns the maximum number of bits that could be one.
Definition KnownBits.h:303
void setAllZero()
Make all bits known to be zero and discard any previous information.
Definition KnownBits.h:84
unsigned getBitWidth() const
Get the bit width of this value.
Definition KnownBits.h:44
static LLVM_ABI KnownBits umax(const KnownBits &LHS, const KnownBits &RHS)
Compute known bits for umax(LHS, RHS).
KnownBits zext(unsigned BitWidth) const
Return known bits for a zero extension of the value we're tracking.
Definition KnownBits.h:176
static KnownBits add(const KnownBits &LHS, const KnownBits &RHS, bool NSW=false, bool NUW=false, bool SelfAdd=false)
Compute knownbits resulting from addition of LHS and RHS.
Definition KnownBits.h:361
static LLVM_ABI KnownBits lshr(const KnownBits &LHS, const KnownBits &RHS, bool ShAmtNonZero=false, bool Exact=false)
Compute known bits for lshr(LHS, RHS).
bool isNonZero() const
Returns true if this value is known to be non-zero.
Definition KnownBits.h:109
static LLVM_ABI KnownBits abdu(const KnownBits &LHS, const KnownBits &RHS)
Compute known bits for abdu(LHS, RHS).
bool isEven() const
Return if the value is known even (the low bit is 0).
Definition KnownBits.h:162
KnownBits extractBits(unsigned NumBits, unsigned BitPosition) const
Return a subset of the known bits from [bitPosition,bitPosition+numBits).
Definition KnownBits.h:239
static LLVM_ABI KnownBits avgFloorU(const KnownBits &LHS, const KnownBits &RHS)
Compute knownbits resulting from APIntOps::avgFloorU.
KnownBits sext(unsigned BitWidth) const
Return known bits for a sign extension of the value we're tracking.
Definition KnownBits.h:184
KnownBits zextOrTrunc(unsigned BitWidth) const
Return known bits for a zero extension or truncation of the value we're tracking.
Definition KnownBits.h:200
unsigned countMinLeadingZeros() const
Returns the minimum number of leading zero bits.
Definition KnownBits.h:262
APInt getMaxValue() const
Return the maximal unsigned value possible given these KnownBits.
Definition KnownBits.h:146
static LLVM_ABI KnownBits fshr(const KnownBits &LHS, const KnownBits &RHS, const APInt &Amt)
Compute known bits for fshr(LHS, RHS, Amt).
static LLVM_ABI KnownBits abds(KnownBits LHS, KnownBits RHS)
Compute known bits for abds(LHS, RHS).
static LLVM_ABI KnownBits smin(const KnownBits &LHS, const KnownBits &RHS)
Compute known bits for smin(LHS, RHS).
static LLVM_ABI KnownBits mulhs(const KnownBits &LHS, const KnownBits &RHS)
Compute known bits from sign-extended multiply-hi.
static LLVM_ABI KnownBits srem(const KnownBits &LHS, const KnownBits &RHS)
Compute known bits for srem(LHS, RHS).
static LLVM_ABI KnownBits udiv(const KnownBits &LHS, const KnownBits &RHS, bool Exact=false)
Compute known bits for udiv(LHS, RHS).
APInt getMinValue() const
Return the minimal unsigned value possible given these KnownBits.
Definition KnownBits.h:130
static LLVM_ABI KnownBits sdiv(const KnownBits &LHS, const KnownBits &RHS, bool Exact=false)
Compute known bits for sdiv(LHS, RHS).
static LLVM_ABI KnownBits avgFloorS(const KnownBits &LHS, const KnownBits &RHS)
Compute knownbits resulting from APIntOps::avgFloorS.
bool isNegative() const
Returns true if this value is known to be negative.
Definition KnownBits.h:103
static LLVM_ABI KnownBits computeForAddCarry(const KnownBits &LHS, const KnownBits &RHS, const KnownBits &Carry)
Compute known bits resulting from adding LHS, RHS and a 1-bit Carry.
Definition KnownBits.cpp:54
static KnownBits sub(const KnownBits &LHS, const KnownBits &RHS, bool NSW=false, bool NUW=false)
Compute knownbits resulting from subtraction of LHS and RHS.
Definition KnownBits.h:376
unsigned countMaxLeadingZeros() const
Returns the maximum number of leading zero bits possible.
Definition KnownBits.h:294
static LLVM_ABI KnownBits avgCeilU(const KnownBits &LHS, const KnownBits &RHS)
Compute knownbits resulting from APIntOps::avgCeilU.
static LLVM_ABI KnownBits uadd_sat(const KnownBits &LHS, const KnownBits &RHS)
Compute knownbits resulting from llvm.uadd.sat(LHS, RHS)
static LLVM_ABI KnownBits mul(const KnownBits &LHS, const KnownBits &RHS, bool NoUndefSelfMultiply=false)
Compute known bits resulting from multiplying LHS and RHS.
KnownBits anyext(unsigned BitWidth) const
Return known bits for an "any" extension of the value we're tracking, where we don't know anything ab...
Definition KnownBits.h:171
static LLVM_ABI KnownBits shl(const KnownBits &LHS, const KnownBits &RHS, bool NUW=false, bool NSW=false, bool ShAmtNonZero=false)
Compute known bits for shl(LHS, RHS).
static LLVM_ABI KnownBits umin(const KnownBits &LHS, const KnownBits &RHS)
Compute known bits for umin(LHS, RHS).
bool isAllOnes() const
Returns true if value is all one bits.
Definition KnownBits.h:81
static LLVM_ABI KnownBits avgCeilS(const KnownBits &LHS, const KnownBits &RHS)
Compute knownbits resulting from APIntOps::avgCeilS.
FPClassTest KnownFPClasses
Floating-point classes the value could be one of.
bool isKnownNeverInfinity() const
Return true if it's known this can never be an infinity.
bool cannotBeOrderedGreaterThanZero() const
Return true if we can prove that the analyzed floating-point value is either NaN or never greater tha...
static LLVM_ABI KnownFPClass sin(const KnownFPClass &Src)
Report known values for sin.
static LLVM_ABI KnownFPClass fdiv_self(const KnownFPClass &Src, DenormalMode Mode=DenormalMode::getDynamic())
Report known values for fdiv x, x.
static constexpr FPClassTest OrderedGreaterThanZeroMask
static constexpr FPClassTest OrderedLessThanZeroMask
void knownNot(FPClassTest RuleOut)
static LLVM_ABI KnownFPClass fmul(const KnownFPClass &LHS, const KnownFPClass &RHS, DenormalMode Mode=DenormalMode::getDynamic())
Report known values for fmul.
static LLVM_ABI KnownFPClass fadd_self(const KnownFPClass &Src, DenormalMode Mode=DenormalMode::getDynamic())
Report known values for fadd x, x.
static KnownFPClass square(const KnownFPClass &Src, DenormalMode Mode=DenormalMode::getDynamic())
static LLVM_ABI KnownFPClass fsub(const KnownFPClass &LHS, const KnownFPClass &RHS, DenormalMode Mode=DenormalMode::getDynamic())
Report known values for fsub.
static LLVM_ABI KnownFPClass canonicalize(const KnownFPClass &Src, DenormalMode DenormMode=DenormalMode::getDynamic())
Apply the canonicalize intrinsic to this value.
LLVM_ABI bool isKnownNeverLogicalZero(DenormalMode Mode) const
Return true if it's known this can never be interpreted as a zero.
static LLVM_ABI KnownFPClass log(const KnownFPClass &Src, DenormalMode Mode=DenormalMode::getDynamic())
Propagate known class for log/log2/log10.
static LLVM_ABI KnownFPClass atan(const KnownFPClass &Src)
Report known values for atan.
static LLVM_ABI KnownFPClass atan2(const KnownFPClass &LHS, const KnownFPClass &RHS)
Report known values for atan2.
static LLVM_ABI KnownFPClass fdiv(const KnownFPClass &LHS, const KnownFPClass &RHS, DenormalMode Mode=DenormalMode::getDynamic())
Report known values for fdiv.
static LLVM_ABI KnownFPClass roundToIntegral(const KnownFPClass &Src, bool IsTrunc, bool IsMultiUnitFPType)
Propagate known class for rounding intrinsics (trunc, floor, ceil, rint, nearbyint,...
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.
static LLVM_ABI KnownFPClass minMaxLike(const KnownFPClass &LHS, const KnownFPClass &RHS, MinMaxKind Kind, DenormalMode DenormMode=DenormalMode::getDynamic())
static LLVM_ABI KnownFPClass exp(const KnownFPClass &Src)
Report known values for exp, exp2 and exp10.
static LLVM_ABI KnownFPClass frexp_mant(const KnownFPClass &Src, DenormalMode Mode=DenormalMode::getDynamic())
Propagate known class for mantissa component of frexp.
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.
bool isKnownNever(FPClassTest Mask) const
Return true if it's known this can never be one of the mask entries.
static LLVM_ABI KnownFPClass fpext(const KnownFPClass &KnownSrc, const fltSemantics &DstTy, const fltSemantics &SrcTy)
Propagate known class for fpext.
static LLVM_ABI KnownFPClass fma(const KnownFPClass &LHS, const KnownFPClass &RHS, const KnownFPClass &Addend, DenormalMode Mode=DenormalMode::getDynamic())
Report known values for fma.
static LLVM_ABI KnownFPClass tan(const KnownFPClass &Src)
Report known values for tan.
static LLVM_ABI KnownFPClass fptrunc(const KnownFPClass &KnownSrc)
Propagate known class for fptrunc.
bool cannotBeOrderedLessThanZero() const
Return true if we can prove that the analyzed floating-point value is either NaN or never less than -...
static LLVM_ABI KnownFPClass sqrt(const KnownFPClass &Src, DenormalMode Mode=DenormalMode::getDynamic())
Propagate known class for sqrt.
static LLVM_ABI KnownFPClass fadd(const KnownFPClass &LHS, const KnownFPClass &RHS, DenormalMode Mode=DenormalMode::getDynamic())
Report known values for fadd.
static LLVM_ABI KnownFPClass fma_square(const KnownFPClass &Squared, const KnownFPClass &Addend, DenormalMode Mode=DenormalMode::getDynamic())
Report known values for fma squared, squared, addend.
static LLVM_ABI KnownFPClass acos(const KnownFPClass &Src)
Report known values for acos.
static LLVM_ABI KnownFPClass frem_self(const KnownFPClass &Src, DenormalMode Mode=DenormalMode::getDynamic())
Report known values for frem.
static LLVM_ABI KnownFPClass powi(const KnownFPClass &Src, const KnownBits &N)
Propagate known class for powi.
static LLVM_ABI KnownFPClass ldexp(const KnownFPClass &Src, const APInt &ConstantRangeMin, const APInt &ConstantRangeMax, const fltSemantics &Flt, DenormalMode Mode=DenormalMode::getDynamic())
Propagate known class for ldexp, assuming the exponent is known to be within [ConstantRangeMin,...
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.