[PATCH] D152772: [LoopSink] Allow sinking to PHI-use

Wenlei He via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Jun 23 09:08:59 PDT 2023


wenlei added inline comments.


================
Comment at: llvm/lib/Transforms/Scalar/LoopSink.cpp:257
     I.replaceUsesWithIf(IC, [N](Use &U) {
       return cast<Instruction>(U.getUser())->getParent() == N;
     });
----------------
When PHI-use is allowed, we also need a tweak here, otherwise the reported ICE could happen. 

```
return cast<Instruction>(U.getUser())->getParent() == N;
```
-->
```
return cast<Instruction>(U.getUser())->getParent() == N &&
             !isa<PHINode>(cast<Instruction>(U.getUser()));
```

This is because the code assumed inserted clone is before all uses in the block, which is not true for PHI-use. The PHI-use is being taken care of by defs in its incoming blocks so we don't need to update PHI-use.

I will reland with this fix included. 


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D152772/new/

https://reviews.llvm.org/D152772



More information about the llvm-commits mailing list