[llvm-dev] llvm.assume after CodeGenPrepare

Markus Lavin via llvm-dev llvm-dev at lists.llvm.org
Tue May 25 03:11:12 PDT 2021


With recent changes in BasicAA (mostly by Nikita Popov I believe) llvm.assumes can now guide in the AA decision making. Which is of course great.

For example for C input (or IR equivalent) as follows it can make a huge difference if the variable 'x' is known to be non-zero when AA is queried during scheduling

__builtin_assume(x != 0);
for (int i = 0; i < 64; i += 4) {
  v[(i + 0) * x] = v[(i + 0) * x] >> 2;
  v[(i + 1) * x] = v[(i + 1) * x] >> 2;
  v[(i + 2) * x] = v[(i + 2) * x] >> 2;
  v[(i + 3) * x] = v[(i + 3) * x] >> 2;
}

Unfortunately it appears that the CodeGenPrepare pass removes llvm.assume so that they never reach the code generator. Currently commit 91c9dee3fb6d89ab3 (and before that commit 6d20937c29a1a1d67) eliminate assumptions in CodeGenPrepare for reasons that appear to be optimization (avoiding blocks that would be empty if it was not for the llvm.assume and its predecessors).

It seems these two efforts are quite contradictory. Is there any deeper thinking behind this? I for one would be in favor of not eliminating assumes.

-Markus
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20210525/050b1757/attachment.html>


More information about the llvm-dev mailing list