[llvm] [ConstraintElimination] Add support for UCMP/SCMP intrinsics (PR #97974)
Florian Hahn via llvm-commits
llvm-commits at lists.llvm.org
Tue Jul 9 11:40:29 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)) {
----------------
fhahn wrote:
Unfortunately I don't have much spare cycles at the moment, but it should be a straight-forward extension. There are a number of cases where signed reasoning could be improved further :)
https://github.com/llvm/llvm-project/pull/97974
More information about the llvm-commits
mailing list