[Mlir-commits] [mlir] 70ec2e4 - [MLIR] Fix type incompatibility in BitcastOp fold (#125193)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Fri Jan 31 05:53:53 PST 2025
Author: Vadim Curcă
Date: 2025-01-31T14:53:47+01:00
New Revision: 70ec2e4a2bf1a17c6f57eaf30b48e6c4523be25a
URL: https://github.com/llvm/llvm-project/commit/70ec2e4a2bf1a17c6f57eaf30b48e6c4523be25a
DIFF: https://github.com/llvm/llvm-project/commit/70ec2e4a2bf1a17c6f57eaf30b48e6c4523be25a.diff
LOG: [MLIR] Fix type incompatibility in BitcastOp fold (#125193)
This commit fixes a bug in the `arith::BitcastOp::fold` function where a
poisoned constant value was incorrectly cast to `IntegerAttr`, causing a
`cast<Ty>() argument of incompatible type!` error.
Added:
Modified:
mlir/lib/Dialect/Arith/IR/ArithOps.cpp
mlir/test/Dialect/Arith/canonicalize.mlir
Removed:
################################################################################
diff --git a/mlir/lib/Dialect/Arith/IR/ArithOps.cpp b/mlir/lib/Dialect/Arith/IR/ArithOps.cpp
index 75d59ba8c1a108..8a9f223089794e 100644
--- a/mlir/lib/Dialect/Arith/IR/ArithOps.cpp
+++ b/mlir/lib/Dialect/Arith/IR/ArithOps.cpp
@@ -1761,6 +1761,10 @@ OpFoldResult arith::BitcastOp::fold(FoldAdaptor adaptor) {
if (llvm::isa<ShapedType>(resType))
return {};
+ /// Bitcast poison.
+ if (llvm::isa<ub::PoisonAttr>(operand))
+ return ub::PoisonAttr::get(getContext());
+
/// Bitcast integer or float to integer or float.
APInt bits = llvm::isa<FloatAttr>(operand)
? llvm::cast<FloatAttr>(operand).getValue().bitcastToAPInt()
diff --git a/mlir/test/Dialect/Arith/canonicalize.mlir b/mlir/test/Dialect/Arith/canonicalize.mlir
index 3a16ee3d4f8fde..e3750bb020cade 100644
--- a/mlir/test/Dialect/Arith/canonicalize.mlir
+++ b/mlir/test/Dialect/Arith/canonicalize.mlir
@@ -1843,6 +1843,28 @@ func.func @bitcastOfBitcast(%arg : i16) -> i16 {
// -----
+// CHECK-LABEL: @bitcastPoisonItoFP(
+func.func @bitcastPoisonItoFP() -> f32 {
+ // CHECK: %[[P:.+]] = ub.poison : f32
+ // CHECK: return %[[P]] : f32
+ %p = ub.poison : i32
+ %res = arith.bitcast %p : i32 to f32
+ return %res : f32
+}
+
+// -----
+
+// CHECK-LABEL: @bitcastPoisonFPtoI(
+func.func @bitcastPoisonFPtoI() -> i32 {
+ // CHECK: %[[P:.+]] = ub.poison : i32
+ // CHECK: return %[[P]] : i32
+ %p = ub.poison : f32
+ %res = arith.bitcast %p : f32 to i32
+ return %res : i32
+}
+
+// -----
+
// 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