From patchwork Thu Jul 3 18:42:22 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 366949 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]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 01734140078 for ; Fri, 4 Jul 2014 04:42:45 +1000 (EST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:cc:subject:message-id:reply-to:mime-version :content-type; q=dns; s=default; b=Ur65P0McK2FHpLHGpoN0+2l3BXZXN wf1sI/3Nnr/SQ+OYyjSILp6i5LqtjQcBR0VW36fXNJ/P2Y7w/ST1/7p7395QeUpR rNcv2xS/52C7EYFr6d9NeQ0ZEakPqUrTU1R2V/1CxOIvHtCKGYfhM0PBn9B0g8aG QiTrNJNreuRqro= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:cc:subject:message-id:reply-to:mime-version :content-type; s=default; bh=0F9BLG2SFcFTlJdKkkaEyE3D9EE=; b=hG4 nmVoO5DEDF/XNWhbQSm4JuiRp+VoqdnLjp1Qc36SjZqzQ58xyHbuLYwhJalKffFN NJOUd1ddoPBB8egkEFqbXKKl4uGUmhV9/gzW5CVzVdAziSJ2YVph1VR/SlJkBIyt /iGTnfy8J9W8Hh37DCF0nJjEmLFOLuapJjLlrlU8= Received: (qmail 26163 invoked by alias); 3 Jul 2014 18:42:38 -0000 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 Received: (qmail 26102 invoked by uid 89); 3 Jul 2014 18:42:32 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-3.5 required=5.0 tests=AWL, BAYES_00, SPF_HELO_PASS, SPF_PASS, T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Thu, 03 Jul 2014 18:42:28 +0000 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s63IgQIR012156 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 3 Jul 2014 14:42:27 -0400 Received: from tucnak.zalov.cz (ovpn-116-32.ams2.redhat.com [10.36.116.32]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id s63IgOhS002193 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Thu, 3 Jul 2014 14:42:25 -0400 Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.14.8/8.14.7) with ESMTP id s63IgNV5015229; Thu, 3 Jul 2014 20:42:23 +0200 Received: (from jakub@localhost) by tucnak.zalov.cz (8.14.8/8.14.8/Submit) id s63IgMlq015228; Thu, 3 Jul 2014 20:42:22 +0200 Date: Thu, 3 Jul 2014 20:42:22 +0200 From: Jakub Jelinek To: Richard Sandiford Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] Fix high handling in wi::mul_internal (PR tree-optimization/61682) Message-ID: <20140703184222.GK31640@tucnak.redhat.com> Reply-To: Jakub Jelinek MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.23 (2014-03-12) X-IsSubscribed: yes Hi! Several places in wi::mul_internal didn't handle high parameter and would return the low bits instead of high bits. Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2014-07-03 Jakub Jelinek PR tree-optimization/61682 * wide-int.cc (wi::mul_internal): Handle high correctly for umul_ppmm using cases and when one of the operands is equal to 1. * gcc.c-torture/execute/pr61682.c: New test. Jakub --- gcc/wide-int.cc.jj 2014-05-30 10:51:11.000000000 +0200 +++ gcc/wide-int.cc 2014-07-03 09:35:11.084228924 +0200 @@ -1,5 +1,5 @@ /* Operations with very long integers. - Copyright (C) 2012-2013 Free Software Foundation, Inc. + Copyright (C) 2012-2014 Free Software Foundation, Inc. Contributed by Kenneth Zadeck This file is part of GCC. @@ -1282,6 +1282,12 @@ wi::mul_internal (HOST_WIDE_INT *val, co && wi::fits_uhwi_p (op1) && wi::fits_uhwi_p (op2)) { + /* This case never overflows. */ + if (high) + { + val[0] = 0; + return 1; + } umul_ppmm (val[1], val[0], op1.ulow (), op2.ulow ()); return 1 + (val[1] != 0 || val[0] < 0); } @@ -1294,6 +1300,8 @@ wi::mul_internal (HOST_WIDE_INT *val, co umul_ppmm (upper, val[0], op1.ulow (), op2.ulow ()); if (needs_overflow) *overflow = (upper != 0); + if (high) + val[0] = upper; return 1; } } @@ -1302,12 +1310,28 @@ wi::mul_internal (HOST_WIDE_INT *val, co /* Handle multiplications by 1. */ if (op1 == 1) { + if (high) + { + if (sgn == SIGNED && wi::neg_p (op2)) + val[0] = -1; + else + val[0] = 0; + return 1; + } for (i = 0; i < op2len; i++) val[i] = op2val[i]; return op2len; } if (op2 == 1) { + if (high) + { + if (sgn == SIGNED && wi::neg_p (op1)) + val[0] = -1; + else + val[0] = 0; + return 1; + } for (i = 0; i < op1len; i++) val[i] = op1val[i]; return op1len; --- gcc/testsuite/gcc.c-torture/execute/pr61682.c.jj 2014-03-19 15:57:57.735114622 +0100 +++ gcc/testsuite/gcc.c-torture/execute/pr61682.c 2014-07-03 09:40:26.215520476 +0200 @@ -0,0 +1,17 @@ +/* PR tree-optimization/61682 */ + +int a, b; +static int *c = &b; + +int +main () +{ + int *d = &a; + for (a = 0; a < 12; a++) + *c |= *d / 9; + + if (b != 1) + __builtin_abort (); + + return 0; +}