[Mlir-commits] [mlir] [MLIR] Erase unreachable blocks before applying patterns in the greedy rewriter (PR #153957)
Matthias Springer
llvmlistbot at llvm.org
Sat Aug 16 11:21:21 PDT 2025
================
@@ -3363,3 +3363,18 @@ func.func @bf16_fma(%arg0: vector<32x32x32xbf16>, %arg1: vector<32x32x32xbf16>,
}
}
#-}
+
+// CHECK-LABEL: func @unreachable()
+// CHECK-NEXT: return
+// CHECK-NOT: arith
+func.func @unreachable() {
+ return
+^unreachable:
+ %c1_i64 = arith.constant 1 : i64
+ // This self referencing operation is legal in an unreachable block.
+ // Many patterns are unsafe with respect to this kind of situation,
+ // check that we don't infinite loop here.
+ %add = arith.addi %add, %c1_i64 : i64
----------------
matthias-springer wrote:
Interesting. The moment a block is unreachable, we completely turn off all dominance checking. It's basically like a graph region from that point on. This IR also verifies:
```mlir
func.func @unreachable() {
return
^unreachable:
%add = arith.addi %add, %c1_i64 : i64
%c1_i64 = arith.constant 1 : i64
cf.br ^unreachable
}
```
> One of the reason why this is really useful is that it preserves the ability to perform local transformation without having to look for "effects at a distance".
I don't follow. When you do a local transformation, you don't know that you are operating on unreachable IR. RAUW etc. must be guarded with extra checks to ensure that no dominance violations are created.
https://github.com/llvm/llvm-project/pull/153957
More information about the Mlir-commits
mailing list