Skip to content

Commit cbdc185

Browse files
[mlir][arith] Fix bug in arith.bitcast canonicalizer (#148795)
`bitcast(bitcast(x))` was incorrectly folded to `x`.
1 parent 5fc844a commit cbdc185

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -313,9 +313,9 @@ def IndexCastUIOfExtUI :
313313
// BitcastOp
314314
//===----------------------------------------------------------------------===//
315315

316-
// bitcast(bitcast(x)) -> x
316+
// bitcast(type1, bitcast(type2, x)) -> bitcast(type1, x)
317317
def BitcastOfBitcast :
318-
Pat<(Arith_BitcastOp (Arith_BitcastOp $x)), (replaceWithValue $x)>;
318+
Pat<(Arith_BitcastOp (Arith_BitcastOp $x)), (Arith_BitcastOp $x)>;
319319

320320
//===----------------------------------------------------------------------===//
321321
// ExtSIOp

mlir/test/Dialect/Arith/canonicalize.mlir

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1940,6 +1940,18 @@ func.func @bitcastPoisonFPtoI() -> i32 {
19401940

19411941
// -----
19421942

1943+
// CHECK-LABEL: func @bitcastChain(
1944+
// CHECK-SAME: %[[arg:.*]]: i16)
1945+
// CHECK: %[[cast:.*]] = arith.bitcast %[[arg]] : i16 to f16
1946+
// CHECK: return %[[cast]]
1947+
func.func @bitcastChain(%arg: i16) -> f16 {
1948+
%0 = arith.bitcast %arg : i16 to bf16
1949+
%1 = arith.bitcast %0 : bf16 to f16
1950+
return %1 : f16
1951+
}
1952+
1953+
// -----
1954+
19431955
// CHECK-LABEL: test_maxsi
19441956
// CHECK-DAG: %[[C0:.+]] = arith.constant 42
19451957
// CHECK-DAG: %[[MAX_INT_CST:.+]] = arith.constant 127

0 commit comments

Comments
 (0)