From patchwork Thu Jan 3 08:23:35 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: Fix vector ABS_EXPR >= 0 folding (PR tree-optimization/55832) From: Jakub Jelinek X-Patchwork-Id: 209193 Message-Id: <20130103082334.GE7269@tucnak.redhat.com> To: Richard Biener Cc: gcc-patches@gcc.gnu.org Date: Thu, 3 Jan 2013 09:23:35 +0100 Hi! While omit_one_operand_loc fold_converts the value to the right type, when type is vector, it is not possible to convert that way integer_one_node. Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2013-01-03 Jakub Jelinek Marc Glisse PR tree-optimization/55832 * fold-const.c (fold_binary_loc): For ABS_EXPR >= 0 and ABS_EXPR < 0 folding use constant_boolean_node instead of integer_{one,zero}_node. * gcc.c-torture/compile/pr55832.c: New test. Jakub --- gcc/fold-const.c.jj 2012-12-06 15:35:35.000000000 +0100 +++ gcc/fold-const.c 2013-01-02 09:48:42.906797768 +0100 @@ -13519,7 +13519,9 @@ fold_binary_loc (location_t loc, "when simplifying comparison of " "absolute value and zero"), WARN_STRICT_OVERFLOW_CONDITIONAL); - return omit_one_operand_loc (loc, type, integer_one_node, arg0); + return omit_one_operand_loc (loc, type, + constant_boolean_node (true, type), + arg0); } /* Convert ABS_EXPR < 0 to false. */ @@ -13533,7 +13535,9 @@ fold_binary_loc (location_t loc, "when simplifying comparison of " "absolute value and zero"), WARN_STRICT_OVERFLOW_CONDITIONAL); - return omit_one_operand_loc (loc, type, integer_zero_node, arg0); + return omit_one_operand_loc (loc, type, + constant_boolean_node (false, type), + arg0); } /* If X is unsigned, convert X < (1 << Y) into X >> Y == 0 --- gcc/testsuite/gcc.c-torture/compile/pr55832.c.jj 2013-01-02 10:00:53.271626853 +0100 +++ gcc/testsuite/gcc.c-torture/compile/pr55832.c 2013-01-02 10:00:44.000000000 +0100 @@ -0,0 +1,23 @@ +/* PR tree-optimization/55832 */ + +int g, b; + +void +foo (void) +{ + union U { int i; unsigned short s; } a = { 0 }; + unsigned char c; + unsigned short d = 0, *p = &a.s; + + if (g) + a.i--; + + if (b && a.i < (d = 1)) + return; + + for (; a.i < 15; a.i++) + b |= d <= c; + + if (!*p) + g = 0; +}