[PATCH] D37163: [LICM] sink through non-trivially replicable PHI
Daniel Berlin via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Aug 31 11:34:19 PDT 2017
dberlin added a comment.
In https://reviews.llvm.org/D37163#857853, @junbuml wrote:
> I agree that the test doesn't really require splitting since the operations of incoming values are the same (sub/mul) and all operands used in the sinkable chain (%N_addr.0.pn, %N, and %N2) dominate the PHI, so we can directly add PHIs for operands and share the same operation in the exit block like you comment. For me, it seems that the test case is a special case in which splitting is not required. In most case, I think splitting is required to sink through a non-trivially replicable PHI. For example, if operations of incoming values are different or any operands in the sinkable chain do not dominate the PHI, we should split preds.
The case where you can't place it somewhere safe should be the case where the edge is critical.
Otherwise, there should always be somewhere to place the computation safely and correctly.
Now, i admit it may be tricky to come up with such an algorithm, but i'd also be surprised if it doesn't exist in literature already.
> For me, SimplifyCFG should clean up such foldable case. The test case seems to be handled properly by SimplifyCFG :
>
> Out12:
> %N_addr.0.pn.lcssa.sink = phi i32 [ %N_addr.0.pn, %Loop ], [ %N_addr.0.pn, %ContLoop ]
> %N.sink = phi i32 [ %N, %Loop ], [ %N2, %ContLoop ]
> %tmp.6.le = mul i32 %N, %N_addr.0.pn.lcssa.sink
> %tmp.7.le = sub i32 %tmp.6.le, %N.sink
>
>
> Would it make sense that LICM split preds for non-trivially replicable PHIs in general and let the SimplyCFG fold such case. If there is any case where SimplyCFG cannot fold, we can improve SimplyCFG.
If we can avoid creating the mess in the first place, i'd rather see us do that.
Changing the CFG like this costs something (incremental dominator updates, etc).
If we don't need to do it, we generally shouldn't do it.
If the algorithm turns out to be wildly complex, sure, let's do the easy thing and split preds and let something clean it up.
But i'd at least like to see us *try*.
https://reviews.llvm.org/D37163
More information about the llvm-commits
mailing list