@@ -1041,45 +1041,39 @@ Instruction *InstCombinerImpl::foldIntrinsicIsFPClass(IntrinsicInst &II) {
10411041 return nullptr ;
10421042}
10431043
1044- static std::optional<bool > getKnownSign (Value *Op, Instruction *CxtI,
1045- const DataLayout &DL, AssumptionCache *AC,
1046- DominatorTree *DT) {
1047- KnownBits Known = computeKnownBits (Op, DL, 0 , AC, CxtI, DT);
1044+ static std::optional<bool > getKnownSign (Value *Op, const SimplifyQuery &SQ) {
1045+ KnownBits Known = computeKnownBits (Op, /* Depth=*/ 0 , SQ);
10481046 if (Known.isNonNegative ())
10491047 return false ;
10501048 if (Known.isNegative ())
10511049 return true ;
10521050
10531051 Value *X, *Y;
10541052 if (match (Op, m_NSWSub (m_Value (X), m_Value (Y))))
1055- return isImpliedByDomCondition (ICmpInst::ICMP_SLT, X, Y, CxtI, DL);
1053+ return isImpliedByDomCondition (ICmpInst::ICMP_SLT, X, Y, SQ. CxtI , SQ. DL );
10561054
1057- return isImpliedByDomCondition (
1058- ICmpInst::ICMP_SLT, Op, Constant::getNullValue (Op->getType ()), CxtI, DL);
1055+ return std::nullopt ;
10591056}
10601057
1061- static std::optional<bool > getKnownSignOrZero (Value *Op, Instruction *CxtI,
1062- const DataLayout &DL,
1063- AssumptionCache *AC,
1064- DominatorTree *DT) {
1065- if (std::optional<bool > Sign = getKnownSign (Op, CxtI, DL, AC, DT))
1058+ static std::optional<bool > getKnownSignOrZero (Value *Op,
1059+ const SimplifyQuery &SQ) {
1060+ if (std::optional<bool > Sign = getKnownSign (Op, SQ))
10661061 return Sign;
10671062
10681063 Value *X, *Y;
10691064 if (match (Op, m_NSWSub (m_Value (X), m_Value (Y))))
1070- return isImpliedByDomCondition (ICmpInst::ICMP_SLE, X, Y, CxtI, DL);
1065+ return isImpliedByDomCondition (ICmpInst::ICMP_SLE, X, Y, SQ. CxtI , SQ. DL );
10711066
10721067 return std::nullopt ;
10731068}
10741069
10751070// / Return true if two values \p Op0 and \p Op1 are known to have the same sign.
1076- static bool signBitMustBeTheSame (Value *Op0, Value *Op1, Instruction *CxtI,
1077- const DataLayout &DL, AssumptionCache *AC,
1078- DominatorTree *DT) {
1079- std::optional<bool > Known1 = getKnownSign (Op1, CxtI, DL, AC, DT);
1071+ static bool signBitMustBeTheSame (Value *Op0, Value *Op1,
1072+ const SimplifyQuery &SQ) {
1073+ std::optional<bool > Known1 = getKnownSign (Op1, SQ);
10801074 if (!Known1)
10811075 return false ;
1082- std::optional<bool > Known0 = getKnownSign (Op0, CxtI, DL, AC, DT );
1076+ std::optional<bool > Known0 = getKnownSign (Op0, SQ );
10831077 if (!Known0)
10841078 return false ;
10851079 return *Known0 == *Known1;
@@ -1628,7 +1622,7 @@ Instruction *InstCombinerImpl::visitCallInst(CallInst &CI) {
16281622 }
16291623
16301624 if (std::optional<bool > Known =
1631- getKnownSignOrZero (IIOperand, II, DL, &AC, &DT )) {
1625+ getKnownSignOrZero (IIOperand, SQ. getWithInstruction (II) )) {
16321626 // abs(x) -> x if x >= 0 (include abs(x-y) --> x - y where x >= y)
16331627 // abs(x) -> x if x > 0 (include abs(x-y) --> x - y where x > y)
16341628 if (!*Known)
@@ -1753,7 +1747,7 @@ Instruction *InstCombinerImpl::visitCallInst(CallInst &CI) {
17531747 bool UseAndN = IID == Intrinsic::smin || IID == Intrinsic::umin;
17541748
17551749 if (IID == Intrinsic::smax || IID == Intrinsic::smin) {
1756- auto KnownSign = getKnownSign (X, II, DL, &AC, &DT );
1750+ auto KnownSign = getKnownSign (X, SQ. getWithInstruction (II) );
17571751 if (KnownSign == std::nullopt ) {
17581752 UseOr = false ;
17591753 UseAndN = false ;
@@ -2614,7 +2608,7 @@ Instruction *InstCombinerImpl::visitCallInst(CallInst &CI) {
26142608 FastMathFlags InnerFlags = cast<FPMathOperator>(Src)->getFastMathFlags ();
26152609
26162610 if ((FMF.allowReassoc () && InnerFlags.allowReassoc ()) ||
2617- signBitMustBeTheSame (Exp, InnerExp, II, DL, &AC, &DT )) {
2611+ signBitMustBeTheSame (Exp, InnerExp, SQ. getWithInstruction (II) )) {
26182612 // TODO: Add nsw/nuw probably safe if integer type exceeds exponent
26192613 // width.
26202614 Value *NewExp = Builder.CreateAdd (InnerExp, Exp);
0 commit comments