[PATCH] D79644: [mlir][StandardToSPIRV] Add support for lowering index_cast to SPIR-V.

Han-Chung Wang via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon May 11 14:35:29 PDT 2020


hanchung added inline comments.


================
Comment at: mlir/lib/Conversion/StandardToSPIRV/ConvertStandardToSPIRV.cpp:870
       ReturnOpPattern, SelectOpPattern, IntStoreOpPattern, StoreOpPattern,
+      TypeCastingOpPattern<IndexCastOp, spirv::SConvertOp>,
       TypeCastingOpPattern<SIToFPOp, spirv::ConvertSToFOp>,
----------------
antiagainst wrote:
> I think we need to special treat the case where the src/target bitwidth == `SPIRVTypeConverter::getIndexType()` by just removing this op? OpSConvert requires the source and target bitwidth to be different. Casting from  `index` to `i32` will result in an invalid OpSConvert.
I think this case is already handled in TypeCastingOpPattern?

```
    auto dstType =
        this->typeConverter.convertType(operation.getResult().getType());
    if (dstType == operands.front().getType()) {
      // Due to type conversion, we are seeing the same source and target type.
      // Then we can just erase this operation by forwarding its operand.
      rewriter.replaceOp(operation, operands.front());
    } else {
      rewriter.template replaceOpWithNewOp<SPIRVOp>(
          operation, dstType, operands, ArrayRef<NamedAttribute>());
    }
```

The first condition will replace it with operand. Let me add more tests for this case.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D79644/new/

https://reviews.llvm.org/D79644





More information about the llvm-commits mailing list