This is an archive of the discontinued LLVM Phabricator instance.

[mlir][spirv] Fix integer type emulation with extension/truncation
ClosedPublic

Authored by antiagainst on Aug 12 2023, 9:57 AM.

Details

Summary

For integer extension or truncation with type emulation, we need
to make sure we perform masking or shifting to discard unwanted
bits to avoid pollute consumer ops.

Diff Detail

Event Timeline

antiagainst created this revision.Aug 12 2023, 9:57 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 12 2023, 9:57 AM
antiagainst requested review of this revision.Aug 12 2023, 9:57 AM
kuhar added inline comments.Aug 12 2023, 12:30 PM
mlir/lib/Conversion/ArithToSPIRV/ArithToSPIRV.cpp
113–114

nit: I implemented a similar helper in wide int emulation: https://github.com/llvm/llvm-project/blob/da56750f82a60b5872679424fc6ae78a42c786a0/mlir/lib/Dialect/Arith/Transforms/EmulateWideInt.cpp#L62-L74.

I think that implementation is a little bit more concise and uses SplatElementsAttr::get without a temporary vector.

565–568

Should we assert that the shift amount is as expected? ([0, BW-1])

579

the right *sign* (i.e., the MSB) bit?

I think the sign bit may not be the leading bit depending on the endiannes, no?

621

Outdated comment? This pattern doesn't generate any selects.

644

Should we do uint64_t(1) << bw if the helper expects u64 anyway? Or even better, use one of the helpers in MathExtras to create a mask: https://llvm.org/doxygen/namespacellvm.html#a79dff91526e31b1a05f59eed6c189eb4?

691

Same: the comment doesn't match the code

713

Also here

antiagainst marked 7 inline comments as done.

Address comments

kuhar accepted this revision.Aug 12 2023, 6:33 PM

LGTM

This revision is now accepted and ready to land.Aug 12 2023, 6:33 PM