|
| 1 | +// RUN: enzymexlamlir-opt --enzyme-hlo-generate-td="patterns=factor_scalars_in_dot_general" --transform-interpreter --enzyme-hlo-remove-transform %s | FileCheck %s |
| 2 | + |
| 3 | +func.func @pass1(%arg0: tensor<10x10xf64> {enzymexla.memory_effects = []}) -> tensor<10x10xf64> attributes {enzymexla.memory_effects = []} { |
| 4 | + %0 = stablehlo.constant dense<4.0> : tensor<10x10xf64> |
| 5 | + %1 = stablehlo.multiply %0, %arg0 : tensor<10x10xf64> |
| 6 | + %2 = stablehlo.dot_general %1, %arg0, contracting_dims = [0] x [0], precision = [DEFAULT, DEFAULT] : (tensor<10x10xf64>, tensor<10x10xf64>) -> tensor<10x10xf64> |
| 7 | + return %2 : tensor<10x10xf64> |
| 8 | +} |
| 9 | + |
| 10 | +// CHECK: func.func @pass1(%arg0: tensor<10x10xf64> {enzymexla.memory_effects = []}) -> tensor<10x10xf64> attributes {enzymexla.memory_effects = []} { |
| 11 | +// CHECK-NEXT: %cst = stablehlo.constant dense<4.000000e+00> : tensor<10x10xf64> |
| 12 | +// CHECK-NEXT: %0 = stablehlo.dot_general %arg0, %arg0, contracting_dims = [0] x [0], precision = [DEFAULT, DEFAULT] : (tensor<10x10xf64>, tensor<10x10xf64>) -> tensor<10x10xf64> |
| 13 | +// CHECK-NEXT: %1 = stablehlo.multiply %cst, %0 : tensor<10x10xf64> |
| 14 | +// CHECK-NEXT: return %1 : tensor<10x10xf64> |
| 15 | +// CHECK-NEXT: } |
| 16 | + |
| 17 | +func.func @pass2(%arg0: tensor<10x10xf64> {enzymexla.memory_effects = []}) -> tensor<10x10xf64> attributes {enzymexla.memory_effects = []} { |
| 18 | + %0 = stablehlo.constant dense<4.0> : tensor<10x10xf64> |
| 19 | + %1 = stablehlo.multiply %0, %arg0 : tensor<10x10xf64> |
| 20 | + %2 = stablehlo.constant dense<2.0> : tensor<10x10xf64> |
| 21 | + %3 = stablehlo.multiply %0, %arg0 : tensor<10x10xf64> |
| 22 | + %4 = stablehlo.dot_general %1, %3, contracting_dims = [1] x [0], precision = [DEFAULT, DEFAULT] : (tensor<10x10xf64>, tensor<10x10xf64>) -> tensor<10x10xf64> |
| 23 | + return %4 : tensor<10x10xf64> |
| 24 | +} |
| 25 | + |
| 26 | +// CHECK: func.func @pass2(%arg0: tensor<10x10xf64> {enzymexla.memory_effects = []}) -> tensor<10x10xf64> attributes {enzymexla.memory_effects = []} { |
| 27 | +// CHECK-NEXT: %cst = stablehlo.constant dense<4.000000e+00> : tensor<10x10xf64> |
| 28 | +// CHECK-NEXT: %0 = stablehlo.dot_general %arg0, %arg0, contracting_dims = [1] x [0], precision = [DEFAULT, DEFAULT] : (tensor<10x10xf64>, tensor<10x10xf64>) -> tensor<10x10xf64> |
| 29 | +// CHECK-NEXT: %1 = stablehlo.multiply %cst, %cst : tensor<10x10xf64> |
| 30 | +// CHECK-NEXT: %2 = stablehlo.multiply %1, %0 : tensor<10x10xf64> |
| 31 | +// CHECK-NEXT: return %2 : tensor<10x10xf64> |
| 32 | +// CHECK-NEXT: } |
| 33 | + |
| 34 | +func.func @pass3(%arg0: tensor<10x10xf64> {enzymexla.memory_effects = []}) -> tensor<10x10xf64> attributes {enzymexla.memory_effects = []} { |
| 35 | + %0 = stablehlo.constant dense<4.0> : tensor<10x10xf64> |
| 36 | + %1 = stablehlo.multiply %0, %arg0 : tensor<10x10xf64> |
| 37 | + %2 = stablehlo.constant dense<2.0> : tensor<10x10xf64> |
| 38 | + %3 = stablehlo.transpose %arg0, dims = [1, 0] : (tensor<10x10xf64>) -> tensor<10x10xf64> |
| 39 | + %4 = stablehlo.multiply %2, %3 : tensor<10x10xf64> |
| 40 | + %5 = stablehlo.dot_general %1, %4, contracting_dims = [1] x [0], precision = [DEFAULT, DEFAULT] : (tensor<10x10xf64>, tensor<10x10xf64>) -> tensor<10x10xf64> |
| 41 | + return %5 : tensor<10x10xf64> |
| 42 | +} |
| 43 | + |
| 44 | +//CHECK: func.func @pass3(%arg0: tensor<10x10xf64> {enzymexla.memory_effects = []}) -> tensor<10x10xf64> attributes {enzymexla.memory_effects = []} { |
| 45 | +//CHECK-NEXT: %cst = stablehlo.constant dense<2.000000e+00> : tensor<10x10xf64> |
| 46 | +//CHECK-NEXT: %cst_0 = stablehlo.constant dense<4.000000e+00> : tensor<10x10xf64> |
| 47 | +//CHECK-NEXT: %0 = stablehlo.transpose %arg0, dims = [1, 0] : (tensor<10x10xf64>) -> tensor<10x10xf64> |
| 48 | +//CHECK-NEXT: %1 = stablehlo.dot_general %arg0, %0, contracting_dims = [1] x [0], precision = [DEFAULT, DEFAULT] : (tensor<10x10xf64>, tensor<10x10xf64>) -> tensor<10x10xf64> |
| 49 | +//CHECK-NEXT: %2 = stablehlo.multiply %cst_0, %cst : tensor<10x10xf64> |
| 50 | +//CHECK-NEXT: %3 = stablehlo.multiply %2, %1 : tensor<10x10xf64> |
| 51 | +//CHECK-NEXT: return %3 : tensor<10x10xf64> |
| 52 | +//CHECK-NEXT: } |
| 53 | + |
| 54 | +func.func @fail1(%arg0: tensor<10x10xf64> {enzymexla.memory_effects = []}) -> tensor<10x10xf64> attributes {enzymexla.memory_effects = []} { |
| 55 | + %0 = stablehlo.constant dense<4.0> : tensor<10x10xf64> |
| 56 | + %1 = stablehlo.multiply %0, %arg0 : tensor<10x10xf64> |
| 57 | + %2 = stablehlo.dot_general %1, %arg0, contracting_dims = [0] x [0], precision = [DEFAULT, DEFAULT] : (tensor<10x10xf64>, tensor<10x10xf64>) -> tensor<10x10xf64> |
| 58 | + %3 = stablehlo.add %2, %1 : tensor<10x10xf64> |
| 59 | + return %3 : tensor<10x10xf64> |
| 60 | +} |
| 61 | + |
| 62 | +// CHECK: func.func @fail1(%arg0: tensor<10x10xf64> {enzymexla.memory_effects = []}) -> tensor<10x10xf64> attributes {enzymexla.memory_effects = []} { |
| 63 | +// CHECK-NEXT: %cst = stablehlo.constant dense<4.000000e+00> : tensor<10x10xf64> |
| 64 | +// CHECK-NEXT: %0 = stablehlo.multiply %cst, %arg0 : tensor<10x10xf64> |
| 65 | +// CHECK-NEXT: %1 = stablehlo.dot_general %0, %arg0, contracting_dims = [0] x [0], precision = [DEFAULT, DEFAULT] : (tensor<10x10xf64>, tensor<10x10xf64>) -> tensor<10x10xf64> |
| 66 | +// CHECK-NEXT: %2 = stablehlo.add %1, %0 : tensor<10x10xf64> |
| 67 | +// CHECK-NEXT: return %2 : tensor<10x10xf64> |
| 68 | +// CHECK-NEXT: } |
0 commit comments