mirror of
https://github.com/RPCSX/llvm.git
synced 2024-12-05 02:16:46 +00:00
6e3744f374
through PHI nodes across iterations. This patch teaches the new advanced loop unrolling heuristics to propagate constants into the loop from the preheader and around the backedge after simulating each iteration. This lets us brute force solve simple recurrances that aren't modeled effectively by SCEV. It also makes it more clear why we need to process the loop in-order rather than bottom-up which might otherwise make much more sense (for example, for DCE). This came out of an attempt I'm making to develop a principled way to account for dead code in the unroll estimation. When I implemented a forward-propagating version of that it produced incorrect results due to failing to propagate *cost* between loop iterations through the PHI nodes, and it occured to me we really should at least propagate simplifications across those edges, and it is quite easy thanks to the loop being in canonical and LCSSA form. Differential Revision: http://reviews.llvm.org/D11706 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@243900 91177308-0d34-0410-b5e6-96231b3b80d8
24 lines
718 B
LLVM
24 lines
718 B
LLVM
; RUN: opt < %s -S -loop-unroll -unroll-max-iteration-count-to-analyze=100 -unroll-dynamic-cost-savings-discount=1000 -unroll-threshold=10 -unroll-percent-dynamic-cost-saved-threshold=50 | FileCheck %s
|
|
target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
|
|
|
|
define i64 @propagate_loop_phis() {
|
|
; CHECK-LABEL: @propagate_loop_phis(
|
|
; CHECK-NOT: br i1
|
|
; CHECK: ret i64 3
|
|
entry:
|
|
br label %loop
|
|
|
|
loop:
|
|
%iv = phi i64 [ 0, %entry ], [ %inc, %loop ]
|
|
%x0 = phi i64 [ 0, %entry ], [ %x2, %loop ]
|
|
%x1 = or i64 %x0, 1
|
|
%x2 = or i64 %x1, 2
|
|
%inc = add nuw nsw i64 %iv, 1
|
|
%cond = icmp sge i64 %inc, 10
|
|
br i1 %cond, label %loop.end, label %loop
|
|
|
|
loop.end:
|
|
%x.lcssa = phi i64 [ %x2, %loop ]
|
|
ret i64 %x.lcssa
|
|
}
|