Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[clang++] operator==(vector of long, vector of long) -> vector of long long #132604

Open
ImpleLee opened this issue Mar 23, 2025 · 5 comments
Open
Labels
ABI Application Binary Interface clang:frontend Language frontend issues, e.g. anything involving "Sema" diverges-from:gcc Does the clang frontend diverge from gcc on this issue

Comments

@ImpleLee
Copy link

ImpleLee commented Mar 23, 2025

When comparing two variables of vector of long, clang++ returns a vector of long long, inconsistent with g++.
https://godbolt.org/z/db9zT6f4r

#include <type_traits>

using T [[gnu::vector_size(sizeof(long))]] = long;

static_assert(std::is_same_v<std::remove_reference_t<decltype((T{} == T{})[0])>, long>);

This makes the following code fails to compile with clang++ with the compilation options -march=x86-64-v4 -std=c++20 (previously reported as gcc bugzilla 118546).
Online link: https://godbolt.org/z/sxqsKrv9e .

#include <experimental/simd>
#include <cstdint>

using deduce_t_element = std::experimental::simd<
    std::uint64_t,
    std::experimental::simd_abi::deduce_t<std::uint64_t, 4>
>;

auto f(deduce_t_element e) {
    return e == 0;
}
@llvmbot llvmbot added the clang Clang issues not falling into any other category label Mar 23, 2025
@EugeneZelenko EugeneZelenko added backend:X86 ABI Application Binary Interface diverges-from:gcc Does the clang frontend diverge from gcc on this issue and removed clang Clang issues not falling into any other category labels Mar 23, 2025
@llvmbot
Copy link
Member

llvmbot commented Mar 23, 2025

@llvm/issue-subscribers-backend-x86

Author: Imple Lee (ImpleLee)

When comparing two variables of vector of long, clang++ returns a vector of long long, inconsistent with g++. https://godbolt.org/z/db9zT6f4r
#include &lt;type_traits&gt;

using T [[gnu::vector_size(sizeof(long))]] = long;

static_assert(std::is_same_v&lt;std::remove_reference_t&lt;decltype((T{} == T{})[0])&gt;, long&gt;);

This makes the following code fails to compile with clang++ with the compilation options -march=x86-64-v4 -std=c++20 (previously reported as gcc bugzilla 118546).
Online link: https://godbolt.org/z/sxqsKrv9e .

#include &lt;experimental/simd&gt;
#include &lt;cstdint&gt;

using deduce_t_element = std::experimental::simd&lt;
    std::uint64_t,
    std::experimental::simd_abi::deduce_t&lt;std::uint64_t, 4&gt;
&gt;;

auto f(deduce_t_element e) {
    return e == 0;
}

@RKSimon RKSimon added clang:frontend Language frontend issues, e.g. anything involving "Sema" and removed backend:X86 labels Mar 24, 2025
@llvmbot
Copy link
Member

llvmbot commented Mar 24, 2025

@llvm/issue-subscribers-clang-frontend

Author: Imple Lee (ImpleLee)

When comparing two variables of vector of long, clang++ returns a vector of long long, inconsistent with g++. https://godbolt.org/z/db9zT6f4r
#include &lt;type_traits&gt;

using T [[gnu::vector_size(sizeof(long))]] = long;

static_assert(std::is_same_v&lt;std::remove_reference_t&lt;decltype((T{} == T{})[0])&gt;, long&gt;);

This makes the following code fails to compile with clang++ with the compilation options -march=x86-64-v4 -std=c++20 (previously reported as gcc bugzilla 118546).
Online link: https://godbolt.org/z/sxqsKrv9e .

#include &lt;experimental/simd&gt;
#include &lt;cstdint&gt;

using deduce_t_element = std::experimental::simd&lt;
    std::uint64_t,
    std::experimental::simd_abi::deduce_t&lt;std::uint64_t, 4&gt;
&gt;;

auto f(deduce_t_element e) {
    return e == 0;
}

@shafik
Copy link
Collaborator

shafik commented Mar 24, 2025

CC @mizvekov

@mizvekov
Copy link
Contributor

The resulting type of the comparison is the signed equivalent of the original vector type.

But the way clang computes this is strange, it gets the size of the element type, and returns a signed vector of the same size,
by searching a list ordered by "largest types" first, so it looks for "long long" before "long".

On triples where sizeof(long long) == sizeof(long), it will always prefer long long, which is what you are seeing here.

@ImpleLee
Copy link
Author

But the way clang computes this is strange, it gets the size of the element type, and returns a signed vector of the same size, by searching a list ordered by "largest types" first, so it looks for "long long" before "long".

Can we make it a type-to-type mapping, so that long always maps to long, and long long always maps to long long, etc? Usable element types in the vector type is limited, after all.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ABI Application Binary Interface clang:frontend Language frontend issues, e.g. anything involving "Sema" diverges-from:gcc Does the clang frontend diverge from gcc on this issue
Projects
None yet
Development

No branches or pull requests

6 participants