This is an archive of the discontinued LLVM Phabricator instance.

[mlir][affine] Enforce each result type to match Reduction ops in affine.parallel verifier
ClosedPublic

Authored by 9Tempest on Aug 15 2023, 7:41 AM.

Details

Summary

affine.parallel will crash on --lower-affine if the corresponding result type cannot match the reduction attribute.

%128 = affine.parallel (%arg2, %arg3) = (0, 0) to (8, 7) reduce ("maxf") -> (memref<8x7xf32>) {
  %alloc_33 = memref.alloc() : memref<8x7xf32>
  affine.yield %alloc_33 : memref<8x7xf32>
}

This will crash and report a type conversion issue when we run mlir-opt --lower-affine

Assertion failed: (isa<To>(Val) && "cast<Ty>() argument of incompatible type!"), function cast, file Casting.h, line 572.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0.	Program arguments: mlir-opt --lower-affine temp.mlir
 #0 0x0000000102a18f18 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/workspacebin/mlir-opt+0x1002f8f18)
 #1 0x0000000102a171b4 llvm::sys::RunSignalHandlers() (/workspacebin/mlir-opt+0x1002f71b4)
 #2 0x0000000102a195c4 SignalHandler(int) (/workspacebin/mlir-opt+0x1002f95c4)
 #3 0x00000001be7894c4 (/usr/lib/system/libsystem_platform.dylib+0x1803414c4)
 #4 0x00000001be771ee0 (/usr/lib/system/libsystem_pthread.dylib+0x180329ee0)
 #5 0x00000001be6ac340 (/usr/lib/system/libsystem_c.dylib+0x180264340)
 #6 0x00000001be6ab754 (/usr/lib/system/libsystem_c.dylib+0x180263754)
 #7 0x0000000106864790 mlir::arith::getIdentityValueAttr(mlir::arith::AtomicRMWKind, mlir::Type, mlir::OpBuilder&, mlir::Location) (.cold.4) (/workspacebin/mlir-opt+0x104144790)
 #8 0x0000000102ba66ac mlir::arith::getIdentityValueAttr(mlir::arith::AtomicRMWKind, mlir::Type, mlir::OpBuilder&, mlir::Location) (/workspacebin/mlir-opt+0x1004866ac)
 #9 0x0000000102ba6910 mlir::arith::getIdentityValue(mlir::arith::AtomicRMWKind, mlir::Type, mlir::OpBuilder&, mlir::Location) (/workspacebin/mlir-opt+0x100486910)
#10 0x0000000104831534 (anonymous namespace)::AffineParallelLowering::matchAndRewrite(mlir::affine::AffineParallelOp, mlir::PatternRewriter&) const (/workspacebin/mlir-opt+0x102111534)
...

More details on issue 64068.

This patch updates AffineParallelOp::verify() to check each result type matches its corresponding reduction op (i.e, the result type must be a FloatType if the reduction attribute is addf)

Another possible solution is to add this checking logic in AffineParallelLowering such that it will notify a match failure instead of aborting the program only when we apply the pass -lower-affine.

This is my first revision to MLIR, so feel free to give any feedback or advice on this revision.

Diff Detail

Event Timeline

9Tempest created this revision.Aug 15 2023, 7:41 AM
9Tempest requested review of this revision.Aug 15 2023, 7:41 AM
9Tempest edited the summary of this revision. (Show Details)Aug 15 2023, 7:43 AM
mehdi_amini accepted this revision.Oct 1 2023, 2:04 PM
This revision is now accepted and ready to land.Oct 1 2023, 2:04 PM