From patchwork Fri Jan 6 16:08:18 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mikael Pettersson X-Patchwork-Id: 711987 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 3tw8cH075lz9sxS for ; Sat, 7 Jan 2017 03:08:46 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="rqj9+sc/"; 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:from :mime-version:content-type:content-transfer-encoding:message-id :date:to:subject; q=dns; s=default; b=kRp9UA7dwYMtGMyik6oIFsuVHy f7MCeHmgUjBXlcXQSKVRM9xCOe5P/ZZ5BasbasWRnqAKvhGr48ewSKCNbeUyvcnj H/XU6TendpjvmLFSxo6tcudY7ah7G6k5jARxqnxQc3/+AuDg2OhBxw3Oj0LwNv+e IfpNpFO9C1j/q3M/Q= 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 :mime-version:content-type:content-transfer-encoding:message-id :date:to:subject; s=default; bh=9l1gPMvsCCqtw/7X9QWekzPhgVA=; b= rqj9+sc/uLlu+IsV2SpUtB/X2BnWUloJgJtRFclS6LiltRCugcQhttsxceNocEW9 eCcDgdDuKnhVieJRs5f94bEwqEzEiPlbgTyPutIFvguAg6gHSBZhTRQPKY3nOuL/ 7IZLeyY8LjT6HbiOBja6v6MAvgS8zj/+gcMhtkuaaFc= Received: (qmail 63747 invoked by alias); 6 Jan 2017 16:08: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 63737 invoked by uid 89); 6 Jan 2017 16:08:34 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.5 required=5.0 tests=AWL, BAYES_00, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, RCVD_IN_SORBS_SPAM, SPF_PASS autolearn=no version=3.3.2 spammy=0l, expander, HImode, himode X-HELO: mail-lf0-f66.google.com Received: from mail-lf0-f66.google.com (HELO mail-lf0-f66.google.com) (209.85.215.66) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 06 Jan 2017 16:08:23 +0000 Received: by mail-lf0-f66.google.com with SMTP id v186so215025lfa.2 for ; Fri, 06 Jan 2017 08:08:23 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:mime-version:content-transfer-encoding :message-id:date:to:subject; bh=Fmmh82o84UvaKqdmzzAb2U9r/0KFj3cbZe8r5EibO9E=; b=cvSLvRAGN3Mn/jk0T/V4civ6NM1XlQ1c9KpXV/Qi+SXAsPjZdV4lwTzDuUqfSdU32/ 7fDIfB3PsV3RxY15gE3HpuzRPmzABggCvfUFtfxbKo5NJw0P5mDMJDDhxaTD59DZgdC7 oELa7TmnkuYzhlrAOQc4WCikJ9oGdyflv9++Zrx3rDo/frwn5lZQcpVJmUkpo8W0uKlG 8yDR98jeLeSG8F1tRUfOGD7jMVj7QsrUEibyA0pZ42V1OkGZuePI2/JdvGn7TdZO1nEE KL4n1M2zLiFeBpIByZmM7a0FjV+G0aXUztUgCkLNin5V4fChEV42lLSkqtPJQDATyt3a GcZQ== X-Gm-Message-State: AIkVDXKf4yuccO7FiS+b/KWYZMB0gaEBTqyL8vPz1zsvH2O8LIViNkrHNKRVE2T8yGKs0A== X-Received: by 10.25.207.138 with SMTP id f132mr23431225lfg.151.1483718901150; Fri, 06 Jan 2017 08:08:21 -0800 (PST) Received: from cascade (h109n3-u-a31.ias.bredband.telia.com. [213.65.120.109]) by smtp.gmail.com with ESMTPSA id n124sm17211351lfn.5.2017.01.06.08.08.19 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 06 Jan 2017 08:08:20 -0800 (PST) From: Mikael Pettersson X-Google-Original-From: "Mikael Pettersson" Received: by cascade (sSMTP sendmail emulation); Fri, 06 Jan 2017 17:08:18 +0100 MIME-Version: 1.0 Message-ID: <22639.49394.656974.300679@gargle.gargle.HOWL> Date: Fri, 6 Jan 2017 17:08:18 +0100 To: gcc-patches@gcc.gnu.org Subject: [PATCH][M68K] allow long offsets in jump tables (wrong-code PR target/57583) This fixes / works-around the wrong-code PR57583 on M68K, caused by overflowing the 16-bit jump table offsets the backend uses. Ideally the backend should define CASE_VECTOR_SHORTEN_MODE, but that AFAIK needs insn length attributes, which the backend only has for CF but not for classic M68K. Instead this patch adds an -mlong-jump-table-offsets option, and adjusts the code for emitting and using jump table offsets to handle both short and long offsets. As long as the option is not selected, the backend behaves exactly as before. John Paul Adrian Glaubitz tested this patch by compiling "mednafen" with it, which previously failed; I also tested earlier versions. Is this Ok for trunk? /Mikael gcc/ 2017-01-06 Mikael Pettersson PR target/57583 * config/m68k/m68k.opt (LONG_JUMP_TABLE_OFFSETS): New option. * config/m68k/linux.h (ASM_RETURN_CASE_JUMP): Handle TARGET_LONG_JUMP_TABLE_OFFSETS. * config/m68k/m68kelf.h (ASM_RETURN_CASE_JUMP): Likewise. * config/m68k/netbsd-elf.h (ASM_RETURN_CASE_JUMP): Likewise. * config/m68k/m68k.h (CASE_VECTOR_MODE): Likewise. (ASM_OUTPUT_ADDR_DIFF_ELF): Likewise. * config/m68k/m68k.md (tablejump expander): Likewise. (*tablejump_pcrel_hi): Renamed from unnamed insn, reject TARGET_LONG_JUMP_TABLE_OFFSETS. (*tablejump_pcrel_si): New insn, handle TARGET_LONG_JUMP_TABLE_OFFSETS. * doc/invoke.texi (M68K options): Add -mlong-jump-table-offsets. --- gcc-7-20170101/gcc/config/m68k/linux.h.~1~ 2017-01-01 13:07:43.000000000 +0100 +++ gcc-7-20170101/gcc/config/m68k/linux.h 2017-01-06 14:36:37.366245875 +0100 @@ -98,9 +98,13 @@ along with GCC; see the file COPYING3. { \ if (ADDRESS_REG_P (operands[0])) \ return "jmp %%pc@(2,%0:l)"; \ + else if (TARGET_LONG_JUMP_TABLE_OFFSETS) \ + return "jmp %%pc@(2,%0:l)"; \ else \ return "ext%.l %0\n\tjmp %%pc@(2,%0:l)"; \ } \ + else if (TARGET_LONG_JUMP_TABLE_OFFSETS) \ + return "jmp %%pc@(2,%0:l)"; \ else \ return "jmp %%pc@(2,%0:w)"; \ } while (0) --- gcc-7-20170101/gcc/config/m68k/m68k.h.~1~ 2017-01-01 13:07:43.000000000 +0100 +++ gcc-7-20170101/gcc/config/m68k/m68k.h 2017-01-06 14:36:37.366245875 +0100 @@ -675,7 +675,7 @@ __transfer_from_trampoline () \ /* This address is OK as it stands. */ #define PIC_CASE_VECTOR_ADDRESS(index) index -#define CASE_VECTOR_MODE HImode +#define CASE_VECTOR_MODE (TARGET_LONG_JUMP_TABLE_OFFSETS ? SImode : HImode) #define CASE_VECTOR_PC_RELATIVE 1 #define DEFAULT_SIGNED_CHAR 1 @@ -857,7 +857,11 @@ do { if (cc_prev_status.flags & CC_IN_68 asm_fprintf (FILE, "\t.long %LL%d\n", VALUE) #define ASM_OUTPUT_ADDR_DIFF_ELT(FILE, BODY, VALUE, REL) \ - asm_fprintf (FILE, "\t.word %LL%d-%LL%d\n", VALUE, REL) + asm_fprintf (FILE, \ + TARGET_LONG_JUMP_TABLE_OFFSETS \ + ? "\t.long %LL%d-%LL%d\n" \ + : "\t.word %LL%d-%LL%d\n", \ + VALUE, REL) /* We don't have a way to align to more than a two-byte boundary, so do the best we can and don't complain. */ --- gcc-7-20170101/gcc/config/m68k/m68k.md.~1~ 2017-01-01 13:07:43.000000000 +0100 +++ gcc-7-20170101/gcc/config/m68k/m68k.md 2017-01-06 14:36:37.366245875 +0100 @@ -6695,7 +6695,9 @@ (define_expand "tablejump" { #if CASE_VECTOR_PC_RELATIVE operands[0] = gen_rtx_PLUS (SImode, pc_rtx, - gen_rtx_SIGN_EXTEND (SImode, operands[0])); + TARGET_LONG_JUMP_TABLE_OFFSETS + ? operands[0] + : gen_rtx_SIGN_EXTEND (SImode, operands[0])); #endif }) @@ -6710,12 +6712,36 @@ (define_insn "*tablejump_internal" [(set_attr "type" "jmp")]) ;; Jump to variable address from dispatch table of relative addresses. -(define_insn "" +(define_insn "*tablejump_pcrel_si" + [(set (pc) + (plus:SI (pc) + (match_operand:SI 0 "register_operand" "r"))) + (use (label_ref (match_operand 1 "" "")))] + "TARGET_LONG_JUMP_TABLE_OFFSETS" +{ +#ifdef ASM_RETURN_CASE_JUMP + ASM_RETURN_CASE_JUMP; +#else + if (TARGET_COLDFIRE) + { + if (ADDRESS_REG_P (operands[0])) + return MOTOROLA ? "jmp (2,pc,%0.l)" : "jmp pc@(2,%0:l)"; + else if (MOTOROLA) + return "jmp (2,pc,%0.l)"; + else + return "jmp pc@(2,%0:l)"; + } + else + return MOTOROLA ? "jmp (2,pc,%0.l)" : "jmp pc@(2,%0:l)"; +#endif +}) + +(define_insn "*tablejump_pcrel_hi" [(set (pc) (plus:SI (pc) (sign_extend:SI (match_operand:HI 0 "register_operand" "r")))) (use (label_ref (match_operand 1 "" "")))] - "" + "!TARGET_LONG_JUMP_TABLE_OFFSETS" { #ifdef ASM_RETURN_CASE_JUMP ASM_RETURN_CASE_JUMP; --- gcc-7-20170101/gcc/config/m68k/m68k.opt.~1~ 2017-01-01 13:07:43.000000000 +0100 +++ gcc-7-20170101/gcc/config/m68k/m68k.opt 2017-01-06 14:45:19.305434346 +0100 @@ -142,6 +142,10 @@ mid-shared-library Target Report Mask(ID_SHARED_LIBRARY) Enable ID based shared library. +mlong-jump-table-offsets +Target Report RejectNegative Mask(LONG_JUMP_TABLE_OFFSETS) +Use 32-bit offsets in jump tables rather than 16-bit offsets. + mnobitfield Target RejectNegative InverseMask(BITFIELD) Do not use the bit-field instructions. --- gcc-7-20170101/gcc/config/m68k/m68kelf.h.~1~ 2017-01-01 13:07:43.000000000 +0100 +++ gcc-7-20170101/gcc/config/m68k/m68kelf.h 2017-01-06 14:36:37.366245875 +0100 @@ -58,9 +58,13 @@ along with GCC; see the file COPYING3. { \ if (ADDRESS_REG_P (operands[0])) \ return "jmp %%pc@(2,%0:l)"; \ + else if (TARGET_LONG_JUMP_TABLE_OFFSETS) \ + return "jmp %%pc@(2,%0:l)"; \ else \ return "ext%.l %0\n\tjmp %%pc@(2,%0:l)"; \ } \ + else if (TARGET_LONG_JUMP_TABLE_OFFSETS) \ + return "jmp %%pc@(2,%0:l)"; \ else \ return "jmp %%pc@(2,%0:w)"; \ } while (0) --- gcc-7-20170101/gcc/config/m68k/netbsd-elf.h.~1~ 2017-01-01 13:07:43.000000000 +0100 +++ gcc-7-20170101/gcc/config/m68k/netbsd-elf.h 2017-01-06 14:36:37.366245875 +0100 @@ -136,9 +136,13 @@ while (0) { \ if (ADDRESS_REG_P (operands[0])) \ return "jmp %%pc@(2,%0:l)"; \ + else if (TARGET_LONG_JUMP_TABLE_OFFSETS) \ + return "jmp %%pc@(2,%0:l)"; \ else \ return "ext%.l %0\n\tjmp %%pc@(2,%0:l)"; \ } \ + else if (TARGET_LONG_JUMP_TABLE_OFFSETS) \ + return "jmp %%pc@(2,%0:l)"; \ else \ return "jmp %%pc@(2,%0:w)"; \ } while (0) --- gcc-7-20170101/gcc/doc/invoke.texi.~1~ 2017-01-01 13:07:43.000000000 +0100 +++ gcc-7-20170101/gcc/doc/invoke.texi 2017-01-06 15:32:04.101803458 +0100 @@ -837,7 +837,7 @@ Objective-C and Objective-C++ Dialects}. -mno-short -mhard-float -m68881 -msoft-float -mpcrel @gol -malign-int -mstrict-align -msep-data -mno-sep-data @gol -mshared-library-id=n -mid-shared-library -mno-id-shared-library @gol --mxgot -mno-xgot} +-mxgot -mno-xgot -mlong-jump-table-offsets} @emph{MCore Options} @gccoptlist{-mhardlit -mno-hardlit -mdiv -mno-div -mrelax-immediates @gol @@ -18460,6 +18460,11 @@ object file that accesses more than 8192 These options have no effect unless GCC is generating position-independent code. +@item -mlong-jump-table-offsets +@opindex mlong-jump-table-offsets +Use 32-bit offsets in @code{switch} tables. The default is to use +16-bit offsets. + @end table @node MCore Options