Skip to content

Incorrect loop fusion in case of a producer with self-dependence #48703

@llvmbot

Description

@llvmbot
Bugzilla Link 49359
Version unspecified
OS Linux
Reporter LLVM Bugzilla Contributor
CC @joker-eph,@bondhugula

Extended Description

Incorrect affine loop fusion occurs in case of a producer that has a self-dependence. As consumer only consumes a part of the memref produced, producer(source) cannot be deleted after the fusion.

Example below:

func @&#8203;trial(%producer : memref<32xf32>, %consumer: memref<16xf32>){
  %cst = constant 2.000000e+00 : f32
  affine.for %arg3 = 0 to 32 {
    %0 = affine.load %producer[%arg3] : memref<32xf32>
    %2 = mulf %0, %cst : f32
    affine.store %2, %producer[%arg3] : memref<32xf32>
  }
  affine.for %arg3 = 0 to 16 {
    %0 = affine.load %producer[%arg3] : memref<32xf32>
    %2 = addf %0, %cst : f32
    affine.store %2, %consumer[%arg3] : memref<16xf32>
  }
  return
}

-affine-loop-fusion results in the following result:

module  {
  func @&#8203;trial(%arg0: memref<16xf32>, %arg1: memref<32xf32>) {
    %cst = constant 2.000000e+00 : f32
    affine.for %arg2 = 0 to 32 {
      %0 = affine.load %arg1[%arg2] : memref<32xf32>
      %1 = mulf %0, %cst : f32
      affine.store %1, %arg1[%arg2] : memref<32xf32>
    }
    affine.for %arg2 = 0 to 16 {
      %0 = affine.load %arg1[%arg2] : memref<32xf32>
      %1 = mulf %0, %cst : f32
      affine.store %1, %arg1[%arg2] : memref<32xf32>
      %2 = affine.load %arg1[%arg2] : memref<32xf32>
      %3 = addf %2, %cst : f32
      affine.store %3, %arg0[%arg2] : memref<16xf32>
    }
    return
  }
}

Metadata

Metadata

Assignees

Labels

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions