[{"id":1761795,"web_url":"http://patchwork.ozlabs.org/comment/1761795/","msgid":"<CAFULd4Yc25gjsr221BL1eZ5g5PcuZzV47SD_Ei1NzzG0ZWD0PA@mail.gmail.com>","list_archive_url":null,"date":"2017-09-01T16:22:11","subject":"Re: [PATCH] Fix x86_64 ICE with -fpie -mcmodel=large (PR\n\ttarget/81766)","submitter":{"id":808,"url":"http://patchwork.ozlabs.org/api/people/808/","name":"Uros Bizjak","email":"ubizjak@gmail.com"},"content":"On Fri, Sep 1, 2017 at 1:42 PM, Jakub Jelinek <jakub@redhat.com> wrote:\n> Hi!\n>\n> As mentioned in the PR, ix86_init_pic_reg for -mcmodel=large PIC creates\n> invalid RTL.  Shrink wrapping managed to work around it by unconditionally\n> running find_many_sub_basic_blocks that has been invoked even when the\n> prologue or split prologue actually didn't contain anything, but that isn't\n> done anymore.\n>\n> The problem is that we add a label into the sequence that we then insert on\n> the single succ edge after ENTRY; but this insertion inserts the label after\n> the NOTE_INSN_BLOCK_BEG, which is invalid, because labels should precede\n> that.\n>\n> Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux, ok for\n> trunk?\n>\n> 2017-09-01  Jakub Jelinek  <jakub@redhat.com>\n>\n>         PR target/81766\n>         * config/i386/i386.c (ix86_init_large_pic_reg): Return label instead of void.\n>         (ix86_init_pic_reg): Remember label from ix86_init_large_pic_reg, if non-NULL\n>         and preceded by NOTE_INSN_BASIC_BLOCK, swap the note and label.\n>\n>         * gcc.target/i386/pr81766.c: New test.\n\nOK.\n\nThanks,\nUros.\n\n> --- gcc/config/i386/i386.c.jj   2017-08-07 18:50:10.000000000 +0200\n> +++ gcc/config/i386/i386.c      2017-08-08 16:01:41.917136120 +0200\n> @@ -8829,7 +8829,7 @@ ix86_use_pseudo_pic_reg (void)\n>\n>  /* Initialize large model PIC register.  */\n>\n> -static void\n> +static rtx_code_label *\n>  ix86_init_large_pic_reg (unsigned int tmp_regno)\n>  {\n>    rtx_code_label *label;\n> @@ -8846,6 +8846,7 @@ ix86_init_large_pic_reg (unsigned int tm\n>    emit_insn (gen_set_got_offset_rex64 (tmp_reg, label));\n>    emit_insn (ix86_gen_add3 (pic_offset_table_rtx,\n>                             pic_offset_table_rtx, tmp_reg));\n> +  return label;\n>  }\n>\n>  /* Create and initialize PIC register if required.  */\n> @@ -8854,6 +8855,7 @@ ix86_init_pic_reg (void)\n>  {\n>    edge entry_edge;\n>    rtx_insn *seq;\n> +  rtx_code_label *label = NULL;\n>\n>    if (!ix86_use_pseudo_pic_reg ())\n>      return;\n> @@ -8863,7 +8865,7 @@ ix86_init_pic_reg (void)\n>    if (TARGET_64BIT)\n>      {\n>        if (ix86_cmodel == CM_LARGE_PIC)\n> -       ix86_init_large_pic_reg (R11_REG);\n> +       label = ix86_init_large_pic_reg (R11_REG);\n>        else\n>         emit_insn (gen_set_got_rex64 (pic_offset_table_rtx));\n>      }\n> @@ -8887,6 +8889,22 @@ ix86_init_pic_reg (void)\n>    entry_edge = single_succ_edge (ENTRY_BLOCK_PTR_FOR_FN (cfun));\n>    insert_insn_on_edge (seq, entry_edge);\n>    commit_one_edge_insertion (entry_edge);\n> +\n> +  if (label)\n> +    {\n> +      basic_block bb = BLOCK_FOR_INSN (label);\n> +      rtx_insn *bb_note = PREV_INSN (label);\n> +      /* If the note preceding the label starts a basic block, and the\n> +        label is a member of the same basic block, interchange the two.  */\n> +      if (bb_note != NULL_RTX\n> +         && NOTE_INSN_BASIC_BLOCK_P (bb_note)\n> +         && bb != NULL\n> +         && bb == BLOCK_FOR_INSN (bb_note))\n> +       {\n> +         reorder_insns_nobb (bb_note, bb_note, label);\n> +         BB_HEAD (bb) = label;\n> +       }\n> +    }\n>  }\n>\n>  /* Initialize a variable CUM of type CUMULATIVE_ARGS\n> --- gcc/testsuite/gcc.target/i386/pr81766.c.jj  2017-08-08 16:10:04.299459808 +0200\n> +++ gcc/testsuite/gcc.target/i386/pr81766.c     2017-08-08 16:09:28.000000000 +0200\n> @@ -0,0 +1,9 @@\n> +/* PR target/81766 */\n> +/* { dg-do compile { target { pie && lp64 } } } */\n> +/* { dg-options \"-O2 -fpie -mcmodel=large\" } */\n> +\n> +int\n> +main ()\n> +{\n> +  return 0;\n> +}\n>\n>         Jakub","headers":{"Return-Path":"<gcc-patches-return-461303-incoming=patchwork.ozlabs.org@gcc.gnu.org>","X-Original-To":"incoming@patchwork.ozlabs.org","Delivered-To":["patchwork-incoming@bilbo.ozlabs.org","mailing list gcc-patches@gcc.gnu.org"],"Authentication-Results":["ozlabs.org;\n\tspf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org\n\t(client-ip=209.132.180.131; helo=sourceware.org;\n\tenvelope-from=gcc-patches-return-461303-incoming=patchwork.ozlabs.org@gcc.gnu.org;\n\treceiver=<UNKNOWN>)","ozlabs.org; dkim=pass (1024-bit key;\n\tunprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org\n\theader.b=\"m/wwODW/\"; dkim-atps=neutral","sourceware.org; auth=none"],"Received":["from sourceware.org (server1.sourceware.org [209.132.180.131])\n\t(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256\n\tbits)) (No client certificate requested)\n\tby ozlabs.org (Postfix) with ESMTPS id 3xkPfD2GSzz9t2x\n\tfor <incoming@patchwork.ozlabs.org>;\n\tSat,  2 Sep 2017 02:22:27 +1000 (AEST)","(qmail 117456 invoked by alias); 1 Sep 2017 16:22:20 -0000","(qmail 117445 invoked by uid 89); 1 Sep 2017 16:22:19 -0000","from mail-vk0-f49.google.com (HELO mail-vk0-f49.google.com)\n\t(209.85.213.49) by sourceware.org\n\t(qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP;\n\tFri, 01 Sep 2017 16:22:14 +0000","by mail-vk0-f49.google.com with SMTP id z187so1968572vkd.2 for\n\t<gcc-patches@gcc.gnu.org>; Fri, 01 Sep 2017 09:22:14 -0700 (PDT)","by 10.103.55.28 with HTTP; Fri, 1 Sep 2017 09:22:11 -0700 (PDT)"],"DomainKey-Signature":"a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id\n\t:list-unsubscribe:list-archive:list-post:list-help:sender\n\t:mime-version:in-reply-to:references:from:date:message-id\n\t:subject:to:cc:content-type; q=dns; s=default; b=Fxm4jy8HvxEzVW0\n\tBMVBSYs/XWvkBusgIt1DCNyBH/1Cd5SJXUN7QMMSv1RuzZ1OPfHDIpxcq4HvDChv\n\tTBLyM4rgc/56nvEBSVsGFURe9udlNLZZ1i73bFn+OpUdnxBkgqpD84aL6eqZFhBQ\n\tq5BI58Ae7xRBPkVHL2dIffcovIpY=","DKIM-Signature":"v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id\n\t:list-unsubscribe:list-archive:list-post:list-help:sender\n\t:mime-version:in-reply-to:references:from:date:message-id\n\t:subject:to:cc:content-type; s=default; bh=us31tUnDPAHT5PR5eivRZ\n\tUNDggA=; b=m/wwODW/iOqfBuJazzRHI//JW6Ht1WqT5WyBsh6ZvWNlW2Eo/u/c/\n\tJxzbKIyY/H49YOIuWjjbYr6FCaacq2OOfJxEWW+E8VZTOQVqqGL/CeqYBxo+kXVv\n\t7bzm1rU5kRf2LfPZEf2xZksOWmmdY1vXr49oNDGwRNrGvbjapNjJcw=","Mailing-List":"contact gcc-patches-help@gcc.gnu.org; run by ezmlm","Precedence":"bulk","List-Id":"<gcc-patches.gcc.gnu.org>","List-Unsubscribe":"<mailto:gcc-patches-unsubscribe-incoming=patchwork.ozlabs.org@gcc.gnu.org>","List-Archive":"<http://gcc.gnu.org/ml/gcc-patches/>","List-Post":"<mailto:gcc-patches@gcc.gnu.org>","List-Help":"<mailto:gcc-patches-help@gcc.gnu.org>","Sender":"gcc-patches-owner@gcc.gnu.org","X-Virus-Found":"No","X-Spam-SWARE-Status":"No, score=-10.7 required=5.0 tests=AWL, BAYES_00,\n\tFREEMAIL_FROM, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE,\n\tRCVD_IN_SORBS_SPAM,\n\tSPF_PASS autolearn=ham version=3.3.2 spammy=","X-HELO":"mail-vk0-f49.google.com","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net;\n\ts=20161025;\n\th=x-gm-message-state:mime-version:in-reply-to:references:from:date\n\t:message-id:subject:to:cc;\n\tbh=h4jsZ/rkkkK3hCLw9g0Sggqor2hgU4kDiLQJD/jJRJc=;\n\tb=LlB31BwFs2RbmH+QCAliqzGn47HJ2Jr4VQ12FZk2+AZsZDOlT7H4/uPWu6sHtQqNuf\n\thxgvJQOEaXK1fubGCaju7cCb/FV0TeW/v3E6e7n5b2hKaRgi7lCW+htWGRbtZNZBvY1m\n\tWh8FXBGOJq5+2gNvTykrJxUmrd8vCdRjKqzz4kmea8lLqhxbaM0vamnlvqRv8MpxwuPn\n\tTIIq+XsHl86+OV/Tfn6NdoYTbxewopTNJUQUNXzc7vaSdqy/F4U3F0WrbP+hIAtgd5NX\n\tKGcmbuxeyc0/BLvoldZSV5AdXgB7Qa4CMr+lR7dkNuf6Nyp6AavnQaB+RWUWMYK/ah3d\n\tsALg==","X-Gm-Message-State":"AHPjjUh/8i0m8Iz36tIVaC8yva8Q7YCE7qwC5LJbxJMY6PwYh4dU+oS5\tIPvu/3sVYpSMU+LpSwjn1t7pweaDPw==","X-Google-Smtp-Source":"ADKCNb4DtUlrr54waNjGOU5b2PbBUK5CTJpt9o291LcNss3JyazMSxIQcqkIMHZWVMwDH12m5Ga1gvNEybMvoFU7MzM=","X-Received":"by 10.31.33.141 with SMTP id h135mr1504360vkh.137.1504282932337;\n\tFri, 01 Sep 2017 09:22:12 -0700 (PDT)","MIME-Version":"1.0","In-Reply-To":"<20170901114251.GH2323@tucnak>","References":"<20170901114251.GH2323@tucnak>","From":"Uros Bizjak <ubizjak@gmail.com>","Date":"Fri, 1 Sep 2017 18:22:11 +0200","Message-ID":"<CAFULd4Yc25gjsr221BL1eZ5g5PcuZzV47SD_Ei1NzzG0ZWD0PA@mail.gmail.com>","Subject":"Re: [PATCH] Fix x86_64 ICE with -fpie -mcmodel=large (PR\n\ttarget/81766)","To":"Jakub Jelinek <jakub@redhat.com>","Cc":"\"gcc-patches@gcc.gnu.org\" <gcc-patches@gcc.gnu.org>","Content-Type":"text/plain; charset=\"UTF-8\""}}]