From patchwork Sat Jun 4 06:10:57 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oleg Endo X-Patchwork-Id: 630137 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org 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 3rM9Zf001Yz9t89 for ; Sat, 4 Jun 2016 16:11:20 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=LHXwz0xq; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :message-id:subject:from:to:date:content-type:mime-version; q= dns; s=default; b=FiPpxnT0fuGArvIZMGP2vGksWYHfiL4sFOYdb02znevCjk iBnoSipJ6JcEzF6O3GV8z4QdJSijpdGQdeV8xia19afq4TNXrZAnZXmYjuUWr9o5 IAWSGqzhh46Ir9hCEifF/lzmeCoYIewp5VEyCeEH17w6hx9nhNTcDm8qXgx6Y= 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 :message-id:subject:from:to:date:content-type:mime-version; s= default; bh=rT6NQ7eK+6BiO+zHqgg4xkRPAZo=; b=LHXwz0xqGQxCdDHs66W0 TVBwnPBXBX6LHQAZNglE1b6OQiJXu547nMDFoWZrUW7xeZlI9kYRxTtQj28s7IxU gTe5PRbdqwR96kAVWj/Dkldzt5umM0Kv5EW/hdTRSMInA71xiKFQB7tTTysp/pwU czMq5W5MJ1hpRRArHRqb0uA= Received: (qmail 61793 invoked by alias); 4 Jun 2016 06:11:10 -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 61756 invoked by uid 89); 4 Jun 2016 06:11:09 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.7 required=5.0 tests=AWL, BAYES_00, KAM_LAZY_DOMAIN_SECURITY, RCVD_IN_DNSWL_NONE, RP_MATCHES_RCVD autolearn=ham version=3.3.2 spammy=mems, Hx-languages-length:1255 X-HELO: mailout04.t-online.de Received: from mailout04.t-online.de (HELO mailout04.t-online.de) (194.25.134.18) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Sat, 04 Jun 2016 06:11:07 +0000 Received: from fwd11.aul.t-online.de (fwd11.aul.t-online.de [172.20.27.152]) by mailout04.t-online.de (Postfix) with SMTP id D8E7D41B1A27 for ; Sat, 4 Jun 2016 08:11:02 +0200 (CEST) Received: from [192.168.0.16] (Vr4L+BZG8hCBe1ByPGrs5OZmWcxmssK5XZjSELDjAUx4ZqBav1v2Nf0ntW4NNBpQHU@[115.165.93.200]) by fwd11.t-online.de with (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384 encrypted) esmtp id 1b94nU-0hfTXc0; Sat, 4 Jun 2016 08:11:00 +0200 Message-ID: <1465020657.15496.108.camel@t-online.de> Subject: [SH][committed] Avoid potential slient wrong-code with reg+reg addr. modes From: Oleg Endo To: gcc-patches Date: Sat, 04 Jun 2016 15:10:57 +0900 Mime-Version: 1.0 X-IsSubscribed: yes Hi, The attached patch removes the hardcoded "r0" when printing reg+reg addressing mode mems on SH. Tested on sh-elf with make -k check RUNTESTFLAGS="--target_board=sh-sim\{-m2/-ml,-m2/-mb, -m2a/-mb,-m4/-ml,-m4/-mb,-m4a/-ml,-m4a/-mb}" Committed as r237088. Cheers, Oleg gcc/ChangeLog: * config/sh/sh.c (sh_print_operand_address): Don't use hardcoded 'r0' for reg+reg addressing mode. diff --git a/gcc/config/sh/sh.c b/gcc/config/sh/sh.c index 2bd917a..74327aa 100644 --- a/gcc/config/sh/sh.c +++ b/gcc/config/sh/sh.c @@ -1038,8 +1038,16 @@ sh_print_operand_address (FILE *stream, machine_mode /*mode*/, rtx x) int base_num = true_regnum (base); int index_num = true_regnum (index); - fprintf (stream, "@(r0,%s)", - reg_names[MAX (base_num, index_num)]); + /* If base or index is R0, make sure that it comes first. + Usually one of them will be R0, but the order might be wrong. + If neither base nor index are R0 it's an error and we just + pass it on to the assembler. This avoids silent wrong code + bugs. */ + if (base_num == 0 && index_num != 0) + std::swap (base_num, index_num); + + fprintf (stream, "@(%s,%s)", reg_names[index_num], + reg_names[base_num]); break; }