[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())) {
----------------
nikic wrote:

For simplicity, just check `!isa<Constant>` here? We'll check the exact value later, but initially just getting the constant on the LHS should be enough...

https://github.com/llvm/llvm-project/pull/143445


More information about the llvm-commits mailing list