LoopVectorizer is analyzing poorly due to unoptimized input
| Bugzilla Link | 32698 |
| Version | trunk |
| OS | Linux |
| Attachments | automatically reduced test case with loop. |
| CC | @JonPsson,@rengolin,@rotateright |
Extended Description
I came across a loop that for the loop vectorizer looks like:
for.body33: %indvars.iv1225 = phi i64 %typed_outval.1909 = phi i32 %arrayidx36 = getelementptr %58 = load i8, i8* %arrayidx36, align 1, !tbaa !11 %conv37 = zext i8 %58 to i32 %conv38 = and i32 %typed_outval.1909, 255 %add39 = add nuw nsw i32 %conv38, %conv37 %indvars.iv.next1226 = add nsw i64 %indvars.iv1225, 1 %cmp31 = icmp slt i64 %indvars.iv.next1226, %57 br i1 %cmp31, label %for.body33, label %for.end43.loopexit
It then thinks about these instructions with TTI individually. The problem is that this is a phi that later gets optimized by InstCombine, because it is actually just an i8 value, due to the 'and 255'.
A first thought is to run the instcombiner or some similar phi optimizer before LoopVectorizer. Another idea is that it seems that SROA is introducing this phi, which it could optimize?
Why is this not done? Compile time?
bin/opt -mtriple=s390x-unknown-linux -mcpu=z13 -O3 ./LoopVec_phi.ll -o ./out.opt.ll -S -debug-only=loop-vectorize
The test case should now be vectorized: https://llvm.godbolt.org/z/5PdvKsGK7
Note that I had to remove the uses of undef/null to avoid the whole function being optimized away.