bx instruction getting generated in arm assembly for O1

Hi,

For the following test:

int (*indirect_func)();

int indirect_call()
{
return indirect_func();
}

when generating the assembly with clang-3.5, for -march=armv5te, there is a difference in the assemblies generated with O0 and O1:

In the assembly generated with O0, we are getting the “blx” instruction whereas with O1 we get “bx” (in 3.4.2 we used to get “blx” for both O0 and O1).

Is this because of this patch: [llvm] r214959 - ARM: do not generate BLX instructions on Cortex-M CPUs

Or I am missing something.

Thanks,

Mayur

Hi,

For the following test:

int (*indirect_func)();

int indirect_call()
{
      return indirect_func();
}

when generating the assembly with clang-3.5, for -march=armv5te, there is a
difference in the assemblies generated with O0 and O1:

In the assembly generated with O0, we are getting the "blx" instruction whereas
with O1 we get "bx" (in 3.4.2 we used to get "blx" for both O0 and O1).

Can you post the asm that you're seeing for this function?

There's a related case to this on armv4t which Iain has a patch for, that I think we forgot about... The problem there is that armv4t doesn't have blx at all, so should be generating a sequence like: 'mov r0, ...; bx _Ltmp; _Ltmp: bl r0'.

Is this because of this patch: [llvm] r214959 - ARM: do not generate BLX
instructions on Cortex-M CPUs

I doubt it. armv5te isn't a cortex-m processor.

Cheers,

Jon

I'm a bit confused about what you think that you're testing - that's exactly what I'd expect to see. Without optimisation, the call will be a blx (call) followed by a function epilog. With optimisation, as the result of the callee is returned in the same register as the caller, it is a tail call, so a simple branch (bx - as you don't know at compile time whether it's a branch to ARM or Thumb code) should be emitted.

David