[PATCH] [LoopUnroll] Fix truncation bug in canUnrollCompletely.
Sanjoy Das
sanjoy at playingwithpointers.com
Fri Jun 5 22:28:19 PDT 2015
REPOSITORY
rL LLVM
http://reviews.llvm.org/D10293
Files:
llvm/trunk/lib/Transforms/Scalar/LoopUnrollPass.cpp
llvm/trunk/test/Transforms/LoopUnroll/full-unroll-bad-cost.ll
Index: llvm/trunk/lib/Transforms/Scalar/LoopUnrollPass.cpp
===================================================================
--- llvm/trunk/lib/Transforms/Scalar/LoopUnrollPass.cpp
+++ llvm/trunk/lib/Transforms/Scalar/LoopUnrollPass.cpp
@@ -227,7 +227,7 @@
bool canUnrollCompletely(Loop *L, unsigned Threshold,
unsigned PercentDynamicCostSavedThreshold,
unsigned DynamicCostSavingsDiscount,
- unsigned UnrolledCost, unsigned RolledDynamicCost);
+ uint64_t UnrolledCost, uint64_t RolledDynamicCost);
};
}
@@ -768,8 +768,8 @@
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");
Index: llvm/trunk/test/Transforms/LoopUnroll/full-unroll-bad-cost.ll
===================================================================
--- llvm/trunk/test/Transforms/LoopUnroll/full-unroll-bad-cost.ll
+++ llvm/trunk/test/Transforms/LoopUnroll/full-unroll-bad-cost.ll
@@ -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
+}
EMAIL PREFERENCES
http://reviews.llvm.org/settings/panel/emailpreferences/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D10293.27264.patch
Type: text/x-patch
Size: 2943 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150606/ed1cd17d/attachment.bin>
More information about the llvm-commits
mailing list