Skip to content

Commit 930996e

Browse files
authored
[ValueTracking][NFC] Pass SimplifyQuery to computeKnownFPClass family (#80657)
This patch refactors the interface of the `computeKnownFPClass` family to pass `SimplifyQuery` directly. The motivation of this patch is to compute known fpclass with `DomConditionCache`, which was introduced by #73662. With `DomConditionCache`, we can do more optimization with context-sensitive information. Example (extracted from [fmt/format.h](https://github.com/fmtlib/fmt/blob/e17bc67547a66cdd378ca6a90c56b865d30d6168/include/fmt/format.h#L3555-L3566)): ``` define float @test(float %x, i1 %cond) { %i32 = bitcast float %x to i32 %cmp = icmp slt i32 %i32, 0 br i1 %cmp, label %if.then1, label %if.else if.then1: %fneg = fneg float %x br label %if.end if.else: br i1 %cond, label %if.then2, label %if.end if.then2: br label %if.end if.end: %value = phi float [ %fneg, %if.then1 ], [ %x, %if.then2 ], [ %x, %if.else ] %ret = call float @llvm.fabs.f32(float %value) ret float %ret } ``` We can prove the signbit of `%value` is always zero. Then the fabs can be eliminated.
1 parent dd70aef commit 930996e

13 files changed

+86
-123
lines changed

llvm/include/llvm/Analysis/ValueTracking.h

Lines changed: 35 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -479,34 +479,35 @@ inline KnownFPClass operator|(const KnownFPClass &LHS, KnownFPClass &&RHS) {
479479
/// point classes should be queried. Queries not specified in \p
480480
/// InterestedClasses should be reliable if they are determined during the
481481
/// query.
482-
KnownFPClass computeKnownFPClass(
483-
const Value *V, const APInt &DemandedElts, const DataLayout &DL,
484-
FPClassTest InterestedClasses = fcAllFlags, unsigned Depth = 0,
485-
const TargetLibraryInfo *TLI = nullptr, AssumptionCache *AC = nullptr,
486-
const Instruction *CxtI = nullptr, const DominatorTree *DT = nullptr,
487-
bool UseInstrInfo = true);
482+
KnownFPClass computeKnownFPClass(const Value *V, const APInt &DemandedElts,
483+
FPClassTest InterestedClasses, unsigned Depth,
484+
const SimplifyQuery &SQ);
488485

489-
KnownFPClass computeKnownFPClass(
490-
const Value *V, const DataLayout &DL,
491-
FPClassTest InterestedClasses = fcAllFlags, unsigned Depth = 0,
492-
const TargetLibraryInfo *TLI = nullptr, AssumptionCache *AC = nullptr,
493-
const Instruction *CxtI = nullptr, const DominatorTree *DT = nullptr,
494-
bool UseInstrInfo = true);
486+
KnownFPClass computeKnownFPClass(const Value *V, FPClassTest InterestedClasses,
487+
unsigned Depth, const SimplifyQuery &SQ);
495488

496-
/// Wrapper to account for known fast math flags at the use instruction.
497489
inline KnownFPClass computeKnownFPClass(
498-
const Value *V, FastMathFlags FMF, const DataLayout &DL,
490+
const Value *V, const DataLayout &DL,
499491
FPClassTest InterestedClasses = fcAllFlags, unsigned Depth = 0,
500492
const TargetLibraryInfo *TLI = nullptr, AssumptionCache *AC = nullptr,
501493
const Instruction *CxtI = nullptr, const DominatorTree *DT = nullptr,
502494
bool UseInstrInfo = true) {
495+
return computeKnownFPClass(
496+
V, InterestedClasses, Depth,
497+
SimplifyQuery(DL, TLI, DT, AC, CxtI, UseInstrInfo));
498+
}
499+
500+
/// Wrapper to account for known fast math flags at the use instruction.
501+
inline KnownFPClass computeKnownFPClass(const Value *V, FastMathFlags FMF,
502+
FPClassTest InterestedClasses,
503+
unsigned Depth,
504+
const SimplifyQuery &SQ) {
503505
if (FMF.noNaNs())
504506
InterestedClasses &= ~fcNan;
505507
if (FMF.noInfs())
506508
InterestedClasses &= ~fcInf;
507509

508-
KnownFPClass Result = computeKnownFPClass(V, DL, InterestedClasses, Depth,
509-
TLI, AC, CxtI, DT, UseInstrInfo);
510+
KnownFPClass Result = computeKnownFPClass(V, InterestedClasses, Depth, SQ);
510511

511512
if (FMF.noNaNs())
512513
Result.KnownFPClasses &= ~fcNan;
@@ -518,15 +519,9 @@ inline KnownFPClass computeKnownFPClass(
518519
/// Return true if we can prove that the specified FP value is never equal to
519520
/// -0.0. Users should use caution when considering PreserveSign
520521
/// denormal-fp-math.
521-
inline bool cannotBeNegativeZero(const Value *V, const DataLayout &DL,
522-
const TargetLibraryInfo *TLI = nullptr,
523-
unsigned Depth = 0,
524-
AssumptionCache *AC = nullptr,
525-
const Instruction *CtxI = nullptr,
526-
const DominatorTree *DT = nullptr,
527-
bool UseInstrInfo = true) {
528-
KnownFPClass Known = computeKnownFPClass(V, DL, fcNegZero, Depth, TLI, AC,
529-
CtxI, DT, UseInstrInfo);
522+
inline bool cannotBeNegativeZero(const Value *V, unsigned Depth,
523+
const SimplifyQuery &SQ) {
524+
KnownFPClass Known = computeKnownFPClass(V, fcNegZero, Depth, SQ);
530525
return Known.isKnownNeverNegZero();
531526
}
532527

@@ -538,69 +533,44 @@ inline bool cannotBeNegativeZero(const Value *V, const DataLayout &DL,
538533
/// -0 --> true
539534
/// x > +0 --> true
540535
/// x < -0 --> false
541-
inline bool cannotBeOrderedLessThanZero(const Value *V, const DataLayout &DL,
542-
const TargetLibraryInfo *TLI = nullptr,
543-
unsigned Depth = 0,
544-
AssumptionCache *AC = nullptr,
545-
const Instruction *CtxI = nullptr,
546-
const DominatorTree *DT = nullptr,
547-
bool UseInstrInfo = true) {
536+
inline bool cannotBeOrderedLessThanZero(const Value *V, unsigned Depth,
537+
const SimplifyQuery &SQ) {
548538
KnownFPClass Known =
549-
computeKnownFPClass(V, DL, KnownFPClass::OrderedLessThanZeroMask, Depth,
550-
TLI, AC, CtxI, DT, UseInstrInfo);
539+
computeKnownFPClass(V, KnownFPClass::OrderedLessThanZeroMask, Depth, SQ);
551540
return Known.cannotBeOrderedLessThanZero();
552541
}
553542

554543
/// Return true if the floating-point scalar value is not an infinity or if
555544
/// the floating-point vector value has no infinities. Return false if a value
556545
/// could ever be infinity.
557-
inline bool isKnownNeverInfinity(const Value *V, const DataLayout &DL,
558-
const TargetLibraryInfo *TLI = nullptr,
559-
unsigned Depth = 0,
560-
AssumptionCache *AC = nullptr,
561-
const Instruction *CtxI = nullptr,
562-
const DominatorTree *DT = nullptr,
563-
bool UseInstrInfo = true) {
564-
KnownFPClass Known = computeKnownFPClass(V, DL, fcInf, Depth, TLI, AC, CtxI,
565-
DT, UseInstrInfo);
546+
inline bool isKnownNeverInfinity(const Value *V, unsigned Depth,
547+
const SimplifyQuery &SQ) {
548+
KnownFPClass Known = computeKnownFPClass(V, fcInf, Depth, SQ);
566549
return Known.isKnownNeverInfinity();
567550
}
568551

569552
/// Return true if the floating-point value can never contain a NaN or infinity.
570-
inline bool isKnownNeverInfOrNaN(
571-
const Value *V, const DataLayout &DL, const TargetLibraryInfo *TLI,
572-
unsigned Depth = 0, AssumptionCache *AC = nullptr,
573-
const Instruction *CtxI = nullptr, const DominatorTree *DT = nullptr,
574-
bool UseInstrInfo = true) {
575-
KnownFPClass Known = computeKnownFPClass(V, DL, fcInf | fcNan, Depth, TLI, AC,
576-
CtxI, DT, UseInstrInfo);
553+
inline bool isKnownNeverInfOrNaN(const Value *V, unsigned Depth,
554+
const SimplifyQuery &SQ) {
555+
KnownFPClass Known = computeKnownFPClass(V, fcInf | fcNan, Depth, SQ);
577556
return Known.isKnownNeverNaN() && Known.isKnownNeverInfinity();
578557
}
579558

580559
/// Return true if the floating-point scalar value is not a NaN or if the
581560
/// floating-point vector value has no NaN elements. Return false if a value
582561
/// could ever be NaN.
583-
inline bool isKnownNeverNaN(const Value *V, const DataLayout &DL,
584-
const TargetLibraryInfo *TLI, unsigned Depth = 0,
585-
AssumptionCache *AC = nullptr,
586-
const Instruction *CtxI = nullptr,
587-
const DominatorTree *DT = nullptr,
588-
bool UseInstrInfo = true) {
589-
KnownFPClass Known = computeKnownFPClass(V, DL, fcNan, Depth, TLI, AC, CtxI,
590-
DT, UseInstrInfo);
562+
inline bool isKnownNeverNaN(const Value *V, unsigned Depth,
563+
const SimplifyQuery &SQ) {
564+
KnownFPClass Known = computeKnownFPClass(V, fcNan, Depth, SQ);
591565
return Known.isKnownNeverNaN();
592566
}
593567

594568
/// Return false if we can prove that the specified FP value's sign bit is 0.
595569
/// Return true if we can prove that the specified FP value's sign bit is 1.
596570
/// Otherwise return std::nullopt.
597-
inline std::optional<bool> computeKnownFPSignBit(
598-
const Value *V, const DataLayout &DL,
599-
const TargetLibraryInfo *TLI = nullptr, unsigned Depth = 0,
600-
AssumptionCache *AC = nullptr, const Instruction *CtxI = nullptr,
601-
const DominatorTree *DT = nullptr, bool UseInstrInfo = true) {
602-
KnownFPClass Known = computeKnownFPClass(V, DL, fcAllFlags, Depth, TLI, AC,
603-
CtxI, DT, UseInstrInfo);
571+
inline std::optional<bool> computeKnownFPSignBit(const Value *V, unsigned Depth,
572+
const SimplifyQuery &SQ) {
573+
KnownFPClass Known = computeKnownFPClass(V, fcAllFlags, Depth, SQ);
604574
return Known.SignBit;
605575
}
606576

llvm/lib/Analysis/InstructionSimplify.cpp

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1852,9 +1852,6 @@ static Value *simplifyAndOrOfFCmps(const SimplifyQuery &Q, FCmpInst *LHS,
18521852
if (LHS0->getType() != RHS0->getType())
18531853
return nullptr;
18541854

1855-
const DataLayout &DL = Q.DL;
1856-
const TargetLibraryInfo *TLI = Q.TLI;
1857-
18581855
FCmpInst::Predicate PredL = LHS->getPredicate(), PredR = RHS->getPredicate();
18591856
if ((PredL == FCmpInst::FCMP_ORD && PredR == FCmpInst::FCMP_ORD && IsAnd) ||
18601857
(PredL == FCmpInst::FCMP_UNO && PredR == FCmpInst::FCMP_UNO && !IsAnd)) {
@@ -1867,9 +1864,9 @@ static Value *simplifyAndOrOfFCmps(const SimplifyQuery &Q, FCmpInst *LHS,
18671864
// (fcmp uno X, NNAN) | (fcmp uno X, Y) --> fcmp uno X, Y
18681865
// (fcmp uno X, NNAN) | (fcmp uno Y, X) --> fcmp uno Y, X
18691866
if (((LHS1 == RHS0 || LHS1 == RHS1) &&
1870-
isKnownNeverNaN(LHS0, DL, TLI, 0, Q.AC, Q.CxtI, Q.DT)) ||
1867+
isKnownNeverNaN(LHS0, /*Depth=*/0, Q)) ||
18711868
((LHS0 == RHS0 || LHS0 == RHS1) &&
1872-
isKnownNeverNaN(LHS1, DL, TLI, 0, Q.AC, Q.CxtI, Q.DT)))
1869+
isKnownNeverNaN(LHS1, /*Depth=*/0, Q)))
18731870
return RHS;
18741871

18751872
// (fcmp ord X, Y) & (fcmp ord NNAN, X) --> fcmp ord X, Y
@@ -1881,9 +1878,9 @@ static Value *simplifyAndOrOfFCmps(const SimplifyQuery &Q, FCmpInst *LHS,
18811878
// (fcmp uno X, Y) | (fcmp uno X, NNAN) --> fcmp uno X, Y
18821879
// (fcmp uno Y, X) | (fcmp uno X, NNAN) --> fcmp uno Y, X
18831880
if (((RHS1 == LHS0 || RHS1 == LHS1) &&
1884-
isKnownNeverNaN(RHS0, DL, TLI, 0, Q.AC, Q.CxtI, Q.DT)) ||
1881+
isKnownNeverNaN(RHS0, /*Depth=*/0, Q)) ||
18851882
((RHS0 == LHS0 || RHS0 == LHS1) &&
1886-
isKnownNeverNaN(RHS1, DL, TLI, 0, Q.AC, Q.CxtI, Q.DT)))
1883+
isKnownNeverNaN(RHS1, /*Depth=*/0, Q)))
18871884
return LHS;
18881885
}
18891886

@@ -4106,9 +4103,8 @@ static Value *simplifyFCmpInst(unsigned Predicate, Value *LHS, Value *RHS,
41064103
// This catches the 2 variable input case, constants are handled below as a
41074104
// class-like compare.
41084105
if (Pred == FCmpInst::FCMP_ORD || Pred == FCmpInst::FCMP_UNO) {
4109-
if (FMF.noNaNs() ||
4110-
(isKnownNeverNaN(RHS, Q.DL, Q.TLI, 0, Q.AC, Q.CxtI, Q.DT) &&
4111-
isKnownNeverNaN(LHS, Q.DL, Q.TLI, 0, Q.AC, Q.CxtI, Q.DT)))
4106+
if (FMF.noNaNs() || (isKnownNeverNaN(RHS, /*Depth=*/0, Q) &&
4107+
isKnownNeverNaN(LHS, /*Depth=*/0, Q)))
41124108
return ConstantInt::get(RetTy, Pred == FCmpInst::FCMP_ORD);
41134109
}
41144110

@@ -4122,8 +4118,7 @@ static Value *simplifyFCmpInst(unsigned Predicate, Value *LHS, Value *RHS,
41224118
fcAllFlags) {
41234119
if (FullKnownClassLHS)
41244120
return *FullKnownClassLHS;
4125-
return computeKnownFPClass(LHS, FMF, Q.DL, InterestedFlags, 0, Q.TLI, Q.AC,
4126-
Q.CxtI, Q.DT, Q.IIQ.UseInstrInfo);
4121+
return computeKnownFPClass(LHS, FMF, InterestedFlags, 0, Q);
41274122
};
41284123

41294124
if (C && Q.CxtI) {
@@ -5631,7 +5626,7 @@ simplifyFAddInst(Value *Op0, Value *Op1, FastMathFlags FMF,
56315626
// fadd X, 0 ==> X, when we know X is not -0
56325627
if (canIgnoreSNaN(ExBehavior, FMF))
56335628
if (match(Op1, m_PosZeroFP()) &&
5634-
(FMF.noSignedZeros() || cannotBeNegativeZero(Op0, Q.DL, Q.TLI)))
5629+
(FMF.noSignedZeros() || cannotBeNegativeZero(Op0, /*Depth=*/0, Q)))
56355630
return Op0;
56365631

56375632
if (!isDefaultFPEnvironment(ExBehavior, Rounding))
@@ -5693,7 +5688,7 @@ simplifyFSubInst(Value *Op0, Value *Op1, FastMathFlags FMF,
56935688
// fsub X, -0 ==> X, when we know X is not -0
56945689
if (canIgnoreSNaN(ExBehavior, FMF))
56955690
if (match(Op1, m_NegZeroFP()) &&
5696-
(FMF.noSignedZeros() || cannotBeNegativeZero(Op0, Q.DL, Q.TLI)))
5691+
(FMF.noSignedZeros() || cannotBeNegativeZero(Op0, /*Depth=*/0, Q)))
56975692
return Op0;
56985693

56995694
// fsub -0.0, (fsub -0.0, X) ==> X
@@ -5762,8 +5757,8 @@ static Value *simplifyFMAFMul(Value *Op0, Value *Op1, FastMathFlags FMF,
57625757
return ConstantFP::getZero(Op0->getType());
57635758

57645759
// +normal number * (-)0.0 --> (-)0.0
5765-
KnownFPClass Known = computeKnownFPClass(
5766-
Op0, FMF, Q.DL, fcInf | fcNan, /*Depth=*/0, Q.TLI, Q.AC, Q.CxtI, Q.DT);
5760+
KnownFPClass Known =
5761+
computeKnownFPClass(Op0, FMF, fcInf | fcNan, /*Depth=*/0, Q);
57675762
if (Known.SignBit == false && Known.isKnownNever(fcInf | fcNan))
57685763
return Op1;
57695764
}
@@ -6217,8 +6212,7 @@ static Value *simplifyUnaryIntrinsic(Function *F, Value *Op0,
62176212
Value *X;
62186213
switch (IID) {
62196214
case Intrinsic::fabs:
6220-
if (computeKnownFPSignBit(Op0, Q.DL, Q.TLI, /*Depth=*/0, Q.AC, Q.CxtI,
6221-
Q.DT) == false)
6215+
if (computeKnownFPSignBit(Op0, /*Depth=*/0, Q) == false)
62226216
return Op0;
62236217
break;
62246218
case Intrinsic::bswap:

llvm/lib/Analysis/ValueTracking.cpp

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5302,26 +5302,23 @@ void computeKnownFPClass(const Value *V, const APInt &DemandedElts,
53025302
}
53035303
}
53045304

5305-
KnownFPClass llvm::computeKnownFPClass(
5306-
const Value *V, const APInt &DemandedElts, const DataLayout &DL,
5307-
FPClassTest InterestedClasses, unsigned Depth, const TargetLibraryInfo *TLI,
5308-
AssumptionCache *AC, const Instruction *CxtI, const DominatorTree *DT,
5309-
bool UseInstrInfo) {
5305+
KnownFPClass llvm::computeKnownFPClass(const Value *V,
5306+
const APInt &DemandedElts,
5307+
FPClassTest InterestedClasses,
5308+
unsigned Depth,
5309+
const SimplifyQuery &SQ) {
53105310
KnownFPClass KnownClasses;
5311-
::computeKnownFPClass(
5312-
V, DemandedElts, InterestedClasses, KnownClasses, Depth,
5313-
SimplifyQuery(DL, TLI, DT, AC, safeCxtI(V, CxtI), UseInstrInfo));
5311+
::computeKnownFPClass(V, DemandedElts, InterestedClasses, KnownClasses, Depth,
5312+
SQ);
53145313
return KnownClasses;
53155314
}
53165315

5317-
KnownFPClass llvm::computeKnownFPClass(
5318-
const Value *V, const DataLayout &DL, FPClassTest InterestedClasses,
5319-
unsigned Depth, const TargetLibraryInfo *TLI, AssumptionCache *AC,
5320-
const Instruction *CxtI, const DominatorTree *DT, bool UseInstrInfo) {
5316+
KnownFPClass llvm::computeKnownFPClass(const Value *V,
5317+
FPClassTest InterestedClasses,
5318+
unsigned Depth,
5319+
const SimplifyQuery &SQ) {
53215320
KnownFPClass Known;
5322-
::computeKnownFPClass(
5323-
V, Known, InterestedClasses, Depth,
5324-
SimplifyQuery(DL, TLI, DT, AC, safeCxtI(V, CxtI), UseInstrInfo));
5321+
::computeKnownFPClass(V, Known, InterestedClasses, Depth, SQ);
53255322
return Known;
53265323
}
53275324

llvm/lib/Target/AMDGPU/AMDGPUCodeGenPrepare.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2095,7 +2095,8 @@ bool AMDGPUCodeGenPrepareImpl::visitMinNum(IntrinsicInst &I) {
20952095

20962096
// Match pattern for fract intrinsic in contexts where the nan check has been
20972097
// optimized out (and hope the knowledge the source can't be nan wasn't lost).
2098-
if (!I.hasNoNaNs() && !isKnownNeverNaN(FractArg, *DL, TLInfo))
2098+
if (!I.hasNoNaNs() &&
2099+
!isKnownNeverNaN(FractArg, /*Depth=*/0, SimplifyQuery(*DL, TLInfo)))
20992100
return false;
21002101

21012102
IRBuilder<> Builder(&I);

llvm/lib/Target/AMDGPU/AMDGPUInstCombineIntrinsic.cpp

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -343,13 +343,9 @@ bool GCNTTIImpl::canSimplifyLegacyMulToMul(const Instruction &I,
343343
return true;
344344
}
345345

346-
auto *TLI = &IC.getTargetLibraryInfo();
347-
if (isKnownNeverInfOrNaN(Op0, IC.getDataLayout(), TLI, 0,
348-
&IC.getAssumptionCache(), &I,
349-
&IC.getDominatorTree()) &&
350-
isKnownNeverInfOrNaN(Op1, IC.getDataLayout(), TLI, 0,
351-
&IC.getAssumptionCache(), &I,
352-
&IC.getDominatorTree())) {
346+
SimplifyQuery SQ = IC.getSimplifyQuery().getWithInstruction(&I);
347+
if (isKnownNeverInfOrNaN(Op0, /*Depth=*/0, SQ) &&
348+
isKnownNeverInfOrNaN(Op1, /*Depth=*/0, SQ)) {
353349
// Neither operand is infinity or NaN.
354350
return true;
355351
}

llvm/lib/Target/AMDGPU/AMDGPULibCalls.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -607,7 +607,7 @@ static bool isKnownIntegral(const Value *V, const DataLayout &DL,
607607

608608
// Need to check int size cannot produce infinity, which computeKnownFPClass
609609
// knows how to do already.
610-
return isKnownNeverInfinity(I, DL);
610+
return isKnownNeverInfinity(I, /*Depth=*/0, SimplifyQuery(DL));
611611
case Instruction::Call: {
612612
const CallInst *CI = cast<CallInst>(I);
613613
switch (CI->getIntrinsicID()) {
@@ -619,7 +619,7 @@ static bool isKnownIntegral(const Value *V, const DataLayout &DL,
619619
case Intrinsic::round:
620620
case Intrinsic::roundeven:
621621
return (FMF.noInfs() && FMF.noNaNs()) ||
622-
isKnownNeverInfOrNaN(I, DL, nullptr);
622+
isKnownNeverInfOrNaN(I, /*Depth=*/0, SimplifyQuery(DL));
623623
default:
624624
break;
625625
}
@@ -754,8 +754,9 @@ bool AMDGPULibCalls::fold(CallInst *CI) {
754754
// pow(x, y) -> powr(x, y) for x >= -0.0
755755
// TODO: Account for flags on current call
756756
if (PowrFunc &&
757-
cannotBeOrderedLessThanZero(FPOp->getOperand(0), M->getDataLayout(),
758-
TLInfo, 0, AC, Call, DT)) {
757+
cannotBeOrderedLessThanZero(
758+
FPOp->getOperand(0), /*Depth=*/0,
759+
SimplifyQuery(M->getDataLayout(), TLInfo, DT, AC, Call))) {
759760
Call->setCalledFunction(PowrFunc);
760761
return fold_pow(FPOp, B, PowrInfo) || true;
761762
}

llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -425,8 +425,8 @@ static bool foldSqrt(Instruction &I, TargetTransformInfo &TTI,
425425
Value *Arg = Call->getArgOperand(0);
426426
if (TTI.haveFastSqrt(Ty) &&
427427
(Call->hasNoNaNs() ||
428-
cannotBeOrderedLessThanZero(Arg, M->getDataLayout(), &TLI, 0, &AC, &I,
429-
&DT))) {
428+
cannotBeOrderedLessThanZero(
429+
Arg, 0, SimplifyQuery(M->getDataLayout(), &TLI, &DT, &AC, &I)))) {
430430
IRBuilder<> Builder(&I);
431431
IRBuilderBase::FastMathFlagGuard Guard(Builder);
432432
Builder.setFastMathFlags(Call->getFastMathFlags());

llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2842,7 +2842,8 @@ Instruction *InstCombinerImpl::visitFSub(BinaryOperator &I) {
28422842
// Note that if this fsub was really an fneg, the fadd with -0.0 will get
28432843
// killed later. We still limit that particular transform with 'hasOneUse'
28442844
// because an fneg is assumed better/cheaper than a generic fsub.
2845-
if (I.hasNoSignedZeros() || cannotBeNegativeZero(Op0, SQ.DL, SQ.TLI)) {
2845+
if (I.hasNoSignedZeros() ||
2846+
cannotBeNegativeZero(Op0, 0, getSimplifyQuery().getWithInstruction(&I))) {
28462847
if (match(Op1, m_OneUse(m_FSub(m_Value(X), m_Value(Y))))) {
28472848
Value *NewSub = Builder.CreateFSubFMF(Y, X, &I);
28482849
return BinaryOperator::CreateFAddFMF(Op0, NewSub, &I);

llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2413,7 +2413,7 @@ Instruction *InstCombinerImpl::visitCallInst(CallInst &CI) {
24132413
case Intrinsic::copysign: {
24142414
Value *Mag = II->getArgOperand(0), *Sign = II->getArgOperand(1);
24152415
if (std::optional<bool> KnownSignBit = computeKnownFPSignBit(
2416-
Sign, getDataLayout(), &TLI, /*Depth=*/0, &AC, II, &DT)) {
2416+
Sign, /*Depth=*/0, getSimplifyQuery().getWithInstruction(II))) {
24172417
if (*KnownSignBit) {
24182418
// If we know that the sign argument is negative, reduce to FNABS:
24192419
// copysign Mag, -Sign --> fneg (fabs Mag)

llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7714,12 +7714,12 @@ Instruction *InstCombinerImpl::visitFCmpInst(FCmpInst &I) {
77147714
// If we're just checking for a NaN (ORD/UNO) and have a non-NaN operand,
77157715
// then canonicalize the operand to 0.0.
77167716
if (Pred == CmpInst::FCMP_ORD || Pred == CmpInst::FCMP_UNO) {
7717-
if (!match(Op0, m_PosZeroFP()) && isKnownNeverNaN(Op0, DL, &TLI, 0,
7718-
&AC, &I, &DT))
7717+
if (!match(Op0, m_PosZeroFP()) &&
7718+
isKnownNeverNaN(Op0, 0, getSimplifyQuery().getWithInstruction(&I)))
77197719
return replaceOperand(I, 0, ConstantFP::getZero(OpType));
77207720

77217721
if (!match(Op1, m_PosZeroFP()) &&
7722-
isKnownNeverNaN(Op1, DL, &TLI, 0, &AC, &I, &DT))
7722+
isKnownNeverNaN(Op1, 0, getSimplifyQuery().getWithInstruction(&I)))
77237723
return replaceOperand(I, 1, ConstantFP::getZero(OpType));
77247724
}
77257725

0 commit comments

Comments
 (0)