This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug target/66120] New: __builtin_add/sub_overflow for int32_t emit poor code on ARM


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66120

            Bug ID: 66120
           Summary: __builtin_add/sub_overflow for int32_t emit poor code
                    on ARM
           Product: gcc
           Version: 5.1.0
            Status: UNCONFIRMED
          Severity: enhancement
          Priority: P3
         Component: target
          Assignee: unassigned at gcc dot gnu.org
          Reporter: gcc.hall at gmail dot com
  Target Milestone: ---

Please see related PR66112 for x86
-------------------------------------------------------------------
#include <stdio.h>
#include <inttypes.h>
int
main( int argc, const char *argv[] )
{
  int32_t result, a = (int32_t)atoi(argv[1]), b = (int32_t)atoi( argv[2] );
  if( __builtin_add_overflow( a, b, &result ) )
    printf( "Overflow\n");
 else
    printf( "Sum is %d\n", result );
}
----------------------------------------------------------------------
Few instructions on ARM set the overflow flag.  Two that do are 32-bit add and
subtract.  For these two, GCC could just emit "adds" or "subs" followed by
"bvs".
Instead (from the last atoi() down) it produces:-

    bl  atoi    @
    add r1, r4, r0  @ tmp121, a, b
    cmp r0, #0  @ b,
    blt .L4 @,
    cmp r1, r4  @ tmp121, a
    bge .L5 @,
    b   .L3 @
.L4:
    cmp r1, r4  @ tmp121, a
    ble .L5 @,


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]