[mlir][StandardToSPIRV] Fix signedness issue in bitwidth emulation.
authorHanhan Wang <hanchung@google.com>
Tue, 19 May 2020 17:55:17 +0000 (10:55 -0700)
committerHanhan Wang <hanchung@google.com>
Tue, 19 May 2020 18:00:01 +0000 (11:00 -0700)
commit520a5702680ea0b5059193a0d4ad52c217da7325
treedc9fb49d36b6791869f55d30a53f3bac862945df
parent15ee8a3a58223b48afbe33cb60084f864ef20889
[mlir][StandardToSPIRV] Fix signedness issue in bitwidth emulation.

Summary:
Previously, after applying the mask, a negative number would convert to a
positive number because the sign flag was forgotten. This patch adds two more
shift operations to do the sign extension. This assumes that we're using two's
complement.

This patch applies sign extension unconditionally when loading a unspported integer width, and it relies the pattern to do the casting because the signedness semantic is carried by operator itself.

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