[llvm] [llvm][InstCombine] Fold signum(x) into scmp(x, 0) (PR #143445)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Fri Jun 13 01:58:33 PDT 2025
================
@@ -3572,6 +3572,28 @@ Instruction *InstCombinerImpl::foldSelectToCmp(SelectInst &SI) {
if (!LHS->getType()->isIntOrIntVectorTy())
return nullptr;
+ // If there is no -1, 0 or 1 at TV, then invert the select statement and try
+ // to canonicalize to one of the forms above
+ if (!match(TV, m_AllOnes()) && !match(TV, m_One()) && !match(TV, m_Zero())) {
+ if (!match(FV, m_AllOnes()) && !match(FV, m_One()) && !match(FV, m_Zero()))
+ return nullptr;
+ Pred = ICmpInst::getInverseCmpPredicate(Pred);
+ std::swap(TV, FV);
+ }
+
+ if (ICmpInst::isGE(Pred) || ICmpInst::isLE(Pred)) {
+ if (ConstantInt *C = dyn_cast<ConstantInt>(RHS)) {
----------------
nikic wrote:
Should check for Constant instead of ConstantInt here. getFlippedStrictnessPredicateAndConstant also supports vectors. (And on that note, we should have a vector test for this.)
https://github.com/llvm/llvm-project/pull/143445
More information about the llvm-commits
mailing list