From patchwork Mon May 27 09:14:43 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Botcazou X-Patchwork-Id: 1105708 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-501707-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=adacore.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="hniuZT17"; 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 45CBBp2kvHz9s5c for ; Mon, 27 May 2019 19:14:55 +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:from :to:subject:date:message-id:mime-version:content-type :content-transfer-encoding; q=dns; s=default; b=yWrC7jv/8VRjTIo5 FTyxUzbpu47Tvr5FYX4enofrSW2YfL35t+j3eshRDV0kqzCsMDzkzrI6SBNnlz7W WugJdDVS4xPmOZ19RDN1vKLiZfaYlgwvG+svxyHDvYp9Ld7zsHWui8+Yp7Xb5qed U5C6Aknl3lr8OHlXAEjcRw4BfO4= 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:from :to:subject:date:message-id:mime-version:content-type :content-transfer-encoding; s=default; bh=M11rCBbh9sXJavNzPXaWGC J1KJ4=; b=hniuZT17uCPlrUY4GPdI34jGr+rDPj47g5pYpWcWn3FLO2SKv/ZKye kuWxOSBA605Zf0hlUu181T3WR9/GWm4UwY1q7nqldEQWPYH/569Cq7u6XJZ9Zjr7 bpYR1PoCbz2UWv8NTBLSrCEop3Vcx9HdpN9qziFkEXbHeueGeVn9Q= Received: (qmail 22520 invoked by alias); 27 May 2019 09:14:49 -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 22510 invoked by uid 89); 27 May 2019 09:14:49 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-6.8 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.1 spammy=compensate, opportunities X-HELO: smtp.eu.adacore.com Received: from mel.act-europe.fr (HELO smtp.eu.adacore.com) (194.98.77.210) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 27 May 2019 09:14:47 +0000 Received: from localhost (localhost [127.0.0.1]) by filtered-smtp.eu.adacore.com (Postfix) with ESMTP id B231E81380 for ; Mon, 27 May 2019 11:14:45 +0200 (CEST) Received: from smtp.eu.adacore.com ([127.0.0.1]) by localhost (smtp.eu.adacore.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id zTDaEFG9YY5Q for ; Mon, 27 May 2019 11:14:45 +0200 (CEST) Received: from polaris.localnet (bon31-6-88-161-99-133.fbx.proxad.net [88.161.99.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.eu.adacore.com (Postfix) with ESMTPSA id 8EB7D81382 for ; Mon, 27 May 2019 11:14:45 +0200 (CEST) From: Eric Botcazou To: gcc-patches@gcc.gnu.org Subject: [Ada] Improve code generated for Left_Rotate from Interfaces Date: Mon, 27 May 2019 11:14:43 +0200 Message-ID: <3139743.B4B5h9gqH0@polaris> MIME-Version: 1.0 This tweaks the GENERIC code emitted by gigi for the Left_Rotate routine from the Interfaces package so as to expose more optimization opportunities. Tested on x86_64-suse-linux, applied on the mainline. 2019-05-27 Eric Botcazou * gcc-interface/trans.c (gnat_to_gnu) : Convert the count to the unsigned version of its base type before proceeding. Index: gcc-interface/trans.c =================================================================== --- gcc-interface/trans.c (revision 271528) +++ gcc-interface/trans.c (working copy) @@ -7422,7 +7422,7 @@ gnat_to_gnu (Node_Id gnat_node) enum tree_code code = gnu_codes[kind]; bool ignore_lhs_overflow = false; location_t saved_location = input_location; - tree gnu_type; + tree gnu_type, gnu_max_shift = NULL_TREE; /* Fix operations set up for boolean types in GNU_CODES above. */ if (Is_Modular_Integer_Type (Underlying_Type (Etype (gnat_node)))) @@ -7445,6 +7445,17 @@ gnat_to_gnu (Node_Id gnat_node) gnu_rhs = gnat_to_gnu (Right_Opnd (gnat_node)); gnu_type = gnu_result_type = get_unpadded_type (Etype (gnat_node)); + /* If this is a shift, take the count as unsigned since that is what + most machines do and will generate simpler adjustments below. */ + if (IN (kind, N_Op_Shift)) + { + tree gnu_count_type + = gnat_unsigned_type_for (get_base_type (TREE_TYPE (gnu_rhs))); + gnu_rhs = convert (gnu_count_type, gnu_rhs); + gnu_max_shift + = convert (TREE_TYPE (gnu_rhs), TYPE_SIZE (gnu_type)); + } + /* Pending generic support for efficient vector logical operations in GCC, convert vectors to their representative array type view and fallthrough. */ @@ -7468,25 +7479,20 @@ gnat_to_gnu (Node_Id gnat_node) /* If this is a shift whose count is not guaranteed to be correct, we need to adjust the shift count. */ - if (IN (kind, N_Op_Shift) && !Shift_Count_OK (gnat_node)) - { - tree gnu_count_type = get_base_type (TREE_TYPE (gnu_rhs)); - tree gnu_max_shift - = convert (gnu_count_type, TYPE_SIZE (gnu_type)); - - if (kind == N_Op_Rotate_Left || kind == N_Op_Rotate_Right) - gnu_rhs = build_binary_op (TRUNC_MOD_EXPR, gnu_count_type, - gnu_rhs, gnu_max_shift); - else if (kind == N_Op_Shift_Right_Arithmetic) - gnu_rhs - = build_binary_op - (MIN_EXPR, gnu_count_type, - build_binary_op (MINUS_EXPR, - gnu_count_type, - gnu_max_shift, - build_int_cst (gnu_count_type, 1)), - gnu_rhs); - } + if ((kind == N_Op_Rotate_Left || kind == N_Op_Rotate_Right) + && !Shift_Count_OK (gnat_node)) + gnu_rhs = build_binary_op (TRUNC_MOD_EXPR, TREE_TYPE (gnu_rhs), + gnu_rhs, gnu_max_shift); + else if (kind == N_Op_Shift_Right_Arithmetic + && !Shift_Count_OK (gnat_node)) + gnu_rhs + = build_binary_op (MIN_EXPR, TREE_TYPE (gnu_rhs), + build_binary_op (MINUS_EXPR, + TREE_TYPE (gnu_rhs), + gnu_max_shift, + build_int_cst + (TREE_TYPE (gnu_rhs), 1)), + gnu_rhs); /* For right shifts, the type says what kind of shift to do, so we may need to choose a different type. In this case, @@ -7533,18 +7539,15 @@ gnat_to_gnu (Node_Id gnat_node) /* If this is a logical shift with the shift count not verified, we must return zero if it is too large. We cannot compensate - above in this case. */ + beforehand in this case. */ if ((kind == N_Op_Shift_Left || kind == N_Op_Shift_Right) && !Shift_Count_OK (gnat_node)) gnu_result - = build_cond_expr - (gnu_type, - build_binary_op (GE_EXPR, boolean_type_node, - gnu_rhs, - convert (TREE_TYPE (gnu_rhs), - TYPE_SIZE (gnu_type))), - build_int_cst (gnu_type, 0), - gnu_result); + = build_cond_expr (gnu_type, + build_binary_op (GE_EXPR, boolean_type_node, + gnu_rhs, gnu_max_shift), + build_int_cst (gnu_type, 0), + gnu_result); } break;