Tree pattern matching for instruction selection is how LLVM's SelectionDAG and GCC's RTL patterns turn IR into clever instructions — recognizing that x*2+y can be one lea on x86. This is the phase that decides whether your code uses madd on ARM or fused multiply-add on x86, worth 2x in numeric kernels.