Bug 91816 - [8/9 Regression] Arm generates out of range conditional branches in Thumb2
Summary: [8/9 Regression] Arm generates out of range conditional branches in Thumb2
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: target (show other bugs)
Version: 10.0
: P2 normal
Target Milestone: 8.5
Assignee: Stam Markianos-Wright
URL:
Keywords: assemble-failure, wrong-code
Depends on:
Blocks:
 
Reported: 2019-09-19 10:02 UTC by Tamar Christina
Modified: 2020-11-30 11:12 UTC (History)
1 user (show)

See Also:
Host:
Target: arm-*
Build:
Known to work:
Known to fail:
Last reconfirmed: 2019-09-24 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Tamar Christina 2019-09-19 10:02:36 UTC
Originally reported at binutils https://sourceware.org/bugzilla/show_bug.cgi?id=24991

The testcase in the report generates an out of range conditional branch because the body of the if is too large.

This condition should have been changed into an unconditional branch by the compiler.
Comment 1 Tamar Christina 2019-09-19 10:03:06 UTC
This needs to be Backported to all supported GCC versions.
Comment 2 Richard Biener 2019-11-14 07:57:25 UTC
The GCC 7 branch is being closed, re-targeting to GCC 8.4.
Comment 3 CVS Commits 2020-02-03 10:32:31 UTC
The master branch has been updated by Stam Markianos-Wright <stammark@gcc.gnu.org>:

https://gcc.gnu.org/g:44f77a6dea2f312ee1743f3dde465c1b8453ee13

commit r10-6404-g44f77a6dea2f312ee1743f3dde465c1b8453ee13
Author: Stam Markianos-Wright <stam.markianos-wright@arm.com>
Date:   Mon Feb 3 10:25:46 2020 +0000

    This patch is for PR target/91816
    
    This is a patch for an issue where the compiler was generating a conditional
    branch in Thumb2, which was too far for b{cond} to handle.
    
    This was originally reported at binutils:
    https://sourceware.org/bugzilla/show_bug.cgi?id=24991
    
    And then raised for GCC:
    https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91816
    
    As can be seen here:
    
    http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dui0489c/Cihfddaf.html
    
    the range of a 32-bit Thumb B{cond} is +/-1MB.
    
    This is now checked for in arm.md and an unconditional branch is generated if
    the jump would be greater than 1MB.
    
    gcc/ChangeLog
    
    2020-02-03  Stam Markianos-Wright  <stam.markianos-wright@arm.com>
    
    	PR target/91816
    	* config/arm/arm-protos.h: New function arm_gen_far_branch prototype.
    	* config/arm/arm.c (arm_gen_far_branch): New function
    	arm_gen_far_branch.
    	* config/arm/arm.md: Update b<cond> for Thumb2 range checks.
    
    gcc/testsuite/ChangeLog
    
    2020-02-03  Stam Markianos-Wright  <stam.markianos-wright@arm.com>
    
    	PR target/91816
    	* gcc.target/arm/pr91816.c: New test.
Comment 4 Jakub Jelinek 2020-03-04 09:38:36 UTC
GCC 8.4.0 has been released, adjusting target milestone.
Comment 5 CVS Commits 2020-11-25 13:04:09 UTC
The master branch has been updated by Stam Markianos-Wright <stammark@gcc.gnu.org>:

https://gcc.gnu.org/g:bc771e6c3a2b1fe74328639a00531fc0c3923e43

commit r11-5332-gbc771e6c3a2b1fe74328639a00531fc0c3923e43
Author: Stam Markianos-Wright <stam.markianos-wright@arm.com>
Date:   Wed Nov 25 12:50:06 2020 +0000

    arm: Add test that was missing from old commit [PR91816]
    
    A while back I submitted GCC10 commit:
    
     44f77a6dea2f312ee1743f3dde465c1b8453ee13
    
    for PR91816.
    
    Turns out I was an idiot and forgot to include the test in the actual git commit.
    
    Tested that the test still passes on a cross arm-none-eabi and also in a
    Cortex A-15 bootstrap with no regressions.
    
    gcc/testsuite/ChangeLog:
            PR target/91816
            * gcc.target/arm/pr91816.c: New test.
