[PATCH] D28147: [LICM] Allow promotion of some stores that are not guaranteed to execute

Michael Kuperstein via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Dec 28 22:00:43 PST 2016


mkuper added a comment.

Thanks, Philip!

Yes, sorry, that was unclear from the description. I think it's clearer in the inline comment.

For promotion to be legal you need two conditions to hold:

1. You can unconditionally dereference the pointer in a hoisted load. This holds is if at least one store or load is guaranteed to execute - but that's not a necessary condition. You may know the pointer is dereferencible through other means.
2. You are allowed to sink the store, from the memory model point of view. The previous code would check that the store is either guaranteed to execute or, if not, stores to a thread local.

What I'm doing here is relaxing condition 2.
Assuming I got the logic right, this patch should not be introducing any cases where the load can fault. That's why my tests have an unconditional load.

This targets reduction loops like

  for (int i = 0; i < n; ++i)
    for (int j = 0; j < m; ++j)
      local[i] += foo(i,j)

Where local[i] would otherwise be promotable within the loop, except that the store is not guaranteed to execute because foo() may throw. Note that the load precedes the call to bar.


https://reviews.llvm.org/D28147





More information about the llvm-commits mailing list