From patchwork Wed Nov 3 10:26:47 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Botcazou X-Patchwork-Id: 69964 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id 4B7A41007D2 for ; Wed, 3 Nov 2010 21:28:53 +1100 (EST) Received: (qmail 15817 invoked by alias); 3 Nov 2010 10:28:51 -0000 Received: (qmail 15809 invoked by uid 22791); 3 Nov 2010 10:28:50 -0000 X-SWARE-Spam-Status: No, hits=-1.9 required=5.0 tests=AWL,BAYES_00,TW_TM X-Spam-Check-By: sourceware.org Received: from mel.act-europe.fr (HELO mel.act-europe.fr) (194.98.77.210) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 03 Nov 2010 10:28:45 +0000 Received: from localhost (localhost [127.0.0.1]) by filtered-smtp.eu.adacore.com (Postfix) with ESMTP id BC595CB0299 for ; Wed, 3 Nov 2010 11:28:42 +0100 (CET) Received: from mel.act-europe.fr ([127.0.0.1]) by localhost (smtp.eu.adacore.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id EPrRIw4YphgS for ; Wed, 3 Nov 2010 11:28:42 +0100 (CET) Received: from [192.168.1.2] (bon31-9-83-155-120-49.fbx.proxad.net [83.155.120.49]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mel.act-europe.fr (Postfix) with ESMTP id 8CBB0CB0274 for ; Wed, 3 Nov 2010 11:28:42 +0100 (CET) From: Eric Botcazou To: gcc-patches@gcc.gnu.org Subject: [patch] Fix type consistency problem in tree-tailcall.c Date: Wed, 3 Nov 2010 11:26:47 +0100 User-Agent: KMail/1.9.9 MIME-Version: 1.0 Message-Id: <201011031126.47769.ebotcazou@adacore.com> Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Hi, the attached testcase exhibits a regression present at -O2 on the mainline with checking enabled: /home/eric/svn/gcc/gcc/testsuite/gnat.dg/opt8.adb:25:5: error: type mismatch in binary expression natural___XDLU_0__2147483647 const integer natural___XDLU_0__2147483647 D.2693_51 = R3b_27 + add_acc.25_49; +===========================GNAT BUG DETECTED==============================+ | 4.6.0 20101102 (experimental) [trunk revision 166172] (i586-suse-linux-gnu) GCC error:| | verify_stmts failed | | Error detected around /home/eric/svn/gcc/gcc/testsuite/gnat.dg/opt8.adb:25:5| The problem is that, while the code to discover tail calls knows how to look through casts, it doesn't reinstate them when it is building expressions to compute the accumulator and multiplicator values. Hence the attached patch. Tested on i586-suse-linux, OK for the mainline? 2010-11-03 Eric Botcazou * tree-tailcall.c (find_tail_calls): Convert the operands to the type of the result before building binary expressions. 2010-11-03 Eric Botcazou * gnat.dg/opt8.ad[sb]: New test. * gnat.dg/opt8_pkg.ads: New helper. Index: tree-tailcall.c =================================================================== --- tree-tailcall.c (revision 166172) +++ tree-tailcall.c (working copy) @@ -532,20 +532,22 @@ find_tail_calls (basic_block bb, struct if (tmp_a) { + tree type = TREE_TYPE (tmp_a); if (a) - a = fold_build2 (PLUS_EXPR, TREE_TYPE (tmp_a), a, tmp_a); + a = fold_build2 (PLUS_EXPR, type, fold_convert (type, a), tmp_a); else a = tmp_a; } if (tmp_m) { + tree type = TREE_TYPE (tmp_m); if (m) - m = fold_build2 (MULT_EXPR, TREE_TYPE (tmp_m), m, tmp_m); + m = fold_build2 (MULT_EXPR, type, fold_convert (type, m), tmp_m); else m = tmp_m; if (a) - a = fold_build2 (MULT_EXPR, TREE_TYPE (tmp_m), a, tmp_m); + a = fold_build2 (MULT_EXPR, type, fold_convert (type, a), tmp_m); } }