On Thu, May 19, 2011 at 2:56 PM, Richard Guenther <richard.guent...@gmail.com> wrote: > On Thu, May 19, 2011 at 2:48 PM, Kai Tietz <ktiet...@googlemail.com> wrote: >> Hello, >> >> This patch improves reassociation folding for comparision. It expands >> expressions within binary-AND/OR expression like (X | Y) == 0 to (X == >> 0 && Y == 0) >> and (X | Y) != 0 to (X != 0 || Y != 0). This is necessary to allow >> better reassociation >> on weak pre-folded logical expressions. This unfolding gets undone >> anyway later by pass, >> so no disadvantage gets introduced. >> Also while going through BB-list, it tries to do some little >> type-sinking for SSA sequences >> like "D1 = (type) bool1; D2 = (type) bool2; D3 = D1 & D2;' to 'D1 = >> bool1 & bool2; D2 = (type) D1;'. >> This folding has the advantage to see better through intermediate >> results with none-boolean type. >> The function eliminate_redundant_comparison () got reworded so, that >> doesn't break in all cases. >> It now continues to find duplicates and tries to find inverse variant >> (folded to constant). By this >> change we don't combine possible weak optimizations too fast, before >> we can find and handle >> inverse or duplicates. > > sinking casting belongs not here but instead to tree-ssa-forwprop. > I'm not sure that a != 0 | b != 0 is the better canonical variant than > a | b != 0 though.
For example w/o your patch I see on the first testcase: <bb 2>: D.2689_3 = a_2(D) != 0; D.2690_5 = b_4(D) != 0; D.2691_6 = D.2690_5 & D.2689_3; if (D.2691_6 != 0) goto <bb 3>; else goto <bb 4>; <bb 3>: D.2693_7 = b_4(D) | a_2(D); D.2694_8 = D.2693_7 == 0; D.2695_10 = c_9(D) != 0; D.2696_11 = D.2695_10 & D.2694_8; D.2685_16 = (int) D.2696_11; canonicalizing to the latter (which is also smaller) would be <bb 2>: D.2691_5 = a_2(D) & b_4(D); D.2691_6 = D.2691_5 != 0; if (D.2691_6 != 0) goto <bb 3>; else goto <bb 4>; <bb 3>: D.2693_7 = b_4(D) | a_2(D); D.2694_8 = ~D.2693_7; D.2696_11 = c_9(D) & D.2694_8; D.2696_11 = D.2696_11 != 0; D.2685_16 = (int) D.2696_11; that looks re-associatable as good as the other. Richard.