iree: [Integrate] Upstream narrow type emulation is breaking iree test
What happened?
https://github.com/llvm/llvm-project/pull/133231 seems to be breaking our subbyte emulation tests.
A simple repro is https://gist.github.com/raikonenfnu/1ea07b7e231d8997bfa1c29502df637d
original test https://github.com/iree-org/iree/blob/1a8d229431e62b50eb297e75ca4bf1dba3b67f65/tests/e2e/linalg/fp_to_subbyte.mlir
Based on the above test, currently IREE is generating code that has different trailing dim and “virtually”/fake non constant offset into the store vector.store %0[%2] where %2 is actually a constant, but since it is inside a branch region, %c0 becomes %2 which is a region argument and is now a non-constant.
The condition above leads our program into this code path where it cannot determine !foldedNumFrontPadElems and fails this lowering. as seen in:
https://github.com/llvm/llvm-project/blob/2de936b6eb38e7a37224a97c2a22aa79b9dfb9dc/mlir/lib/Dialect/Vector/Transforms/VectorEmulateNarrowType.cpp#L619-L629
IIUC, that PR is somewhat correct, as long as the trailing dim does not match, we may need partial stores.
I don’t think I have enough context on the best way to solve this. We can:
- Fold away that region since the condition to the regions are constants or somehow constant fold S.T we have constant offset in vector.store
- Add some code in vector dialect’s EmulateNarrowType vector::StoreOp conversion to handle non constant cases through series of bitcasting and memref.generic_atomic_rmws. (this seems much harder and require some more thinking)
Steps to reproduce your issue
-
iree-opt --iree-codegen-emulate-narrow-type emulate_failure.mlir -o out.mlir
emulate.mlir:18:3: error: failed to legalize operation ‘vector.store’ that was explicitly marked illegal
What component(s) does this issue relate to?
No response
Version information
No response
Additional context
No response
About this issue
- Original URL
- State: open
- Created 2 years ago
- Comments: 16 (13 by maintainers)
Commits related to this issue
- Integrate llvm/llvm-project@1c8e5e2 Updated LIT test from landing llvm/llvm-project#136640 which folds linalg.index when size is unit dim (1). This patch carries revert of llvm/llvm-project#133231.... — committed to raikonenfnu/iree by raikonenfnu 2 years ago
- Integrate llvm/llvm-project@1c8e5e2 (#20646) Updated LIT test from landing llvm/llvm-project#136640 which folds linalg.index when size is unit dim (1). Added chipSet argument into populateGpuToROCDL... — committed to iree-org/iree by raikonenfnu 2 years ago
- Integrate llvm/llvm-project@5953f19 (#20657) This patch carries 4 reverts from https://github.com/iree-org/iree/pull/20646: llvm/llvm-project#133231. This PR breaks fp_to_subbytes and emulation_su... — committed to iree-org/iree by IanWood1 2 years ago
- Integrate llvm/llvm-project@7b70fc7 (#20674) Carries the same 4 reverts as https://github.com/iree-org/iree/pull/20657: - llvm/llvm-project#133231. This PR breaks fp_to_subbytes and emulation_subbyt... — committed to iree-org/iree by IanWood1 2 years ago
- Integrate llvm/llvm-project@1c8e5e2 (#20646) Updated LIT test from landing llvm/llvm-project#136640 which folds linalg.index when size is unit dim (1). Added chipSet argument into populateGpuToROCDL... — committed to KyleHerndon/iree by raikonenfnu 2 years ago
- Integrate llvm/llvm-project@5953f19 (#20657) This patch carries 4 reverts from https://github.com/iree-org/iree/pull/20646: llvm/llvm-project#133231. This PR breaks fp_to_subbytes and emulation_su... — committed to KyleHerndon/iree by IanWood1 2 years ago
- Integrate llvm/llvm-project@7b70fc7 (#20674) Carries the same 4 reverts as https://github.com/iree-org/iree/pull/20657: - llvm/llvm-project#133231. This PR breaks fp_to_subbytes and emulation_subbyt... — committed to KyleHerndon/iree by IanWood1 2 years ago
- [Integrate] Mirror and prioritize the old ConvertVectorStore pattern. (#20981) It mirrors the old upstream pattern to IREE, and drops the revert. Ideally, we should have a better control in upstream ... — committed to iree-org/iree by hanhanW a year ago
I’d prefer not using this approach atm, because we can get all the needed information from IR. I can be convinced if there are other use cases.
I’m not sure how integrate range analysis works with upstream patterns. It seems like the analysis should only be run once because of efficiency. Then we collect the ops and apply the transform. Also, the analysis is only available in IREE, so I’m not sure how they can be connected.
Anyway, I think we have a solid plan, and we can fix it if someone pick this up.
yeah, especially for stuff like this I just assume (hah) upstream doesn’t support what we need in conjunction with our better type support and assume ops.
really good detective work on this - very tricky interactions!
So, I think what should be done there is that the slow path should be guarded by a runtime condition as in https://github.com/llvm/llvm-project/pull/135014
But, in addition, the narrow type emulation should be moved before scf-to-cf - heck, before OptimizeIntArithmetic - so that we can take advantage of divisibility analysis