llvm/test/Transforms/LoopUnroll/full-unroll-bad-cost.ll
Sanjoy Das 68081f41fa [LoopUnroll] Fix truncation bug in canUnrollCompletely.
Summary:
canUnrollCompletely takes `unsigned` values for `UnrolledCost` and
`RolledDynamicCost` but is passed in `uint64_t`s that are silently
truncated.  Because of this, when `UnrolledSize` is a large integer
that has a small remainder with UINT32_MAX, LLVM tries to completely
unroll loops with high trip counts.

Reviewers: mzolotukhin, chandlerc

Subscribers: llvm-commits

Differential Revision: http://reviews.llvm.org/D10293

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@239218 91177308-0d34-0410-b5e6-96231b3b80d8
2015-06-06 05:24:10 +00:00

59 lines
1.3 KiB
LLVM

; RUN: opt -S -loop-unroll < %s | FileCheck %s
; LLVM should not try to fully unroll this loop.
declare void @f()
declare void @g()
declare void @h()
define void @trivial_loop() {
; CHECK-LABEL: @trivial_loop(
entry:
br label %loop
loop:
%idx = phi i32 [ 0, %entry ], [ %idx.inc, %loop ]
%idx.inc = add i32 %idx, 1
call void @f()
call void @g()
call void @h()
call void @f()
call void @g()
call void @h()
call void @f()
call void @g()
call void @h()
call void @f()
call void @g()
call void @h()
call void @f()
call void @g()
call void @h()
%be = icmp slt i32 %idx, 268435456
br i1 %be, label %loop, label %exit
; CHECK: loop:
; CHECK-NEXT: %idx = phi i32 [ 0, %entry ], [ %idx.inc, %loop ]
; CHECK-NEXT: %idx.inc = add i32 %idx, 1
; CHECK-NEXT: call void @f()
; CHECK-NEXT: call void @g()
; CHECK-NEXT: call void @h()
; CHECK-NEXT: call void @f()
; CHECK-NEXT: call void @g()
; CHECK-NEXT: call void @h()
; CHECK-NEXT: call void @f()
; CHECK-NEXT: call void @g()
; CHECK-NEXT: call void @h()
; CHECK-NEXT: call void @f()
; CHECK-NEXT: call void @g()
; CHECK-NEXT: call void @h()
; CHECK-NEXT: call void @f()
; CHECK-NEXT: call void @g()
; CHECK-NEXT: call void @h()
; CHECK-NEXT: %be = icmp slt i32 %idx, 268435456
; CHECK-NEXT: br i1 %be, label %loop, label %exit
exit:
ret void
}