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

Vector ops optimization #938

Closed
Temtaime opened this issue May 22, 2015 · 8 comments
Closed

Vector ops optimization #938

Temtaime opened this issue May 22, 2015 · 8 comments

Comments

@Temtaime
Copy link
Contributor

First:

auto foo(ref float[4] a, float c) {
  typeof(a) b;
  b[] = a[] * c;
  return b;
}

Creates a call to _arraySliceExpMulSliceAssign_f function, but it think it needs to be inlined and turned in only one mulps.

Second:

auto foo(ref float[4] a, float c) {
  typeof(a) b;
  foreach(i, ref v; b) v = a[i] * c;
  return b;
}

OK, this code creates only one mulps.

We can increase size of a and it will be OK: http://goo.gl/jzjRH9
But for example if we make count of elements in a >= 32 (http://goo.gl/q1uKEZ), then ldc generates unnecessary initializations with nan. Is it llvm problem or ldc? Can we tell llvm that initialization is unnecessary ?

@redstar
Copy link
Member

redstar commented May 22, 2015

At first example: this is a missed optimization opportunity. I try to solve this.

At second example: what about adding = void;:

auto foo(ref float[4] a, float c) {
  typeof(a) b = void;
  foreach(i, ref v; b) v = a[i] * c;
  return b;
}

The NaNs are generated by ldc because of the language specification: http://dlang.org/declaration.html#VoidInitializer

@Temtaime
Copy link
Contributor Author

HI Kai !
Yes i know that it's because of language specification but all the elements are overwritten, so there no chance that compiler can optimize it by himself ?

redstar added a commit to redstar/ldc that referenced this issue May 23, 2015
The functions for all arrayops are compiler-generated but the functions
which are also defined in druntime are never emitted. This prevents
inlining of the function body and causes issue ldc-developers#938.

The fix is to emit the arrayops if inlining is enabled and otherwise
use the druntime provided implementations.

An alternative approach could be to always emit the arrayops and
never use the druntime version.
@redstar
Copy link
Member

redstar commented May 23, 2015

@Temtaime Could you check PR #939? This should fix the first example with -O2 or higher.

redstar added a commit to redstar/ldc that referenced this issue May 23, 2015
The functions for all arrayops are compiler-generated but the functions
which are also defined in druntime are never emitted. This prevents
inlining of the function body and causes issue ldc-developers#938.

The fix is to emit the arrayops if inlining is enabled and otherwise
use the druntime provided implementations.

An alternative approach could be to always emit the arrayops and
never use the druntime version.
@Temtaime
Copy link
Contributor Author

http://goo.gl/QdFsZP
Yes, now all is OK. Thanks you, Kai !

@Temtaime
Copy link
Contributor Author

@redstar
I discovered another strange thing.
Compare http://goo.gl/8jb9h2 with link in my previous post.
After ret there are some strange artefacts. Is it normal ?

@redstar
Copy link
Member

redstar commented May 24, 2015

I think this is a bug in the tool.
The code is the function _arraySliceExpMulSliceAssign_f which is also emitted. The label above the code is missing.

@dnadlinger
Copy link
Member

Closing, as the problem seems to be fixed and the linked site with the code examples seems to be offline. Please feel free to re-open if the problem still persists.

@Temtaime
Copy link
Contributor Author

Temtaime commented Jul 4, 2015

All is OK, thanks.
I'll bring up the site soon btw.

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

3 participants