[PATCH] Fix two bugs in loop unswitching related to trivial unswitching and the threshold parameter

Bjarke Hammersholt Roune broune at google.com
Wed Jun 10 17:14:37 PDT 2015


Hi hfinkel, eli.friedman, meheff,

This change fixes two bugs in loop unswitching. This change causes an 81% speed-up on a benchmark that is based on EigenConvolutionKernel2D from Eigen3, where the lack of loop unswitching blocks hoisting of loads out of a nested loop.

First fix: Unswitching on trivial conditions should always happen regardless of the computed unswitching cost, as really the cost is zero. While there is code to make that happen, the logic that checks the unswitching cost against a threshold was moved to an earlier point (revision 147935) than the point where trivial unswitching is detected, so trivial unswitching is currently blocked by the cost threshold. This change fixes that.

Second fix: Before revision 147935 (from 2012-01-11), the threshold parameter was a per-loop threshold. So an unswitching happened only if the cost of the unswitching was less than the threshold. In an indirect way (and I believe unintentionally), the logic for this since then has been that the threshold is an over-all budget across all loops for all loop unswitching done by a given LoopUnswitch loop pass object. So if an unswitching with cost 100 happens in one function, that in effect reduces the threshold from 100 to 0 for the loops even in another function. This persists for the lifetime of that loop pass object. This makes no difference for most small examples but it is important for large examples. This revision fixes that.

I've tried to make the change minimally invasive while staying with what I think was the original intent of the code.

http://reviews.llvm.org/D10376

Files:
  lib/Transforms/Scalar/LoopUnswitch.cpp
  test/Transforms/LoopUnswitch/2015-06-10-Threshold.ll
  test/Transforms/LoopUnswitch/2015-06-10-Trivial.ll

EMAIL PREFERENCES
  http://reviews.llvm.org/settings/panel/emailpreferences/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D10376.27480.patch
Type: text/x-patch
Size: 7316 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150611/ee9b368f/attachment.bin>


More information about the llvm-commits mailing list