Here is original C code:
void topup(int a[], unsigned long i) {
for (; i < 16; i++) {
a[i] = 1;
}
}
Here is the IR before the pass where I expect SCEV to return trip-count value
; Function Attrs: nofree norecurse nounwind uwtable writeonly
define dso_local void @topup(i32* nocapture %a, i64 %i) local_unnamed_addr #0 {
entry:
%cmp3 = icmp ult i64 %i, 16
br i1 %cmp3, label %for.body.preheader, label %for.end
for.body.preheader: ; preds = %entry
br label %for.body
for.body: ; preds = %for.body.preheader, %for.body
%i.addr.04 = phi i64 [ %inc, %for.body ], [ %i, %for.body.preheader ]
%arrayidx = getelementptr inbounds i32, i32* %a, i64 %i.addr.04
store i32 1, i32* %arrayidx, align 4, !tbaa !2
%inc = add nuw nsw i64 %i.addr.04, 1
%exitcond = icmp eq i64 %inc, 16
br i1 %exitcond, label %for.end.loopexit, label %for.body
for.end.loopexit: ; preds = %for.body
br label %for.end
for.end: ; preds = %for.end.loopexit, %entry
ret void
}
I have also checked that at a pass before above pass SCEV works and returns 16.
Here is the IR before a pass where SCEV works as per the expectations:
; Preheader:
for.body.preheader: ; preds = %entry
br label %for.body
; Loop:
for.body: ; preds = %for.body.preheader, %for.body
%i.addr.04 = phi i64 [ %inc, %for.body ], [ %i, %for.body.preheader ]
%arrayidx = getelementptr inbounds i32, i32* %a, i64 %i.addr.04
store i32 1, i32* %arrayidx, align 4, !tbaa !2
%inc = add nuw nsw i64 %i.addr.04, 1
%cmp = icmp ult i64 %inc, 16
br i1 %cmp, label %for.body, label %for.end.loopexit
; Exit blocks
for.end.loopexit: ; preds = %for.body
br label %for.end