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 middle-end/11821] New: Operator implementation as a library call fails with constants


PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=11821

           Summary: Operator implementation as a library call fails with
                    constants
           Product: gcc
           Version: 3.4
            Status: UNCONFIRMED
          Severity: minor
          Priority: P3
         Component: middle-end
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: alga at rgai dot hu
                CC: gcc-bugs at gcc dot gnu dot org
 GCC build triplet: i686-pc-linux-gnu
  GCC host triplet: i686-pc-linux-gnu
GCC target triplet: arm-unknown-elf

If the C source code contains an operator which doesn't have a machine code
instruction but has a library implementation (such as % and /) and the second
operand is a constant, then GCC inserts an inline implementation of the operator
into the assembly code (example_1) rather than a function call (example_2) to
the library routine (e.g. __modsi3). In a general case the appropriate function
call is generated.
GCC should avoid operator inlining in the case when optimizing for size.

--- c example_1 ---
// arm-elf-gcc -S -g0 -Os -o func-in-1.s func-in-1.c
int a;
int foo ()
{
  return (a % 5);
} 
--- c example_2 ---
// arm-elf-gcc -S -g0 -Os -o func-in-2.s func-in-2.c
int a;
int foo ()
{
  return (12 % a);
}

--- arm code example_1 ---
foo:
 ldr r3, .L2
 ldr r2, [r3, #0]
 ldr r3, .L2+4
 smull r1, r3, r2, r3
 mov r0, r2, asr #31
 rsb r0, r0, r3, asr #1
 add r0, r0, r0, asl #2
 rsb r0, r0, r2
 mov pc, lr 

--- arm code example_2 ---
foo:
 mov ip, sp
 stmfd sp!, {fp, ip, lr, pc}
 ldr r3, .L2
 sub fp, ip, #4
 ldr r1, [r3, #0]
 mov r0, #12
 bl __modsi3
 ldmea fp, {fp, sp, pc}


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