public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/101651] New: constexpr write to simd vector element
@ 2021-07-27 20:46 glisse at gcc dot gnu.org
  2021-07-27 20:52 ` [Bug c++/101651] vector extension and element write vs C++17 constexpr functions pinskia at gcc dot gnu.org
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: glisse at gcc dot gnu.org @ 2021-07-27 20:46 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101651

            Bug ID: 101651
           Summary: constexpr write to simd vector element
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: glisse at gcc dot gnu.org
  Target Milestone: ---

(adapted from https://stackoverflow.com/q/68517921/1918193)

#ifdef WORK
 #include <array>
 typedef std::array<char,16> vec;
#else
 typedef char vec __attribute__((vector_size(16)));
#endif
constexpr auto gen () {
    vec ret{};
    for (int i = 0; i < sizeof(vec); ++i) {
        ret[i] = 2;
    }
    return ret;
};
constexpr auto m = gen();


c.cc:9:23:   in 'constexpr' expansion of 'gen()'
c.cc:9:24: error: modification of '(char [16])ret' is not a constant expression
    9 | constexpr auto m = gen();
      |                        ^

However, with -DWORK to use std::array instead of the vector extension, it
compiles just fine, so there shouldn't be any strong obstacle to implement
this.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug c++/101651] vector extension and element write vs C++17 constexpr functions
  2021-07-27 20:46 [Bug c++/101651] New: constexpr write to simd vector element glisse at gcc dot gnu.org
@ 2021-07-27 20:52 ` pinskia at gcc dot gnu.org
  2021-07-27 20:59 ` [Bug c++/101651] vector extension and element access " pinskia at gcc dot gnu.org
  2021-07-27 21:09 ` pinskia at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-07-27 20:52 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101651

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
     Ever confirmed|0                           |1
             Status|UNCONFIRMED                 |NEW
           Keywords|                            |rejects-valid
   Last reconfirmed|                            |2021-07-27
             Blocks|                            |55004
            Summary|constexpr write to simd     |vector extension and
                   |vector element              |element write vs C++17
                   |                            |constexpr functions

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Confirmed.
I really doubt any of the vector extensions are really supported with
constexpr.


Referenced Bugs:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=55004
[Bug 55004] [meta-bug] constexpr issues

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug c++/101651] vector extension and element access vs C++17 constexpr functions
  2021-07-27 20:46 [Bug c++/101651] New: constexpr write to simd vector element glisse at gcc dot gnu.org
  2021-07-27 20:52 ` [Bug c++/101651] vector extension and element write vs C++17 constexpr functions pinskia at gcc dot gnu.org
@ 2021-07-27 20:59 ` pinskia at gcc dot gnu.org
  2021-07-27 21:09 ` pinskia at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-07-27 20:59 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101651

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|vector extension and        |vector extension and
                   |element write vs C++17      |element access vs C++17
                   |constexpr functions         |constexpr functions

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
So it is any vector array that matters:
#ifdef WORK
 #include <array>
 typedef std::array<char,2> vec;
#else
 typedef char vec __attribute__((vector_size(2)));
#endif
constexpr auto gen () {
    vec ret{1,2};
    vec ret1{1,2};
    for (int i = 0; i < sizeof(vec); ++i) {
        ret[i] = ret1[0];
    }
 //   ret1[0] =3;
 //   ret1[0] =ret[0];
    return ret1;
};
 auto m = gen();

Note clang rejects the above for non -DWORK case.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug c++/101651] vector extension and element access vs C++17 constexpr functions
  2021-07-27 20:46 [Bug c++/101651] New: constexpr write to simd vector element glisse at gcc dot gnu.org
  2021-07-27 20:52 ` [Bug c++/101651] vector extension and element write vs C++17 constexpr functions pinskia at gcc dot gnu.org
  2021-07-27 20:59 ` [Bug c++/101651] vector extension and element access " pinskia at gcc dot gnu.org
@ 2021-07-27 21:09 ` pinskia at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-07-27 21:09 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101651

--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to Andrew Pinski from comment #2)
Here is clang's error message which is 10000% wrong.

<source>:7:16: error: constexpr function never produces a constant expression
[-Winvalid-constexpr]
constexpr auto gen () {
               ^
<source>:11:18: note: subexpression not valid in a constant expression
        ret[i] = ret1[0];
                 ^
1 error generated.
Compiler returned: 1

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-07-27 21:09 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-27 20:46 [Bug c++/101651] New: constexpr write to simd vector element glisse at gcc dot gnu.org
2021-07-27 20:52 ` [Bug c++/101651] vector extension and element write vs C++17 constexpr functions pinskia at gcc dot gnu.org
2021-07-27 20:59 ` [Bug c++/101651] vector extension and element access " pinskia at gcc dot gnu.org
2021-07-27 21:09 ` pinskia at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).