This patch teaches LazyValueInfo to use the invariant intrinsic. Like with the known-bits patch, this requires feeding a "context" instruction pointer through many functions. Aside from a little refactoring to reuse the logic that turns predicates into constant ranges in LVI, the only new code is that which can 'merge' the range from an invariant into that otherwise computed. There is also a small addition to JumpThreading so that it can have LVI use invariants in the same block as the comparison feeding a conditional branch.
With this patch, we can now simplify this as expected:
int foo(int a) {
__builtin_assume(a > 5); if (a > 3) { bar(); return 1; } return 0;
}
See comment on the other patch, it will end up applying here as well.