[PATCH] D103255: [LV] Mark increment of main vector loop induction variable as NUW.

Florian Hahn via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 7 14:58:52 PDT 2021


fhahn added a comment.

In D103255#2796605 <https://reviews.llvm.org/D103255#2796605>, @reames wrote:

> LGTM as well.  I'm not super familiar with this code, but I skimmed the callers and the necessary conditions seemed to be locally implied.
>
> As an aside, do you have a test case where SCEV can't figure this out?  I've got D103118 <https://reviews.llvm.org/D103118> out for review now, and am interested in other such cases.

The motivating case is something like the function below, where `nuw` improves the results. There are a few other improvements I am planning as follow-up.

  define i32 @f(i32 %n) {
  entry:
    %cmp5 = icmp ult i32 %n, 13
    tail call void @llvm.assume(i1 %cmp5)
    %cmp16 = icmp ult i32 %n, 1
    br i1 %cmp16, label %middle.block, label %if.end.preheader
  
  if.end.preheader:                                 ; preds = %entry
    %min.iters.check = icmp ult i32 %n, 8
    br i1 %min.iters.check, label %middle.block, label %vector.ph
  
  vector.ph:                                        ; preds = %if.end.preheader
    %n.mod.vf = urem i32 %n, 8
    %n.vec = sub i32 %n, %n.mod.vf
    %ind.end = sub i32 %n, %n.vec
    br label %vector.body
  
  vector.body:                                      ; preds = %vector.body, %vector.ph
    %index = phi i32 [ 0, %vector.ph ], [ %index.next, %vector.body ]
    %index.next = add nuw i32 %index, 8
    %ec = icmp eq i32 %index.next, %n.vec
    br i1 %ec, label %middle.block, label %vector.body
  
  middle.block:
    ret i32 10
  }
  
  ; Function Attrs: inaccessiblememonly nofree nosync nounwind willreturn mustprogress
  declare void @llvm.assume(i1 noundef %0) #1


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D103255/new/

https://reviews.llvm.org/D103255



More information about the llvm-commits mailing list