[llvm] [SelectionDAG] Remove redundant KnownBits smin and smax operations (PR #89519)

via llvm-commits llvm-commits at lists.llvm.org
Sat Apr 20 16:11:46 PDT 2024


https://github.com/AtariDreams updated https://github.com/llvm/llvm-project/pull/89519

>From d80ab75cd7ff8de1fb26c4ad0121d86cae7d8976 Mon Sep 17 00:00:00 2001
From: Rose <gfunni234 at gmail.com>
Date: Sat, 20 Apr 2024 19:10:26 -0400
Subject: [PATCH] [SelectionDAG] Remove redundant KnownBits smin and smax
 operations

It turns out that if any of the operations can be zero, and neither of the operands can be proven to be positive, it is possible for smax to be zero, and KnownBits cannot prove otherwise even with KnownBits::smax. In fact, proving it based on the KnownBits itself at that point without increasing the depth is actually, provably impossible.

Same with smin.

This covers all the possible cases and is proven to be complete.
---
 llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp | 6 ------
 1 file changed, 6 deletions(-)

diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
index 7dbf83b7adeef0..b63b8b893fdbf1 100644
--- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
@@ -5399,9 +5399,6 @@ bool SelectionDAG::isKnownNeverZero(SDValue Op, unsigned Depth) const {
     if (Op1.isNonZero() && Op0.isNonZero())
       return true;
 
-    if (KnownBits::smax(Op0, Op1).isNonZero())
-      return true;
-
     return isKnownNeverZero(Op.getOperand(1), Depth + 1) &&
            isKnownNeverZero(Op.getOperand(0), Depth + 1);
   }
@@ -5417,9 +5414,6 @@ bool SelectionDAG::isKnownNeverZero(SDValue Op, unsigned Depth) const {
     if (Op1.isNonZero() && Op0.isNonZero())
       return true;
 
-    if (KnownBits::smin(Op0, Op1).isNonZero())
-      return true;
-
     return isKnownNeverZero(Op.getOperand(1), Depth + 1) &&
            isKnownNeverZero(Op.getOperand(0), Depth + 1);
   }



More information about the llvm-commits mailing list