[Mlir-commits] [mlir] [mlir] IntegerRangeAnalysis: add support for vector type (PR #112292)

Ivan Butygin llvmlistbot at llvm.org
Tue Oct 15 09:20:21 PDT 2024


Hardcode84 wrote:

> > The end goal of these changes is to be able to optimize vectorized index calculations.
> 
> Would you mind sharing a bit more? I'm intrigued. And in particular, how does this compare to ValueBoundsAnalysis?

`IntegerRangeAnalysis` propagates integer range info through the program using dataflow framework.

`ValueBoundsOpInterface` was added much later IIRC, and currently completely isolated from `IntegerRangeAnalysis`.
Ideally, they should be unified at some point, but it's out of scope currently.

In my specific use case, I have code like this:
```
          %178 = arith.muli %arg3, %c32 : index
          %179 = arith.addi %178, %8 : index
          %180 = vector.splat %179 : vector<8xindex>
          %181 = arith.addi %180, %cst_8 : vector<8xindex>
          %182 = arith.remsi %181, %cst_7 : vector<8xindex>
          %183 = arith.muli %182, %cst_6 : vector<8xindex>
          %184 = arith.remsi %181, %cst_5 : vector<8xindex>
          %185 = arith.divsi %184, %cst_7 : vector<8xindex>
          %186 = arith.muli %185, %cst_4 : vector<8xindex>
          %187 = arith.muli %arg3, %c288 : index
          %188 = arith.addi %187, %19 : index
          %189 = arith.muli %188, %c9 : index
          %190 = vector.splat %189 : vector<8xindex>
          %191 = arith.addi %190, %cst_3 : vector<8xindex>
          %192 = arith.divsi %191, %cst_2 : vector<8xindex>
          %193 = arith.addi %192, %20 : vector<8xindex>
          %194 = arith.addi %193, %21 : vector<8xindex>
          %195 = arith.addi %194, %186 : vector<8xindex>
          %196 = arith.addi %195, %183 : vector<8xindex>
          %197 = arith.addi %196, %22 : vector<8xindex>
          %198 = vector.gather %0[%c0, %c0, %c0, %c0] [%197], %23, %cst_1 : memref<2x66x66x640xf16, strided<[2787840, 42240, 640, 1], offset: ?>>, vector<8xindex>, vector<8xi1>, vector<8xf16> into vector<8xf16>
```
And a lot of these index calculations can be potentially truncated to `i32` using `IntegerRangeAnalysis`.

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


More information about the Mlir-commits mailing list