Skip to content

[MLIR] normalize-memrefs: Ilegal IR on memref.load/memref.store #111646

Open
@mgehre-amd

Description

@mgehre-amd

-normalize-memrefs on

#map = affine_map<(d0, d1) -> (d1, d0)>
func.func @forward(%arg0: index, %arg1: index) {
    %alloc = memref.alloc() : memref<85x40xf32, #map>
    %8 = memref.load %alloc[%arg0, %arg1] : memref<85x40xf32, #map>
    return
}

produces

  func.func @forward(%arg0: index, %arg1: index) {
    %alloc = memref.alloc() : memref<40x85xf32>
    %0 = memref.load %alloc[%arg0, %arg1] : memref<40x85xf32>
    return
  }

where the indices into %alloc within the memref.load have not been swapped as they should be.
I would expect the result to be

  func.func @forward(%arg0: index, %arg1: index) {
    %alloc = memref.alloc() : memref<40x85xf32>
    %0 = memref.load %alloc[%arg1, %arg0] : memref<40x85xf32>
    return
  }

As comparison, applying this to the same IR with affine.load:

func.func @affine(%arg0: index, %arg1: index) {
    %alloc = memref.alloc() : memref<85x40xf32, #map>
    %8 = affine.load %alloc[%arg0, %arg1] : memref<85x40xf32, #map>
    return
}

results in a correct swap of the indices:

  func.func @affine(%arg0: index, %arg1: index) {
    %alloc = memref.alloc() : memref<40x85xf32>
    %0 = affine.load %alloc[symbol(%arg1), symbol(%arg0)] : memref<40x85xf32>
    return
  }

Reproducer: https://godbolt.org/z/5Pffq5fKP

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugIndicates an unexpected problem or unintended behaviormlir:memref

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions