This is an archive of the discontinued LLVM Phabricator instance.

[GlobalISel] Translate <1 x N> getelementptrs to scalar G_PTR_ADDs
ClosedPublic

Authored by paquette on Jul 1 2021, 2:05 PM.

Details

Summary

In IRTranslator::translateGetElementPtr, when we run into a vector gep with some scalar operands, we try to normalize those operands using buildSplatVector.

This is fine except for when the getelementptr has a <1 x N> type. In that case it is treated as a scalar. If we run into one of these then every call to

// With VectorWidth = 1
LLT::fixed_vector(VectorWidth, PtrTy)

will assert.

Here's an example (equivalent to the added testcase):

https://godbolt.org/z/hGsTnMYdW

llc: llvm/include/llvm/Support/LowLevelTypeImpl.h:67: static llvm::LLT llvm::LLT::vector(llvm::ElementCount, llvm::LLT): Assertion `!EC.isScalar() && "invalid number of vector elements"' failed.

To get around this, this patch adds a variable, WantSplatVector, which is true when our vector type ought to actually be represented using a vector. When it's false, we'll translate as a scalar. This checks if VectorWidth > 1.

This fixes this bug: https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=35496

Diff Detail

Event Timeline

paquette created this revision.Jul 1 2021, 2:05 PM
paquette requested review of this revision.Jul 1 2021, 2:05 PM
Herald added a project: Restricted Project. · View Herald TranscriptJul 1 2021, 2:05 PM
Herald added a subscriber: wdng. · View Herald Transcript
aemerson accepted this revision.Jul 1 2021, 2:11 PM
This revision is now accepted and ready to land.Jul 1 2021, 2:11 PM