[ValueTracking] Know alignment of pointer IVs stepped by a GEP (#237132)
A pointer phi that is advanced by a getelementptr of itself, such as
%iv = phi ptr [ %start, %preheader ], [ %iv.next, %latch ]
%iv.next = getelementptr i8, ptr %iv, i64 16
had no known alignment unless an llvm.assume anchored it. The existing
recurrence handling in computeKnownBitsFromOperator() only matches a
BinaryOperator step, so pointer IVs were not covered.
Every value the phi takes is the start value plus a whole number of
steps, and tz(a + b) >= min(tz(a), tz(b)). Use the trailing zeros of the
start value, evaluated on its incoming edge, and the maximum preserved
alignment of the step GEP as a lower bound on the trailing zeros of the
phi.
This lets InferAlignment and other clients of known bits recover the
alignment of loop-carried pointers.
This PR fixes: https://github.com/llvm/llvm-project/issues/237131
Co-authored-by: Anilava Kundu <anilkund@hu-anilkund-blr.qualcomm.com>
Co-authored-by: Sumanth Gundapaneni <sgundapa@qti.qualcomm.com>