@@ -27,32 +27,6 @@ using namespace mlir;
2727using namespace mlir ::arith;
2828using namespace mlir ::dataflow;
2929
30- // / Succeeds when a value is statically non-negative in that it has a lower
31- // / bound on its value (if it is treated as signed) and that bound is
32- // / non-negative.
33- // TODO: IntegerRangeAnalysis internally assumes index is 64bit and this pattern
34- // relies on this. These transformations may not be valid for 32bit index,
35- // need more investigation.
36- static LogicalResult staticallyNonNegative (DataFlowSolver &solver, Value v) {
37- auto *result = solver.lookupState <IntegerValueRangeLattice>(v);
38- if (!result || result->getValue ().isUninitialized ())
39- return failure ();
40- const ConstantIntRanges &range = result->getValue ().getValue ();
41- return success (range.smin ().isNonNegative ());
42- }
43-
44- // / Succeeds if an op can be converted to its unsigned equivalent without
45- // / changing its semantics. This is the case when none of its openands or
46- // / results can be below 0 when analyzed from a signed perspective.
47- static LogicalResult staticallyNonNegative (DataFlowSolver &solver,
48- Operation *op) {
49- auto nonNegativePred = [&solver](Value v) -> bool {
50- return succeeded (staticallyNonNegative (solver, v));
51- };
52- return success (llvm::all_of (op->getOperands (), nonNegativePred) &&
53- llvm::all_of (op->getResults (), nonNegativePred));
54- }
55-
5630// / Succeeds when the comparison predicate is a signed operation and all the
5731// / operands are non-negative, indicating that the cmpi operation `op` can have
5832// / its predicate changed to an unsigned equivalent.
@@ -103,6 +77,10 @@ class DataFlowListener : public RewriterBase::Listener {
10377 DataFlowSolver &s;
10478};
10579
80+ // TODO: IntegerRangeAnalysis internally assumes index is 64bit and this pattern
81+ // (via staticallyNonNegative) relies on this. These transformations may not be
82+ // valid for 32bit index, need more investigation.
83+
10684template <typename Signed, typename Unsigned>
10785struct ConvertOpToUnsigned final : OpRewritePattern<Signed> {
10886 ConvertOpToUnsigned (MLIRContext *context, DataFlowSolver &s)
0 commit comments