llvm-project
34385a9b - [CIR] Return the value stored to the return slot directly (#246252)

Commit
1 day ago
[CIR] Return the value stored to the return slot directly (#246252) Classic codegen returns the value stored to the return slot directly when that store dominates the return, and then drops the slot (`findDominatingStoreToReturnValue` in CGCall.cpp). CIR always lowered the slot to an alloca, store, load and ret, so most functions returning a scalar differed from classic codegen. This adds a `cir-forward-return-slot` function pass. In a function with a single `cir.return` of a load from the return slot, it returns the stored value directly when either: - the store is the slot's only other use and reaches the load through a chain of single predecessors, or - the store immediately precedes the load. These are classic codegen's rules. Volatile, atomic, record, array and complex slots are left alone. The return keeps its own location, which CIRGen already sets to the return statement's. The pass runs before LLVM lowering, after FlattenCFG and ABI lowering, so `-emit-cir` output does not change. The existing tests change only in their LLVM checks; where a function's LLVM and OGCG checks are now identical, they share the LLVM prefix. Assisted-by: Claude Code (claude-opus-5-5).
Author
Parents
Loading