We use two approaches for determining the minimum bitwidth.
- Demanded bits
- Value tracking
If demanded bits doesn't result in a narrower type, we then try value tracking. We need this if we want to root SLP trees with the indices of getelementptr instructions since all the bits of the indices are demanded.
But there is a missing piece though. We need to be able to distinguish "demanded and shrinkable" from "demanded and not shrinkable". For example, the bits of %i in
%i = sext i32 %e1 to i64 %gep = getelementptr inbounds i64, i64* %p, i64 %i
are demanded, but we can shrink %i's type to i32 because it won't change the result of the getelementptr. On the other hand, in
%tmp15 = sext i32 %tmp14 to i64 %tmp16 = insertvalue { i64, i64 } undef, i64 %tmp15, 0
it doesn't make sense to shrink %tmp15 and we can skip the value tracking.
This patch still adds z|sext to demote list, but does not use value tracking if they are not shrinkable. So, cast<vect>, trunc <vect>, exctract <vect>, cast <extract> are only generated when they are useful (shrinkable). For now, this patch only considers gep index as a shrinkable usage.
Most words above are from @mssimpso .
You don't capture anything in lambda, so remove & from the capture list.