Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SelectionDAG] Use computeForAddSub to prove that ISD::ADD is not 0 #86453

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

AtariDreams
Copy link
Contributor

No description provided.

@llvmbot llvmbot added the llvm:SelectionDAG SelectionDAGISel as well label Mar 24, 2024
@llvmbot
Copy link
Collaborator

llvmbot commented Mar 24, 2024

@llvm/pr-subscribers-llvm-selectiondag

Author: AtariDreams (AtariDreams)

Changes

Full diff: https://github.com/llvm/llvm-project/pull/86453.diff

1 Files Affected:

  • (modified) llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp (+8-1)
diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
index 0ab5142ab81676..8e79ab9541676b 100644
--- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
@@ -5405,7 +5405,14 @@ bool SelectionDAG::isKnownNeverZero(SDValue Op, unsigned Depth) const {
       if (isKnownNeverZero(Op.getOperand(1), Depth + 1) ||
           isKnownNeverZero(Op.getOperand(0), Depth + 1))
         return true;
-    // TODO: There are a lot more cases we can prove for add.
+    if (KnownBits::computeForAddSub(
+            true, Op->getFlags().hasNoSignedWrap(),
+            Op->getFlags().hasNoUnsignedWrap(),
+            computeKnownBits(Op.getOperand(0), Depth + 1),
+            computeKnownBits(Op.getOperand(1), Depth + 1))
+            .isNonZero())
+      return true;
+    // TODO: Are there more cases we can prove for add not covered by the above?
     break;
 
   case ISD::SUB: {

Copy link

✅ With the latest revision this PR passed the C/C++ code formatter.

Copy link

✅ With the latest revision this PR passed the Python code formatter.

@@ -5405,7 +5405,14 @@ bool SelectionDAG::isKnownNeverZero(SDValue Op, unsigned Depth) const {
if (isKnownNeverZero(Op.getOperand(1), Depth + 1) ||
isKnownNeverZero(Op.getOperand(0), Depth + 1))
return true;
// TODO: There are a lot more cases we can prove for add.
if (KnownBits::computeForAddSub(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't we call computeKnownBits(Op, Depth).isNonZero(); after the switch in this function? That does the same thing as this in a more general way.

@RKSimon RKSimon self-requested a review March 25, 2024 11:40
@RKSimon
Copy link
Collaborator

RKSimon commented Mar 25, 2024

@AtariDreams Its great that you're working through the (far too many.......) TODOs in the codebase, but you have to begin with creating tests that show the missing functionality, not just add code and hope it gets tested.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
llvm:SelectionDAG SelectionDAGISel as well
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants