Skip to content

Commit 9145514

Browse files
authored
[mlir][arith] fix canonicalization of mulsi_extended for i1 (#90150)
There is the `MulSIExtendedRHSOne` canonicalization for arith.mulsi_extended that is defined as follows: `mulsi_extended(x, 1) -> [x, extsi(cmpi slt, x, 0)]`. In the implementation of this, there is a `IsScalarOrSplatOne` constraint for the second argument. However, this constraint does not correctly handle situation when multiplying i1 values. Therefore, an additional constraint has been added which checks the second argument for strict positivity. fix #88732
1 parent 85a9528 commit 9145514

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

mlir/lib/Dialect/Arith/IR/ArithCanonicalization.td

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ def MulSIExtendedToMulI :
175175
def IsScalarOrSplatOne :
176176
Constraint<And<[
177177
CPred<"succeeded(getIntOrSplatIntValue($0))">,
178+
CPred<"getIntOrSplatIntValue($0)->isStrictlyPositive()">,
178179
CPred<"*getIntOrSplatIntValue($0) == 1">]>>;
179180

180181
// mulsi_extended(x, 1) -> [x, extsi(cmpi slt, x, 0)]

mlir/test/Dialect/Arith/canonicalize.mlir

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1223,6 +1223,28 @@ func.func @mulsiExtendedOneRhsSplat(%arg0: vector<3xi32>) -> (vector<3xi32>, vec
12231223
return %low, %high : vector<3xi32>, vector<3xi32>
12241224
}
12251225

1226+
// CHECK-LABEL: @mulsiExtendedOneRhsI1
1227+
// CHECK-SAME: (%[[ARG:.+]]: i1) -> (i1, i1)
1228+
// CHECK-NEXT: %[[T:.+]] = arith.constant true
1229+
// CHECK-NEXT: %[[LOW:.+]], %[[HIGH:.+]] = arith.mulsi_extended %[[ARG]], %[[T]] : i1
1230+
// CHECK-NEXT: return %[[LOW]], %[[HIGH]] : i1, i1
1231+
func.func @mulsiExtendedOneRhsI1(%arg0: i1) -> (i1, i1) {
1232+
%one = arith.constant true
1233+
%low, %high = arith.mulsi_extended %arg0, %one: i1
1234+
return %low, %high : i1, i1
1235+
}
1236+
1237+
// CHECK-LABEL: @mulsiExtendedOneRhsSplatI1
1238+
// CHECK-SAME: (%[[ARG:.+]]: vector<3xi1>) -> (vector<3xi1>, vector<3xi1>)
1239+
// CHECK-NEXT: %[[TS:.+]] = arith.constant dense<true> : vector<3xi1>
1240+
// CHECK-NEXT: %[[LOW:.+]], %[[HIGH:.+]] = arith.mulsi_extended %[[ARG]], %[[TS]] : vector<3xi1>
1241+
// CHECK-NEXT: return %[[LOW]], %[[HIGH]] : vector<3xi1>, vector<3xi1>
1242+
func.func @mulsiExtendedOneRhsSplatI1(%arg0: vector<3xi1>) -> (vector<3xi1>, vector<3xi1>) {
1243+
%one = arith.constant dense<true> : vector<3xi1>
1244+
%low, %high = arith.mulsi_extended %arg0, %one: vector<3xi1>
1245+
return %low, %high : vector<3xi1>, vector<3xi1>
1246+
}
1247+
12261248
// CHECK-LABEL: @mulsiExtendedUnusedHigh
12271249
// CHECK-SAME: (%[[ARG:.+]]: i32) -> i32
12281250
// CHECK-NEXT: %[[RES:.+]] = arith.muli %[[ARG]], %[[ARG]] : i32

0 commit comments

Comments
 (0)