Skip to content

Commit 92caacb

Browse files
remove UB canonicalization
1 parent 04a3be8 commit 92caacb

File tree

6 files changed

+3
-41
lines changed

6 files changed

+3
-41
lines changed

mlir/include/mlir/Dialect/ControlFlow/IR/ControlFlowOps.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ include "mlir/Interfaces/SideEffectInterfaces.td"
2222
def ControlFlow_Dialect : Dialect {
2323
let name = "cf";
2424
let cppNamespace = "::mlir::cf";
25-
let dependentDialects = ["arith::ArithDialect", "ub::UBDialect"];
25+
let dependentDialects = ["arith::ArithDialect"];
2626
let description = [{
2727
This dialect contains low-level, i.e. non-region based, control flow
2828
constructs. These constructs generally represent control flow directly

mlir/include/mlir/Dialect/UB/IR/UBOps.td

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@ def UnreachableOp : UB_Op<"unreachable", [Terminator]> {
8484
}];
8585

8686
let assemblyFormat = "attr-dict";
87-
let hasCanonicalizeMethod = 1;
8887
}
8988

9089
#endif // MLIR_DIALECT_UB_IR_UBOPS_TD

mlir/lib/Dialect/ControlFlow/IR/ControlFlowOps.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -447,6 +447,8 @@ struct CondBranchTruthPropagation : public OpRewritePattern<CondBranchOp> {
447447
}
448448
};
449449

450+
/// If the destination block of a conditional branch contains only
451+
/// ub.unreachable, unconditionally branch to the other destination.
450452
struct DropUnreachableCondBranch : public OpRewritePattern<CondBranchOp> {
451453
using OpRewritePattern<CondBranchOp>::OpRewritePattern;
452454

mlir/lib/Dialect/UB/IR/UBOps.cpp

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212

1313
#include "mlir/IR/Builders.h"
1414
#include "mlir/IR/DialectImplementation.h"
15-
#include "mlir/IR/PatternMatch.h"
1615
#include "llvm/ADT/TypeSwitch.h"
1716

1817
#include "mlir/Dialect/UB/IR/UBOpsDialect.cpp.inc"
@@ -58,33 +57,8 @@ Operation *UBDialect::materializeConstant(OpBuilder &builder, Attribute value,
5857
return nullptr;
5958
}
6059

61-
//===----------------------------------------------------------------------===//
62-
// PoisonOp
63-
//===----------------------------------------------------------------------===//
64-
6560
OpFoldResult PoisonOp::fold(FoldAdaptor /*adaptor*/) { return getValue(); }
6661

67-
//===----------------------------------------------------------------------===//
68-
// UnreachableOp
69-
//===----------------------------------------------------------------------===//
70-
71-
LogicalResult UnreachableOp::canonicalize(UnreachableOp unreachableOp,
72-
PatternRewriter &rewriter) {
73-
Block *block = unreachableOp->getBlock();
74-
if (llvm::hasSingleElement(*block))
75-
return rewriter.notifyMatchFailure(
76-
unreachableOp, "unreachable op is the only operation in the block");
77-
78-
// Erase all other operations in the block. They must be dead.
79-
for (Operation &op : llvm::make_early_inc_range(*block)) {
80-
if (&op == unreachableOp.getOperation())
81-
continue;
82-
op.dropAllUses();
83-
rewriter.eraseOp(&op);
84-
}
85-
return success();
86-
}
87-
8862
#include "mlir/Dialect/UB/IR/UBOpsInterfaces.cpp.inc"
8963

9064
#define GET_ATTRDEF_CLASSES

mlir/test/Dialect/ControlFlow/canonicalize.mlir

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -644,7 +644,6 @@ func.func @drop_unreachable_branch_1(%c: i1) {
644644
"test.foo"() : () -> ()
645645
return
646646
^bb2:
647-
"test.bar"() : () -> ()
648647
ub.unreachable
649648
}
650649

@@ -653,9 +652,7 @@ func.func @drop_unreachable_branch_1(%c: i1) {
653652
func.func @drop_unreachable_branch_2(%c: i1) {
654653
cf.cond_br %c, ^bb1, ^bb2
655654
^bb1:
656-
"test.foo"() : () -> ()
657655
ub.unreachable
658656
^bb2:
659-
"test.bar"() : () -> ()
660657
ub.unreachable
661658
}

mlir/test/Dialect/UB/canonicalize.mlir

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,3 @@ func.func @merge_poison() -> (i32, i32) {
99
%1 = ub.poison : i32
1010
return %0, %1 : i32, i32
1111
}
12-
13-
// -----
14-
15-
// CHECK-LABEL: func @drop_ops_before_unreachable()
16-
// CHECK-NEXT: ub.unreachable
17-
func.func @drop_ops_before_unreachable() {
18-
"test.foo"() : () -> ()
19-
"test.bar"() : () -> ()
20-
ub.unreachable
21-
}

0 commit comments

Comments
 (0)