[PATCH] Remove loop variant range check when induction variable is strictly increasing
Philip Reames
listmail at philipreames.com
Thu May 14 16:55:45 PDT 2015
Hi atrick, sanjoy, nlewycky,
Given a range check on an induction variable, we can convert that range check to a loop invariant check against the starting value of the induction variable if the check would fail on the first iteration or not at all. This creates a check which is easily unswitched and thus effectively removes the range check from within the loop entirely.
Given C code:
for(int i = M; i < N; i++) // i is known not to overflow
if (i < 0) break;
a[i] = 0;
}
This transformation produces:
for(int i = M; i < N; i++)
if (M < 0) break;
a[i] = 0;
}
Which can be unswitched into:
if (M < 0) break;
for(int i = M; i < N; i++)
a[i] = 0;
}
I'm not entirely sure this is done in the best place. I couldn't really find a more natural fit for it, but the bit of code walking the use of each candidate induction variable didn't really seem elegant. Suggestions on a better way to structure this are very welcome.
http://reviews.llvm.org/D9784
Files:
lib/Transforms/Utils/SimplifyIndVar.cpp
test/Transforms/IndVarSimplify/strictly-increasing.ll
EMAIL PREFERENCES
http://reviews.llvm.org/settings/panel/emailpreferences/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D9784.25827.patch
Type: text/x-patch
Size: 10106 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150514/58f05d56/attachment.bin>
More information about the llvm-commits
mailing list