This is an archive of the discontinued LLVM Phabricator instance.

[LV] Make scalable-vectorization not work if there is a specified scalable pragma hint.
Needs ReviewPublic

Authored by fakepaper56 on Jul 11 2022, 1:30 AM.

Details

Summary

For issue github.com/llvm/llvm-project/issues/56462, the patch make
ForceScalableVectorization have lower priority than pragma, in other word,
ForceScalableVectorization will only work if there is no specified scalable
pragma hint.

After the patch, we could disable vectorization with -scalable-vectorization=on
by pragma vectorize_width(1, fixed).

Diff Detail

Event Timeline

fakepaper56 created this revision.Jul 11 2022, 1:30 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 11 2022, 1:30 AM
Herald added a subscriber: hiraditya. · View Herald Transcript
fakepaper56 requested review of this revision.Jul 11 2022, 1:30 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 11 2022, 1:30 AM
sdesmalen requested changes to this revision.Jul 11 2022, 3:06 AM

After this change, the behaviour no longer matches the behaviour described above on lines 118-120:

// If the metadata doesn't explicitly specify whether to enable scalable
// vectorization, then decide based on the following criteria (increasing
// level of priority):
//  - Target default
//  - Metadata width
//  - Force option (always overrides)

because it no longer overrides the loop hint if one is specified.

This revision now requires changes to proceed.Jul 11 2022, 3:06 AM

After this change, the behaviour no longer matches the behaviour described above on lines 118-120:

// If the metadata doesn't explicitly specify whether to enable scalable
// vectorization, then decide based on the following criteria (increasing
// level of priority):
//  - Target default
//  - Metadata width
//  - Force option (always overrides)

because it no longer overrides the loop hint if one is specified.

Sorry, I don't understand your idea. I think the change not only reserves the priority of the three cases but also realize the predicate "If the metadata doesn't explicitly specify whether to enable scalable".

When compiling the following example with your patch applied and passing -mllvm -scalable-vectorization=off, the loop still vectorizes using scalable vectors:

void foo(int * restrict dst, int * src, int N) {
  #pragma clang loop vectorize_width(4, scalable)
  for (int i=0; i<N; ++i)
    dst[i] = src[i] + 42;
}

The idea behind giving this flag highest priority was to give users the ability to blanket disable scalable VFs in case they find any issues, since they're still a relatively new feature compared to fixed-width vectors. e.g. https://godbolt.org/z/fE8Exjos9.

I guess it's not very common for users to write these pragmas and perhaps we want to change it such that the pragma has priority over the (force) flag. If so, it would mean changing the comment on the lines above.
@paulwalker-arm, @reames, @fhahn any thoughts/opinions on this?

@fakepaper56 Could you add a test case guarding the functional change in this patch?

Add test case and remove some dead code.

Thank @sdesmalen telling the origin intent of -scalable-vectorization=. I haven't think that before.