This is an archive of the discontinued LLVM Phabricator instance.

[InstCombine] Freeze other uses of frozen value
ClosedPublic

Authored by nikic on May 10 2022, 8:53 AM.

Details

Summary

If there is a freeze %x, we currently replace all other uses of %x with freeze %x -- as long as they are dominated by the freeze instruction. This patch extends this behavior to cases where we did not originally dominate the use by moving the freeze instruction to the nearest common dominator.

The motivation can be seen in test @combine_and_after_freezing_uses: Canonicalizing everything to freeze %x allows folds that are based on value identity (i.e. same operand occurring in two places) to trigger. This also covers the case from D125248.

Diff Detail

Event Timeline

nikic created this revision.May 10 2022, 8:53 AM
Herald added a project: Restricted Project. · View Herald TranscriptMay 10 2022, 8:53 AM
Herald added a subscriber: hiraditya. · View Herald Transcript
nikic requested review of this revision.May 10 2022, 8:53 AM
Herald added a project: Restricted Project. · View Herald TranscriptMay 10 2022, 8:53 AM

could you also add the test from D125248 - can't hurt to have more.

llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
3838–3843

wouldn't going to the def of Op be sufficient and compile-time cheaper?

nikic added inline comments.May 10 2022, 11:35 AM
llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
3838–3843

Yes, that would work as well. The reason I went for the nearest common dominator is to avoid hoisting the freeze more than necessary, e.g. out of a loop. Though now that I write that, LICM would do that anyway, so probably that concern doesn't make sense.

nikic updated this revision to Diff 428605.May 11 2022, 3:02 AM

Insert the freeze directly after the definition of the op, rather than at the nearest common dominator of the uses.

Finding the correct insert position "directly after the def" is annoyingly tricky...

mtrofin accepted this revision.May 11 2022, 7:33 AM
This revision is now accepted and ready to land.May 11 2022, 7:33 AM
This revision was landed with ongoing or failed builds.May 11 2022, 7:47 AM
This revision was automatically updated to reflect the committed changes.