|
18 | 18 | #include "mlir/Dialect/LLVMIR/FunctionCallUtils.h" |
19 | 19 | #include "mlir/Dialect/LLVMIR/LLVMDialect.h" |
20 | 20 | #include "mlir/Dialect/MemRef/IR/MemRef.h" |
| 21 | +#include "mlir/Dialect/MemRef/Utils/MemRefUtils.h" |
21 | 22 | #include "mlir/Dialect/Vector/IR/VectorOps.h" |
22 | 23 | #include "mlir/Dialect/Vector/Interfaces/MaskableOpInterface.h" |
23 | 24 | #include "mlir/Dialect/Vector/Transforms/LoweringPatterns.h" |
@@ -223,16 +224,6 @@ static void replaceLoadOrStoreOp(vector::MaskedStoreOp storeOp, |
223 | 224 | storeOp, adaptor.getValueToStore(), ptr, adaptor.getMask(), align); |
224 | 225 | } |
225 | 226 |
|
226 | | -/// Returns true if all strides of `memRefTy` are static and non-negative. A |
227 | | -/// negative (or dynamic, hence unknown-sign) stride would make `mul nuw` on the |
228 | | -/// index arithmetic wrap, so `nuw` must not be emitted in that case. |
229 | | -static bool hasNonNegativeStrides(MemRefType memRefTy) { |
230 | | - auto [strides, offset] = memRefTy.getStridesAndOffset(); |
231 | | - return llvm::all_of(strides, [](int64_t stride) { |
232 | | - return !ShapedType::isDynamic(stride) && stride >= 0; |
233 | | - }); |
234 | | -} |
235 | | - |
236 | 227 | /// Conversion pattern for a vector.load, vector.store, vector.maskedload, and |
237 | 228 | /// vector.maskedstore. |
238 | 229 | template <class LoadOrStoreOp> |
@@ -283,10 +274,12 @@ class VectorLoadStoreConversion : public ConvertOpToLLVMPattern<LoadOrStoreOp> { |
283 | 274 | "vector.load/store requires unit trailing memref stride"); |
284 | 275 | if (enableGEPInboundsNuw) { |
285 | 276 | noWrapFlags = noWrapFlags | LLVM::GEPNoWrapFlags::inbounds; |
286 | | - // `nuw` additionally requires non-negative strides; skip it when the |
287 | | - // memref has dynamic or negative strides to avoid emitting poison. |
288 | | - if (hasNonNegativeStrides(memRefTy)) |
289 | | - noWrapFlags = noWrapFlags | LLVM::GEPNoWrapFlags::nuw; |
| 277 | + |
| 278 | + // `nuw` additionally requires non-negative strides. |
| 279 | + assert( |
| 280 | + !(memref::hasNegativeStaticStride(memRefTy)) && |
| 281 | + "Invalid MemRef type - should have been rejected by Op verifier."); |
| 282 | + noWrapFlags = noWrapFlags | LLVM::GEPNoWrapFlags::nuw; |
290 | 283 | } |
291 | 284 | } |
292 | 285 | auto vtype = cast<VectorType>( |
|
0 commit comments