That one is called scalar evolution, llvm abbreviates it as SCEV. The implementation is relatively complicated.