-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Closed
Labels
area-CodeGen-coreclrCLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMICLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMIenhancementProduct code improvement that does NOT require public API changes/additionsProduct code improvement that does NOT require public API changes/additionsoptimizationtenet-performancePerformance related issuePerformance related issue
Milestone
Description
Currently the JITter is smart enough to elide bounds checks when forward-iterating over arrays or spans, as in the below sample.
byte[] array;
for (int i = 0; i < array.Length; i++) {
// consume array[i]
}
It would help certain tight loops if the JITter could also recognize the reverse-iteration pattern and elide the bounds checks in that scenario as well.
byte[] array;
for (int i = array.Length - 1; i >= 0 /* or any non-negative const */; i--) {
// consume array[i]
}
This optimization would save a cmp
and jae
instruction in these tight loops, and in certain cases it would also allow omitting the stack frame setup that normally accompanies methods that might throw exceptions.
category:cq
theme:bounds-checks
skill-level:expert
cost:medium
impact:small
bbowyersmyth, airbreather, ViktorHofer, pentp, Thealexbarney and 7 more
Metadata
Metadata
Assignees
Labels
area-CodeGen-coreclrCLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMICLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMIenhancementProduct code improvement that does NOT require public API changes/additionsProduct code improvement that does NOT require public API changes/additionsoptimizationtenet-performancePerformance related issuePerformance related issue