This is an archive of the discontinued LLVM Phabricator instance.

[Analysis][LoopVectorize] do not try to form reductions of pointers
ClosedPublic

Authored by spatel on Feb 19 2021, 6:26 AM.

Details

Summary

This is a fix for https://llvm.org/PR49215 either before/after we make a verifier enhancement for vector reductions with D96904.

I'm not sure what the current thinking is for pointer math/logic in IR. We allow icmp on pointer values. Therefore, we match min/max patterns, so without this patch, the vectorizer could form a vector reduction from that sequence.

But the LangRef definitions for min/max and vector reduction intrinsics do not allow pointer types:
https://llvm.org/docs/LangRef.html#llvm-smax-intrinsic
https://llvm.org/docs/LangRef.html#llvm-vector-reduce-umax-intrinsic

So we would crash/assert at some point - either in IR verification, in the cost model, or in codegen. If we do want to allow this kind of transform, we will need to update the LangRef and all of those parts of the compiler.

Diff Detail

Event Timeline

spatel created this revision.Feb 19 2021, 6:26 AM
spatel requested review of this revision.Feb 19 2021, 6:26 AM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 19 2021, 6:26 AM
nikic accepted this revision.Feb 19 2021, 6:54 AM

LGTM. While we may want to support pointer min/max in the future (probably not worth it though), we clearly don't now, so bailing out is the right thing to do.

Just one suggestion on placement of the check.

llvm/lib/Analysis/IVDescriptors.cpp
246

Personally, I'd add an else if (RecurrenceType->isIntegerTy()) here and then else return false. This seems like the place that is making the implicit assumption that the type can only be float or int.

This revision is now accepted and ready to land.Feb 19 2021, 6:54 AM
spatel marked an inline comment as done.Feb 19 2021, 11:01 AM