[llvm] [InstCombine] Fold `(x == y) ? 0 : (x > y ? 1 : -1)` into `ucmp/scmp(x,y)` (PR #107314)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Thu Sep 5 03:17:33 PDT 2024
================
@@ -3575,6 +3573,32 @@ Instruction *InstCombinerImpl::foldSelectToCmp(SelectInst &SI) {
ICmpInst::getSwappedPredicate(ExtendedCmpPredicate) == Pred))
Replace = true;
+ // (x == y) ? 0 : (x > y ? 1 : -1)
+ ICmpInst::Predicate FalseBranchSelectPredicate;
+ ConstantInt *InnerTV, *InnerFV;
+ if (Pred == ICmpInst::ICMP_EQ && match(TV, m_Zero()) &&
+ match(FV, m_Select(m_c_ICmp(FalseBranchSelectPredicate, m_Specific(LHS),
+ m_Specific(RHS)),
+ m_ConstantInt(InnerTV), m_ConstantInt(InnerFV)))) {
----------------
nikic wrote:
m_ConstantInt -> m_APInt. m_ConstantInt doesn't support vectors. Can you please also add a vector test?
https://github.com/llvm/llvm-project/pull/107314
More information about the llvm-commits
mailing list