[all-commits] [llvm/llvm-project] 45e666: [Clang][inlineasm] Add special support for "rm" ou...

Bill Wendling via All-commits all-commits at lists.llvm.org
Sat Feb 14 05:02:46 PST 2026


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 45e666a8531c1148bdb170b9a120f99e1500c427
      https://github.com/llvm/llvm-project/commit/45e666a8531c1148bdb170b9a120f99e1500c427
  Author: Bill Wendling <morbo at google.com>
  Date:   2026-02-14 (Sat, 14 Feb 2026)

  Changed paths:
    M clang/lib/CodeGen/CGStmt.cpp
    M clang/test/CodeGen/asm.c
    R llvm/include/llvm/CodeGen/CallBrPrepare.h
    A llvm/include/llvm/CodeGen/InlineAsmPrepare.h
    M llvm/include/llvm/CodeGen/Passes.h
    M llvm/include/llvm/CodeGen/TargetLowering.h
    M llvm/include/llvm/IR/InlineAsm.h
    M llvm/include/llvm/InitializePasses.h
    M llvm/include/llvm/Passes/CodeGenPassBuilder.h
    M llvm/lib/CodeGen/CMakeLists.txt
    R llvm/lib/CodeGen/CallBrPrepare.cpp
    M llvm/lib/CodeGen/CodeGen.cpp
    A llvm/lib/CodeGen/InlineAsmPrepare.cpp
    M llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
    M llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.h
    M llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp
    M llvm/lib/CodeGen/TargetPassConfig.cpp
    M llvm/lib/Passes/PassBuilder.cpp
    M llvm/lib/Passes/PassRegistry.def
    M llvm/test/CodeGen/AArch64/O0-pipeline.ll
    M llvm/test/CodeGen/AArch64/O3-pipeline.ll
    M llvm/test/CodeGen/AArch64/callbr-prepare.ll
    M llvm/test/CodeGen/AMDGPU/llc-pipeline-npm.ll
    M llvm/test/CodeGen/AMDGPU/llc-pipeline.ll
    M llvm/test/CodeGen/ARM/O3-pipeline.ll
    M llvm/test/CodeGen/LoongArch/O0-pipeline.ll
    M llvm/test/CodeGen/LoongArch/opt-pipeline.ll
    M llvm/test/CodeGen/PowerPC/O0-pipeline.ll
    M llvm/test/CodeGen/PowerPC/O3-pipeline.ll
    M llvm/test/CodeGen/RISCV/O0-pipeline.ll
    M llvm/test/CodeGen/RISCV/O3-pipeline.ll
    M llvm/test/CodeGen/SPIRV/llc-pipeline.ll
    M llvm/test/CodeGen/X86/O0-pipeline.ll
    A llvm/test/CodeGen/X86/asm-constraints-rm.ll
    A llvm/test/CodeGen/X86/inline-asm-prepare-memory.ll
    M llvm/test/CodeGen/X86/inlineasm-sched-bug.ll
    M llvm/test/CodeGen/X86/llc-pipeline-npm.ll
    M llvm/test/CodeGen/X86/opt-pipeline.ll
    M llvm/tools/opt/optdriver.cpp
    M llvm/utils/gn/secondary/llvm/lib/CodeGen/BUILD.gn

  Log Message:
  -----------
  [Clang][inlineasm] Add special support for "rm" output constraints (#92040)

Clang isn't able to support multiple constraints on inputs and outputs,
like "rm". Instead, it picks the "safest" one to use, i.e. the memory
constraint for "rm". This leads to obviously horrible code:

  asm __volatile__ ("pushf\n\t"
                    "popq %0"
                    : "=rm" (x));

is compiled to:

        pushf
	popq -8(%rsp)
	movq	-8(%rsp), %rax

It gets worse when inlined into other functions, because it may
introduce
a stack where none is needed.

With this change, Clang now generates IR for the more optimistic choice
("r"). All but the fast register allocator are able to fold registers if
it turns out that register pressure is too high.

This leaves the fast register allocator. The fast register allocator, as
the name suggests, is built for execution speed, not code quality. Thus,
we add special processing to convert the "optimistic" IR into the
"conservative" choice (again at the IR level), which we know it can
handle.

We focus on "rm" for the initial commit, but that can be expanded in the
future for other constraints where Clang generates ++ungood code (like
"g").

Fixes: https://github.com/llvm/llvm-project/issues/20571



To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications


More information about the All-commits mailing list