Merge branch 'algebraic-sign-extend' into 'main'

nir/algebraic: Optimize away re-extracts of packs.

See merge request mesa/mesa!41303
This commit is contained in:
Emma Anholt 2026-05-08 00:12:08 +00:00
commit ad69f3a7bd

View file

@ -2045,6 +2045,20 @@ for pack, bits, compbits in [('pack_64_2x32', 64, 32), ('pack_32_2x16', 32, 16)]
((pack, (unpack, a)), a),
]
# No-op extracts from packs.
for (bits, chans, compbits) in ((32, 4, 8), (32, 2, 16), (64, 4, 16)):
for chan in range(chans):
chanvar = 'abcd'[chan]
optimizations += [((f'extract_i{compbits}', (f'pack_{bits}_{chans}x{compbits}', a), chan), ('i2i', 'a.' + 'xyzw'[chan]))]
optimizations += [((f'extract_u{compbits}', (f'pack_{bits}_{chans}x{compbits}', a), chan), ('u2u', 'a.' + 'xyzw'[chan]))]
if not (bits == 64 and compbits == 16):
if chans == 4:
optimizations += [((f'extract_i{compbits}', (f'pack_{bits}_{chans}x{compbits}_split', a, b, c, d), chan), ('i2i', chanvar))]
optimizations += [((f'extract_u{compbits}', (f'pack_{bits}_{chans}x{compbits}_split', a, b, c, d), chan), ('u2u', chanvar))]
if chans == 2:
optimizations += [((f'extract_i{compbits}', (f'pack_{bits}_{chans}x{compbits}_split', a, b), chan), ('i2i', chanvar))]
optimizations += [((f'extract_u{compbits}', (f'pack_{bits}_{chans}x{compbits}_split', a, b), chan), ('u2u', chanvar))]
optimizations.extend([
(('unpack_64_2x32_split_y', ('u2u64', 'a@1')), 0),
(('unpack_64_2x32_split_y', ('u2u64', 'a@8')), 0),