[llvm] [InstCombine] Implement folds of icmp of UCMP/SCMP call and a constant (PR #96118)
Yingwei Zheng via llvm-commits
llvm-commits at lists.llvm.org
Fri Jun 21 09:10:41 PDT 2024
================
@@ -3926,6 +3926,52 @@ foldICmpUSubSatOrUAddSatWithConstant(ICmpInst::Predicate Pred,
ConstantInt::get(Op1->getType(), EquivInt));
}
+static Instruction *
+foldICmpOfCmpIntrinsicWithConstant(ICmpInst::Predicate Pred, IntrinsicInst *I,
+ const APInt &C,
+ InstCombiner::BuilderTy &Builder) {
+ std::optional<ICmpInst::Predicate> NewPredicate = std::nullopt;
+ switch (Pred) {
+ case ICmpInst::ICMP_EQ:
+ case ICmpInst::ICMP_NE:
+ if (C.isZero())
+ NewPredicate = Pred;
+ if (C.isOne())
+ NewPredicate =
+ Pred == ICmpInst::ICMP_EQ ? ICmpInst::ICMP_UGT : ICmpInst::ICMP_ULE;
+ if (C.isAllOnes())
+ NewPredicate =
+ Pred == ICmpInst::ICMP_EQ ? ICmpInst::ICMP_ULT : ICmpInst::ICMP_UGE;
----------------
dtcxzyw wrote:
```suggestion
else if (C.isOne())
NewPredicate =
Pred == ICmpInst::ICMP_EQ ? ICmpInst::ICMP_UGT : ICmpInst::ICMP_ULE;
else if (C.isAllOnes())
NewPredicate =
Pred == ICmpInst::ICMP_EQ ? ICmpInst::ICMP_ULT : ICmpInst::ICMP_UGE;
```
https://github.com/llvm/llvm-project/pull/96118
More information about the llvm-commits
mailing list