From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 17058 invoked by alias); 4 Jul 2005 17:04:00 -0000 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org Received: (qmail 17034 invoked by uid 48); 4 Jul 2005 17:03:52 -0000 Date: Mon, 04 Jul 2005 17:04:00 -0000 Message-ID: <20050704170352.17033.qmail@sourceware.org> From: "pinskia at gcc dot gnu dot org" To: gcc-bugs@gcc.gnu.org In-Reply-To: <20050423170606.21180.pinskia@gcc.gnu.org> References: <20050423170606.21180.pinskia@gcc.gnu.org> Reply-To: gcc-bugzilla@gcc.gnu.org Subject: [Bug middle-end/21180] [4.1 Regression] checking on fold no longer happens in some cases X-Bugzilla-Reason: CC X-SW-Source: 2005-07/txt/msg00337.txt.bz2 List-Id: ------- Additional Comments From pinskia at gcc dot gnu dot org 2005-07-04 17:03 ------- s/face/fact/ This is the patch I am testing right now: * fold-const.c (fold_build1): Add checksum for the operands. (fold_build2): Likewise. (fold_build3): Likewise. Index: fold-const.c =============================================================== ==== RCS file: /cvs/gcc/gcc/gcc/fold-const.c,v retrieving revision 1.600 diff -u -p -r1.600 fold-const.c --- fold-const.c 2 Jul 2005 16:24:25 -0000 1.600 +++ fold-const.c 4 Jul 2005 17:02:26 -0000 @@ -10322,11 +10322,33 @@ recursive_label: tree fold_build1 (enum tree_code code, tree type, tree op0) { - tree tem = fold_unary (code, type, op0); - if (tem) - return tem; - - return build1 (code, type, op0); + tree tem; +#ifdef ENABLE_FOLD_CHECKING + unsigned char checksum_before[16], checksum_after[16]; + struct md5_ctx ctx; + htab_t ht; + + ht = htab_create (32, htab_hash_pointer, htab_eq_pointer, NULL); + md5_init_ctx (&ctx); + fold_checksum_tree (op0, &ctx, ht); + md5_finish_ctx (&ctx, checksum_before); + htab_empty (ht); +#endif + + tem = fold_unary (code, type, op0); + if (!tem) + tem = build1 (code, type, op0); + +#ifdef ENABLE_FOLD_CHECKING + md5_init_ctx (&ctx); + fold_checksum_tree (op0, &ctx, ht); + md5_finish_ctx (&ctx, checksum_after); + htab_delete (ht); + + if (memcmp (checksum_before, checksum_after, 16)) + fold_check_failed (op0, tem); +#endif + return tem; } /* Fold a binary tree expression with code CODE of type TYPE with @@ -10337,11 +10359,49 @@ fold_build1 (enum tree_code code, tree t tree fold_build2 (enum tree_code code, tree type, tree op0, tree op1) { - tree tem = fold_binary (code, type, op0, op1); - if (tem) - return tem; + tree tem; +#ifdef ENABLE_FOLD_CHECKING + unsigned char checksum_before_op0[16], + checksum_before_op1[16], + checksum_after_op0[16], + checksum_after_op1[16]; + struct md5_ctx ctx; + htab_t ht; + + ht = htab_create (32, htab_hash_pointer, htab_eq_pointer, NULL); + md5_init_ctx (&ctx); + fold_checksum_tree (op0, &ctx, ht); + md5_finish_ctx (&ctx, checksum_before_op0); + htab_empty (ht); + + md5_init_ctx (&ctx); + fold_checksum_tree (op1, &ctx, ht); + md5_finish_ctx (&ctx, checksum_before_op1); + htab_empty (ht); +#endif + + tem = fold_binary (code, type, op0, op1); + if (!tem) + tem = build2 (code, type, op0, op1); + +#ifdef ENABLE_FOLD_CHECKING + md5_init_ctx (&ctx); + fold_checksum_tree (op0, &ctx, ht); + md5_finish_ctx (&ctx, checksum_after_op0); + htab_empty (ht); - return build2 (code, type, op0, op1); + if (memcmp (checksum_before_op0, checksum_after_op0, 16)) + fold_check_failed (op0, tem); + + md5_init_ctx (&ctx); + fold_checksum_tree (op1, &ctx, ht); + md5_finish_ctx (&ctx, checksum_after_op1); + htab_delete (ht); + + if (memcmp (checksum_before_op1, checksum_after_op1, 16)) + fold_check_failed (op1, tem); +#endif + return tem; } /* Fold a ternary tree expression with code CODE of type TYPE with @@ -10351,12 +10411,64 @@ fold_build2 (enum tree_code code, tree t tree fold_build3 (enum tree_code code, tree type, tree op0, tree op1, tree op2) -{ - tree tem = fold_ternary (code, type, op0, op1, op2); - if (tem) - return tem; +{ tree tem; +#ifdef ENABLE_FOLD_CHECKING + unsigned char checksum_before_op0[16], + checksum_before_op1[16], + checksum_before_op2[16], + checksum_after_op0[16], + checksum_after_op1[16], + checksum_after_op2[16]; + struct md5_ctx ctx; + htab_t ht; + + ht = htab_create (32, htab_hash_pointer, htab_eq_pointer, NULL); + md5_init_ctx (&ctx); + fold_checksum_tree (op0, &ctx, ht); + md5_finish_ctx (&ctx, checksum_before_op0); + htab_empty (ht); + + md5_init_ctx (&ctx); + fold_checksum_tree (op1, &ctx, ht); + md5_finish_ctx (&ctx, checksum_before_op1); + htab_empty (ht); + + md5_init_ctx (&ctx); + fold_checksum_tree (op2, &ctx, ht); + md5_finish_ctx (&ctx, checksum_before_op2); + htab_empty (ht); +#endif + + tem = fold_ternary (code, type, op0, op1, op2); + if (!tem) + tem = build3 (code, type, op0, op1, op2); + +#ifdef ENABLE_FOLD_CHECKING + md5_init_ctx (&ctx); + fold_checksum_tree (op0, &ctx, ht); + md5_finish_ctx (&ctx, checksum_after_op0); + htab_empty (ht); - return build3 (code, type, op0, op1, op2); + if (memcmp (checksum_before_op0, checksum_after_op0, 16)) + fold_check_failed (op0, tem); + + md5_init_ctx (&ctx); + fold_checksum_tree (op1, &ctx, ht); + md5_finish_ctx (&ctx, checksum_after_op1); + htab_empty (ht); + + if (memcmp (checksum_before_op1, checksum_after_op1, 16)) + fold_check_failed (op1, tem); + + md5_init_ctx (&ctx); + fold_checksum_tree (op2, &ctx, ht); + md5_finish_ctx (&ctx, checksum_after_op2); + htab_delete (ht); + + if (memcmp (checksum_before_op2, checksum_after_op2, 16)) + fold_check_failed (op2, tem); +#endif + return tem; } /* Perform constant folding and related simplification of initializer -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=21180