LLVM 22.x tile for building compilers, language runtimes, and out-of-tree tooling
88
83%
Does it follow best practices?
Impact
96%
1.23xAverage score across 5 eval scenarios
Passed
No known issues
Reference: AliasAnalysis.h | MemoryLocation
Alias analysis answers whether two memory references may, must, or cannot refer to the same underlying object. Almost every memory optimization (load/store motion, dead store elimination, vectorization) depends on it.
AliasResultTypical outcomes when comparing two locations:
| Result | Meaning |
|---|---|
NoAlias | Never overlap for the accessed sizes |
MustAlias | Always the same object / same base for the accessed range |
MayAlias | Conservative unknown |
PartialAlias | Overlap but not identical footprint |
MemoryLocationA memory reference is described by:
Value* (or pseudo-location for unknown memory)LocationSize)Construct helpers include MemoryLocation::get / getBeforeOrAfter for LoadInst, StoreInst, etc.
ModRef information classifies whether a call reads, writes, or neither for a given MemoryLocation:
ModRefInfo::NoModRef, Ref, Mod, ModRefPasses use this to hoist loads past calls or to eliminate stores.
In the New Pass Manager, alias results are obtained through the analysis manager stack, not getAnalysis<AliasAnalysis>(). The usual pattern from a function pass is to obtain the AAResults facade for that function’s context (the exact helper may be getAA(FAM)-style depending on your pass boilerplate—verify the signature in LLVM 22’s AliasAnalysis.h and PassBuilder.cpp when you wire code).
Conceptually:
// Illustrative — confirm API names against LLVM 22 headers:
// AAResults AA = ... obtained from FunctionAnalysisManager for Function F;
MemoryLocation LocA = MemoryLocation::get(LI);
MemoryLocation LocB = MemoryLocation::get(SI);
AliasResult AR = AA.alias(LocA, LocB);
if (AR == AliasResult::NoAlias) {
// Safe to reorder / CSE under the right additional checks
}Always re-query after IR changes that may affect memory behavior; invalidate analyses via PreservedAnalyses and FAM.invalidate when you break assumptions.
Before writing a custom AA pass, use what LLVM already understands:
| Mechanism | Effect |
|---|---|
noalias on parameters / returns | Asserts non-aliasing with other pointers per LangRef rules |
tbaa metadata | Type-based alias analysis |
scoped noalias domains and scopes | Control-flow-scoped non-aliasing |
| Function attributes | argmemonly, readnone, readonly, etc. (see attributes-metadata.md) |
A precise frontend that emits noalias and TBAA often yields large wins without any C++ alias analysis code.
Adding a new alias analysis implementation is advanced and tightly coupled to LLVM’s internal AA pipeline. The high-level steps:
BasicAA and any scoped AA implementations in llvm/lib/Analysis/ as templates.AnalysisInfoMixin, run() returning a result type that participates in the AA stack—match the LLVM 22 pattern used by sibling analyses).PassRegistry.def the same way other function analyses are registered.AAResults (ordering and delegation are easy to get wrong).Out-of-tree: shipping a third-party AA that plugs into opt like in-tree passes is uncommon; most teams push facts into IR (metadata/attributes) or run a custom pass that uses AAResults only as a client, not as a new provider.
If your language guarantees that immutable global tables never alias mutable heap objects, you may:
noalias at call boundaries where the language rules allow it.That reuses existing BasicAA + TBAA instead of forking AA.
AAResults across transformations without invalidation.Value* can MustAlias (e.g., different GEPs with same object).noalias, function attributesFunctionAnalysisManager, analysis registrationdocs
evals
scenario-1
scenario-2
scenario-3
scenario-4
scenario-5
skills
add-alias-analysis
add-attributes-metadata
add-calling-convention
add-debug-info
add-exception-handling
add-gc-statepoints
add-intrinsic
add-lto
add-sanitizer
add-vectorization-hint
frontend-to-ir
jit-setup
lit-filecheck
lower-struct-types
new-target
out-of-tree-setup
tessl-llvm
version-sync