Bounds-checking elimination is a compiler optimization useful in programming languages or runtimes that enforce bounds checking, the practice of checking every index into an array to verify that the index is within the defined valid range of indexes. Its goal is to detect which of these indexing operations do not need to be validated at runtime, and eliminating those checks.
Questions tagged [bounds-check-elimination]
15 questions
53
votes
4 answers
Array bounds check efficiency in .net 4 and above
I'm interested in how efficient low-level algorithms can be in .net. I would like to enable us to choose to write more of our code in C# rather than C++ in the future, but one stumbling block is the bounds checking in .net that occurs with looping…

TooTone
- 7,129
- 5
- 34
- 60
41
votes
4 answers
How can I code Java to allow SSE use and bounds-check elimination (or other advanced optimizations)?
The Situation:
I'm optimizing a pure-java implementation of the LZF compression algorithm, which involves a lot of byte[] access and basic int mathematics for hashing and comparison. Performance really matters, because the goal of the compression…

BobMcGee
- 19,824
- 10
- 45
- 57
20
votes
3 answers
Why the bounds check doesn't get eliminated?
I wrote a simple benchmark in order to find out if bounds check can be eliminated when the array gets computed via bitwise and. This is basically what nearly all hash tables do: They compute
h & (table.length - 1)
as an index into the table, where…

maaartinus
- 44,714
- 32
- 161
- 320
15
votes
1 answer
Eliminate Haskell array bounds check for Bounded type?
I am making a good many arrays whose index type is Bounded and whose index range is (minBound, maxBound). For such an array, a bounds check ought to be unnecessary. How can I persuade GHC to eliminate the bounds check?
My particular application…

Norman Ramsey
- 198,648
- 61
- 360
- 533
11
votes
1 answer
Missing bounds checking elimination in String constructor?
Looking into UTF8 decoding performance, I noticed the performance of protobuf's UnsafeProcessor::decodeUtf8 is better than String(byte[] bytes, int offset, int length, Charset charset) for the following non ascii string: "Quizdeltagerne spiste…

Amir Hadadi
- 421
- 4
- 13
11
votes
2 answers
Bounds Checking in Java
"Hotspot can remove bounds checking in Java." Can any one explain this please? Actually im analysing the differences between C++ and Java. It is not a homework and im analysing on my own interest.

Jothsna Nalla
- 189
- 3
- 9
8
votes
1 answer
Can Hotspot eliminate bounds checks when the range of the index is resticted via and?
Consider the following function:
int foo(int[] indices) {
int[] lookup = new int[256];
fill(lookup); // populate values, not shown
int sum = 0;
for (int i : indices) {
sum += lookup[i & 0xFF]; // array access
}
return sum;
}
Can…

BeeOnRope
- 60,350
- 16
- 207
- 386
8
votes
2 answers
Remove bounds checking in Rust loop in attempt to reach optimal compiler output
In an attempt to determine whether I can/should use Rust instead of the default C/C++ I'm looking into various edge cases, mostly with this question in mind: In the 0.1% of cases where it does matter, can I always get compiler output as good as…

mcmayer
- 1,931
- 12
- 22
7
votes
1 answer
Array Bounds Check Elimination in the CLR?
I was recently reading this article by Dave Detlefs in which he presents a few cases where the CLR performs array bounds check elimination. I decided to test this myself, so I did the following:
Opened Visual Studio 2010 Ultimate SP1
Created a new…

Asik
- 21,506
- 6
- 72
- 131
5
votes
5 answers
What is the special case with the foreach loop that eliminates bounds checking?
What is the special case with the foreach/for loop that eliminates bounds checking? Also which bounds checking is it?

Joan Venge
- 315,713
- 212
- 479
- 689
4
votes
4 answers
Array boundaries check optimization in a for-loop
var ar = new int[500000000];
var sw = new Stopwatch();
sw.Start();
var length = ar.Length;
for (var i = 0; i < length; i++)
{
if (ar[i] == 0);
}
…

aush
- 2,108
- 1
- 14
- 24
3
votes
1 answer
Why JIT does so poor job of bound checks elimination?
I'm testing HotSpot JIT array bound checks elimination capabilities. Here are two versions of the same heapsort implementation, one use ordinary array indexing, another sun.misc.Unsafe API, free of bound checks:
public class HeapSort {
// copied…

leventov
- 14,760
- 11
- 69
- 98
2
votes
2 answers
A Java bounds-checking optimization example
I have read that some of the JVMs out there can optimize code execution by removing bounds checking. What I am trying to figure out is what coding technique will work better.
In method example1 below would the JVM ever figure it out and eliminate…

AlanObject
- 9,613
- 19
- 86
- 142
2
votes
2 answers
Array bounds check in DynamicAssembly only works when evaluation stack is empty
I've got simple for loop with array access written using ILGenerator. When method is created with this exact code, I open disassembly and it's ok, no array bounds check.
But when I first put instance of other class on evaluation stack, then run for…

Ondrej Petrzilka
- 1,449
- 18
- 24
1
vote
1 answer
Implementing loop bounds check via overflow interrupt
I had this idea today that one could implement a bounds checked loop over an array by constructing an iteration counter that will overflow on the last increment and stop the execution based on the generated overflow interrupt.
So assume you have an…

Christian Beikov
- 15,141
- 2
- 32
- 58