Take: ``` int foo(long n3) { int j = 0; for(int i=0; i<n3; i++) j=j^1; return j; } int foo1(long n3) { int j = 0; if (n3>=0) j = j ^ (n3&1); return j; } ``` We should figure out that j as the result is just alternating between 0 and 1 (VRP figures that that is the range) in SCCP pattern matching. I Noticed this while looking into PR 111972
This shows up in a really really bad benchmark: https://github.com/kdlucas/byte-unixbench/blob/master/UnixBench/src/whets.c
Confirmed. I think it should apply even to int foo(long n3, int j, int x) { for(int i=0; i<n3; i++) j=j^x; return j; } which alternates between 'j' and 'j^x', thus the result is n3&1 ? j^x : j? I wonder if there's some online symbolic calculus service that we can feed IL during compilation ;)
We already have analyze_and_compute_bitop_with_inv_effect, but it only works when inv is an SSA_NAME, it should be extended to constant.
Fixed via r14-5428-gfd1596f9962569afff6c9298a7c79686c6950bef .
(In reply to Andrew Pinski from comment #4) > Fixed via r14-5428-gfd1596f9962569afff6c9298a7c79686c6950bef . Note, my patch only handles constant tripcount for XOR, but not do the transformation when tripcount is variable.
(In reply to Hongtao.liu from comment #5) > (In reply to Andrew Pinski from comment #4) > > Fixed via r14-5428-gfd1596f9962569afff6c9298a7c79686c6950bef . > > Note, my patch only handles constant tripcount for XOR, but not do the > transformation when tripcount is variable. Oh.