----- Original Message ----- From: "Richard Guenther" To: "Kai Tietz" Cc: gcc-patches@gcc.gnu.org Sent: Wednesday, June 29, 2011 12:14:10 PM Subject: Re: [patch tree-optimization]: Do bitwise operator optimizations for X op !X patterns On Tue, Jun 28, 2011 at 5:05 PM, Kai Tietz wrote: > Hello, > > this patch implements the X op !X patterns within tree-ssa-forwprop.c without using here const-fold routines.  Additionally it does some trivial folding for X op X.  Implementation > also looks through [(type)] X op [(type)] !X, if type of X is integral and precision is suitable > for operation. > > ChangeLog gcc/ > > 2011-06-28  Kai Tietz   > >        * tree-ssa-forwprop.c (operand_precision_onep): New >        function. >        (find_possible_not_expr_argument): Likewise. >        (simplify_bitwise_binary_1): Likewise. >        (simplify_bitwise_binary): Use simplify_bitwise_binary_1 >        for detecting various X op !X optimizations. > > ChangeLog gcc/testsuite > > 2011-06-28  Kai Tietz   > >        * gcc.dg/binop-notand1a.c: New test. >        * gcc.dg/binop-notand2a.c: New test. >        * gcc.dg/binop-notand3a.c: New test. >        * gcc.dg/binop-notand4a.c: New test. >        * gcc.dg/binop-notand5a.c: New test. >        * gcc.dg/binop-notand6a.c: New test. >        * gcc.dg/binop-notor1.c: New test. >        * gcc.dg/binop-notor2.c: New test. >        * gcc.dg/binop-notxor1.c: New test. >        * gcc.dg/binop-notxor2.c: New test. > > Bootstrapped and regression tested for all languages plus Ada and Obj-C for x86_64-pc-linux-gnu. Ok for apply? I can't follow the code in find_possible_not_expr_argument or its uses at all. Please try to produce patches that look more obvious in what they are doing - don't try to solve every testcase you can come up with in a single patch. Especially don't write functions like find_possible_not_expr_argument which seems to have evolved a lot after you wrote the overall function comment. Thanks, Richard. > Regards, > Kai > Well, I added some comments to these functions and renamed the find_possible_not_expr_argument function to detect_not_expr_operand, which hits its use better. The cause for this function is, that there are more then one variant of expressing a logical-not and all of them are used. This routine simply tries to detect different variants used for not. Eg ~X == !X and (X ^ 1) == !X for integral type of X with precision one. For X with integral type, (X == 0) == !X. The folding for the three different bitwise-operations is pretty easy and it makes sense to implement them at once. I see here no good point to separate them into different patches. To separate them might even lead to questions about abstracting some code-pieces out of the main function. I didn't added testcases for all variants I am aware now. Just those, which are now handled. So hope you can read and understand logic of patch better by updated patch. Regards, Kai