This is an archive of the discontinued LLVM Phabricator instance.

[LoopVectorize] use IR fast-math-flags exclusively (not function attributes)
ClosedPublic

Authored by spatel on Jan 26 2021, 9:13 AM.

Details

Summary

I am trying to untangle the fast-math-flags propagation logic in the vectorizers (see a6f022127 for SLP).

The loop vectorizer has a mix of checking FP function attributes, IR-level FMF, and just wrong assumptions.

I am trying to avoid regressions while fixing this, and I think the IR-level logic is good enough for that, but it's hard to say for sure. This would be the 1st step in the clean-up.

The existing test that I changed to include 'fast' actually shows a miscompile: the function only had the equivalent of nnan, but we created new instructions that had fast (all FMF set). This is similar to the example in https://llvm.org/PR35538

Diff Detail

Event Timeline

spatel created this revision.Jan 26 2021, 9:13 AM
spatel requested review of this revision.Jan 26 2021, 9:13 AM
Herald added a project: Restricted Project. · View Herald TranscriptJan 26 2021, 9:13 AM
Herald added a subscriber: vkmr. · View Herald Transcript

Should InductionDescriptor::hasUnsafeAlgebra be using isFast, or can it be something more precise? Just reassoc or does it need NoNan for some reason? Any others like NoInf?

I don't have a strong reason to think that is necessary though. This sounds fine to me as most of it is an NFC, with the only difference being the FP induction change. Removing NoNaN from VPReductionRecipe is nice now that they can come from the RecurrenceDesc.

Should InductionDescriptor::hasUnsafeAlgebra be using isFast, or can it be something more precise? Just reassoc or does it need NoNan for some reason? Any others like NoInf?

Good question - if we want to be more precise (and we do!), it will depend on the type of induction (RecurKind). I'd make that a follow-up patch to reduce change/risk.
For fmul/fadd, we should require reassoc and to be safer nsz (I don't think nnan is actually necessary because reassoc covers that).
For fmin/fmax, we should require nnan and nsz. We may want to update the variable naming to better indicate exactly what we mean by "UnsafeAlgebra" - that's a leftover from before the creation of FMF I think.
There's an additional complication for fmin/fmax in that we don't have a complete story for FMF propagation on fcmp/select yet. We'll probably need to mildly hack around that to preserve existing optimizations.

dmgreen accepted this revision.Jan 27 2021, 8:09 AM

Sounds good. This LGTM then.

This revision is now accepted and ready to land.Jan 27 2021, 8:09 AM