This is an archive of the discontinued LLVM Phabricator instance.

[GVN] Refactor findDominatingLoad function
ClosedPublic

Authored by kachkov98 on Jan 13 2023, 5:21 AM.

Details

Summary

Improve findDominatingLoad implementation:

  1. Result is saved into gvn::AvailableValue struct
  2. Search is done in extended BB (while there is a single predecessor or limit is reached)

Diff Detail

Event Timeline

kachkov98 created this revision.Jan 13 2023, 5:21 AM
Herald added a project: Restricted Project. · View Herald TranscriptJan 13 2023, 5:21 AM
Herald added a subscriber: hiraditya. · View Herald Transcript
kachkov98 requested review of this revision.Jan 13 2023, 5:21 AM
Herald added a project: Restricted Project. · View Herald TranscriptJan 13 2023, 5:21 AM
kachkov98 updated this revision to Diff 489544.Jan 16 2023, 6:50 AM

Rebase
Split pre-commit test

nikic added inline comments.Jan 17 2023, 7:03 AM
llvm/lib/Transforms/Scalar/GVN.cpp
201

clobbered

1128

Can you please add a test where the loads have the same size but different types? I think you need to compare pointer and type here, not location.

llvm/test/Transforms/GVN/PRE/pre-load-through-select.ll
80

Precommit test please.

kachkov98 updated this revision to Diff 489848.Jan 17 2023, 8:54 AM

Check that load types are matched (add negative test for that)

kachkov98 added inline comments.Jan 17 2023, 9:01 AM
llvm/lib/Transforms/Scalar/GVN.cpp
1128

Added check that types are the same, in future cast instruction can be generated for such cases (there is also posibility to generate shift + truncate if found load has bigger memory location that is fully covering the needed MemLoc). Memory location instead of pointer value is used to refine clobber check with TBAA (location also stores AA tags)

nikic accepted this revision.Jan 19 2023, 6:06 AM

LGTM

llvm/lib/Transforms/Scalar/GVN.cpp
1125

It would be better to create a BatchAAResults instance before the loop.

This revision is now accepted and ready to land.Jan 19 2023, 6:06 AM
This revision was landed with ongoing or failed builds.Jan 20 2023, 12:54 AM
This revision was automatically updated to reflect the committed changes.
kachkov98 marked an inline comment as done.Jan 20 2023, 12:58 AM

Thank you for the reviews!

uabelho added inline comments.
llvm/lib/Transforms/Scalar/GVN.cpp
1123

This limit and the fact that we iterate over all instructions in the BB (including debug instructions/intrinsics) unfortunately makes GVN behave in different ways depending on if we have debug information present or not.

This can be seen with
opt "-passes=gvn" bbi-86242.ll -S -o -

If we remove the debug intrinsics from the input we see that GVN does more changes than with the debug stuff present
(the input can probably be reduced a lot if we pass -gvn-max-num-visited-insts=<something small> to opt).

kachkov98 added inline comments.Sep 11 2023, 9:37 AM
llvm/lib/Transforms/Scalar/GVN.cpp
1123

Thank you for the report! I've created PR to fix it: https://github.com/llvm/llvm-project/pull/65977