mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-12-02 08:26:29 +00:00
[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 llvm-svn: 239218
This commit is contained in:
parent
212ab571c4
commit
7dbb3087e2
@ -227,7 +227,7 @@ namespace {
|
||||
bool canUnrollCompletely(Loop *L, unsigned Threshold,
|
||||
unsigned PercentDynamicCostSavedThreshold,
|
||||
unsigned DynamicCostSavingsDiscount,
|
||||
unsigned UnrolledCost, unsigned RolledDynamicCost);
|
||||
uint64_t UnrolledCost, uint64_t RolledDynamicCost);
|
||||
};
|
||||
}
|
||||
|
||||
@ -768,8 +768,8 @@ static void SetLoopAlreadyUnrolled(Loop *L) {
|
||||
bool LoopUnroll::canUnrollCompletely(Loop *L, unsigned Threshold,
|
||||
unsigned PercentDynamicCostSavedThreshold,
|
||||
unsigned DynamicCostSavingsDiscount,
|
||||
unsigned UnrolledCost,
|
||||
unsigned RolledDynamicCost) {
|
||||
uint64_t UnrolledCost,
|
||||
uint64_t RolledDynamicCost) {
|
||||
|
||||
if (Threshold == NoThreshold) {
|
||||
DEBUG(dbgs() << " Can fully unroll, because no threshold is set.\n");
|
||||
|
58
test/Transforms/LoopUnroll/full-unroll-bad-cost.ll
Normal file
58
test/Transforms/LoopUnroll/full-unroll-bad-cost.ll
Normal file
@ -0,0 +1,58 @@
|
||||
; 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
|
||||
}
|
Loading…
Reference in New Issue
Block a user