[mlir][StandardToSPIRV] Use spv.UMod for index re-calculation
authorLei Zhang <antiagainst@google.com>
Mon, 13 Jul 2020 20:20:59 +0000 (16:20 -0400)
committerLei Zhang <antiagainst@google.com>
Wed, 5 Aug 2020 18:52:04 +0000 (14:52 -0400)
commit0d03b3901d38484683cd9d6d0d6382967599e92b
tree539d29fd7c0a1e73e556973dbc29d1e706e34482
parentf3056dcc02d5dcde1669f61084a940e1ded3dfda
[mlir][StandardToSPIRV] Use spv.UMod for index re-calculation

Per Vulkan's SPIR-V environment spec: "While the OpSRem and OpSMod
instructions are supported by the Vulkan environment, they require
non-negative values and thus do not enable additional functionality
beyond what OpUMod provides."

The `getOffsetForBitwidth` function is used for lowering std.load
and std.store, whose indices are of `index` type and cannot be
negative. So we should be okay to use spv.UMod directly here to
be exact. Also made the comment explicit about the assumption.

Differential Revision: https://reviews.llvm.org/D83714
mlir/lib/Conversion/StandardToSPIRV/ConvertStandardToSPIRV.cpp
mlir/test/Conversion/StandardToSPIRV/std-ops-to-spirv.mlir