[llvm] [ConstraintElimination] Add support for UCMP/SCMP intrinsics (PR #97974)
Antonio Frighetto via llvm-commits
llvm-commits at lists.llvm.org
Wed Jul 10 06:03:59 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)) {
----------------
antoniofrighetto 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?
https://github.com/llvm/llvm-project/pull/97974
More information about the llvm-commits
mailing list