Hello<br><br>I compiled the following program using the web interface<br><br>#include <stdio.h><br>#include <stdlib.h><br><br>int main(int argc, char **argv) {<br> int a; int b; int c; int d;<br> int X = 10;<br>
a = 777;<br> b = a | (atoi(argv[1]));<br> c = b | (atoi(argv[2]));<br> a = c | (atoi(argv[4]));<br> b = a | (atoi(argv[5]));<br> d = b | (atoi(argv[6]));<br> a = d | (atoi(argv[7]));<br> b = a | (atoi(argv[8]));<br>
c = b | (atoi(argv[9]));<br> if (c) {<br> X = 2000;<br> }<br> printf("%d\n", X);<br> return 0;<br>}<br><br><br>It is easy to see that the condition of the if statement will be satisfied, but non of the optimization levels of the web interface seem to understand this. If I remove all OR operations except the first two, then the code will be optimized as expected. I guess this is because InstCombine, SCCP or whatever pass who is responsible for this optimization is called a constant number of times rather than "enough times". (For example call it in a loop until it reports no simplification was done). Now my questions:<br>
<br>1- Is my understanding correct that this optimization is not done? Maybe if I choose flags correctly it is done?<br><br>2- Do you think I can use LLVM library in way that this kind of optimization is performed? For example is it possible that I call passes responsible for this in a loop and then ask them in each iteration if they did something useful and then I stop when they say they didn't find something new?<br>
<br>Best<br>Ehsan<br>