llvm-project/llvm/lib
Evan Cheng 0e8f4612a9 For functions with ARM target specific calling convention, when simplify-libcall
optimize a call to a llvm intrinsic to something that invovles a call to a C
library call, make sure it sets the right calling convention on the call.

e.g.
extern double pow(double, double);
double t(double x) {
  return pow(10, x);
}

Compiles to something like this for AAPCS-VFP:
define arm_aapcs_vfpcc double @t(double %x) #0 {
entry:
  %0 = call double @llvm.pow.f64(double 1.000000e+01, double %x)
  ret double %0
}

declare double @llvm.pow.f64(double, double) #1

Simplify libcall (part of instcombine) will turn the above into:
define arm_aapcs_vfpcc double @t(double %x) #0 {
entry:
  %__exp10 = call double @__exp10(double %x) #1
  ret double %__exp10
}

declare double @__exp10(double)

The pre-instcombine code works because calls to LLVM builtins are special.
Instruction selection will chose the right calling convention for the call.
However, the code after instcombine is wrong. The call to __exp10 will use
the C calling convention.

I can think of 3 options to fix this.

1. Make "C" calling convention just work since the target should know what CC
   is being used.

   This doesn't work because each function can use different CC with the "pcs"
   attribute.

2. Have Clang add the right CC keyword on the calls to LLVM builtin.

   This will work but it doesn't match the LLVM IR specification which states
   these are "Standard C Library Intrinsics".

3. Fix simplify libcall so the resulting calls to the C routines will have the
   proper CC keyword. e.g.
   %__exp10 = call arm_aapcs_vfpcc double @__exp10(double %x) #1

   This works and is the solution I implemented here.

Both solutions #2 and #3 would work. After carefully considering the pros and
cons, I decided to implement #3 for the following reasons.

1. It doesn't change the "spec" of the intrinsics.
2. It's a self-contained fix.

There are a couple of potential downsides.
1. There could be other places in the optimizer that is broken in the same way
   that's not addressed by this.
2. There could be other calling conventions that need to be propagated by
   simplify-libcall that's not handled.

But for now, this is the fix that I'm most comfortable with.

llvm-svn: 203488
2014-03-10 20:49:45 +00:00
..
Analysis [TTI] There is actually no realistic way to pop TTI implementations off 2014-03-10 02:45:14 +00:00
AsmParser IR: Change inalloca's grammar a bit 2014-03-09 06:41:58 +00:00
Bitcode [C++11] Add range based accessors for the Use-Def chain of a Value. 2014-03-09 03:16:01 +00:00
CodeGen [C++11] Remove 'virtual' keyword from methods marked with 'override' keyword. 2014-03-10 05:29:18 +00:00
DebugInfo Replace OwningPtr<T> with std::unique_ptr<T>. 2014-03-06 05:51:42 +00:00
ExecutionEngine Make createObjectImage and createObjectImageFromFile static methods on the 2014-03-08 18:45:12 +00:00
IR For functions with ARM target specific calling convention, when simplify-libcall 2014-03-10 20:49:45 +00:00
IRReader Replace OwningPtr<T> with std::unique_ptr<T>. 2014-03-06 05:51:42 +00:00
LTO [C++11] Add 'override' keyword to virtual methods that override their base class. 2014-03-08 07:51:20 +00:00
LineEditor [CMake] Use LINK_LIBS instead of target_link_libraries(). 2014-02-26 06:41:29 +00:00
Linker [Layering] Sink Linker.h into a Linker subdirectory to make it 2014-03-06 03:42:23 +00:00
MC MC: Appease the buildbots 2014-03-10 01:04:18 +00:00
Object Replace OwningPtr<T> with std::unique_ptr<T>. 2014-03-06 05:51:42 +00:00
Option Avoid buffer copies when a Twine already is a StringRef. 2013-12-03 18:18:28 +00:00
Support [C++11] Remove 'virtual' keyword from methods marked with 'override' keyword. 2014-03-10 03:53:12 +00:00
TableGen Replace OwningPtr<T> with std::unique_ptr<T>. 2014-03-06 05:51:42 +00:00
Target [mips] Implement NaCl sandboxing of loads, stores and SP changes: 2014-03-10 20:34:23 +00:00
Transforms For functions with ARM target specific calling convention, when simplify-libcall 2014-03-10 20:49:45 +00:00
CMakeLists.txt Introduce line editor library. 2014-01-31 23:46:14 +00:00
LLVMBuild.txt Introduce line editor library. 2014-01-31 23:46:14 +00:00
Makefile Introduce line editor library. 2014-01-31 23:46:14 +00:00