[llvm] [ConstraintElimination] Add support for UCMP/SCMP intrinsics (PR #97974)
via llvm-commits
llvm-commits at lists.llvm.org
Wed Jul 10 09:46:16 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)) {
----------------
Poseydon42 wrote:
For the second test case the simplest solution would probably be checking `EQ`/`NE` predicates against both constraint system. I'm not sure about the performace impact though and don't reallly know how to check it.
https://github.com/llvm/llvm-project/pull/97974
More information about the llvm-commits
mailing list