Skip to content

Commit

Permalink
[ValueTracking] Consistently propagate DemandedElts is `computeKnow…
Browse files Browse the repository at this point in the history
…nFPClass`

Summary: Closes #99080

Test Plan: 

Reviewers: 

Subscribers: 

Tasks: 

Tags: 


Differential Revision: https://phabricator.intern.facebook.com/D60250820
  • Loading branch information
goldsteinn authored and yuxuanchen1997 committed Jul 25, 2024
1 parent deb6463 commit 0575198
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 13 deletions.
22 changes: 17 additions & 5 deletions llvm/include/llvm/Analysis/ValueTracking.h
Original file line number Diff line number Diff line change
Expand Up @@ -526,16 +526,17 @@ inline KnownFPClass computeKnownFPClass(
}

/// Wrapper to account for known fast math flags at the use instruction.
inline KnownFPClass computeKnownFPClass(const Value *V, FastMathFlags FMF,
FPClassTest InterestedClasses,
unsigned Depth,
const SimplifyQuery &SQ) {
inline KnownFPClass
computeKnownFPClass(const Value *V, const APInt &DemandedElts,
FastMathFlags FMF, FPClassTest InterestedClasses,
unsigned Depth, const SimplifyQuery &SQ) {
if (FMF.noNaNs())
InterestedClasses &= ~fcNan;
if (FMF.noInfs())
InterestedClasses &= ~fcInf;

KnownFPClass Result = computeKnownFPClass(V, InterestedClasses, Depth, SQ);
KnownFPClass Result =
computeKnownFPClass(V, DemandedElts, InterestedClasses, Depth, SQ);

if (FMF.noNaNs())
Result.KnownFPClasses &= ~fcNan;
Expand All @@ -544,6 +545,17 @@ inline KnownFPClass computeKnownFPClass(const Value *V, FastMathFlags FMF,
return Result;
}

inline KnownFPClass computeKnownFPClass(const Value *V, FastMathFlags FMF,
FPClassTest InterestedClasses,
unsigned Depth,
const SimplifyQuery &SQ) {
auto *FVTy = dyn_cast<FixedVectorType>(V->getType());
APInt DemandedElts =
FVTy ? APInt::getAllOnes(FVTy->getNumElements()) : APInt(1, 1);
return computeKnownFPClass(V, DemandedElts, FMF, InterestedClasses, Depth,
SQ);
}

/// Return true if we can prove that the specified FP value is never equal to
/// -0.0. Users should use caution when considering PreserveSign
/// denormal-fp-math.
Expand Down
5 changes: 3 additions & 2 deletions llvm/lib/Analysis/ValueTracking.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5274,8 +5274,9 @@ void computeKnownFPClass(const Value *V, const APInt &DemandedElts,
}
// reverse preserves all characteristics of the input vec's element.
case Intrinsic::vector_reverse:
Known = computeKnownFPClass(II->getArgOperand(0), II->getFastMathFlags(),
InterestedClasses, Depth + 1, Q);
Known = computeKnownFPClass(
II->getArgOperand(0), DemandedElts.reverseBits(),
II->getFastMathFlags(), InterestedClasses, Depth + 1, Q);
break;
case Intrinsic::trunc:
case Intrinsic::floor:
Expand Down
7 changes: 1 addition & 6 deletions llvm/test/Analysis/ValueTracking/known-fpclass.ll
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,7 @@ define <4 x i1> @vector_reverse_fpclass2(<4 x double> nofpclass(nzero) %x) {

define i1 @vector_reverse_fpclass_demanded(<4 x double> %vec, double nofpclass(nzero nan) %x) {
; CHECK-LABEL: @vector_reverse_fpclass_demanded(
; CHECK-NEXT: [[X_ABS:%.*]] = call double @llvm.fabs.f64(double [[X:%.*]])
; CHECK-NEXT: [[VEC_X:%.*]] = insertelement <4 x double> [[VEC:%.*]], double [[X_ABS]], i64 1
; CHECK-NEXT: [[REV:%.*]] = call <4 x double> @llvm.vector.reverse.v4f64(<4 x double> [[VEC_X]])
; CHECK-NEXT: [[ELE:%.*]] = extractelement <4 x double> [[REV]], i64 2
; CHECK-NEXT: [[CMP:%.*]] = fcmp oge double [[ELE]], 0.000000e+00
; CHECK-NEXT: ret i1 [[CMP]]
; CHECK-NEXT: ret i1 true
;

%x.abs = call double @llvm.fabs.f64(double %x)
Expand Down

0 comments on commit 0575198

Please sign in to comment.