[Mlir-commits] [mlir] [IntegerRangeAnalysis] remove constraint on integer-typed results (PR #72007)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Fri Nov 10 16:50:56 PST 2023


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-mlir

Author: Jeremy Kun (j2kun)

<details>
<summary>Changes</summary>

I have an out-of-tree situation in which I'd like to run this analysis, but with custom types and integer ranges attached to types that are not classical integers. No upstream tests depend on this condition, and so relaxing it seems like a natural way to make it more useful out of tree.

I'm open to making any additional changes if the reviewer foresees some unexpected problems as a result of this change. E.g., if having this analysis available in an IR with mixed arith/non-arith ops would cause a pass like `IntRangeOptimizationsPass` to misbehave, but I imagine it would not because the patterns match against specific arith ops.

I can add a regression test if there's a strong desire, but I feel the chance of this regressing is relatively low compared to the effort to write the test.

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


2 Files Affected:

- (modified) mlir/include/mlir/Analysis/DataFlow/IntegerRangeAnalysis.h (+7-1) 
- (modified) mlir/lib/Analysis/DataFlow/IntegerRangeAnalysis.cpp (-16) 


``````````diff
diff --git a/mlir/include/mlir/Analysis/DataFlow/IntegerRangeAnalysis.h b/mlir/include/mlir/Analysis/DataFlow/IntegerRangeAnalysis.h
index 99f620ed26a1b4b..8bd7cf880c6afb5 100644
--- a/mlir/include/mlir/Analysis/DataFlow/IntegerRangeAnalysis.h
+++ b/mlir/include/mlir/Analysis/DataFlow/IntegerRangeAnalysis.h
@@ -8,7 +8,10 @@
 //
 // This file declares the dataflow analysis class for integer range inference
 // so that it can be used in transformations over the `arith` dialect such as
-// branch elimination or signed->unsigned rewriting
+// branch elimination or signed->unsigned rewriting.
+//
+// One can also implement InferIntRangeInterface on ops in custom dialects,
+// and then use this analysis to propagate ranges with custom semantics.
 //
 //===----------------------------------------------------------------------===//
 
@@ -81,6 +84,9 @@ class IntegerValueRangeLattice : public Lattice<IntegerValueRange> {
 /// Integer range analysis determines the integer value range of SSA values
 /// using operations that define `InferIntRangeInterface` and also sets the
 /// range of iteration indices of loops with known bounds.
+///
+/// This analysis depends on DeadCodeAnalysis, and will be a silent no-op
+/// if DeadCodeAnalysis is not loaded in the same solver context.
 class IntegerRangeAnalysis
     : public SparseForwardDataFlowAnalysis<IntegerValueRangeLattice> {
 public:
diff --git a/mlir/lib/Analysis/DataFlow/IntegerRangeAnalysis.cpp b/mlir/lib/Analysis/DataFlow/IntegerRangeAnalysis.cpp
index a43263bc11113b8..39b3a0996396ffb 100644
--- a/mlir/lib/Analysis/DataFlow/IntegerRangeAnalysis.cpp
+++ b/mlir/lib/Analysis/DataFlow/IntegerRangeAnalysis.cpp
@@ -79,22 +79,6 @@ void IntegerRangeAnalysis::visitOperation(
     return;
   }
 
-  // Ignore non-integer outputs - return early if the op has no scalar
-  // integer results
-  bool hasIntegerResult = false;
-  for (auto it : llvm::zip(results, op->getResults())) {
-    Value value = std::get<1>(it);
-    if (value.getType().isIntOrIndex()) {
-      hasIntegerResult = true;
-    } else {
-      IntegerValueRangeLattice *lattice = std::get<0>(it);
-      propagateIfChanged(lattice,
-                         lattice->join(IntegerValueRange::getMaxRange(value)));
-    }
-  }
-  if (!hasIntegerResult)
-    return;
-
   auto inferrable = dyn_cast<InferIntRangeInterface>(op);
   if (!inferrable)
     return setAllToEntryStates(results);

``````````

</details>


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


More information about the Mlir-commits mailing list