[llvm] [InstructionSimplify] Convert isDivZero to range analysis (PR #100683)
via llvm-commits
llvm-commits at lists.llvm.org
Thu Jul 25 19:21:31 PDT 2024
https://github.com/AtariDreams created https://github.com/llvm/llvm-project/pull/100683
None
>From 91f5bb8a6fc74f3b673663872c9900a77d07567e Mon Sep 17 00:00:00 2001
From: Rose <gfunni234 at gmail.com>
Date: Thu, 25 Jul 2024 22:18:43 -0400
Subject: [PATCH] [InstructionSimplify] Convert isDivZero to range analysis
---
llvm/lib/Analysis/InstructionSimplify.cpp | 11 ++++++-----
1 file changed, 6 insertions(+), 5 deletions(-)
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?
More information about the llvm-commits
mailing list