This is an archive of the discontinued LLVM Phabricator instance.

[LoopUnroll] Double thresholds instead of increasing to pragma-unroll-threshold for llvm.loop.unroll.enable
AbandonedPublic

Authored by MaskRay on Jul 15 2021, 10:04 PM.

Details

Summary

Fix PR51084: #pragma unroll aggressively increases UP.Threshold from (150
for -O2 and 300 for -O3) to 16384. This is usually undesired. Just double the
thresholds.

Diff Detail

Event Timeline

MaskRay created this revision.Jul 15 2021, 10:04 PM
MaskRay requested review of this revision.Jul 15 2021, 10:04 PM
Herald added a project: Restricted Project. · View Herald TranscriptJul 15 2021, 10:04 PM
MaskRay edited the summary of this revision. (Show Details)Jul 15 2021, 10:07 PM

I'm not really sold on this. I suspect the fix should either be in LSR, or perhaps it's working as intended.
I guess the main problem is - is there proper documentation for #pragma clang loop unroll(enable)?

I agree with Roman, this does not seem obvious. The bug seems to be either a) an issue with LSR, or b) invalid (e.g. we obeyed a user directive which was a poor choice - but not our choice).

MaskRay abandoned this revision.EditedJul 18 2021, 3:09 PM

I agree. I wasn't aware of the semantics of unroll pragmas.

LangRef: "This metadata suggests that the loop should be fully unrolled if the trip count is known at compile time and partially unrolled if the trip count is not known at compile time."

https://clang.llvm.org/docs/LanguageExtensions.html#loop-unrolling : "If unroll(enable) is specified the unroller will attempt to fully unroll the loop if the trip count is known at compile time."

"If unroll(full) is specified the unroller will attempt to fully unroll the loop if the trip count is known at compile time identically to unroll(enable)."

Full unrolling does what the user asks, even though such a large trip count may look silly.

MaskRay edited the summary of this revision. (Show Details)Jul 18 2021, 3:11 PM