[llvm] [ConstraintElimination] Add support for UCMP/SCMP intrinsics (PR #97974)
Yingwei Zheng via llvm-commits
llvm-commits at lists.llvm.org
Thu Jul 11 10:57:27 PDT 2024
================
@@ -1434,6 +1436,33 @@ static bool checkAndReplaceMinMax(MinMaxIntrinsic *MinMax, ConstraintInfo &Info,
return false;
}
+static bool checkAndReplaceCmp(IntrinsicInst *II, ConstraintInfo &Info,
+ SmallVectorImpl<Instruction *> &ToRemove) {
+ bool IsSigned = II->getIntrinsicID() == Intrinsic::scmp;
+ Value *LHS = II->getOperand(0);
+ Value *RHS = II->getOperand(1);
+ if (checkCondition(IsSigned ? ICmpInst::ICMP_SGT : ICmpInst::ICMP_UGT, LHS,
+ RHS, II, Info)
+ .value_or(false)) {
+ II->replaceAllUsesWith(ConstantInt::get(II->getType(), 1));
+ ToRemove.push_back(II);
+ return true;
+ }
+ if (checkCondition(IsSigned ? ICmpInst::ICMP_SLT : ICmpInst::ICMP_ULT, LHS,
+ RHS, II, Info)
+ .value_or(false)) {
+ II->replaceAllUsesWith(ConstantInt::getSigned(II->getType(), -1));
+ ToRemove.push_back(II);
+ return true;
+ }
+ if (checkCondition(ICmpInst::ICMP_EQ, LHS, RHS, II, Info).value_or(false)) {
----------------
dtcxzyw wrote:
> I think that, for the first example, it could suffice to check whether the equality holds and change the predicate to unsigned. Compile-time does not look good though: https://llvm-compile-time-tracker.com/compare.php?from=7911fb1a257b3a7014b44b4e7d04ee5c3b73a3e3&to=612eaf91c85d5e4c6e3fdddd46ebe6a41d19dfcb&stat=instructions:u. Perhaps there's a better way to achieve this?
`doesHold(CmpInst::ICMP_EQ, Op0, Op1)` will build another constraint system to solve. It's no surprise that the optimization slows down when you do this.
It would be better to add eq constraint into the signed system in `ConstraintInfo::addFact`.
Sorry about the misleading emoji :)
https://github.com/llvm/llvm-project/pull/97974
More information about the llvm-commits
mailing list