[PATCH] D149348: RFD: Do not CSE convergent calls in different basic blocks

Jay Foad via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 27 07:44:00 PDT 2023


foad created this revision.
foad added reviewers: AMDGPU, nhaehnle, sameerds, yaxunl.
Herald added subscribers: kosarev, StephenFan, kerbowa, hiraditya, jvesely.
Herald added a project: All.
foad requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

"convergent" is documented as meaning that the call cannot be made
control-dependent on more values, but in practice we also require that
it cannot be made control-dependent on fewer values, e.g. it cannot be
hoisted out of the body of an "if" statement.

In code like this, if we allow CSE to combine the two calls:

  x = convergent_call();
  if (cond) {
    y = convergent_call();
    use y;
  }

then we get this:

  x = convergent_call();
  if (cond) {
    use x;
  }

This is conceptually equivalent to moving the second call out of the
body of the "if", up to the location of the first call, so it should be
disallowed.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D149348

Files:
  llvm/lib/IR/Instruction.cpp
  llvm/lib/Transforms/Scalar/EarlyCSE.cpp
  llvm/test/CodeGen/AMDGPU/cse-convergent.ll
  llvm/test/Transforms/SimplifyCFG/convergent.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D149348.517552.patch
Type: text/x-patch
Size: 5036 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230427/b5fb3bf2/attachment.bin>


More information about the llvm-commits mailing list