This is an archive of the discontinued LLVM Phabricator instance.

[LSR] do not replace PHI nodes if its scev is SCEVUnknown
AbandonedPublic

Authored by shchenz on Apr 1 2020, 4:20 AM.

Details

Summary

This fixes a bug related to LSR PHI node elimination.

In the touching case, LSR should not eliminate %lsr.iv30, it is not congruent with %lsr.iv99. Their start value are not same.
But for now, Scalar Evolution returns same SCEVUnknown SCEV to them. This should be a bug for scalar evolution.

%scevgep26 = getelementptr [0 x %_elem_type_of_ap], [0 x %_elem_type_of_ap]* %.ap, i64 0, i64 28
%scevgep2627 = bitcast %_elem_type_of_ap* %scevgep26 to [0 x %_elem_type_of_ap]*
%lsr.iv30 = phi [0 x %_elem_type_of_ap]* [ %24, %_scf_2_skip_ ], [ %scevgep2627, %_loop_1_do_.lr.ph ]

%scevgep97 = getelementptr [0 x %_elem_type_of_ap], [0 x %_elem_type_of_ap]* %.ap, i64 0, i64 -1
%scevgep9798 = bitcast %_elem_type_of_ap* %scevgep97 to [0 x %_elem_type_of_ap]*
%lsr.iv99 = phi [0 x %_elem_type_of_ap]* [ %24, %_scf_2_skip_ ], [ %scevgep9798, %_loop_1_do_.lr.ph ]

This patch solves the issue when Scalar Evolution wrongly returns the same SCEVUnknown SCEV object for two Values.

But of course, we should find out the bug inside scalar evolution and fix it there.
Here we make some protection when Scalar Evolution gets some bug and will meet functionality issues.

Diff Detail

Event Timeline

shchenz created this revision.Apr 1 2020, 4:20 AM
shchenz updated this revision to Diff 254164.Apr 1 2020, 4:25 AM
fhahn added a subscriber: fhahn.Apr 1 2020, 4:29 AM

I think it would be helpful to describe what goes wrong in the patch description.

I feel like the patch doesn't actually describe what the problem is, or why giving up on SCEVUnknown resolves (hides?) it.

shchenz edited the summary of this revision. (Show Details)Apr 1 2020, 5:20 AM
samparker added inline comments.Apr 1 2020, 7:11 AM
llvm/lib/Analysis/ScalarEvolutionExpander.cpp
2040

From your description of the problem, can we just check the incoming values of the phis too?

shchenz marked 2 inline comments as done.Apr 1 2020, 6:53 PM
shchenz added inline comments.
llvm/lib/Analysis/ScalarEvolutionExpander.cpp
2040

I think we should not check the incoming value of the phi from loop preheader to decide whether we should eliminate the PHI. SCEV for the phi should be the only factor to do this. Reason why it checks incoming value from loop latch is to eliminate iv.inc in loop latch early. Hope I get a right understanding here. Thanks for your comments Sam

shchenz abandoned this revision.Apr 2 2020, 3:10 AM
shchenz marked an inline comment as done.

We decide to fix it in scalar evolution. I will abandon this patch.