In the following code, only one comparison will be done, because the compiler knows the conditions are exclusive and we will always enter the second condition as bar
will be necessary > 32:
int foo(int bar) {
if (bar <= 64)
return 1;
if (bar > 32) {
printf("Too many elements");
}
return 0;
}
Now, imagine I know bar
is always higher than 64. Because of the input of the system, configuration, or else. How can I hint the compiler to do no comparison at all, like if the if (bar <= 64) return
was compiled, except it actually isn't kept in the final ASM.
Something like:
int foo(int bar) {
@precond(bar > 64);
if (bar > 32) {
printf("Too many elements");
}
return 0;
}
Is my only solution to write eg a LLVM pass?