From patchwork Thu Oct 19 17:41:47 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Uros Bizjak X-Patchwork-Id: 828296 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-464567-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="r7uxs/Oc"; 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 3yHx840q8dz9t4r for ; Fri, 20 Oct 2017 04:42:11 +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 :mime-version:from:date:message-id:subject:to:content-type; q= dns; s=default; b=e0XOldPLEXDRTqLcq+L5oo5v0wRQLE1vPGRHY4ROdRUTxa VgQVhjLJED3y9B3ztw37vsh+10UG6UVl9+DysGErKDrH10DP22hyl5EgJ4uAe8e0 dHjuD8tluz7JwPiKhnFgaDRlnaQfxkWovdR7rz5qHoxr6azqHp9SIMlkX7Y1Y= 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 :mime-version:from:date:message-id:subject:to:content-type; s= default; bh=3x3moA1/srI4CbkRRzAG5Gw64wo=; b=r7uxs/OclzjzX5H7NaXT GW5wC6yGZo/qakIFNWokJLr7B7U9vpxSBJzEF55iP0zI7lxXEZNitzTI4zKHYeRT J4BpuhKiZSQJDCWpX727P8Lqz23Q9taHpjgBqkANZapYoRwiBX3w8AB61Dpykvge E6ViLU8g0RiPOzIEs+PUnao= Received: (qmail 2221 invoked by alias); 19 Oct 2017 17:41:51 -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 2197 invoked by uid 89); 19 Oct 2017 17:41:51 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-10.0 required=5.0 tests=AWL, BAYES_00, FREEMAIL_FROM, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, RCVD_IN_DNSWL_NONE, RCVD_IN_SORBS_SPAM, SPF_PASS autolearn=ham version=3.3.2 spammy= X-HELO: mail-it0-f46.google.com Received: from mail-it0-f46.google.com (HELO mail-it0-f46.google.com) (209.85.214.46) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 19 Oct 2017 17:41:50 +0000 Received: by mail-it0-f46.google.com with SMTP id j140so10674919itj.1 for ; Thu, 19 Oct 2017 10:41:49 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=tLuAZeRE06zMAM4SExn28nxGMfgto9mpJtqnHZjSyrA=; b=DuoN3TBVTvCIvztku0cLdGO9qWQKmlRpGMXA4hihBYKxGh8YYhDyuNzcf2RBXhldPU Qh59XAilH+oT3Fe6/6KlYciQj4Ag5hgbwdtTNKHtYr0Gxfpal0kdzLVP/nXYVCepyr7a /gkuK9z/7ASXChOw5BxpyJ+ns1FVKUSbBT00qio0KDsAQzAA1IGHqs6NkpI+0aa7XA22 mD19Ok3OJ7lYYC8IYzFn3OnKoK9ArbF0a5h+L1fzcDuxpVeaEAW7Dgd2j6K9djjKRR19 f/BtPJyEoYKI94484xIrKkTU8sUv1gewbjSFGJu200Y7Enzh9lQik/sVK7UetlXWFfiD fU9A== X-Gm-Message-State: AMCzsaVHlUKSvAY1MtqNYouJz48Lq9ZOfloysvDYZ47SJC4oM5H+ymQv rV9RwWxsUhySsMcDXmzc8999+W33Llnn4W1OjBV26w== X-Google-Smtp-Source: ABhQp+TKeUt7OwU74A2tHgfKq6nOFf2c0Ibo8IC90v5vgVjZGM2hDN3QS2OwZrWQS7/PYEDk84CnVcg7p7aNzzo16dI= X-Received: by 10.36.121.150 with SMTP id z144mr3655691itc.28.1508434908049; Thu, 19 Oct 2017 10:41:48 -0700 (PDT) MIME-Version: 1.0 Received: by 10.2.74.18 with HTTP; Thu, 19 Oct 2017 10:41:47 -0700 (PDT) From: Uros Bizjak Date: Thu, 19 Oct 2017 19:41:47 +0200 Message-ID: Subject: [PATCH, i386]: PR 82618, Inefficient double-word subtraction on x86_64 To: "gcc-patches@gcc.gnu.org" Attached patch converts SUB with its output unused to CMP. This can happen in double-word subtraction when lowpart of the result is unused (but highpart subtraction still needs to borrow carry flag). 2017-10-19 Uros Bizjak PR target/82618 * config/i386/i386.md (sub to cmp): New peephole2 pattern. testsuite/ChangeLog: 2017-10-18 Uros Bizjak Jakub Jelinek PR target/82618 * gcc.target/i386/pr82618.c: New test. Bootstrapped and regression tested on x86_64-linux-gnu {,-m32}. Committed to mainline SVN. Uros. Index: config/i386/i386.md =================================================================== --- config/i386/i386.md (revision 253899) +++ config/i386/i386.md (working copy) @@ -6766,6 +6766,17 @@ [(set_attr "type" "alu") (set_attr "mode" "")]) +(define_peephole2 + [(parallel + [(set (reg:CC FLAGS_REG) + (compare:CC (match_operand:SWI 0 "general_reg_operand") + (match_operand:SWI 1 "general_gr_operand"))) + (set (match_dup 0) + (minus:SWI (match_dup 0) (match_dup 1)))])] + "find_regno_note (peep2_next_insn (0), REG_UNUSED, REGNO (operands[0])) != 0" + [(set (reg:CC FLAGS_REG) + (compare:CC (match_dup 0) (match_dup 1)))]) + (define_insn "*subsi_3_zext" [(set (reg FLAGS_REG) (compare (match_operand:SI 1 "register_operand" "0") Index: testsuite/gcc.target/i386/pr82618.c =================================================================== --- testsuite/gcc.target/i386/pr82618.c (nonexistent) +++ testsuite/gcc.target/i386/pr82618.c (working copy) @@ -0,0 +1,18 @@ +/* PR target/82618 */ +/* { dg-do compile } */ +/* { dg-options "-O2" } */ + +#ifdef __SIZEOF_INT128__ +typedef unsigned __int128 U; +typedef unsigned long long H; +#else +typedef unsigned long long U; +typedef unsigned int H; +#endif + +H f0 (U x, U y) +{ + return (x - y) >> (__CHAR_BIT__ * sizeof (H)); +} + +/* { dg-final { scan-assembler {\mcmp} } } */