@@ -1041,45 +1041,39 @@ Instruction *InstCombinerImpl::foldIntrinsicIsFPClass(IntrinsicInst &II) {
1041
1041
return nullptr ;
1042
1042
}
1043
1043
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);
1048
1046
if (Known.isNonNegative ())
1049
1047
return false ;
1050
1048
if (Known.isNegative ())
1051
1049
return true ;
1052
1050
1053
1051
Value *X, *Y;
1054
1052
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 );
1056
1054
1057
- return isImpliedByDomCondition (
1058
- ICmpInst::ICMP_SLT, Op, Constant::getNullValue (Op->getType ()), CxtI, DL);
1055
+ return std::nullopt;
1059
1056
}
1060
1057
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))
1066
1061
return Sign;
1067
1062
1068
1063
Value *X, *Y;
1069
1064
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 );
1071
1066
1072
1067
return std::nullopt;
1073
1068
}
1074
1069
1075
1070
// / 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);
1080
1074
if (!Known1)
1081
1075
return false ;
1082
- std::optional<bool > Known0 = getKnownSign (Op0, CxtI, DL, AC, DT );
1076
+ std::optional<bool > Known0 = getKnownSign (Op0, SQ );
1083
1077
if (!Known0)
1084
1078
return false ;
1085
1079
return *Known0 == *Known1;
@@ -1628,7 +1622,7 @@ Instruction *InstCombinerImpl::visitCallInst(CallInst &CI) {
1628
1622
}
1629
1623
1630
1624
if (std::optional<bool > Known =
1631
- getKnownSignOrZero (IIOperand, II, DL, &AC, &DT )) {
1625
+ getKnownSignOrZero (IIOperand, SQ. getWithInstruction (II) )) {
1632
1626
// abs(x) -> x if x >= 0 (include abs(x-y) --> x - y where x >= y)
1633
1627
// abs(x) -> x if x > 0 (include abs(x-y) --> x - y where x > y)
1634
1628
if (!*Known)
@@ -1753,7 +1747,7 @@ Instruction *InstCombinerImpl::visitCallInst(CallInst &CI) {
1753
1747
bool UseAndN = IID == Intrinsic::smin || IID == Intrinsic::umin;
1754
1748
1755
1749
if (IID == Intrinsic::smax || IID == Intrinsic::smin) {
1756
- auto KnownSign = getKnownSign (X, II, DL, &AC, &DT );
1750
+ auto KnownSign = getKnownSign (X, SQ. getWithInstruction (II) );
1757
1751
if (KnownSign == std::nullopt) {
1758
1752
UseOr = false ;
1759
1753
UseAndN = false ;
@@ -2614,7 +2608,7 @@ Instruction *InstCombinerImpl::visitCallInst(CallInst &CI) {
2614
2608
FastMathFlags InnerFlags = cast<FPMathOperator>(Src)->getFastMathFlags ();
2615
2609
2616
2610
if ((FMF.allowReassoc () && InnerFlags.allowReassoc ()) ||
2617
- signBitMustBeTheSame (Exp, InnerExp, II, DL, &AC, &DT )) {
2611
+ signBitMustBeTheSame (Exp, InnerExp, SQ. getWithInstruction (II) )) {
2618
2612
// TODO: Add nsw/nuw probably safe if integer type exceeds exponent
2619
2613
// width.
2620
2614
Value *NewExp = Builder.CreateAdd (InnerExp, Exp);
0 commit comments