llvm-project
ba0fef9f - [MLIR] Add `IntegerDivisibilityAnalysis` and `InferIntDivisibilityOpInterface` (#197728)

Commit
192 days ago
[MLIR] Add `IntegerDivisibilityAnalysis` and `InferIntDivisibilityOpInterface` (#197728) This patch is a port from https://github.com/iree-org/iree/blob/main/compiler/src/iree/compiler/Dialect/Util/Analysis/IntegerDivisibilityAnalysis.cpp to upstream It introduces a dataflow analysis that tracks integer divisibility (divisor + remainder lattice) for SSA values, plus an op interface `InferIntDivisibilityOpInterface` for ops to participate. It adds: * `IntegerDivisibilityAnalysis` produces a `Divisibility` lattice `{divisor, remainder}` * `InferIntDivisibilityOpInterface` interface * External-model implementations for `arith` and `affine` ops * `test-int-divisibility` test pass + lit tests Example: Here is the usual approach to laod element `i` from `i4` buffer emulated in `i8` buffer: ```mlir %byte_idx = arith.divui %i, %c2 : index %bit_off = arith.remui %i, %c2 : index %byte = memref.load %buf[%byte_idx] : memref<?xi8> %shifted = arith.shrui %byte, %bit_off_as_i8 %nibble = arith.andi %shifted, %c0xF : i8 ``` If `i` comes from `affine.apply (d0) -> (d0 * 8 + 0)` over loop IV, analysis derives `divisor=8, remainder=0` for `%i`. Then we can emit more concise code by avoiding the shift. There are more scenarios that could benefit from this analysis.
Author
Parents
Loading