[llvm] [InstructionSimplify] Convert isDivZero to range analysis (PR #100683)

via llvm-commits llvm-commits at lists.llvm.org
Thu Jul 25 19:22:01 PDT 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-llvm-analysis

Author: AtariDreams (AtariDreams)

<details>
<summary>Changes</summary>



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


1 Files Affected:

- (modified) llvm/lib/Analysis/InstructionSimplify.cpp (+6-5) 


``````````diff
diff --git a/llvm/lib/Analysis/InstructionSimplify.cpp b/llvm/lib/Analysis/InstructionSimplify.cpp
index 3a7ae577bb068..bfa03e2a8f8c0 100644
--- a/llvm/lib/Analysis/InstructionSimplify.cpp
+++ b/llvm/lib/Analysis/InstructionSimplify.cpp
@@ -1061,12 +1061,13 @@ static bool isDivZero(Value *X, Value *Y, const SimplifyQuery &Q,
   // IsSigned == false.
 
   // Is the unsigned dividend known to be less than a constant divisor?
-  // TODO: Convert this (and above) to range analysis
-  //      ("computeConstantRangeIncludingKnownBits")?
   const APInt *C;
-  if (match(Y, m_APInt(C)) &&
-      computeKnownBits(X, /* Depth */ 0, Q).getMaxValue().ult(*C))
-    return true;
+  if (match(Y, m_APInt(C))) {
+    ConstantRange XRange =
+        computeConstantRangeIncludingKnownBits(X, /*ForSigned=*/false, Q);
+    if (!XRange.isFullSet() && XRange.icmp(CmpInst::ICMP_ULT, *C))
+      return true;
+  }
 
   // Try again for any divisor:
   // Is the dividend unsigned less than the divisor?

``````````

</details>


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


More information about the llvm-commits mailing list