[llvm] [llvm][InstCombine] Fold signum(x) into scmp(x, 0) (PR #143445)

Yash Solanki via llvm-commits llvm-commits at lists.llvm.org
Wed Jun 11 10:06:21 PDT 2025


================
@@ -3603,6 +3603,18 @@ Instruction *InstCombinerImpl::foldSelectToCmp(SelectInst &SI) {
        ICmpInst::getSwappedPredicate(ExtendedCmpPredicate) == Pred))
     Replace = true;
 
+  // Handle the edge case (x > -1) ? zext(x != 0), -1
+  if (IsSigned && ICmpInst::isGT(Pred) && match(FV, m_AllOnes()) &&
----------------
yashnator wrote:

Thanks for the report! I missed it, my bad. I handled more general inequalities and added this as a test case. It should work now.

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


More information about the llvm-commits mailing list