mirror of
				https://github.com/c64scene-ar/llvm-6502.git
				synced 2025-11-03 14:21:30 +00:00 
			
		
		
		
	When we compute the size of a loop, we include the branch on the backedge and the comparison feeding the conditional branch. Under normal circumstances, these don't get replicated with the rest of the loop body when we unroll. This led to the somewhat surprising behavior that really small loops would not get unrolled enough -- they could be unrolled more and the resulting loop would be below the threshold, because we were assuming they'd take (LoopSize * UnrollingFactor) instructions after unrolling, instead of (((LoopSize-2) * UnrollingFactor)+2) instructions. This fixes that computation. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@225565 91177308-0d34-0410-b5e6-96231b3b80d8
		
			
				
	
	
		
			53 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			LLVM
		
	
	
	
	
	
			
		
		
	
	
			53 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			LLVM
		
	
	
	
	
	
; RUN: opt < %s -S -loop-unroll -unroll-allow-partial | FileCheck %s
 | 
						|
; Loop size = 3, when the function has the optsize attribute, the
 | 
						|
; OptSizeUnrollThreshold, i.e. 50, is used, hence the loop should be unrolled
 | 
						|
; by 32 times because (1 * 32) + 2 < 50 (whereas (1 * 64 + 2) is not).
 | 
						|
define void @unroll_opt_for_size() nounwind optsize {
 | 
						|
entry:
 | 
						|
  br label %loop
 | 
						|
 | 
						|
loop:
 | 
						|
  %iv = phi i32 [ 0, %entry ], [ %inc, %loop ]
 | 
						|
  %inc = add i32 %iv, 1
 | 
						|
  %exitcnd = icmp uge i32 %inc, 1024
 | 
						|
  br i1 %exitcnd, label %exit, label %loop
 | 
						|
 | 
						|
exit:
 | 
						|
  ret void
 | 
						|
}
 | 
						|
 | 
						|
; CHECK:      add
 | 
						|
; CHECK-NEXT: add
 | 
						|
; CHECK-NEXT: add
 | 
						|
; CHECK-NEXT: add
 | 
						|
; CHECK-NEXT: add
 | 
						|
; CHECK-NEXT: add
 | 
						|
; CHECK-NEXT: add
 | 
						|
; CHECK-NEXT: add
 | 
						|
; CHECK-NEXT: add
 | 
						|
; CHECK-NEXT: add
 | 
						|
; CHECK-NEXT: add
 | 
						|
; CHECK-NEXT: add
 | 
						|
; CHECK-NEXT: add
 | 
						|
; CHECK-NEXT: add
 | 
						|
; CHECK-NEXT: add
 | 
						|
; CHECK-NEXT: add
 | 
						|
; CHECK-NEXT: add
 | 
						|
; CHECK-NEXT: add
 | 
						|
; CHECK-NEXT: add
 | 
						|
; CHECK-NEXT: add
 | 
						|
; CHECK-NEXT: add
 | 
						|
; CHECK-NEXT: add
 | 
						|
; CHECK-NEXT: add
 | 
						|
; CHECK-NEXT: add
 | 
						|
; CHECK-NEXT: add
 | 
						|
; CHECK-NEXT: add
 | 
						|
; CHECK-NEXT: add
 | 
						|
; CHECK-NEXT: add
 | 
						|
; CHECK-NEXT: add
 | 
						|
; CHECK-NEXT: add
 | 
						|
; CHECK-NEXT: add
 | 
						|
; CHECK-NEXT: add
 | 
						|
; CHECK-NEXT: icmp
 | 
						|
 |