Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

emcc does not lower too-large vector types #4789

Closed
allanlw opened this issue Dec 12, 2016 · 6 comments
Closed

emcc does not lower too-large vector types #4789

allanlw opened this issue Dec 12, 2016 · 6 comments

Comments

@allanlw
Copy link

allanlw commented Dec 12, 2016

Consider the following program:

#include <stdio.h>

#define vs 4
#define vt double

typedef vt myvector __attribute__ ((vector_size (sizeof(vt) * vs)));

int main() {
  myvector a = {0}, b = {0};
  for (int i = 0; i < vs; i++) { a[i] = i; b[i] = i; }

  a *= b;

  for (int i = 0; i < vs; i++) {
    printf("%f\n", a[i]);
  }
}

emcc fails to compile this with an unexplained assertion error: LLVM ERROR: VT->getBitWidth() <= 128, but clang and GCC handle it fine. The solution is to lower the too-large SIMD types until they are of supported width.

@juj juj added the SIMD label Dec 13, 2016
@juj
Copy link
Collaborator

juj commented Dec 13, 2016

Yeah, this is a current limitation, we don't split up too large SIMD operations to smaller ones. I wonder if LLVM might have some kind of automated higher level machinery to do that. Note that SIMD.js doesn't have a double * 2 type ("SIMD.Float64x2") even, so vs=2, vt=double is not expected to work here either, although for Emscripten purposes we use an unofficial polyfill for that, and Firefox has an unofficial implementation for that type in Nightly.

@juj
Copy link
Collaborator

juj commented Dec 13, 2016

For reference, here's a starting trail to the conversations about Float64x2 not getting in, tc39/ecmascript_simd#229 . That type was postponed to a "phase 2" implementation, the summary being that there were no presented cases to provide measurable speedups.

@allanlw
Copy link
Author

allanlw commented Dec 13, 2016

In my specific case I don't care about SIMD speedups per-se, I care about compiling an existing codebase that uses vectors that are too large and expects the compiler to lower them.

My impression is that LLVM normally does this through TargetLowering but that emscripten skips the SelectionDAG stuff altogether, so this machinery can't be reused. Doing this through an opt pass might not be too bad, to lower into, say an array of vectors, although some care would need to be taken to implement gather and scatter and to make sure that a later pass does not re-vectorize. Perhaps for the more complex vector intrinsics, it might be easier to not replace them inline and instead call out to a polyfill function.

I might take a crack at writing such an opt pass if I ever get some free time.

@dschuff
Copy link
Member

dschuff commented Dec 13, 2016 via email

@DiamondLovesYou
Copy link

I did this work years ago for PNaCl: https://codereview.chromium.org/1423873002. Sadly it never got merged, but it should still work for this.

@stale
Copy link

stale bot commented Aug 30, 2019

This issue has been automatically marked as stale because there has been no activity in the past 2 years. It will be closed automatically if no further activity occurs in the next 7 days. Feel free to re-open at any time if this issue is still relevant.

@stale stale bot added the wontfix label Aug 30, 2019
@stale stale bot closed this as completed Sep 6, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants