[Mlir-commits] [mlir] [MLIR] Let matchers work on int ranges (PR #102494)

Tobias Gysi llvmlistbot at llvm.org
Fri Aug 9 07:16:17 PDT 2024


================
@@ -385,6 +446,13 @@ inline detail::constant_int_predicate_matcher m_NonZero() {
   return {[](const APInt &value) { return 0 != value; }};
 }
 
+/// Matches a constant scalar / vector splat / tensor splat integer or a
+/// unsigned integer range that does not contain zero. Note that this matcher
+/// interprets the target value as an unsigned integer.
+inline detail::constant_int_range_predicate_matcher m_NonZeroU() {
+  return {[](const ConstantIntRanges &range) { return range.umin().ugt(0); }};
----------------
gysit wrote:

In the case of matching a constant operation or an attribute the overhead is limited to calling:
1) `ConstantIntRanges::constant(value)`
2) `range.umin().ugt(0) `
That should be a very limited constant overhead. 

If we happen to call the interface, which for the divisions is probably the common case, the overhead is still constant but we do a bit more work than today. E.g. we have to construct an `IntegerValueRange` for every operand of the matched operation and actually execute the `inferResultRange` function. 

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


More information about the Mlir-commits mailing list