Skip to content

Commit c5afecc

Browse files
xiangzh1David Salinas
authored andcommitted
[LoopUnroll] Make use of MaxTripCount for loops with "#pragma unroll" (llvm#74703)
Fix loop unroll fail caused by branches folding. For example: SimplifyCFG foldloop branches then cause loop unroll failed for "#program unroll" loop. ``` for (int I = 0; I < ConstNum; ++I) { // folding "I < ConstNum" and "Cond2" if (Cond2) { break; } xxx loop body; } ``` The pragma unroll metadata only takes effect if there is an exact trip count, but not if there is an upper bound trip count. This patch make it work with an upper bound trip count as well in shouldPragmaUnroll(). Loop unroll is important in stack nervous devices (e.g. GPU, and that is why a lot of GPU code mark loop with "#program unroll"). It usually much simplify the address (offset) calculations in old iterations, then we can do a lot of others optimizations, e.g, SROA, for these simplifed address (escape alloca the whole aggregates). Change-Id: Ibd1a1a6cdcf98fd36be43dd2594976a7b0c588cf
1 parent 3cee196 commit c5afecc

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

llvm/lib/Transforms/Scalar/LoopUnrollPass.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -780,7 +780,7 @@ shouldPragmaUnroll(Loop *L, const PragmaInfo &PInfo,
780780
return TripCount;
781781

782782
if (PInfo.PragmaEnableUnroll && !TripCount && MaxTripCount &&
783-
MaxTripCount <= UP.MaxUpperBound)
783+
MaxTripCount <= UnrollMaxUpperBound)
784784
return MaxTripCount;
785785

786786
// if didn't return until here, should continue to other priorties

0 commit comments

Comments
 (0)