You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
when running "cargo test" on the following code with "rustc 1.24.0-nightly (1abeb436d 2017-12-27)" I get
LLVM ERROR: Do not know how to split the result of this operator!
externcrate stdsimd;use stdsimd::vendor::*;use stdsimd::simd::u32x8;//Find minimum val within 3 registers and splat it to a new registerpubfnsplat_min(v1:u32x8,v2:u32x8,v3:u32x8) -> u32x8{unsafe{//across registersletmut min = _mm256_min_epu32(_mm256_min_epu32(v1, v2), v3);//within 128 bit halfsletmut tmp = _mm256_shuffle_epi32(min.into(),0x4E).into();
min = _mm256_min_epu32(min, tmp);
tmp = _mm256_shuffle_epi32(min.into(),0xB1).into();
min = _mm256_min_epu32(min, tmp);//across 128 bit halfs
tmp = _mm256_permute2f128_si256(min.into(), min.into(),1).into();_mm256_min_epu32(min, tmp)}}#[cfg(test)]mod tests {usesuper::*;#[test]fntest(){let v1 = u32x8::new(0,1,2,3,4,5,6,7);let v2 = u32x8::new(8,9,10,11,12,13,14,15);let v3 = u32x8::new(16,17,18,19,20,21,22,23);assert_eq!(splat_min(v1,v2,v3), u32x8::splat(0));}}
I'm having a similar issue with non-avx2 instructions - I think the issue is caused by calling an intrinsic in an assert! macro, but I've only came across the issue in my doctests.
Here's a smaller example which I copied from the stdsimd test for _mm256_permute2f128_si256
If get the error with
cargo run
but not with
cargo run --release
adding
#[target_feature = "+avx"]
just before main, also fixes it
Which mean's it's probably not going to compile to the right instruction anyway. But it would nice if it returned a more useful error if it shouldn't compile.
externcrate stdsimd;use stdsimd::vendor::_mm256_permute2f128_si256;use stdsimd::simd::i32x8;fnmain(){unsafe{let a = i32x8::new(1,2,3,4,1,2,3,4);let b = i32x8::new(5,6,7,8,5,6,7,8);let r = _mm256_permute2f128_si256(a, b,0x20);let e = i32x8::new(1,2,3,4,5,6,7,8);assert_eq!(r, e);}}
@Cocalus last example is compiling main with SSE, but unconditionally calling an AVX2 function in it so unless it is compiled with -C target-feature=+avx2 this example has undefined behavior. In --release LLVM probably just deduces that fn main() can only run in AVX2 targets (it's UB otherwise) and just compiles it with AVX2 (which will work on AVX2 hosts, and crash otherwise).
In debug mode, main is compiled with SSE, and because i32x8 has a different ABI in SSE than in AVX2 this should trigger: rust-lang/rust#44367 , why it triggers the LLVM error instead, I don't know (sometimes this works and crashes, sometimes it doesn't compile; once the rust issue is fixed the ABIs will be automatically converted).
However, I don't understand why using #[target_feature = "+avx"] fn main() { ... } fixes this issue in debug builds. It should not: i32x8 also has a different ABI in AVX than in AVX2, which should again trigger: rust-lang/rust#44367
I was wondering why all the vendor functions were marked unsafe, I guess the requirement on the programmer is that they are only used a section of code where the relevant target features are enabled. It seems like it should be possible to statically check that _mm256_permute2f128_si256 is only called in a an avx enabled section of code, then a lot of unsafe blocks could be avoided. I'm might be missing other reasons the vendor functions are tagged as unsafe.
In my original code I had the splat_min as an inner function and I expected the target_feature to apply to everything within the function, including inner functions and closures. Which is apparently not the case. I haven't figured out the incantation to get closures to work. Though this could also be related to repr(simd) issue.
Using cargo run on this only produces the right answer for good. Notable there is no unsafe here.
In general these are probably either LLVM bugs or otherwise consequences of rust-lang/rust#44367 where we're mismatching enabled target features per function.
It seems like it should be possible to statically check that _mm256_permute2f128_si256 is only called in a an avx enabled section of code, then a lot of unsafe blocks could be avoided.
I've opened #306 to close out this issue as my suspected cause, rust-lang/rust#44367 , has since been fixed and it unfortunately didn't fix this issue!
Activity
AdamNiederer commentedon Dec 28, 2017
I'm having a similar issue with non-avx2 instructions - I think the issue is caused by calling an intrinsic in an
assert!macro, but I've only came across the issue in my doctests.See here for another example of this issue.
Cocalus commentedon Dec 28, 2017
I still get the error even if I remove the assert
Cocalus commentedon Dec 28, 2017
Here's a smaller example which I copied from the stdsimd test for _mm256_permute2f128_si256
If get the error with
cargo run
but not with
cargo run --release
adding
#[target_feature = "+avx"]
just before main, also fixes it
Which mean's it's probably not going to compile to the right instruction anyway. But it would nice if it returned a more useful error if it shouldn't compile.
gnzlbg commentedon Dec 29, 2017
@Cocalus last example is compiling
mainwith SSE, but unconditionally calling an AVX2 function in it so unless it is compiled with-C target-feature=+avx2this example has undefined behavior. In--releaseLLVM probably just deduces thatfn main()can only run in AVX2 targets (it's UB otherwise) and just compiles it with AVX2 (which will work on AVX2 hosts, and crash otherwise).In debug mode,
mainis compiled with SSE, and becausei32x8has a different ABI in SSE than in AVX2 this should trigger: rust-lang/rust#44367 , why it triggers the LLVM error instead, I don't know (sometimes this works and crashes, sometimes it doesn't compile; once the rust issue is fixed the ABIs will be automatically converted).However, I don't understand why using
#[target_feature = "+avx"] fn main() { ... }fixes this issue in debug builds. It should not:i32x8also has a different ABI in AVX than in AVX2, which should again trigger: rust-lang/rust#44367@alexcrichton ?
Cocalus commentedon Dec 29, 2017
I was wondering why all the vendor functions were marked unsafe, I guess the requirement on the programmer is that they are only used a section of code where the relevant target features are enabled. It seems like it should be possible to statically check that _mm256_permute2f128_si256 is only called in a an avx enabled section of code, then a lot of unsafe blocks could be avoided. I'm might be missing other reasons the vendor functions are tagged as unsafe.
In my original code I had the splat_min as an inner function and I expected the target_feature to apply to everything within the function, including inner functions and closures. Which is apparently not the case. I haven't figured out the incantation to get closures to work. Though this could also be related to repr(simd) issue.
Using cargo run on this only produces the right answer for good. Notable there is no unsafe here.
alexcrichton commentedon Dec 29, 2017
In general these are probably either LLVM bugs or otherwise consequences of rust-lang/rust#44367 where we're mismatching enabled target features per function.
gnzlbg commentedon Dec 29, 2017
@Cocalus There is an RFC for that: rust-lang/rfcs#2212
Move from #[inline(always)] to #[inline]
alexcrichton commentedon Jan 29, 2018
I've opened #306 to close out this issue as my suspected cause, rust-lang/rust#44367 , has since been fixed and it unfortunately didn't fix this issue!
Move from #[inline(always)] to #[inline] (#306)