This is an archive of the discontinued LLVM Phabricator instance.

[test] Fix FullUnroll.ll
ClosedPublic

Authored by aeubanks on Aug 24 2020, 1:47 PM.

Details

Summary

I believe the intention of this test added in
https://reviews.llvm.org/D71687 was to test LoopFullUnrollPass with
clang's -fno-unroll-loops, not its interaction with optnone. Loop
unrolling passes don't run under optnone/-O0.

Also added back unintentionally removed -disable-loop-unrolling from
https://reviews.llvm.org/D85578.

Diff Detail

Event Timeline

aeubanks created this revision.Aug 24 2020, 1:47 PM
Herald added a project: Restricted Project. · View Herald TranscriptAug 24 2020, 1:47 PM
aeubanks requested review of this revision.Aug 24 2020, 1:47 PM

The code has a pragma to turn on loop unrolling. I actually did want to check with optnone.

The code has a pragma to turn on loop unrolling. I actually did want to check with optnone.

But the pragmas don't have an effect for -O0 in both the legacy and new PMs. And the legacy PM skipped loop unrolling on all optnone functions: https://github.com/llvm/llvm-project/blob/c1d25e9a82554aa580b3cc0b97fc5c7db8164042/llvm/lib/Transforms/Scalar/LoopUnrollPass.cpp#L1231. So the NPM pass probably also should.

$ cat /tmp/a.c
void b();

void a() {
#pragma clang loop unroll(full)
        for (int i = 0; i < 50; i++) {
                b();
        }
}
$ ./build_debug/bin/clang -S -emit-llvm /tmp/a.c -O0 -o -
... not unrolled LLVM IR
$ ./build_debug/bin/clang -S -emit-llvm /tmp/a.c -O0 -o - -fexperimental-new-pass-manager
... not unrolled LLVM IR
$ ./build_debug/bin/clang -S -emit-llvm /tmp/a.c -O1 -o -
... unrolled LLVM IR
$ ./build_debug/bin/clang -S -emit-llvm /tmp/a.c -O1 -o - -fexperimental-new-pass-manager
... unrolled LLVM IR

I don't think your statement matches what I was seeing. I may have
constructed the testcase poorly, but there were differences being shown.
Also keep in mind that your clang run is testing what I've already fixed. :)

Happy to work with you on a testcase here, but I don't have time this week.

rnk added a subscriber: rnk.Sep 16 2020, 1:41 PM

Here is the sequence of what happened as I understand it:

  • D71687 is intended to fix the full loop unrolling pragma with the NPM at -O1. The accompanying clang test covers this.
  • D71687 also adds an LLVM IR test. It is an integration test: it started from unoptimized IR and ran the full -O1 NPM pipeline. The IR happens to contain optnone. Maybe that was unintentional, since one used to be able to run clang foo.c -emit-llvm -o - | opt -O1 -S and get optimized IR. Now clang applies the optnone attribute, and that no longer works.
  • D85578 made the IR test more targeted: now it only runs the full unrolling pass instead of the O1 pipeline.

There is value in integration tests, so maybe the thing to do is to bring back the IR integration test in addition to this unit test. The unit test seems correct to me. If optnone is present, I would not expect the loop unroll metadata to be honored.

The code has a pragma to turn on loop unrolling. I actually did want to check with optnone.

Is that the intended behavior? Is clang supposed to fully unroll such a loop at -O0? I would expect it not to. The documentation doesn't say anything:
http://clang.llvm.org/docs/LanguageExtensions.html#extensions-for-loop-hint-optimizations

echristo accepted this revision.Sep 17 2020, 11:09 AM
In D86485#2277714, @rnk wrote:

Here is the sequence of what happened as I understand it:

  • D71687 is intended to fix the full loop unrolling pragma with the NPM at -O1. The accompanying clang test covers this.
  • D71687 also adds an LLVM IR test. It is an integration test: it started from unoptimized IR and ran the full -O1 NPM pipeline. The IR happens to contain optnone. Maybe that was unintentional, since one used to be able to run clang foo.c -emit-llvm -o - | opt -O1 -S and get optimized IR. Now clang applies the optnone attribute, and that no longer works.
  • D85578 made the IR test more targeted: now it only runs the full unrolling pass instead of the O1 pipeline.

There is value in integration tests, so maybe the thing to do is to bring back the IR integration test in addition to this unit test. The unit test seems correct to me. If optnone is present, I would not expect the loop unroll metadata to be honored.

I think I did, but I also don't feel strongly about it one way or another.

The code has a pragma to turn on loop unrolling. I actually did want to check with optnone.

Is that the intended behavior? Is clang supposed to fully unroll such a loop at -O0? I would expect it not to. The documentation doesn't say anything:
http://clang.llvm.org/docs/LanguageExtensions.html#extensions-for-loop-hint-optimizations

*shrug* :)

I thought so, but I'm ok not. As long as we can continue to test it's fine. I'll ack this and just hope we're not removing a testing expectation at the moment. :)

This revision is now accepted and ready to land.Sep 17 2020, 11:09 AM
This revision was automatically updated to reflect the committed changes.