On Fri, Jun 4, 2021 at 1:01 PM Hongtao Liu wrote: > > On Tue, Jun 1, 2021 at 6:17 PM Marc Glisse wrote: > > > > On Tue, 1 Jun 2021, Hongtao Liu via Gcc-patches wrote: > > > > > Hi: > > > This patch is about to simplify (view_convert:type ~a) < 0 to > > > (view_convert:type a) >= 0 when type is signed integer. Similar for > > > (view_convert:type ~a) >= 0. > > > Bootstrapped and regtested on x86_64-linux-gnu{-m32,}. > > > Ok for the trunk? > > > > > > gcc/ChangeLog: > > > > > > PR middle-end/100738 > > > * match.pd ((view_convert ~a) < 0 --> (view_convert a) >= 0, > > > (view_convert ~a) >= 0 --> (view_convert a) < 0): New GIMPLE > > > simplification. > > > > We already have > > > > /* Fold ~X op C as X op' ~C, where op' is the swapped comparison. */ > > (for cmp (simple_comparison) > > scmp (swapped_simple_comparison) > > (simplify > > (cmp (bit_not@2 @0) CONSTANT_CLASS_P@1) > > (if (single_use (@2) > > && (TREE_CODE (@1) == INTEGER_CST || TREE_CODE (@1) == VECTOR_CST)) > > (scmp @0 (bit_not @1))))) > > > > Would it make sense to try and generalize it a bit, say with > > > > (cmp (nop_convert1? (bit_not @0)) CONSTANT_CLASS_P) > > > > (scmp (view_convert:XXX @0) (bit_not @1)) > > > Thanks for your advice, it looks great. > And can I use *view_convert1?* instead of *nop_convert1?* here, > because the original case is view_convert, and nop_convert would fail > to simplify the case. Here is updated patch gcc/ChangeLog: PR middle-end/100738 * match.pd (Fold ~X op C as X op' ~C): Extend GIMPLE simplification to handle view_convert ~X. gcc/testsuite/ChangeLog: PR middle-end/100738 * g++.target/i386/avx2-pr100738-1.C: New test. * g++.target/i386/sse4_1-pr100738-1.C: New test. > > (I still believe that it is a bad idea that SSA_NAMEs are strongly typed, > > encoding the type in operations would be more convenient, but I think the > > time for that choice has long gone) > > > > -- > > Marc Glisse > > > > -- > BR, > Hongtao -- BR, Hongtao