Hi, I have a case where the code looks roughly like foo = i1 <op> i2; if (test1) bar1 = i1 <op> i2; if (test2) bar2 = i1 <op> i2;
This can get converted into reg = i1 <op> i2 foo = reg if (test1) bar1 = reg if (test2) bar2 = reg GCC 4.3 does fine here except when the operator is "logical and" (see attached. test.c uses logical and and test1.c uses plus) It seems that shortcut evaluation of the "logical and" throws off common subexpression elimination. i.e the code generated is like foo = (i1 != 0 ) && (i2 != 0) if (test1) { if (i1 != 0) then lab2: else lab 3: lab2: if (i2 != 0) then lab 4 lab 3: temp = 0; lab 4 : temp = 1 bar1 = temp } if (test2) { same as the body of the above if condition. } The entire body of the two if stmts can be pulled out but it isnt. This kind of cse works when the operator is an arithmetic operator like +. Am I missing something here ? Is there something I can do to improve the case with the "logical and" May be this is difficult on hardware that uses the CC register ? But I am working on a private port that doesnt use the CC register. Thanks, Pranav
short ione; short itwo; short ithree; short ifour; short ifive; int one_array[50]; short a[50]; void foo () { ione = gen_short(1); itwo = gen_short(1); ithree = gen_short(1); ifour = gen_short(1); ifive = gen_short(1); a[0] = ione && itwo && ithree && ifour && ifive; if (one_array[1]) a[1] = ione && itwo && ithree && ifour && ifive; if (one_array[2]) a[2] = ione && itwo && ithree && ifour && ifive; return; }
short ione; short itwo; short ithree; short ifour; short ifive; int one_array[50]; short a[50]; void foo () { ione = gen_short(1); itwo = gen_short(1); ithree = gen_short(1); ifour = gen_short(1); ifive = gen_short(1); a[0] = ione + itwo + ithree + ifour + ifive; if (one_array[1]) a[1] = ione + itwo + ithree + ifour + ifive; if (one_array[2]) a[2] = ione + itwo + ithree + ifour + ifive; return; }