[LoopFusion] sink second loop PHIs
authorJoshua Cao <cao.joshua@yahoo.com>
Tue, 13 Dec 2022 17:37:18 +0000 (09:37 -0800)
committerArthur Eubanks <aeubanks@google.com>
Tue, 13 Dec 2022 18:13:39 +0000 (10:13 -0800)
commit5004320590aed2e27140fb458ebd67b68af05a91
tree8cba8e77fb98d14cbc4d63e1a0795f0c4fb9bfca
parent7e2a6af82c887915500aac64d77f93f1e79e8d28
[LoopFusion] sink second loop PHIs

Fixes https://github.com/llvm/llvm-project/issues/59023

PHI nodes that are in the second loop only have the first loop as its
predecessor. These PHI nodes should be sunk to the end of the fused
loop. If the second loop uses the PHI, then the loops cannot be fused.

I don't think this should happen in typical compilation workflows.
The PHI will be in a dedicated exit block of the first loop following
LCSSA transformations.

Reviewed By: aeubanks

Differential Revision: https://reviews.llvm.org/D139812
llvm/lib/Transforms/Scalar/LoopFuse.cpp
llvm/test/Transforms/LoopFusion/lcssa.ll [new file with mode: 0644]