OpenCilk / opencilk-project

Monorepo for the OpenCilk compiler. Forked from llvm/llvm-project and based on Tapir/LLVM.
Other
93 stars 29 forks source link

Hyperobjects inhibit vectorization #157

Closed VoxSciurorum closed 1 year ago

VoxSciurorum commented 1 year ago

The following code is not vectorized because

remark: loop not vectorized: unsafe dependent memory operations in loop.
static void zero(void *p) { *(long *)p = 0; }
static void plus(void *l, void *r) { *(long *)l += *(long *)r; }

long sum_cilk_for_pointer(const long *begin, const long *end)
{
  long _Hyperobject(zero, plus) sum = 0;
  _Cilk_for (const long *p = begin; p != end; ++p)
    sum += *p;
  return sum;
}

One approach is to teach vectorization to recognize reducers as reduction variables.

It is likely that other loop optimizations would benefit from treating hyerpobjects as ordinary IR values (in SSA form with a PHI at the top of the loop).

neboat commented 1 year ago

I looked into this a bit, out of curiosity. I think there may be a simpler underlying problem. This alias-analysis code, which is used to check for aliasing involving view lookups, checks for the wrong attribute: https://github.com/OpenCilk/opencilk-project/blob/dev/14.x/llvm/lib/Analysis/BasicAliasAnalysis.cpp#L1611-L1615

VoxSciurorum commented 1 year ago

That's the problem. A regression introduced last summer. A fix with test case is on the way.