[cfe-dev] Allow constexpr in vector extensions

Jeff Hammond via cfe-dev cfe-dev at lists.llvm.org
Tue Aug 29 11:36:35 PDT 2017


I see no errors with Clang 3.8, 3.9, 4.0 and GCC 5, 6, 7 on my Haswell
Mac.  Try setting -std= appropriately, given that constexpr is a C++11
feature.

Jeff

$ cat v4si.cc

typedef int v4si __attribute__ ((vector_size (16)));


int main()

{

    constexpr v4si a = {1,2,3,4};

    constexpr v4si b = {2,0,0,0};

    v4si c = a + b;

}


$ for cxx in /usr/bin/clang++ /usr/local/Cellar/llvm/4.0.1/bin/clang++
/usr/local/Cellar/llvm at 3.8/3.8.1/bin/clang++-3.8
/usr/local/Cellar/llvm at 3.9/3.9.1_1/bin/clang++
g++-7 g++-6 g++-5 ; do $cxx  -std=c++1z v4si.cc && echo $cxx SUCCESS ||
echo $cxx FAIL ; done

/usr/bin/clang++ SUCCESS

/usr/local/Cellar/llvm/4.0.1/bin/clang++ SUCCESS

/usr/local/Cellar/llvm at 3.8/3.8.1/bin/clang++-3.8 SUCCESS

/usr/local/Cellar/llvm at 3.9/3.9.1_1/bin/clang++ SUCCESS

g++-7 SUCCESS

g++-6 SUCCESS

g++-5 SUCCESS

$ for cxx in /usr/bin/clang++ /usr/local/Cellar/llvm/4.0.1/bin/clang++
/usr/local/Cellar/llvm at 3.8/3.8.1/bin/clang++-3.8
/usr/local/Cellar/llvm at 3.9/3.9.1_1/bin/clang++
g++-7 g++-6 g++-5 ; do $cxx  -std=c++11 v4si.cc && echo $cxx SUCCESS ||
echo $cxx FAIL ; done

/usr/bin/clang++ SUCCESS

/usr/local/Cellar/llvm/4.0.1/bin/clang++ SUCCESS

/usr/local/Cellar/llvm at 3.8/3.8.1/bin/clang++-3.8 SUCCESS

/usr/local/Cellar/llvm at 3.9/3.9.1_1/bin/clang++ SUCCESS

g++-7 SUCCESS

g++-6 SUCCESS

g++-5 SUCCESS

$ for cxx in /usr/bin/clang++ /usr/local/Cellar/llvm/4.0.1/bin/clang++
/usr/local/Cellar/llvm at 3.8/3.8.1/bin/clang++-3.8
/usr/local/Cellar/llvm at 3.9/3.9.1_1/bin/clang++
g++-7 g++-6 g++-5 ; do $cxx  -std=c++14 v4si.cc && echo $cxx SUCCESS ||
echo $cxx FAIL ; done

/usr/bin/clang++ SUCCESS

/usr/local/Cellar/llvm/4.0.1/bin/clang++ SUCCESS

/usr/local/Cellar/llvm at 3.8/3.8.1/bin/clang++-3.8 SUCCESS

/usr/local/Cellar/llvm at 3.9/3.9.1_1/bin/clang++ SUCCESS

g++-7 SUCCESS

g++-6 SUCCESS

g++-5 SUCCESS

On Tue, Aug 29, 2017 at 5:45 AM, Tom Westerhout via cfe-dev <
cfe-dev at lists.llvm.org> wrote:

> Greetings!
>
>
> This is my first post on this ML so, please, do tell me if I'm doing it
> wrong.
>
> I've noticed the following difference between GCC and Clang. Consider
> this piece of code
>
> ```
> typedef int v4si __attribute__ ((vector_size (16)));
>
> int main()
> {
>     constexpr v4si a = {1,2,3,4};
>     constexpr v4si b = {2,0,0,0};
>     v4si c = a + b;
> }
> ```
>
> It compiles cleanly with both GCC and Clang. However, if I try to make c
> constexpr, Clang tells me that operator+ on vectors is not constexpr. I'm
> wondering if there's a reason for that. There are no constrains from the
> Standard as these are intrinsics, so I see no reason why we couldn't
> allow constexpr code benefit from SIMD.
>
>
> Tom
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
>



-- 
Jeff Hammond
jeff.science at gmail.com
http://jeffhammond.github.io/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20170829/ddb1959f/attachment.html>


More information about the cfe-dev mailing list