[llvm] [LoopPeel] LCSSA form is destroyed by LoopPeel, preserve it (PR #78696)
Vedant Paranjape via llvm-commits
llvm-commits at lists.llvm.org
Fri Feb 16 21:27:22 PST 2024
vedantparanjape-amd wrote:
> @vedantparanjape-amd If the LCSSA of the parent loop is already destroyed by the time we enter LoopPeel, then I don't think trying to recover it inside LoopPeel is the right thing to do. We should fix this at the point where LCSSA is broken.
>
> Do I understand correctly that the only relation LoopPeel has to anything here is that it contains this LCSSA assertion? It looks like adding
Yeah. that's correct ! It has no relation as such with LoopPeel.
>
> ```
> for (Loop *L : LI)
> assert(L->isRecursivelyLCSSAForm(DT, LI));
> ```
>
> to the end of unrolling triggers the assertion even without peeling.
>
> For the record, here is the test case with cleaned up block naming:
>
> ```llvm
> target triple = "x86_64-unknown-linux-gnu"
>
> define void @test() !prof !0 {
> entry:
> br label %loop1
>
> loop1:
> %phi = phi i32 [ 1, %entry ], [ 0, %loop1.latch ]
> br label %loop2
>
> loop2:
> %phi3 = phi i64 [ 0, %loop1 ], [ %sext, %loop2.latch ]
> br label %loop3
>
> loop3:
> %phi5 = phi i64 [ %phi3, %loop2 ], [ %sext, %loop3.latch ]
> %phi6 = phi i32 [ 1, %loop2 ], [ %add10, %loop3.latch ]
> %trunc = trunc i64 %phi5 to i32
> br i1 true, label %loop3.latch, label %exit
>
> loop3.latch:
> %add = add i32 1, %phi
> %sext = sext i32 %add to i64
> %add10 = add i32 %phi6, 1
> %icmp = icmp ugt i32 %add10, 2
> br i1 %icmp, label %loop2.latch, label %loop3
>
> loop2.latch:
> br i1 false, label %loop4.preheader, label %loop2
>
> loop4.preheader:
> br label %loop4
>
> loop4:
> br i1 false, label %loop1.latch, label %loop4
>
> loop1.latch:
> br label %loop1
>
> exit:
> %phi8 = phi i32 [ %trunc, %loop3 ]
> ret void
> }
>
> !0 = !{!"function_entry_count", i64 32768}
> !1 = !{!"branch_weights", i32 1, i32 1}
> ```
Thanks for the cleaned up testcase.
https://github.com/llvm/llvm-project/pull/78696
More information about the llvm-commits
mailing list