[Mlir-commits] [mlir] [mlir][arith] Fix bug in `arith.bitcast` canonicalizer (PR #148795)
Matthias Springer
llvmlistbot at llvm.org
Tue Jul 15 01:13:50 PDT 2025
https://github.com/matthias-springer updated https://github.com/llvm/llvm-project/pull/148795
>From 70daffc44f6a070f503f2b72bfd159ab9746c160 Mon Sep 17 00:00:00 2001
From: Matthias Springer <me at m-sp.org>
Date: Tue, 15 Jul 2025 07:24:59 +0000
Subject: [PATCH] [mlir][arith] Fix bug in `arith.bitcast` canonicalizer
---
mlir/lib/Dialect/Arith/IR/ArithCanonicalization.td | 4 ++--
mlir/test/Dialect/Arith/canonicalize.mlir | 12 ++++++++++++
2 files changed, 14 insertions(+), 2 deletions(-)
diff --git a/mlir/lib/Dialect/Arith/IR/ArithCanonicalization.td b/mlir/lib/Dialect/Arith/IR/ArithCanonicalization.td
index 64eccc76a6642..4558d827e8563 100644
--- a/mlir/lib/Dialect/Arith/IR/ArithCanonicalization.td
+++ b/mlir/lib/Dialect/Arith/IR/ArithCanonicalization.td
@@ -313,9 +313,9 @@ def IndexCastUIOfExtUI :
// BitcastOp
//===----------------------------------------------------------------------===//
-// bitcast(bitcast(x)) -> x
+// bitcast(type1, bitcast(type2, x)) -> bitcast(type1, x)
def BitcastOfBitcast :
- Pat<(Arith_BitcastOp (Arith_BitcastOp $x)), (replaceWithValue $x)>;
+ Pat<(Arith_BitcastOp (Arith_BitcastOp $x)), (Arith_BitcastOp $x)>;
//===----------------------------------------------------------------------===//
// ExtSIOp
diff --git a/mlir/test/Dialect/Arith/canonicalize.mlir b/mlir/test/Dialect/Arith/canonicalize.mlir
index 076f3a99cd393..3d5a46d13e59d 100644
--- a/mlir/test/Dialect/Arith/canonicalize.mlir
+++ b/mlir/test/Dialect/Arith/canonicalize.mlir
@@ -1940,6 +1940,18 @@ func.func @bitcastPoisonFPtoI() -> i32 {
// -----
+// CHECK-LABEL: func @bitcastChain(
+// CHECK-SAME: %[[arg:.*]]: i16)
+// CHECK: %[[cast:.*]] = arith.bitcast %[[arg]] : i16 to f16
+// CHECK: return %[[cast]]
+func.func @bitcastChain(%arg: i16) -> f16 {
+ %0 = arith.bitcast %arg : i16 to bf16
+ %1 = arith.bitcast %0 : bf16 to f16
+ return %1 : f16
+}
+
+// -----
+
// CHECK-LABEL: test_maxsi
// CHECK-DAG: %[[C0:.+]] = arith.constant 42
// CHECK-DAG: %[[MAX_INT_CST:.+]] = arith.constant 127
More information about the Mlir-commits
mailing list