This is an archive of the discontinued LLVM Phabricator instance.

GVN: If a branch has two identical successors, we cannot declare either dead.
ClosedPublic

Authored by pcc on Jun 25 2015, 12:52 AM.

Details

Summary

This previously caused miscompilations as a result of phi nodes receiving
undef incoming values from blocks dominated by such successors.

Diff Detail

Repository
rL LLVM

Event Timeline

pcc updated this revision to Diff 28440.Jun 25 2015, 12:52 AM
pcc retitled this revision from to GVN: If a branch has two identical successors, we cannot declare either dead..
pcc updated this object.
pcc edited the test plan for this revision. (Show Details)
pcc added a reviewer: spatel.
pcc added a subscriber: Unknown Object (MLST).
spatel accepted this revision.Jun 25 2015, 10:22 AM
spatel edited edge metadata.

I'm by no means a GVN expert, but the code change looks trivially safer, so LGTM.

I'd like to improve the test case though:

  1. Please minimize/edit to make it more obvious how this can cause a miscompile.
  2. Add a comment to explain why the test exists (something similar to the code comment should do it).

This may not be minimal, and with the 'undefs' I don't think it can actually cause a miscompile, but I whittled it down this far to see what happens before and after the patch:

define void @widget() {
entry:
br label %bb2

bb2:
%t1 = phi i64 [ 0, %entry ], [ %t5, %bb7 ]
%t2 = add i64 %t1, 1
%t3 = icmp ult i64 0, %t2
br i1 %t3, label %bb3, label %bb4

bb3:
%t4 = call i64 @f()
br label %bb4

bb4:
; CHECK-NOT: phi {{.*}} undef
%foo = phi i64 [ %t4, %bb3 ], [ 0, %bb2 ]
br i1 undef, label %bb5, label %bb6

bb5:
br i1 true, label %bb7, label %bb7

bb6:
br i1 true, label %bb7, label %bb7

bb7:
%t5 = add i64 %t1, 1
br i1 undef, label %bb2, label %bb8

bb8:
ret void

}

This revision is now accepted and ready to land.Jun 25 2015, 10:22 AM
pcc added a comment.Jun 25 2015, 11:32 AM

Thanks for working on reducing the test case! I was able to eliminate the undefinedness in the branches using a function argument. I couldn't find a way to reduce it any further though.

This revision was automatically updated to reflect the committed changes.