[clang] [CIR] Split side_effect into memory effects, nounwind, and willreturn (PR #223890)

Adam Smith via cfe-commits cfe-commits at lists.llvm.org
Sun Sep 20 17:58:52 PDT 2026


================
@@ -4297,7 +4297,7 @@ def CIR_FuncOp : CIR_Op<"func", [
     OptionalAttr<DictArrayAttr>:$arg_attrs,
     OptionalAttr<DictArrayAttr>:$res_attrs,
     OptionalAttr<FlatSymbolRefAttr>:$aliasee,
-    OptionalAttr<CIR_SideEffectAttr>:$side_effect,
+    OptionalAttr<CIR_MemoryEffectsAttr>:$memory_effects,
----------------
adams381 wrote:

I started the `MemoryEffectsOpInterface` follow-up and have a question before I clean it up for review.

Implementing `getEffects` on `cir.call` makes an unused `memory(none) nounwind willreturn` call trivially dead, and `cir-canonicalize` runs at every optimization level, so MLIR's greedy driver erases it.  At `-O0`:

```c
__attribute__((const)) int f(void);
void g(void) { { f(); } }
```

classic emits `call i32 @f()` and CIR now emits an empty function.  It takes the enclosing scope to trigger, since the canonicalizer's worklist reaches `cir.scope` and `cir.cleanup.scope` but not the function body directly, so `void h(void) { f(); }` still keeps its call.  LLVM deletes the same call at `-O1`, so this is CIR doing it earlier rather than doing something different.

Is that divergence acceptable as the price of the interface, or should it land with something that keeps `-O0` output matching classic?

https://github.com/llvm/llvm-project/pull/223890


More information about the cfe-commits mailing list