Comment 6 CVS Commits 2020-11-25 13:41:13 UTC
The releases/gcc-10 branch has been updated by Stam Markianos-Wright <stammark@gcc.gnu.org>:

https://gcc.gnu.org/g:8804b6ae3da91f3baa82da2fe28090025d5717d3

commit r10-9079-g8804b6ae3da91f3baa82da2fe28090025d5717d3
Author: Stam Markianos-Wright <stam.markianos-wright@arm.com>
Date:   Wed Nov 25 13:11:09 2020 +0000

        arm: Add test that was missing from old commit [PR91816]
    
        A while back I submitted GCC10 commit:
    
         44f77a6dea2f312ee1743f3dde465c1b8453ee13
    
        for PR91816.
    
        Turns out I was an idiot and forgot to include the test in the actual git commit.
    
        Tested that the test still passes on a cross arm-none-eabi and also in a
        Cortex A-15 bootstrap with no regressions.
    
    gcc/testsuite/ChangeLog:
    
    2020-11-25  Stam Markianos-Wright  <stam.markianos-wright@arm.com>
    
            PR target/91816
            * gcc.target/arm/pr91816.c: New test.
Comment 7 CVS Commits 2020-11-30 10:56:39 UTC
The releases/gcc-8 branch has been updated by Stam Markianos-Wright <stammark@gcc.gnu.org>:

https://gcc.gnu.org/g:3a936a9ecddef58ad5b6ee11697c3f791b942708

commit r8-10655-g3a936a9ecddef58ad5b6ee11697c3f791b942708
Author: Stam Markianos-Wright <stam.markianos-wright@arm.com>
Date:   Mon Nov 30 10:47:54 2020 +0000

    Backport of the patch for PR target/91816
    
    This is a patch for an issue where the compiler was generating a
    conditional branch in Thumb2, which was too far for b{cond} to handle.
    
    This backport also includes the subsequent fixes to the test in this
    patch.
    
    gcc/ChangeLog
    
            PR target/91816
            * config/arm/arm-protos.h: New function arm_gen_far_branch prototype.
            * config/arm/arm.c (arm_gen_far_branch): New function
            arm_gen_far_branch.
            * config/arm/arm.md: Update b<cond> for Thumb2 range checks.
    
    gcc/testsuite/ChangeLog
    
            PR target/91816
            * gcc.target/arm/pr91816.c: New test.
Comment 8 CVS Commits 2020-11-30 11:10:45 UTC
The releases/gcc-9 branch has been updated by Stam Markianos-Wright <stammark@gcc.gnu.org>:

https://gcc.gnu.org/g:6b7ab0e565d79a7e6ae5dbbf17a5eb4eafe56dc8

commit r9-9081-g6b7ab0e565d79a7e6ae5dbbf17a5eb4eafe56dc8
Author: Stam Markianos-Wright <stam.markianos-wright@arm.com>
Date:   Mon Nov 30 11:05:30 2020 +0000

    Backport of the patch for PR target/91816
    
    This is a patch for an issue where the compiler was generating a
    conditional branch in Thumb2, which was too far for b{cond} to handle.
    
    This backport also includes the subsequent fixes to the test in this
    patch.
    
    gcc/ChangeLog
    
            * config/arm/arm-protos.h: New function arm_gen_far_branch prototype.
            * config/arm/arm.c (arm_gen_far_branch): New function
            arm_gen_far_branch.
            * config/arm/arm.md: Update b<cond> for Thumb2 range checks.
    
    gcc/testsuite/ChangeLog
    
            * gcc.target/arm/pr91816.c: New test.
Comment 9 Stam Markianos-Wright 2020-11-30 11:12:01 UTC
Patch is now on all active branches, so moving to RESOLVED. Thanks to all for their reviews!