This is an archive of the discontinued LLVM Phabricator instance.

[WebAssembly] Select BUILD_VECTOR with large unsigned lane values
AcceptedPublic

Authored by tlively on Jul 15 2023, 9:29 PM.

Details

Reviewers
aheejin
dschuff
Summary

Previously we expected lane constants to be in the range of signed values for
each lane size, but the included test case produced large unsigned values that
fall outside that range. Allow instruction selection to proceed in this case
rather than failing.

Fixes #63817.

Diff Detail

Event Timeline

tlively created this revision.Jul 15 2023, 9:29 PM
Herald added a project: Restricted Project. · View Herald TranscriptJul 15 2023, 9:29 PM
Herald added subscribers: pmatos, asb, wingo and 4 others. · View Herald Transcript
tlively requested review of this revision.Jul 15 2023, 9:29 PM
Herald added a project: Restricted Project. · View Herald TranscriptJul 15 2023, 9:29 PM
dschuff accepted this revision.Jul 17 2023, 9:22 AM
This revision is now accepted and ready to land.Jul 17 2023, 9:22 AM
aheejin added inline comments.Jul 17 2023, 12:50 PM
llvm/lib/Target/WebAssembly/WebAssemblyInstrSIMD.td
53

Why are the negative range and the positive range different?

tlively added inline comments.Jul 18 2023, 7:26 AM
llvm/lib/Target/WebAssembly/WebAssemblyInstrSIMD.td
53

The signed values range from -2^(n-1) to 2^(n-1)-1 and the unsigned values range from 0 to 2^n, so the union of the ranges is -2^(n-1) to 2^n.

I realized this code will be UB and broken when SIZE is 64 because the 1 << 64 is nonsense, so I will have to fix and test that before I land this.

aheejin added inline comments.Jul 18 2023, 1:33 PM
llvm/lib/Target/WebAssembly/WebAssemblyInstrSIMD.td
53

Then are immediates in SIMD signed or unsigned?

Peter added a subscriber: Peter.Sep 22 2023, 1:14 PM

Hi all, thanks for the patch. Are there any updates on this patch? Do we plan to merge it to upstream?

Peter added inline comments.Sep 22 2023, 1:19 PM
llvm/lib/Target/WebAssembly/WebAssemblyInstrSIMD.td
53

I think you can use less equal 2^n -1 to avoid UB. The expression is complicated but const expr can be folded during compilation I think.

Imm <= ((1 << ("#SIZE#" - 1)) - 1) * 2 + 1