For C code below:
void foo(int a){
use(a+a);
if(0 < a && a < 100)
use((a+a)/a);
}
EarlyCSE merges inner a+a
into outer a+a
, and therefore IPSCCP fails to add nuw,nsw flag to inner use of (a + a). We fail to fold (a+a)/a
into 2 here. This occurs everywhere passes check overflow flags.
For this reason, I thought about some solutions like changing phase-ordering, which is much more complex. Attaching flag to every Use would solve it. But multiple calculation of case-sensitive information is expensive. I’m curious about whether it’s worthwhile & possible and whether there are
other trade-off methods?