forked from OSchip/llvm-project
LoopAnalysis: isContiguousAccess fail gracefully
Existing implementation of isContiguousAccess asserts that one of the function arguments is within certain range, depending on another parameter. However, the value of this argument may come from outside, in particular in the loop vectorization pass it may come from command line arguments. This leads to 'mlir-opt' crashing on an assertion depending on flags. Handle the error gracefully by reporting error returning a negative result instead. This negative result prevents any further transformation by the vectorizer so the IR remains valid. PiperOrigin-RevId: 227029496
This commit is contained in:
parent
057984d05d
commit
a63f440601
|
@ -197,6 +197,11 @@ static bool isContiguousAccess(const MLValue &iv, const LoadOrStoreOp &memoryOp,
|
|||
std::is_same<LoadOrStoreOp, StoreOp>::value,
|
||||
"Must be called on either const LoadOp & or const StoreOp &");
|
||||
auto memRefType = memoryOp.getMemRefType();
|
||||
if (fastestVaryingDim >= memRefType.getRank()) {
|
||||
memoryOp.emitError("fastest varying dim out of bounds");
|
||||
return false;
|
||||
}
|
||||
|
||||
auto layoutMap = memRefType.getAffineMaps();
|
||||
// TODO(ntv): remove dependence on Builder once we support non-identity
|
||||
// layout map.
|
||||
|
@ -207,11 +212,9 @@ static bool isContiguousAccess(const MLValue &iv, const LoadOrStoreOp &memoryOp,
|
|||
b.getMultiDimIdentityMap(layoutMap[0].getNumDims())))) {
|
||||
return memoryOp.emitError("NYI: non-trivial layoutMap"), false;
|
||||
}
|
||||
assert(fastestVaryingDim < memRefType.getRank());
|
||||
|
||||
auto indices = memoryOp.getIndices();
|
||||
// TODO(clattner): should iterator_range have a size method?
|
||||
auto numIndices = indices.end() - indices.begin();
|
||||
auto numIndices = llvm::size(indices);
|
||||
unsigned d = 0;
|
||||
for (auto index : indices) {
|
||||
if (fastestVaryingDim == (numIndices - 1) - d++) {
|
||||
|
|
Loading…
Reference in New Issue