skills/compiler-internals/compiler-optimizations-deep/SKILL.md
Deep compiler optimizations skill for RA, ISel, and PGO. Use when explaining register allocation, instruction selection, LICM, vectorization limits, or profile-guided optimization beyond -O3. Activates on queries about register allocation, instruction selection, LICM, auto-vectorization failure, PGO, or BOLT.
npx skillsauth add mohitmishra786/low-level-dev-skills compiler-optimizations-deepInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Explain optimization phases beyond flags: mid-level IR opts, register allocation, instruction selection/scheduling, vectorization boundaries, PGO, and post-link BOLT — bridging skills/compilers/pgo and LLVM/GCC internals.
-O3 did not vectorize a hot loopFrontend → LLVM IR / GCC GIMPLE
├── Mid-level: DCE, GVN, LICM, inlining
├── Loop opts: unroll, vectorize
├── Codegen prep: legalize types
├── Instruction selection (DAG → machine ops)
├── Register allocation (greedy, linear scan)
└── Peephole / scheduling
clang -O3 -Rpass=loop-vectorize -Rpass-missed=loop-vectorize foo.c
| Miss reason | Typical fix |
|-------------|-------------|
| Unknown trip count | peel loop; assert count |
| Dependence | reorder / separate accumulators |
| Function call in loop | inline or outline |
| Alignment unknown | __builtin_assume_aligned |
When live ranges exceed physical registers, the allocator spills to stack slots — costly loads/stores. Reducing live ranges (splitting variables, rematerialization) helps.
GCC/LLVM both use graph coloring variants (LLVM "greedy regalloc").
clang -fprofile-instr-generate -O2 -o app foo.c
./app # training workload
llvm-profdata merge default.profraw -o default.profdata
clang -fprofile-instr-use=default.profdata -O2 -o app_pgo foo.c
Improves branch layout, inlining, and vectorization thresholds.
See skills/compilers/pgo for GCC and BOLT.
llvm-bolt -instrument app -o app.inst
./app.inst
llvm-bolt -data=perf.fdata -reorder-blocks=+ -o app.bolt app
Optimizes layout after linker — needs relocations (-Wl,--emit-relocs).
Loop-invariant code motion hoists x * scale out of inner loop when legal — reduces work per iteration.
/compiler-optimizations-deep Why did LLVM fail to vectorize this reduction loop?
| Symptom | Cause | Fix |
|---------|-------|-----|
| PGO no gain | Unrepresentative training | Match production input |
| BOLT crash | Stripped binary | Keep symbols + relocs |
| Spills in asm | Register pressure | Simplify live ranges |
| -O3 slower | Code bloat / cache | Try -O2 or PGO |
| Different GCC/Clang | Pass ordering differs | Compare IR + asm |
skills/compilers/pgo — PGO and BOLT detailskills/compiler-internals/llvm-ir-and-passes — IR-level optsskills/compiler-internals/code-generation-and-backends — ISel and backendsskills/computer-architecture/cpu-pipelines-and-hazards — scheduling contextskills/low-level-programming/simd-intrinsics — manual vectorizationdevelopment
QEMU/KVM skill for virtualization and kernel development. Use when running qemu-system-x86_64 with KVM, configuring virtio devices, VFIO passthrough, QMP monitor, libvirt, or booting custom kernels. Activates on queries about QEMU, KVM, virtio, VFIO, virsh, virt-install, or -kernel -append.
development
Hardware virtualization internals skill for Intel VT-x and AMD-V. Use when studying VMCS/VMCB, EPT/NPT page tables, VMEXIT handling, APIC virtualization, or building minimal hypervisors. Activates on queries about VMX, SVM, VMCS, EPT, NPT, VMEXIT, or type-1 hypervisor.
testing
Linux containers internals skill for namespaces, cgroups, and OCI. Use when understanding clone/unshare namespaces, cgroups v2 limits, overlayfs, runc, seccomp profiles, capabilities, or escape mitigations. Activates on queries about namespaces, cgroups, overlayfs, runc, seccomp-bpf, OCI spec, or container escape.
tools
Reverse engineering skill for binary analysis. Use when decompiling with Ghidra, analyzing with radare2, scripting RE tools, triaging with strings/file/xxd, or diffing binaries. Activates on queries about Ghidra, radare2, r2, decompiler, Binary Ninja, Diaphora, or stripped binary analysis.