Bug 81948 - vectorize exp2 using exp
Summary: vectorize exp2 using exp
Status: NEW
Alias: None
Product: gcc
Classification: Unclassified
Component: tree-optimization (show other bugs)
Version: 8.0
: P3 enhancement
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: missed-optimization
Depends on:
Blocks: vectorizer
  Show dependency treegraph
 
Reported: 2017-08-23 14:38 UTC by Marc Glisse
Modified: 2017-08-24 10:22 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2017-08-24 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Marc Glisse 2017-08-23 14:38:40 UTC
Using -Ofast -mavx2 and a recent glibc, g++ vectorizes

#include <cmath>
void f(double*d){
  d=(double*)__builtin_assume_aligned(d,256);
  for(int i=0;i<1024;++i)
    d[i]=std::exp(d[i]*std::log(2));
}

However, if I write d[i]=std::exp2(d[i]) instead, it fails to vectorize (libmvec does not provide a vector version of exp2). It would be good, when checking if a standard function like exp2 has a vector version, to also check related, more canonical functions (exp in this case).

(this could also be vaguely related to PR 81706)
Comment 1 Richard Biener 2017-08-24 10:22:20 UTC
Confirmed.  glibc uses a different alg for exp2 than exp but for exp10 it simply does exp(x * log(10)) it seems.

Probably requires some refactoring in vectorizable_simd_clone_call.

Or we decide that with -funsafe-math-optimizations canonicalizing expN/logN
to exp/log is worthwhile.

The best thing would be to enhance glibc of course.