This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug middle-end/40887] GCC generates suboptimal code for indirect function calls on ARM
- From: "lessen42+gcc at gmail dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 28 Jul 2009 08:45:26 -0000
- Subject: [Bug middle-end/40887] GCC generates suboptimal code for indirect function calls on ARM
- References: <bug-40887-17992@http.gcc.gnu.org/bugzilla/>
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
------- Comment #3 from lessen42+gcc at gmail dot com 2009-07-28 08:45 -------
(In reply to comment #2)
> The point made is correct but there is something you've missed in your patch !
> loading lr with the address of the function you want to call, destroys the
> return address ,- so your code is never going to return !
>
> Instead you want -
>
> ldr r3,[r3]
> blx r3
>
> Or better still bx r3 but that is PR19599 :)
blx sets the link register to the correct return address as a part of the
instruction, and the return address of the calling function has to already have
been saved before this point or the mov lr, pc would destroy it already.
Though perhaps the code should just always use ip with armv5+ like on the other
side of the if() since that's callee saved and the tail-optimized "bx lr" would
be suboptimal, since that's considered a function return.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40887