stdarch icon indicating copy to clipboard operation
stdarch copied to clipboard

`_mm_adds_epu8` doesn't generate the right instruction.

Open ruriww opened this issue 5 months ago • 2 comments

https://godbolt.org/z/KTTPcKP58

#[target_feature(enable = "sse2")]
pub fn simd_gte2(x: __m128i) -> i32 {
  let bc = _mm_set1_epi8(0x7e);
  let y = _mm_adds_epu8(x, bc);
  
   _mm_movemask_epi8(y)
}
.LCPI0_0:
        .zero   16,2
example::simd_gte2:
        movdqa  xmm0, xmmword ptr [rdi]
        movdqa  xmm1, xmmword ptr [rip + .LCPI0_0]
        pmaxub  xmm1, xmm0 ; 1
        pcmpeqb xmm1, xmm0 ; 2: these two instructions can be simplified to paddusb
        pmovmskb        eax, xmm1
        ret

ruriww avatar Jun 07 '26 19:06 ruriww

Looks like a missed optimization in LLVM. Can you report it there as "[X86] Poor codegen for ..."?

Our implementation seems pretty reasonable

pub const fn _mm_adds_epu8(a: __m128i, b: __m128i) -> __m128i {
    unsafe { transmute(simd_saturating_add(a.as_u8x16(), b.as_u8x16())) }
}

folkertdev avatar Jun 07 '26 22:06 folkertdev

@rustbot label +A-x86 +A-llvm

bardiharborow avatar Nov 22 '26 02:11 bardiharborow