From patchwork Fri Nov 24 21:38:13 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 841180 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-467882-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="FPhGwcEC"; 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 3yk8h36GRLz9s03 for ; Sat, 25 Nov 2017 08:38:27 +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=xEcmMjK1alayRjHWDHHAyyZeTs6An 9OFOyPKqduIbdqBXblIuKad/I4FXvAJAP0sjoXMs/oVoKBvyfAA9ceuzPlHQfMG4 Ihh9F0g27mUeLrLImHc0Z3DLNMLdwJ6u0ejEX9c0n5UyjAGi1zZEl879bwNMJx3Q lyTsYF7zFg0faw= 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=B2YgAio7lJmj5L7XAQ29aXpYpYw=; b=FPh GwcECclTg9/9tjBRwCeRO7HZA0u23OvT183EY11qti8LIsYENGk9GWwK/hQTVOLH iz1a9ZO4byAQlrV6rVZaUBQOTyT3AGjUHSnMfmSzkVoQ3ZUDghXtlZwF8u8D9Hk1 XxuTmmCkpgMvCV3k9lOU4YxkhJUcDhFpOKpFSi9k= Received: (qmail 129741 invoked by alias); 24 Nov 2017 21:38:20 -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 129732 invoked by uid 89); 24 Nov 2017 21:38:19 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-11.7 required=5.0 tests=BAYES_00, GIT_PATCH_2, GIT_PATCH_3, KB_WAM_FROM_NAME_SINGLEWORD, SPF_HELO_PASS, T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 spammy=2017-11-19, if_then_else 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 ESMTP; Fri, 24 Nov 2017 21:38:18 +0000 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 70AB237E74; Fri, 24 Nov 2017 21:38:17 +0000 (UTC) Received: from tucnak.zalov.cz (ovpn-116-247.ams2.redhat.com [10.36.116.247]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 07A1260465; Fri, 24 Nov 2017 21:38:16 +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 vAOLcEMI010358; Fri, 24 Nov 2017 22:38:15 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.15.2/8.15.2/Submit) id vAOLcDO5010357; Fri, 24 Nov 2017 22:38:13 +0100 Date: Fri, 24 Nov 2017 22:38:13 +0100 From: Jakub Jelinek To: Segher Boessenkool Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] Fix combine's simplify_if_then_else (PR rtl-optimization/81553) Message-ID: <20171124213813.GB14653@tucnak> Reply-To: Jakub Jelinek MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.7.1 (2016-10-04) X-IsSubscribed: yes Hi! The following testcase ICEs in wide-int*, but the reason is a mode mismatch (we build a SImode MULT with one QImode argument and one VOIDmode argument, then it is folded into SImode NEG with QImode argument, ...). The bug is in assuming that the mode of c1 must be m, that is usually the case, but shifts are special, the second argument can have a different mode. The following patch makes sure we perform the computation of the new shift count in the right mode. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2017-11-24 Jakub Jelinek PR rtl-optimization/81553 * combine.c (simplify_if_then_else): In (if_then_else COND (OP Z C1) Z) to (OP Z (mult COND (C1 * STORE_FLAG_VALUE))) optimization, if OP is a shift where C1 has different mode than the whole shift, use C1's mode for MULT rather than the shift's mode. * gcc.c-torture/compile/pr81553.c: New test. Jakub --- gcc/combine.c.jj 2017-11-19 18:08:08.000000000 +0100 +++ gcc/combine.c 2017-11-24 12:07:25.701480794 +0100 @@ -6639,11 +6639,15 @@ simplify_if_then_else (rtx x) if (z) { - temp = subst (simplify_gen_relational (true_code, m, VOIDmode, + machine_mode cm = m; + if ((op == ASHIFT || op == LSHIFTRT || op == ASHIFTRT) + && GET_MODE (c1) != VOIDmode) + cm = GET_MODE (c1); + temp = subst (simplify_gen_relational (true_code, cm, VOIDmode, cond_op0, cond_op1), pc_rtx, pc_rtx, 0, 0, 0); - temp = simplify_gen_binary (MULT, m, temp, - simplify_gen_binary (MULT, m, c1, + temp = simplify_gen_binary (MULT, cm, temp, + simplify_gen_binary (MULT, cm, c1, const_true_rtx)); temp = subst (temp, pc_rtx, pc_rtx, 0, 0, 0); temp = simplify_gen_binary (op, m, gen_lowpart (m, z), temp); --- gcc/testsuite/gcc.c-torture/compile/pr81553.c.jj 2017-11-24 12:11:25.681551110 +0100 +++ gcc/testsuite/gcc.c-torture/compile/pr81553.c 2017-11-24 12:10:55.000000000 +0100 @@ -0,0 +1,10 @@ +/* PR rtl-optimization/81553 */ + +int a, b, c, d; + +void +foo (void) +{ + d = 1 >> c >> 1; + b = ~(209883449764912897ULL & d) << (0 >= a) | ~d; +}