• Given the following LLVM MLIR dialect example (example.mlir ): llvm.func @f(%arg0: i16) { %0 = llvm.mlir.constant(64 : i16) : i16 %1 = llvm.mlir.constant(32 : i16) : i16 %5 = llvm.icmp “slt” %arg0, %1 : i16 llvm.cond_br %5, ^bb1, ^bb2 ^bb1: llvm.inline_asm has_side_effects “foo_inst … • ${0}”, “i,{memory}” %1 : (i16) -> () llvm.br ^bb3 ^bb2: llvm.inline_asm has_side_effects “foo_inst … • ${0}”, “i,{memory}” %0 : (i16) -> () llvm.br ^bb3 ^bb3: // pred: ^bb1 llvm.return } if I run the following command: mlir-opt –canonicalize example.mlir I will get this: module { llvm.func @f(%arg0: i16) { %0 = llvm.mlir.constant(64 : i16) : i16 %1 = llvm.mlir.constant(32 : i16) : i16 %2 = llvm.icmp “slt” %arg0, %1 : i16 llvm.cond_br %2, ^bb1(%1 : i16), ^bb1(%0 : i16) ^bb1(%3: i16): // 2 preds: ^bb0, ^bb0 llvm.inline_asm has_side_effects “foo_inst … • ${0}”, “i,{memory}” %3 : (i16) -> () llvm.br ^bb2 ^bb2: // pred: ^bb1 llvm.return } } The problem with the code above is that when you try to lower it into LLVM IR it will produce the following: define void @f(i16 %0) { %4 = icmp slt i16 %0, 32 br i1 %4, label %5, label %8 5: ; preds = %8, %1 %6 = phi i16 [ %9, %8 ], [ 32, %1 ] call void asm sideeffect “foo_inst … • ${0}”, “i,{memory}"(i16 %6) br label %7 7: ; preds = %5 ret void 8: ; preds = %1 %9 = phi i16 [ 64, %1 ] br label %5 } which will then produce the error: error: invalid operand for inline asm constraint ‘i’ I suppose the error is produced because a phi node cannot be an op

Article Summaries:

  • The user reports a bug in LLVM’s MLIR canonicalizer: when two llvm.inline_asm operations with identical constraints are merged, the resulting operation receives its operand from a block argument that becomes a PHI node. The i constraint (immediate) cannot be satisfied by a PHI, causing a compile‑time error “invalid operand for inline asm constraint ‘i’”. The user suspects the canonicalizer ignores inline‑asm constraints and asks whether this is correct and how to fix it. The suggested workaround is to manually splice constants into the asm string or otherwise avoid merging the ops, but the user seeks confirmation and guidance.

Sources: