This is an archive of the discontinued LLVM Phabricator instance.

[PowerPC] Check if the latch block is in the value list for the PHI before get the incoming value.
ClosedPublic

Authored by Esme on Mar 5 2023, 8:44 PM.

Details

Summary

Fixes #60990.
There is a crash reported during Running pass 'Prepare loop for ppc preferred instruction forms'. The crash occurs in 32bit PowerPC.

Diff Detail

Event Timeline

Esme created this revision.Mar 5 2023, 8:44 PM
Esme requested review of this revision.Mar 5 2023, 8:44 PM
Herald added a project: Restricted Project. · View Herald TranscriptMar 5 2023, 8:44 PM
shchenz added inline comments.Mar 6 2023, 2:37 AM
llvm/test/CodeGen/PowerPC/loop-instr-form-non-inc.ll
6

This is a reduced case from bugpoint:

define dso_local void @test_no_inc() local_unnamed_addr align 2 {
entry:
  %call = tail call noundef i32 @_ZN1e1fEv()
  %cmp10 = icmp sgt i32 %call, 0
  br label %for.cond

for.cond:                                         ; preds = %for.cond.cleanup, %entry
  %g.0 = phi i32 [ 1, %entry ], [ %g.1.lcssa, %for.cond.cleanup ]
  br i1 %cmp10, label %for.body.preheader, label %for.cond.cleanup

for.body.preheader:                               ; preds = %for.cond
  %0 = add i32 %call, %g.0
  br label %for.cond.cleanup

for.cond.cleanup:                                 ; preds = %for.body.preheader, %for.cond
  %g.1.lcssa = phi i32 [ %g.0, %for.cond ], [ %0, %for.body.preheader ]
  %arrayidx5 = getelementptr inbounds i8, ptr null, i32 %g.1.lcssa
  store i8 0, ptr %arrayidx5, align 1
  br label %for.cond
}

declare noundef i32 @_ZN1e1fEv() local_unnamed_addr

This should be able to further reduce, for example, using a parameter for %call, so that we can remove the external function call. And also we can add nounwind to the function, so that the cfi related instructions will not be generated.

Esme updated this revision to Diff 502924.Mar 6 2023, 10:07 PM

Address comment.

shchenz accepted this revision as: shchenz.Mar 7 2023, 5:33 PM

LGTM. Thank you for the fix!

Please add Fixes #60990 in the summary and the commit message.

This revision is now accepted and ready to land.Mar 7 2023, 5:33 PM
Esme edited the summary of this revision. (Show Details)Mar 7 2023, 11:19 PM
This revision was landed with ongoing or failed builds.Mar 7 2023, 11:21 PM
This revision was automatically updated to reflect the committed changes.