Skip to content

Commit

Permalink
jl_special_vector_alignment: Remove work-around for old LLVM version …
Browse files Browse the repository at this point in the history
…(<=3.8) (#34490)

LLVM <= 3.8 segfaults when LLVM SIMD vectors are not powers of 2 (or a sum
of 2 different powers of 2). This LLVM bug was corrected in 2017 (see
<https://bugs.llvm.org/show_bug.cgi?id=27708>). This change removes this
work-around, finally allowing arbitrary SIMD vector lengths in Julia.

This changes Julia's ABI for SIMD types. All SIMD types are now represented
as SIMD vectors in LLVM. The work-around represented some SIMD types as
LLVM arrays instead to avoid the LLVM segfault. I don't think that SIMD
vector lengths that are not a power of 2 were in widespread use, if at all.

(cherry picked from commit e0740fe)
  • Loading branch information
eschnett authored and KristofferC committed Feb 5, 2020
1 parent ca11925 commit 2a64ee2
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 18 deletions.
12 changes: 0 additions & 12 deletions src/datatype.c
Original file line number Diff line number Diff line change
Expand Up @@ -191,18 +191,6 @@ unsigned jl_special_vector_alignment(size_t nfields, jl_value_t *t)
{
if (!jl_is_vecelement_type(t))
return 0;
// LLVM 3.7 and 3.8 either crash or generate wrong code for many
// SIMD vector sizes N. It seems the rule is that N can have at
// most 2 non-zero bits. (This is true at least for N<=100.) See
// also <https://llvm.org/bugs/show_bug.cgi?id=27708>.
size_t mask = nfields;
// See e.g.
// <https://graphics.stanford.edu/%7Eseander/bithacks.html> for an
// explanation of this bit-counting algorithm.
mask &= mask-1; // clear least-significant 1 if present
mask &= mask-1; // clear another 1
if (mask)
return 0; // nfields has more than two 1s
assert(jl_datatype_nfields(t)==1);
jl_value_t *ty = jl_field_type((jl_datatype_t*)t, 0);
if (!jl_is_primitivetype(ty))
Expand Down
6 changes: 0 additions & 6 deletions test/vecelement.jl
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,6 @@ end
# Test various SIMD Vectors with known good sizes
for T in (Float64, Float32, Int64, Int32)
for N in 1:36
# For some vectortypes Julia emits llvm arrays instead of vectors
if N % 7 == 0 || N % 11 == 0 || N % 13 == 0 || N % 15 == 0 ||
N % 19 == 0 || N % 23 == 0 || N % 25 == 0 || N % 27 == 0 ||
N % 29 == 0 || N % 31 == 0
continue
end
a = ntuple(i->VecElement(T(i)), N)
result = ntuple(i-> VecElement(T(i+i)), N)
b = vecadd(a, a)
Expand Down

0 comments on commit 2a64ee2

Please sign in to comment.