Upstream unrolling patterns + canonicalization
-
Vectorizing
tensor.pad
- Apply vectorization to generate vectors of the original tensor shape for
tensor.pad
ops. - https://github.com/iree-org/iree/blob/main/compiler/src/iree/compiler/Codegen/SPIRV/SPIRVInitialVectorLowering.cpp#L306
- Apply vectorization to generate vectors of the original tensor shape for
-
Peephole optimizations
- Shuffle broadcast/transpose ops to cancel them or embed into contract ops.
- https://github.com/iree-org/iree/blob/main/compiler/src/iree/compiler/Codegen/SPIRV/SPIRVInitialVectorLowering.cpp#L318
-
Trimming contract leading unit dims
- Drop the leading unit batch dimension for 1-D convolution ops
- https://github.com/iree-org/iree/blob/main/compiler/src/iree/compiler/Codegen/SPIRV/SPIRVInitialVectorLowering.cpp#L342
-
Folding tensor extract/insert slice ops
- Fold
tensor.extract_slice
andtensor.insert_slice
ops into transfer ops - https://github.com/iree-org/iree/blob/main/compiler/src/iree/compiler/Codegen/SPIRV/SPIRVInitialVectorLowering.cpp#L362
- Fold
-
Lowering multi reduction ops
- Lower
vector.multi_dimension
early if any operand is a transpose op. The lowering itself generates transpose ops. - https://github.com/iree-org/iree/blob/main/compiler/src/iree/compiler/Codegen/SPIRV/SPIRVInitialVectorLowering.cpp#L381
- Lower
-
Preparing for SPIR-V dot product lowering
-
Unrolling vector ops
- Unroll vectors to native vector size
- https://github.com/iree-org/iree/blob/main/compiler/src/iree/compiler/Codegen/SPIRV/SPIRVInitialVectorLowering.cpp#L414
-
Lowering size-1 reduction contract ops
-
Lowering transpose ops
- Lower vector transpose by converting them into extract and insert pairs, in preparation of futher transformations to canonicalize/cancel
- https://github.com/iree-org/iree/blob/main/compiler/src/iree/compiler/Codegen/SPIRV/SPIRVInitialVectorLowering.cpp#L450
-
Trimming leading unit dims
- Run canonicalization to cast away leading size-1 dimensions which can be generated from vector unrolling
- https://github.com/iree-org/iree/blob/main/compiler/src/iree/compiler/Codegen/SPIRV/SPIRVInitialVectorLowering.cpp#L450
-
Lowering to SPIR-V dot product
- Lower vector reduction to SPIR-V integer dot product
- https://github.com/iree-org/iree/blob/main/compiler/src/iree/compiler/Codegen/SPIRV/SPIRVInitialVectorLowering.cpp#L501
-
Breaking down loop carried variables
- Convert
scf.for
loop-carried values < 128 total bits, but more than 4 elements - E.g. insert
vector.bitcast
ops to castvector<8xf16>
tovector<4xf32>
- The loop-carried values will be lowered into SPIR-V local variables
- This pattern allows packing i4/i8/f16 values into i32 variables tightly so that we can generate shader conformant SPIR-V
- https://github.com/iree-org/iree/blob/7e06b6e5ece2adcda91352331db817adaa058e85/compiler/src/iree/compiler/Codegen/Common/ForOpCanonicalizationPass.cpp#L186
- Convert
-
Breaking down other large vectors
- Convert
vector.extract_strided_slice
into a chain ofvector.extract
and then a chain ofvector.insert
ops - Helps to cancel with previous
vector.extract
andvector.insert
ops - https://github.com/iree-org/iree/blob/main/compiler/src/iree/compiler/Codegen/SPIRV/SPIRVBreakDownLargeVector.cpp#L138
- Convert
-
Convert to
memref<vector>
+ bitcasts to get 128 bit read/store width on < 32 bit data types