[Mlir-commits] [mlir] [mlir] fix IntegerRangeAnalysis::staticallyNonNegative (PR #134003)

Maksim Levental llvmlistbot at llvm.org
Tue Apr 1 16:11:44 PDT 2025


https://github.com/makslevental created https://github.com/llvm/llvm-project/pull/134003

After https://github.com/llvm/llvm-project/pull/133541, `ConstantIntRanges` can sometimes have 0-bitwidth APInt. This leads to 

```
llvm/include/llvm/ADT/APInt.h:1044: bool llvm::APInt::operator[](unsigned int) const: Assertion `bitPosition < getBitWidth() && "Bit position out of bounds!"' failed.
```

somewhere around here. This isn't a great fix (basically a band-aid) but I'm putting it up so we can centralize discussion of how to actually fix - possibly we might first revert https://github.com/llvm/llvm-project/pull/133541? Not sure.

>From 16ccba009df34c308cba86956064ffb8fb063080 Mon Sep 17 00:00:00 2001
From: Maksim Levental <maksim.levental at gmail.com>
Date: Tue, 1 Apr 2025 19:09:30 -0400
Subject: [PATCH] [mlir] fix IntegerRangeAnalysis::staticallyNonNegative

---
 mlir/lib/Analysis/DataFlow/IntegerRangeAnalysis.cpp | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/mlir/lib/Analysis/DataFlow/IntegerRangeAnalysis.cpp b/mlir/lib/Analysis/DataFlow/IntegerRangeAnalysis.cpp
index c7a950d9a8871..6cbd83c8652e6 100644
--- a/mlir/lib/Analysis/DataFlow/IntegerRangeAnalysis.cpp
+++ b/mlir/lib/Analysis/DataFlow/IntegerRangeAnalysis.cpp
@@ -43,6 +43,9 @@ LogicalResult staticallyNonNegative(DataFlowSolver &solver, Value v) {
   if (!result || result->getValue().isUninitialized())
     return failure();
   const ConstantIntRanges &range = result->getValue().getValue();
+  if (range.umin().getBitWidth() || range.umax().getBitWidth() ||
+      range.smin().getBitWidth() || range.smax().getBitWidth())
+    return false;
   return success(range.smin().isNonNegative());
 }
 



More information about the Mlir-commits mailing list