Skip to content

Commit

Permalink
ValueTracking: Implement computeKnownFPClass for frexp
Browse files Browse the repository at this point in the history
Work around the lack of proper multiple return values by looking
at the extractvalue.

https://reviews.llvm.org/D150982
  • Loading branch information
arsenm committed Jul 21, 2023
1 parent 35f9fdb commit d873a14
Show file tree
Hide file tree
Showing 3 changed files with 176 additions and 112 deletions.
47 changes: 45 additions & 2 deletions llvm/lib/Analysis/ValueTracking.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5121,8 +5121,51 @@ void computeKnownFPClass(const Value *V, const APInt &DemandedElts,
break;
}
case Instruction::ExtractValue: {
computeKnownFPClass(Op->getOperand(0), DemandedElts, InterestedClasses,
Known, Depth + 1, Q);
const ExtractValueInst *Extract = cast<ExtractValueInst>(Op);
ArrayRef<unsigned> Indices = Extract->getIndices();
const Value *Src = Extract->getAggregateOperand();
if (isa<StructType>(Src->getType()) && Indices.size() == 1 &&
Indices[0] == 0) {
if (const auto *II = dyn_cast<IntrinsicInst>(Src)) {
switch (II->getIntrinsicID()) {
case Intrinsic::frexp: {
Known.knownNot(fcSubnormal);

KnownFPClass KnownSrc;
computeKnownFPClass(II->getArgOperand(0), DemandedElts,
InterestedClasses, KnownSrc, Depth + 1, Q);

const Function *F = cast<Instruction>(Op)->getFunction();

if (KnownSrc.isKnownNever(fcNegative))
Known.knownNot(fcNegative);
else {
if (F && KnownSrc.isKnownNeverLogicalNegZero(*F, Op->getType()))
Known.knownNot(fcNegZero);
if (KnownSrc.isKnownNever(fcNegInf))
Known.knownNot(fcNegInf);
}

if (KnownSrc.isKnownNever(fcPositive))
Known.knownNot(fcPositive);
else {
if (F && KnownSrc.isKnownNeverLogicalPosZero(*F, Op->getType()))
Known.knownNot(fcPosZero);
if (KnownSrc.isKnownNever(fcPosInf))
Known.knownNot(fcPosInf);
}

Known.propagateNaN(KnownSrc);
return;
}
default:
break;
}
}
}

computeKnownFPClass(Src, DemandedElts, InterestedClasses, Known, Depth + 1,
Q);
break;
}
case Instruction::PHI: {
Expand Down

0 comments on commit d873a14

Please sign in to comment.