Skip to content

🐛 Operation folds are not modifier-aware, leaving modifier body in unexpected state after fold to identity #1678

@J4MMlE

Description

@J4MMlE

System and Environment Information

  • clang/mlir/llvm version 22.1.0-rc3
  • OS: NixOS 26.05 (Yarara), kernel 6.19.10-cachyos, x86_64
  • MQT Core: main (54c3016)

Bug Description

Folds on QCO operations (e.g. POp::fold) are not aware that the op may live inside a modifier body (e.g. qco.ctrl). When a fold reduces the op to identity, the modifier body is left containing only qco.yield - an unexpected state, causing a crash.

Steps to Reproduce

Try to compile this with mqt-cc (will segfault):

module {
    func.func @controlled-zero-phase() {
      %ctrl = qco.alloc : !qco.qubit
      %tgt  = qco.alloc : !qco.qubit
      %cst  = arith.constant 0.0 : f64
      %ctrl_1, %tgt_1 = qco.ctrl(%ctrl) targets(%t = %tgt) {
        %t_1 = qco.p(%cst) %t : !qco.qubit -> !qco.qubit
        qco.yield %t_1
      } : ({!qco.qubit}, {!qco.qubit}) -> ({!qco.qubit}, {!qco.qubit})
      qco.sink %ctrl_1 : !qco.qubit
      qco.sink %tgt_1  : !qco.qubit
      return
    }
  }

Metadata

Metadata

Assignees

Labels

MLIRAnything related to MLIRbugSomething isn't working

Type

No fields configured for Bug.

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions