From patchwork Fri Mar 16 20:17:22 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 887119 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-474880-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="i6sDw19Y"; dkim-atps=neutral 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 402xb529xBz9sML for ; Sat, 17 Mar 2018 07:17:37 +1100 (AEDT) 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=PhjFOi6wXCLKoRWiECJqb5rk4xmNv eQ8A6JDx6QH4QAqYzNkx560yIg/XgpDAPu+awbfzle/SfnJ3DpBLqMk7wq9cnERw OFE8B3VkDGXF/3JMj/LeGoWswv80eOOCLETaFCywEfRiyrQ0G5Qbt23IMDaEHncR 2UidF74eWpIKdQ= 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=BQ2HqxyHDch+lTuhlnd2R5Lg5zs=; b=i6s Dw19YG3Y/ucsYwd5DAeXSkFb+TE2/5cJ9d24AU5YXTqIRf8q65/Un/oYdKU3R+VI nD/PpXriTNiO+PYqBOBW9ShbWUE+7ZpFfZmhg4fHW/dik/KvlzcqHNb7MTMzefq6 xwwPi7qlrHygVVY52ewTJhFeYX2ppXD1NtmMIPJc= Received: (qmail 99319 invoked by alias); 16 Mar 2018 20:17:29 -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 99308 invoked by uid 89); 16 Mar 2018 20:17:28 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-11.6 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_2, GIT_PATCH_3, T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 spammy= X-HELO: mx1.redhat.com Received: from mx3-rdu2.redhat.com (HELO mx1.redhat.com) (66.187.233.73) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 16 Mar 2018 20:17:27 +0000 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 07600400186C; Fri, 16 Mar 2018 20:17:26 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.36.118.110]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B65ABDEED2; Fri, 16 Mar 2018 20:17:25 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.15.2/8.15.2) with ESMTP id w2GKHNrD005012; Fri, 16 Mar 2018 21:17:24 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.15.2/8.15.2/Submit) id w2GKHMlT005011; Fri, 16 Mar 2018 21:17:22 +0100 Date: Fri, 16 Mar 2018 21:17:22 +0100 From: Jakub Jelinek To: Richard Biener , Jeff Law Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] Fix postreload constant merging (PR target/84899) Message-ID: <20180316201722.GI8577@tucnak> Reply-To: Jakub Jelinek MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.9.2 (2017-12-15) X-IsSubscribed: yes Hi! The following testcase ICEs on powerpc-linux, because we merge SImode constants 0x7fffffff and 1 into 0x80000000, which is not valid SImode CONST_INT - -0x80000000 is. Fixed by calling trunc_int_for_mode, and to avoid UB in the compiler do the addition in unsigned type. Bootstrapped/regtested on x86_64-linux and i686-linux and tested on the testcase with powerpc64-linux cross with -m32, ok for trunk? 2018-03-16 Jakub Jelinek PR target/84899 * postreload.c (reload_combine_recognize_pattern): Perform INTVAL addition in unsigned HOST_WIDE_INT type to avoid UB and truncate_int_for_mode the result for the destination's mode. * gcc.dg/pr84899.c: New test. Jakub --- gcc/postreload.c.jj 2018-01-03 10:19:55.572534024 +0100 +++ gcc/postreload.c 2018-03-16 18:19:17.819417570 +0100 @@ -1157,11 +1157,13 @@ reload_combine_recognize_pattern (rtx_in value in PREV, the constant loading instruction. */ validate_change (prev, &SET_DEST (prev_set), index_reg, 1); if (reg_state[regno].offset != const0_rtx) - validate_change (prev, - &SET_SRC (prev_set), - GEN_INT (INTVAL (SET_SRC (prev_set)) - + INTVAL (reg_state[regno].offset)), - 1); + { + HOST_WIDE_INT c + = trunc_int_for_mode (UINTVAL (SET_SRC (prev_set)) + + UINTVAL (reg_state[regno].offset), + GET_MODE (index_reg)); + validate_change (prev, &SET_SRC (prev_set), GEN_INT (c), 1); + } /* Now for every use of REG that we have recorded, replace REG with REG_SUM. */ --- gcc/testsuite/gcc.dg/pr84899.c.jj 2018-03-16 18:22:39.243512333 +0100 +++ gcc/testsuite/gcc.dg/pr84899.c 2018-03-16 18:22:22.353504390 +0100 @@ -0,0 +1,12 @@ +/* PR target/84899 */ +/* { dg-do compile } */ +/* { dg-options "-O -funroll-all-loops -fno-move-loop-invariants" } */ + +void +foo (int x) +{ + int a = 1 / x, b = 0; + + while ((a + b + 1) < x) + b = __INT_MAX__; +}