Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions mlir/lib/Dialect/Arith/IR/ArithOps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
22 changes: 22 additions & 0 deletions mlir/test/Dialect/Arith/canonicalize.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down