This is an archive of the discontinued LLVM Phabricator instance.

[GVNHoist] Don't clone allocas (PR28606)
AbandonedPublic

Authored by hans on Jul 21 2016, 1:32 PM.

Details

Summary

This fixes the tests in 32-bit Windows self-hosts (see bug).

I'm anxious to get this in as the bug is blocking the 3.9 release candidate and Windows snapshot.

Diff Detail

Event Timeline

hans updated this revision to Diff 64949.Jul 21 2016, 1:32 PM
hans retitled this revision from to [GVNHoist] Don't clone allocas (PR28606).
hans updated this object.
hans added reviewers: spop, rnk.
hans added a subscriber: llvm-commits.
majnemer added inline comments.
lib/Transforms/Scalar/GVNHoist.cpp
615–616

This should logic should go earlier, before we cloned the gep.

hans marked an inline comment as done.Jul 21 2016, 1:41 PM
hans added inline comments.
lib/Transforms/Scalar/GVNHoist.cpp
615–616

Oops, thanks!

hans updated this revision to Diff 64951.Jul 21 2016, 1:41 PM
hans marked an inline comment as done.

Address David's comment.

majnemer requested changes to this revision.Jul 21 2016, 1:56 PM
majnemer added a reviewer: majnemer.

This value cloning is still quite dangerous...

Consider:

define void @test(i1 %b, i8** %y, i8** %z) {
entry:
  %x = load volatile i8*, i8** %z
  br i1 %b, label %true, label %false

true:
  %p = getelementptr inbounds i8*, i8** %y, i32 0
  store i8* %x, i8** %p, align 4
  br label %exit

false:
  %p2 = getelementptr inbounds i8*, i8** %y, i32 0
  store i8* %x, i8** %p2, align 4
  br label %exit

exit:
  ret void
}

gvn-hoist will make this:

define void @test(i1 %b, i8** %y, i8** %z) {
entry:
  %x = load volatile i8*, i8** %z, align 4
  %0 = load volatile i8*, i8** %z, align 4
  store i8* %0, i8** %y, align 4
  br i1 %b, label %true, label %false

true:                                             ; preds = %entry
  br label %exit

false:                                            ; preds = %entry
  br label %exit

exit:                                             ; preds = %false, %true
  ret void
}

This is bad, we just cloned a volatile instruction.

To be honest, I'm not entirely sure why we must clone the value because we've already checked to see that it is available at the hoist point...

This revision now requires changes to proceed.Jul 21 2016, 1:56 PM
sebpop accepted this revision.Jul 21 2016, 1:57 PM
sebpop added a reviewer: sebpop.
sebpop added a subscriber: sebpop.

LGTM.
Thanks for beating me at fixing it ;-)

sebpop requested changes to this revision.Jul 21 2016, 2:06 PM
sebpop edited edge metadata.

To be honest, I'm not entirely sure why we must clone the value because we've already checked to see that it is available at the hoist point

Right, I think we do not need to clone the value.
I think we still need to clone a GEP as they are not hoisted without their ld/st.
As we are after the check for allOperandsAvailable on the stored value,
we should remove all the code cloning the stored value.

hans added a comment.Jul 21 2016, 2:22 PM

To be honest, I'm not entirely sure why we must clone the value because we've already checked to see that it is available at the hoist point

Right, I think we do not need to clone the value.
I think we still need to clone a GEP as they are not hoisted without their ld/st.
As we are after the check for allOperandsAvailable on the stored value,
we should remove all the code cloning the stored value.

I tried to just do that, but the hoistStores test fails:

Instruction does not dominate all uses!
  %incdec.ptr = getelementptr inbounds i16, i16* %1, i32 1
  store i16* %incdec.ptr, i16** %2, align 8

Sebastian: can you give this a shot? I probably won't get any further today.

In D22644#491959, @hans wrote:

Sebastian: can you give this a shot? I probably won't get any further today.

Yes. Thanks also for the reduced testcase.

As I was not able to update the diff, I created a new ticket:
https://reviews.llvm.org/D22652

hans abandoned this revision.Jul 22 2016, 6:15 AM

Thanks! Abandoning this one.