Bug 82915 - Please mark intrinsics as constexpr
Summary: Please mark intrinsics as constexpr
Status: NEW
Alias: None
Product: gcc
Classification: Unclassified
Component: target (show other bugs)
Version: 7.2.0
: P3 enhancement
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks: constexpr
  Show dependency treegraph
 
Reported: 2017-11-09 07:28 UTC by Daniel Fruzynski
Modified: 2018-01-03 23:46 UTC (History)
1 user (show)

See Also:
Host:
Target: x86_64-*-*
Build:
Known to work:
Known to fail:
Last reconfirmed: 2017-11-09 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Daniel Fruzynski 2017-11-09 07:28:09 UTC
Intrinsics are marked as inline now. However gcc knows what they do, and is able to optimize out some code code which uses them - e.g. in example below both count1a() and count2a() are optimized to "mov eax, 5; ret". Because of this intrinsics could be marked as constexpr. This would allow gcc to better optimize code. It also would allow to perform quick code validation in tools like Compiler Explorer, by using code like below.

#include "immintrin.h"

constexpr int data[8] = {0, 1, 0, 2, 0, 3};

constexpr int count1(const int* d)
{
  int cnt = 0;
  for (int n = 0; n < 8; ++n)
    if (0 == d[n])
      ++cnt;
  return cnt;
}

int count1a()
{
  return count1(data);
}

inline int count2(const int* d)
{
  __m256i v = _mm256_loadu_si256((const __m256i*)d);
  v = _mm256_cmpeq_epi32(v, _mm256_setzero_si256());
  return _mm256_movemask_epi8(v) >> 2;
}

int count2a()
{
  return count1(data);
}
Comment 1 Richard Biener 2017-11-09 08:26:52 UTC
Confirmed.  Note this trivially applies to all open-coded intrinsics not using
__builtin_ia32_* calls, marking those constexpr would require significant work
(work that might be useful anyways for optimization, of course).
Comment 2 Daniel Fruzynski 2018-01-03 19:23:33 UTC
SIMD ISAa for other CPU types (e.g. ARM/AARCH64 NEON) also can benefit from this.
Comment 3 Martin Sebor 2018-01-03 23:31:56 UTC
Is this request to make just x86_64 intrinsics constexpr or all of them?  (IMO, all intrinsics that could be should be made constexpr -- see bug 70816 for a target-independent example; some others may have already been made to work to help libstdc++).
Comment 4 Daniel Fruzynski 2018-01-03 23:46:40 UTC
For tracking purposes it probably would be better to have separate issues for every CPU type which could benefit this. So this one could be for x86, and you could open other requests for other CPUs which supports SIMD instructions.