Open
Description
LLVM already has a fairly shaky optimization that doesn't make it through isel when followed by a left or right shift. https://rust.godbolt.org/z/a6eexcE6z
#![no_std]
#![feature(portable_simd)]
use core::simd::prelude::*;
// Generates vpmulhw
pub fn mulhw(a: i16x16, b: i16x16) -> i16x16 {
(((a.cast::<i32>()) * (b.cast::<i32>())) >> 16).cast::<i16>()
}
// Generates a mess
pub fn mulhw_and_shift(a: i16x16, b: i16x16) -> i16x16 {
mulhw(a, b) >> 1
}
A dedicated function that can multiply two integers and take the high parts would be very beneficial when handling fixed-point integers. And hopefully it'll have a better chance of surviving optimization passes.