This is an archive of the discontinued LLVM Phabricator instance.

Value-number GVNHoist loads by result type as well as pointer address.
ClosedPublic

Authored by clin1 on Mar 25 2022, 8:44 PM.

Details

Summary

Avoids merge errors when opaque pointers are loaded into different types.

Diff Detail

Event Timeline

clin1 created this revision.Mar 25 2022, 8:44 PM
Herald added a project: Restricted Project. · View Herald TranscriptMar 25 2022, 8:44 PM
clin1 requested review of this revision.Mar 25 2022, 8:44 PM
Herald added a project: Restricted Project. · View Herald TranscriptMar 25 2022, 8:44 PM
nikic added a reviewer: nikic.Mar 26 2022, 2:35 AM
nikic added a subscriber: nikic.
nikic added inline comments.
llvm/lib/Transforms/Scalar/GVNHoist.cpp
193

The load type is not necessarily a primitive. I don't think you can get around including the full load type in the key here, otherwise you risk collisions.

llvm/test/Transforms/GVNHoist/opaque-diff-type.ll
2

Use update_test_checks.py please.

Allen added a subscriber: Allen.Mar 26 2022, 2:41 AM
jcranmer-intel added inline comments.Mar 28 2022, 8:27 AM
llvm/lib/Transforms/Scalar/GVNHoist.cpp
192

I'm not sure this is true for pointers in different address spaces.

clin1 added inline comments.Mar 28 2022, 11:11 AM
llvm/lib/Transforms/Scalar/GVNHoist.cpp
192

You're right about that... if we key off the whole type as suggested above, it will fix this problem too.

clin1 updated this revision to Diff 418677.Mar 28 2022, 12:32 PM

Widen 2nd element of key to uintptr_t, store entire Type*. Add test for different addrspaces, use update_test_checks.

One minor change, but otherwise LGTM

llvm/lib/Transforms/Scalar/GVNHoist.cpp
162

You'll want to transpose the ~ and the (uintptr_t) here.

clin1 updated this revision to Diff 418692.Mar 28 2022, 1:50 PM
jcranmer-intel accepted this revision.Mar 28 2022, 2:31 PM
This revision is now accepted and ready to land.Mar 28 2022, 2:31 PM
hiraditya accepted this revision.Mar 30 2022, 7:23 AM

GVN hoist did not have the logic for opaque pointers because opaque pointers were added later IIRC.
Thanks for fixing this!
LGTM.

This revision was landed with ongoing or failed builds.Mar 30 2022, 11:33 AM
This revision was automatically updated to reflect the committed changes.