This is an archive of the discontinued LLVM Phabricator instance.

[NewGVN] Don't ignore poison in cyclic PHIs
Needs ReviewPublic

Authored by ManuelJBrito on Aug 18 2023, 5:57 AM.

Details

Reviewers
asbirlea
nlopes
Summary

NewGVN gets stuck in a infinite loop for the following test case.

define void @foo() {
  br label %1

1: 
  %2 = phi i32 [ %3, %1 ], [ undef, %0 ]
  %3 = lshr i32 %2, 973496514
  br label %1

With the following steps:

%2 -> undef (edge <%1, %1> is initially unreachable)
%3 -> 0 ; start of evaluation loop
%2 -> phi [0, undef]
%3 -> poison
%2 -> phi [poison, undef] -> undef 
%3 -> 0
; repeat

The problem here is that poison and undef simplify differently and we have a cyclic dependency, so the value numbering never converges.
Not ignoring the poison breaks the cycle.

Diff Detail

Event Timeline

ManuelJBrito created this revision.Aug 18 2023, 5:57 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 18 2023, 5:57 AM
ManuelJBrito requested review of this revision.Aug 18 2023, 5:57 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 18 2023, 5:57 AM
nlopes added inline comments.Aug 18 2023, 6:11 AM
llvm/test/Transforms/NewGVN/cycle_poison.ll
8

this could be folded to just undef.

16

can the test case have a terminating loop pls?
non-terminating loops are evil for verification and semantics-wise.