Quantcast

odd code generation

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

odd code generation

David W. Schultz
I am trying to understand why the TI gcc compiler (version from 9 Feb
2015) is generating some wildly inefficient code.

The line:

  v = corrected(results[0]) - p->offsets[0];

Appears to generate this:

   2fe0:       1c 42 7e 03     mov     &0x037e,r12
    2fe4:       b0 12 9e 2f     call    #0x2f9e

00002fe8 <.LVL12>:
    2fe8:       3d 40 40 10     mov     #4160,  r13     ;#0x1040
    2fec:       5e 4d 02 00     mov.b   2(r13), r14     ;0x0002(r13)
    2ff0:       5d 4d 03 00     mov.b   3(r13), r13     ;0x0003(r13)
    2ff4:       0d 5d           rla     r13
    2ff6:       0d 5d           rla     r13
    2ff8:       0d 5d           rla     r13
    2ffa:       0d 5d           rla     r13
    2ffc:       0d 5d           rla     r13
    2ffe:       0d 5d           rla     r13
    3000:       0d 5d           rla     r13
    3002:       0d 5d           rla     r13
    3004:       0d de           bis     r14,    r13

00003006 <.Loc.223.1>:
    3006:       0c 8d           sub     r13,    r12
    3008:       30 41           ret

In spite of the type for offsets being an int, the compiler generates
code that fetches it a byte at a time and then shifts to combine. This
is with optimization on. (-O2) Looking at some other spots where I read
the information memory, it also reads it a byte at a time.

Why is it being so stupid? Even the shift is stupid since a single swpb
would do the trick.

--
David W. Schultz
http://home.earthlink.net/~david.schultz
Returned for Regrooving



------------------------------------------------------------------------------
_______________________________________________
Mspgcc-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/mspgcc-users
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: odd code generation

David W. Schultz
Answered my own question, sort of.

The TI version of gcc doesn't have the hooks to linker defined symbols
like mspgcc did so I edited the linker script to provide symbols
defining the information memory. I also used the now missing crtld.h as
a guide and included "char __infoc[];"

When I changed that to a type int, the generated code is much better.

So the compiler is seeing the type cast but remembering that the
original type is char. It is also apparently assuming that the alignment
will be completely random so generates code assuming misalignment.

Easily fixed in my case but still very surprising.


--
David W. Schultz
http://home.earthlink.net/~david.schultz
Returned for Regrooving



------------------------------------------------------------------------------
_______________________________________________
Mspgcc-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/mspgcc-users
Loading...