Poor code gen identified in Andreas Fredriksson's GDC 2016 Talk 'Taming the Jaguar: x86 Optimization at Insomniac Games':
http://schedule.gdconf.com/session/taming-the-jaguar-x86-optimization-at-insomniac-games
(see details in PR27136)
Differential D24760
Failure to hoist constant out of loop avt77 on Sep 20 2016, 6:17 AM. Authored by
Details Poor code gen identified in Andreas Fredriksson's GDC 2016 Talk 'Taming the Jaguar: x86 Optimization at Insomniac Games': (see details in PR27136)
Diff Detail Event TimelineComment Actions The previously committed test was updated to mirror changes in CodeGen. Please, review this version. Comment Actions This certainly seems like the right thing to do. Have you run the test suite, etc. to check for performance regressions? Comment Actions All tests from llvm-test-suite passed and there are no performance degradations. I used the following command: lnt runtest nt -v -sandbox SANDBOX --cc WORKSPACE/build/bin/clang --test-suite ~/llvm-test-suite Is it enough or I should do more testing? Comment Actions A couple of small comments, but fair warning: I am not a qualified reviewer for this code and won't be able to sign off.
Comment Actions I created a simple test to check the performance: #define N 1000000000 bool search(long needle, const uint32_t *haystack, int count) { for (int i = 0; i < count; ++i) if (needle == haystack[i]) return true; return false; } long a [N]; int main () { int i; for (i = 0; i < N; i++) { a[i] = i; } for (long j = 0; j < M; j++) { search (j % N, (const uint32_t *)&a, N); } } time ./search.o The improvement is about 8%. Hal, could you give me your LGTM on this patch? Comment Actions Okay; LGTM. Can you also put together a patch to add your test to the test-suite? That way we can track the performance. Comment Actions Sorry, don't understand: do you mean I should add my perf test into the patch? But it is not a LIT test, it's an application. How can I add it to the test suit? I'll do it with my follow-up patch (on the next week) but please explain me how I should do it. Comment Actions Applications get added to the test suite (not the lit-run regressions tests). You know how to run the test suite (you did it with lnt as you indicated above). You could submit a patch to add your test to https://llvm.org/svn/llvm-project/test-suite/trunk, probably by placing it in the SingleSource/UnitTests subdirectory. The patch gets directed to llvm-commits as with this one. Comment Actions kparzysz, not long ago you added test tail-dup-merge-loop-headers.ll (maybe you added some other tests as well at that time). And this test (plus some others) failed now if I add this patch to the trunk code. Could you review my really tiny patch and could you give me a hint what's wrong with your code if I apply this patch? Comment Actions For tail-dup-merge-loop-headers.ll That is a layout test, and your change affected the final layout. Your change is innocuous because it's really checking for the presence/absence of blocks. In general: Comment Actions logan, jroelofs, ab, iteratee, tnorthover: this patch fails your tests: Comment Actions Mind uploading these as full-context diffs? Phab's way of showing them as raw files isn't particularly helpful reviewing / making comments. Comment Actions for ifcvt-rescan-diamonds.ll Nothing is broken, the test just gets optimized away. Change the 0 in the phi of %cond.end84 to a load and you'll be fine. Change the CHECK lines to match. Comment Actions I've fixed all failed tests. Test owners please review my changes: they are rather small that's why it should not take a lot of time from you. Comment Actions Hi @avt77: For atomic-cmpxchg.ll, I found that your output is the same as the version I originally committed. The test was updated by @danielcdh in D24818 / rL284757. You may wish to add him as reviewer. Comment Actions Looks like the hoisting issue described in PR27136 is already fixed at head? My guess is that the fix is from https://reviews.llvm.org/rL284757 Comment Actions Yes, you're right: the current trunk does not have the issue with test/CodeGen/X86/loop-search.ll. It was fixed. But the hosting issue is still here: this patch really improves code for several tests. Should we continue with this patch or we should simply close it because loop_search.ll was fixed?
Comment Actions Abandon this? Its seems to be fixed in trunk - there are still some issues in PR27136 but no constant hoisting. |
If I understand the issue correctly, this might be better phrased in terms of this predicate. Essentially, we know that we can rematerialize the constant *without* creating a copy even if there is a PHI use. I can see why this follows for loop exit phis. I'm not quite as clear I follow for phi's inside the loop.