[PATCH] D22630: Loop rotation

Aditya Kumar via llvm-commits llvm-commits at lists.llvm.org
Tue Jul 26 13:17:06 PDT 2016


hiraditya added a comment.

In https://reviews.llvm.org/D22630#496459, @mzolotukhin wrote:

> Hi,
>
> FWIW, I'm also working on a patch for loop-rotate, my goal also being to teach it to rotate loops with more complicated CFG.
>
> As an example I use the following simple test:
>
>   declare void @use(i32)
>  
>   define void @test(i32 %v) {
>   entry:
>     br label %for_header
>  
>   for_header:
>     %iv = phi i32 [ 0, %entry ], [ %inc, %for_crit ]
>     %inc = add nsw i32 %iv, 1
>     %cmp = icmp slt i32 %iv, 1
>     br i1 %cmp, label %for_crit, label %for_end
>  
>   for_crit:
>     call void @use(i32 %iv)
>     br label %for_header
>  
>   for_end:
>     %x = phi i32 [%iv, %for_header]
>     ret void
>   }
>
>
> This test is base on a real one, and the ultimate goal is to unroll it removing the loop completely. Currently we can't do it, because loop-rotation bails out early, and unfortunately, this patch also doesn't help here. I'll post my patch soon, and hopefully we'll be able to assemble all-best version out of two.


Could you tell what is the desired output. With this patch I'm getting:

  ; ModuleID = '<stdin>'
  source_filename = "<stdin>"
  
  declare void @use(i32)
  
  define void @test(i32 %v) {
  entry:
    br label %for_header.lr
  
  for_header.lr:                                    ; preds = %entry
    %iv.lr = phi i32 [ 0, %entry ]
    %inc.lr = add nsw i32 %iv.lr, 1
    %cmp.lr = icmp slt i32 %iv.lr, 1
    br i1 %cmp.lr, label %for_crit.lr.ph, label %for_end
  
  for_crit.lr.ph:                                   ; preds = %for_header.lr
    br label %for_crit
  
  for_crit:                                         ; preds = %for_crit.lr.ph, %for_header
    %phi.nh1 = phi i32 [ %inc, %for_header ], [ %inc.lr, %for_crit.lr.ph ]
    %phi.nh = phi i32 [ %iv, %for_header ], [ %iv.lr, %for_crit.lr.ph ]
    call void @use(i32 %phi.nh)
    br label %for_header
  
  for_header:                                       ; preds = %for_crit
    %iv = phi i32 [ %phi.nh1, %for_crit ]
    %inc = add nsw i32 %iv, 1
    %cmp = icmp slt i32 %iv, 1
    br i1 %cmp, label %for_crit, label %for_end
  
  for_end:                                          ; preds = %for_header.lr, %for_header
    %x = phi i32 [ %iv, %for_header ], [ %iv.lr, %for_header.lr ]
    ret void
  }


https://reviews.llvm.org/D22630





More information about the llvm-commits mailing list