Skip to content

Commit 061b777

Browse files
authored
[mlir][affine] Add dependency on UBDialect for PoisonAttr (#77691)
The folder for `AffineApplyOp` will try creating a `PoisonAttr` under certain circumstances. However, this will result in a crash if the `UBDialect` isn't loaded. This patch adds a dependency of `AffineDialect` on `UBDialect`.
1 parent 21e1bf2 commit 061b777

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

mlir/include/mlir/Dialect/Affine/IR/AffineOps.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def Affine_Dialect : Dialect {
2424
let name = "affine";
2525
let cppNamespace = "::mlir::affine";
2626
let hasConstantMaterializer = 1;
27-
let dependentDialects = ["arith::ArithDialect"];
27+
let dependentDialects = ["arith::ArithDialect", "ub::UBDialect"];
2828
}
2929

3030
// Base class for Affine dialect ops.

mlir/test/Dialect/Affine/constant-fold.mlir

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ func.func @affine_min(%variable: index) -> (index, index) {
6464
// -----
6565

6666
func.func @affine_apply_poison_division_zero() {
67-
// This is just for mlir::context to load ub dailect
67+
// This is just for mlir::context to load ub dialect
6868
%ub = ub.poison : index
6969
%c16 = arith.constant 16 : index
7070
%0 = affine.apply affine_map<(d0)[s0] -> (d0 mod (s0 - s0))>(%c16)[%c16]
@@ -81,3 +81,12 @@ func.func @affine_apply_poison_division_zero() {
8181
// CHECK-NEXT: %[[alloc:.*]] = memref.alloc(%[[poison]], %[[poison]], %[[poison]])
8282
// CHECK-NEXT: %[[load:.*]] = affine.load %[[alloc]][%[[poison]], %[[poison]], %[[poison]]] : memref<?x?x?xi1>
8383
// CHECK-NEXT: affine.store %[[load]], %alloc[%[[poison]], %[[poison]], %[[poison]]] : memref<?x?x?xi1>
84+
85+
// -----
86+
87+
// Check that this doesn't crash because the ub dialect is automatically loaded
88+
func.func @affine_apply_poison_division_zero_2() -> index {
89+
%c16 = arith.constant 16 : index
90+
%0 = affine.apply affine_map<(d0)[s0] -> (d0 mod (s0 - s0))>(%c16)[%c16]
91+
return %0 : index
92+
}

0 commit comments

Comments
 (0)