[llvm] [CodeGen] Fix MachineInstr::isSafeToMove handling of inline asm. (PR #126807)

Eli Friedman via llvm-commits llvm-commits at lists.llvm.org
Tue Feb 11 22:02:51 PST 2025


efriedma-quic wrote:

Making inline asm "speculatable" by default seems like it has weird effects in all sorts of scenarios:

- You can't guard an instruction which is only valid on some CPUs with a runtime check.  For example, if you use cpuid.h to check whether an instruction is legal, you can only use the instruction in a volatile asm.
- You can't use an instruction which is only valid with certain operands, because speculation can change the operands to anything.  For example, cpuid.h is broken because it doesn't mark the asm volatile.

It's hard enough to use inline asm correctly without adding more weird edge cases.

We're not even getting much benefit from speculating inline asm, currently; we only do it in a couple obscure optimizations in the backend.  Middle-end LLVM IR analysis already treats inline asm as potentially trapping.

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


More information about the llvm-commits mailing list