Skip to content

[MLIR][Affine] Canonicalizing a valid IR leads to invalid IR #128403

@bondhugula

Description

@bondhugula

Canonicalizing an IR like this leads to invalid IR. When the operands of the affine.apply here are composed into its users, the resulting IR becomes invalid. This IR itself should have been invalid, but we are missing the necessary verification check.

#map = affine_map<()[s0, s1] -> (s0 * 23 + s1)>
module {
  func.func @func1(%arg0: memref<1x23x26xi32, strided<[?, ?, ?], offset: ?>>) -> () {
    %cst = arith.constant 63.9809875 : f32
    %cst_0 = arith.constant 1.19825836E-6 : f32
    %cst_1 = arith.constant 1.18534706E-4 : f32
    %cst_2 = arith.constant 0.00226843474 : f32
    %cst_3 = arith.constant 0.00489352504 : f32
    %cst_4 = arith.constant -2.76076837E-16 : f32
    %cst_5 = arith.constant 2.00018794E-13 : f32
    %cst_6 = arith.constant -8.60467184E-11 : f32
    %cst_7 = arith.constant 5.12229725E-8 : f32
    %cst_8 = arith.constant 1.48572235E-5 : f32
    %cst_9 = arith.constant 6.37261954E-4 : f32
    %cst_10 = arith.constant 0.00489352457 : f32
    %cst_11 = arith.constant 7.99881172 : f32
    %cst_12 = arith.constant 0.000000e+00 : f32
    %alloc = memref.alloc() {alignment = 64 : i64} : memref<23x26xf32>
    affine.for %arg1 = 0 to 23 {
      affine.for %arg2 = 0 to 26 {
        %0 = math.fma %cst, %cst_4, %cst_5 : f32
        %1 = math.fma %cst, %0, %cst_6 : f32
        %2 = math.fma %cst, %1, %cst_7 : f32
        %3 = math.fma %cst, %2, %cst_8 : f32
        %4 = math.fma %cst, %3, %cst_9 : f32
        %5 = math.fma %cst, %4, %cst_10 : f32
        %6 = arith.mulf %5, %cst_11 : f32
        %7 = math.fma %cst, %cst_0, %cst_1 : f32
        %8 = math.fma %cst, %7, %cst_2 : f32
        %9 = math.fma %cst, %8, %cst_3 : f32
        %10 = arith.divf %6, %9 : f32
        affine.store %10, %alloc[%arg1, %arg2] : memref<23x26xf32>
      }
    }
    %alloc_13 = memref.alloc() {alignment = 64 : i64} : memref<1x26xf32>
    affine.for %arg1 = 0 to 1 {
      affine.for %arg2 = 0 to 23 {
        affine.for %arg3 = 0 to 26 {
          %0 = affine.apply #map()[%arg1, %arg2]
          %1 = affine.load %alloc[%0, %arg3] : memref<23x26xf32>
          %2 = affine.load %alloc_13[%arg1, %arg3] : memref<1x26xf32>
          %3 = arith.addf %1, %2 : f32
          affine.store %3, %alloc_13[%arg1, %arg3] : memref<1x26xf32>
        }
      }
    }
    return 
  }
}
bin/mlir-opt -canonicalize canonicalize.mlir 
canonicalize.mlir:40:16: error: 'affine.load' op operand cannot be used as a symbol
          %1 = affine.load %alloc[%0, %arg3] : memref<23x26xf32>
               ^
canonicalize.mlir:40:16: note: see current operation: %15 = "affine.load"(%13, %arg3, %arg1, %arg2) <{map = affine_map<(d0)[s0, s1] -> (s0 * 23 + s1, d0)>}> : (memref<23x26xf32>, index, index, index) -> f32
bin/mlir-opt -canonicalize canonicalize.mlir 
canonicalize.mlir:40:16: error: 'affine.load' op operand cannot be used as a symbol
          %1 = affine.load %alloc[%0, %arg3] : memref<23x26xf32>
               ^
canonicalize.mlir:40:16: note: see current operation: %15 = "affine.load"(%13, %arg3, %arg1, %arg2) <{map = affine_map<(d0)[s0, s1] -> (s0 * 23 + s1, d0)>}> : (memref<23x26xf32>, index, index, index) -> f32

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions