This is an archive of the discontinued LLVM Phabricator instance.

[MLIR][SPIRVToLLVM] Implemented shift conversion pattern
ClosedPublic

Authored by georgemitenkov on Jun 10 2020, 2:49 AM.

Details

Summary

This patch has shift ops conversion implementation. In SPIR-V dialect, Shift and Base may have different bit width. On the contrary, in LLVM dialect both Base and Shift have to be of the same bit width. This leads to the following cases:

  • if Base has the same bit width as Shift, the conversion is straightforward.
  • if Base has a greater bit width than Shift, shift is sign/zero extended first. Then the extended value is passed to the shift.
  • otherwise the conversion is considered to be illegal.

The case when Base has a greater bit width than Shift is not very common, but I think it should be handled for consistency with SPIR-V spec?

Diff Detail

Event Timeline

georgemitenkov created this revision.Jun 10 2020, 2:49 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 10 2020, 2:49 AM
ftynse accepted this revision.Jun 11 2020, 1:39 AM

LGTM after comments are addressed

mlir/lib/Conversion/SPIRVToLLVM/ConvertSPIRVToLLVM.cpp
130

This can return success(); immediately, so there's no need to have a long "else" block.

131

I don't know the SPIRV dialect well enough, does it guarantee that the destination type and the type of the first operand are the same (then it's sufficient to only cast the second operand to the destination type) ?

134

Please avoid trivial braces in MLIR in general

This revision is now accepted and ready to land.Jun 11 2020, 1:39 AM
georgemitenkov marked 4 inline comments as done.
  • [MLIR][SPIRVToLLVM] Restyled if blocks in the code
  • [MLIR][SPIRVToLLVM] Refactored the code to follow clang style

Rebased against master. Removed long else block, adding a return success() in equla types branch. Kept the same structure for if-else block since ternary operator couldn't be applied.

antiagainst accepted this revision.Jun 12 2020, 4:03 PM

Awesome!

This revision was automatically updated to reflect the committed changes.