This is an archive of the discontinued LLVM Phabricator instance.

GVNSink: add test to show GVN-aware sinking
AbandonedPublic

Authored by artagnon on Jul 27 2023, 10:20 AM.

Details

Summary

As a follow-up to D156451, add a test corresponding to the following
program, after running it through GVN:

void BeamFormWeights(int a[20000], int beam) {
  for (int i = 0; i < 10000; ++i) {
    if (i == beam)
      a[2 * i] = 0;
    else
      a[2 * i] = 1;
  }
}

Sinking in this particular case is particularly challenging, and can
only be done by a GVN-aware sinking pass.

Diff Detail

Event Timeline

artagnon created this revision.Jul 27 2023, 10:20 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 27 2023, 10:20 AM
Herald added a subscriber: StephenFan. · View Herald Transcript
artagnon requested review of this revision.Jul 27 2023, 10:20 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 27 2023, 10:20 AM
nikic added inline comments.Jul 27 2023, 2:09 PM
llvm/test/Transforms/GVNSink/gvn-awareness.ll
51

Please at least run this through SROA. The test is a weird mix of completely unoptimized IR plus a GVN replacement.

artagnon added inline comments.Jul 28 2023, 2:53 AM
llvm/test/Transforms/GVNSink/gvn-awareness.ll
51

When I run it through SROA, gvn-sink no longer works.

xbolva00 added inline comments.Jul 28 2023, 3:01 AM
llvm/test/Transforms/GVNSink/gvn-awareness.ll
51

Maybe also add phaseordering test?

If this fails to work after sroa, than this optimization will not work anyway with -O2/-O3

artagnon updated this revision to Diff 545101.Jul 28 2023, 4:35 AM

Address review comment; run test through opt pipeline until gvn-sink.

artagnon marked an inline comment as done.Jul 28 2023, 4:35 AM
artagnon added inline comments.
llvm/test/Transforms/GVNSink/gvn-awareness.ll
51

Sorry, what do you mean by a phaseordering test?

nikic added inline comments.Jul 28 2023, 6:24 AM
llvm/test/Transforms/GVNSink/gvn-awareness.ll
51

A phase ordering test checks the whole O3 pipeline. In cases like these where optimization depends on precise pass ordering, a phase ordering test ensures that the correct pass interaction is preserved going forward.

I've committed a phase ordering test for your motivating case in https://github.com/llvm/llvm-project/commit/bbe2887f5e9ca005b0f1b96c858969ee3ba646f4 and submitted D156532 for a possible fix that does not rely on GVNSink.

artagnon added inline comments.Jul 28 2023, 6:42 AM
llvm/test/Transforms/GVNSink/gvn-awareness.ll
51

Thanks a lot for this! Since the motivating example is fixed, and since gvn-sink only seems to cause regressions on benchmarks, I'm tempted to stop working on gvn-sink. Do you think we should abandon this patch?

artagnon abandoned this revision.Sep 22 2023, 4:58 AM