diff --git a/mlir/lib/Dialect/Arith/IR/ArithOps.cpp b/mlir/lib/Dialect/Arith/IR/ArithOps.cpp index 75d59ba8c1a10..8a9f223089794 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(resType)) return {}; + /// Bitcast poison. + if (llvm::isa(operand)) + return ub::PoisonAttr::get(getContext()); + /// Bitcast integer or float to integer or float. APInt bits = llvm::isa(operand) ? llvm::cast(operand).getValue().bitcastToAPInt() diff --git a/mlir/test/Dialect/Arith/canonicalize.mlir b/mlir/test/Dialect/Arith/canonicalize.mlir index 3a16ee3d4f8fd..e3750bb020cad 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