From patchwork Thu May 10 21:02:29 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Uros Bizjak X-Patchwork-Id: 911556 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-477543-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="EY7xMuse"; 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 40hlzk47xbz9s19 for ; Fri, 11 May 2018 07:02:41 +1000 (AEST) 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=uIJmdpWpJgR9J4L/Ju0zNVeAw5teD/1O/cCVtt+vzWHafl 5Rg6IyYMG15A7GeNxMFl39IzQtU6DoG0+ygS+6jlfY9zgnN4PT+5CJ6keAAayATR q7CT8fgNmUtpcd8tYr+nY0iJelcUhkPXo2rRZtB1oNmyer2Q8jiL0KjEj2NB8= 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=2eCo8FM9603yv9hA6KOYUmtg0QE=; b=EY7xMuseKfP07VAw4F81 9LI/NaRh62xxWL1RrM+hdFazq9XXkwyUjOCQUQCHIJ5bPgV/BYEfJRHDd9EdGsKJ FE6UJeEi3+9IqfoMXKE/PwLbWBm4e+NWKQZvrlbzgMdwy99u/MBvOxYcXwfoMgQZ s21XO1To8AkgVJVi1pNMddE= Received: (qmail 53179 invoked by alias); 10 May 2018 21:02:34 -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 53166 invoked by uid 89); 10 May 2018 21:02:33 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-11.0 required=5.0 tests=AWL, BAYES_00, FREEMAIL_FROM, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy=H*r:sk:c9-v6so, _xgetbv X-HELO: mail-io0-f174.google.com Received: from mail-io0-f174.google.com (HELO mail-io0-f174.google.com) (209.85.223.174) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 10 May 2018 21:02:32 +0000 Received: by mail-io0-f174.google.com with SMTP id c9-v6so4624650iob.12 for ; Thu, 10 May 2018 14:02:31 -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=4wFtFk0xy8EsYM7exd98hM7xhip+k1eW5eiJ3zGVZPY=; b=Ec7AD8FvDvlfWKuzOGwT5kig4J8uMSi8e614EQj8F9aLiatQ+OnuHegw88AUnYI6C0 VbjMVmUb9YPYhTGGl+TJa84gXLRzizOHokWbjluM3aYFcFmXzmmeVmjkcyTE+gpnSzdw hwFhFfb4UvAIEOqqugcOIQf/CsH822/FJjS0nspF/aYBWVqOdIY59984NEgMkI9pEebY i8ib+SJXrz85/9uE821AgjP76HupVKXnW9g0J9vWuwq15WBnOU8v0KnHvMvHvJhzZfxt LgROwd391o/PW29nUktXd+IShZdaGYiZc2qyCfNJ4Qxjq/ZF2moU8w1uIVkde1ncWhT5 3G9Q== X-Gm-Message-State: ALKqPwf9exnTmv/T/XGLuG4s4ddfWTpDsjzrNs2/CFcLuUNfS4ykQsEG uxY4YytC6O9IV4/6jlxpRNqf1eKJBL/6V4scQIkLyWm2 X-Google-Smtp-Source: AB8JxZqUUZnYkiw1eE7vRrS3r5NQyClkdn5B3tgCMrbpmBzyNUK5Y8YrYtf6isNsqbG1FvS4fmXHFE1oQVXyRtgkYC4= X-Received: by 2002:a6b:bc06:: with SMTP id m6-v6mr3051205iof.205.1525986149956; Thu, 10 May 2018 14:02:29 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a02:a30b:0:0:0:0:0 with HTTP; Thu, 10 May 2018 14:02:29 -0700 (PDT) From: Uros Bizjak Date: Thu, 10 May 2018 23:02:29 +0200 Message-ID: Subject: [PATCH, i386]: Fix and improve a couple of builtin expansions To: "gcc-patches@gcc.gnu.org" Hello! The missing return in _xgetbv is a bug and will be backported to release branches. 2018-05-10 Uros Bizjak * config/i386/i386.c (ix86_expand_builtin) : Generate SImode target register for null target. : Ditto. : Optimize LSHIFTRT generation. * config/i386/xsaveintrin.h (_xgetbv): Add missing return. testsuite/ChangeLog: 2018-05-10 Uros Bizjak * gcc.target/i386/xgetsetbv.c: Check also variable arguments. Bootstrapped and regression tested on x86_64-linux-gnu {,-m32}. Committed to mainline SVN. Uros. Index: config/i386/i386.c =================================================================== --- config/i386/i386.c (revision 260116) +++ config/i386/i386.c (working copy) @@ -37085,7 +37085,7 @@ ix86_expand_builtin (tree exp, rtx target, rtx sub case IX86_BUILTIN_RDPID: - op0 = gen_reg_rtx (TARGET_64BIT ? DImode : SImode); + op0 = gen_reg_rtx (word_mode); if (TARGET_64BIT) { @@ -37094,18 +37094,16 @@ ix86_expand_builtin (tree exp, rtx target, rtx sub } else insn = gen_rdpid (op0); + emit_insn (insn); - if (target == 0) - { - /* mode is VOIDmode if __builtin_rdpid has been called - without lhs. */ - if (mode == VOIDmode) - return target; - target = gen_reg_rtx (mode); - } + if (target == 0 + || !register_operand (target, SImode)) + target = gen_reg_rtx (SImode); + emit_move_insn (target, op0); return target; + case IX86_BUILTIN_RDPMC: case IX86_BUILTIN_RDTSC: case IX86_BUILTIN_RDTSCP: @@ -37164,14 +37162,9 @@ ix86_expand_builtin (tree exp, rtx target, rtx sub emit_move_insn (gen_rtx_MEM (SImode, op4), op2); } - if (target == 0) - { - /* mode is VOIDmode if __builtin_rd* has been called - without lhs. */ - if (mode == VOIDmode) - return target; - target = gen_reg_rtx (mode); - } + if (target == 0 + || !register_operand (target, DImode)) + target = gen_reg_rtx (DImode); if (TARGET_64BIT) { @@ -37260,25 +37253,23 @@ ix86_expand_builtin (tree exp, rtx target, rtx sub if (!REG_P (op0)) op0 = copy_to_mode_reg (SImode, op0); + op1 = force_reg (DImode, op1); + if (TARGET_64BIT) { op2 = expand_simple_binop (DImode, LSHIFTRT, op1, GEN_INT (32), NULL, 1, OPTAB_DIRECT); + icode = CODE_FOR_xsetbv_rex64; + op2 = gen_lowpart (SImode, op2); op1 = gen_lowpart (SImode, op1); - if (!REG_P (op1)) - op1 = copy_to_mode_reg (SImode, op1); - if (!REG_P (op2)) - op2 = copy_to_mode_reg (SImode, op2); - icode = CODE_FOR_xsetbv_rex64; pat = GEN_FCN (icode) (op0, op1, op2); } else { - if (!REG_P (op1)) - op1 = copy_to_mode_reg (DImode, op1); icode = CODE_FOR_xsetbv; + pat = GEN_FCN (icode) (op0, op1); } if (pat) Index: config/i386/xsaveintrin.h =================================================================== --- config/i386/xsaveintrin.h (revision 260116) +++ config/i386/xsaveintrin.h (working copy) @@ -59,7 +59,7 @@ extern __inline long long __attribute__((__gnu_inline__, __always_inline__, __artificial__)) _xgetbv (unsigned int __A) { - __builtin_ia32_xgetbv (__A); + return __builtin_ia32_xgetbv (__A); } #ifdef __x86_64__ Index: testsuite/gcc.target/i386/xgetsetbv.c =================================================================== --- testsuite/gcc.target/i386/xgetsetbv.c (revision 260116) +++ testsuite/gcc.target/i386/xgetsetbv.c (working copy) @@ -1,13 +1,27 @@ /* { dg-do compile } */ /* { dg-options "-O2 -mxsave" } */ -/* { dg-final { scan-assembler "xgetbv" } } */ -/* { dg-final { scan-assembler "xsetbv" } } */ +/* { dg-final { scan-assembler-times "xgetbv" 3 } } */ +/* { dg-final { scan-assembler-times "xsetbv" 3 } } */ #include -unsigned int -xgetsetbv (void) +unsigned long long +foo (unsigned x, unsigned y) { + _xsetbv (x, y); + return _xgetbv (x); +} + +unsigned long long +bar (unsigned x, unsigned long long y) +{ + _xsetbv (x, y); + return _xgetbv (x); +} + +unsigned long long +baz (void) +{ _xsetbv (0, 0); return _xgetbv (0); }