@@ -1041,10 +1041,9 @@ 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
+ std::optional<bool > InstCombinerImpl::getKnownSign (Value *Op,
1045
+ Instruction *CxtI) const {
1046
+ KnownBits Known = llvm::computeKnownBits (Op, DL, /* Depth*/ 0 , &AC, CxtI, &DT);
1048
1047
if (Known.isNonNegative ())
1049
1048
return false ;
1050
1049
if (Known.isNegative ())
@@ -1058,13 +1057,10 @@ static std::optional<bool> getKnownSign(Value *Op, Instruction *CxtI,
1058
1057
ICmpInst::ICMP_SLT, Op, Constant::getNullValue (Op->getType ()), CxtI, DL);
1059
1058
}
1060
1059
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))
1060
+ std::optional<bool >
1061
+ InstCombinerImpl::getKnownSignOrZero (Value *Op, Instruction *CxtI) const {
1062
+ if (std::optional<bool > Sign = getKnownSign (Op, CxtI))
1066
1063
return Sign;
1067
-
1068
1064
Value *X, *Y;
1069
1065
if (match (Op, m_NSWSub (m_Value (X), m_Value (Y))))
1070
1066
return isImpliedByDomCondition (ICmpInst::ICMP_SLE, X, Y, CxtI, DL);
@@ -1074,12 +1070,11 @@ static std::optional<bool> getKnownSignOrZero(Value *Op, Instruction *CxtI,
1074
1070
1075
1071
// / Return true if two values \p Op0 and \p Op1 are known to have the same sign.
1076
1072
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);
1073
+ InstCombinerImpl &IC) {
1074
+ std::optional<bool > Known1 = IC.getKnownSign (Op1, CxtI);
1080
1075
if (!Known1)
1081
1076
return false ;
1082
- std::optional<bool > Known0 = getKnownSign (Op0, CxtI, DL, AC, DT );
1077
+ std::optional<bool > Known0 = IC. getKnownSign (Op0, CxtI);
1083
1078
if (!Known0)
1084
1079
return false ;
1085
1080
return *Known0 == *Known1;
@@ -1627,8 +1622,7 @@ Instruction *InstCombinerImpl::visitCallInst(CallInst &CI) {
1627
1622
return replaceOperand (*II, 0 , XY);
1628
1623
}
1629
1624
1630
- if (std::optional<bool > Known =
1631
- getKnownSignOrZero (IIOperand, II, DL, &AC, &DT)) {
1625
+ if (std::optional<bool > Known = getKnownSignOrZero (IIOperand, 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, 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, II, * this )) {
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