From patchwork Tue Aug 17 09:49:40 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: Deal with (T *)p + CST in comparison folding From: Richard Guenther X-Patchwork-Id: 61874 Message-Id: To: gcc-patches@gcc.gnu.org Date: Tue, 17 Aug 2010 11:49:40 +0200 (CEST) We fold (T *)(p + CST) to ((T *)p) + CST, so the comparison folding code needs adjustment to handle (T*)p + 4 > (T*)p. Bootstrapped and tested on x86_64-unknown-linux-gnu, applied. Richard. 2010-08-16 Richard Guenther * fold-const.c (fold_comparison): Strip nops inside POINTER_PLUS_EXPR. Index: gcc/fold-const.c =================================================================== --- gcc/fold-const.c (revision 163278) +++ gcc/fold-const.c (working copy) @@ -8683,6 +8683,7 @@ fold_comparison (location_t loc, enum tr else if (TREE_CODE (arg0) == POINTER_PLUS_EXPR) { base0 = TREE_OPERAND (arg0, 0); + STRIP_SIGN_NOPS (base0); if (TREE_CODE (base0) == ADDR_EXPR) { base0 = TREE_OPERAND (base0, 0); @@ -8705,6 +8706,7 @@ fold_comparison (location_t loc, enum tr else if (TREE_CODE (arg1) == POINTER_PLUS_EXPR) { base1 = TREE_OPERAND (arg1, 0); + STRIP_SIGN_NOPS (base1); if (TREE_CODE (base1) == ADDR_EXPR) { base1 = TREE_OPERAND (base1, 0);