With the LLVM_ENABLE_EXPENSIVE_CHECKS enabled, following sequence of passes are executed:
… Dominator Tree Construction Basic Alias Analysis (stateless AA impl) Function Alias Analysis Results Natural Loop Information Branch Probability Analysis MIPS DAG->DAG Pattern Instruction Selection Branch Probability Analysis MIPS DAG->DAG Pattern Instruction Selection Expand ISel Pseudo-instructions Tail Duplication ….
The Dominator tree is the indirect require dependency of "MIPS DAG->DAG Pattern Instruction Selection" pass. The dominator tree construction pass is freed before the second pass of "MIPS DAG->DAG Pattern Instruction Selection". This causes code to crash when it verify the preserved analysis after the second pass is executed
This include should come after: #include "llvm/IR/CFG.h"