1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-22 18:54:02 +01:00

[BuildLibCalls] Properly set ABI attributes on arguments

Some floating point lib calls have ABI attributes that need to be set on
the caller. Found via D103412.

Reviewed By: rnk

Differential Revision: https://reviews.llvm.org/D103415
This commit is contained in:
Arthur Eubanks 2021-05-31 09:15:25 -07:00
parent fcb0b24958
commit cf3b931893
5 changed files with 43 additions and 34 deletions

View File

@ -11,8 +11,10 @@
//===----------------------------------------------------------------------===//
#include "llvm/Transforms/Utils/BuildLibCalls.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/ADT/Statistic.h"
#include "llvm/Analysis/MemoryBuiltins.h"
#include "llvm/Analysis/TargetLibraryInfo.h"
#include "llvm/IR/Constants.h"
#include "llvm/IR/DataLayout.h"
@ -22,7 +24,6 @@
#include "llvm/IR/LLVMContext.h"
#include "llvm/IR/Module.h"
#include "llvm/IR/Type.h"
#include "llvm/Analysis/MemoryBuiltins.h"
using namespace llvm;
@ -1498,9 +1499,15 @@ static Value *emitBinaryFloatFnCallHelper(Value *Op1, Value *Op2,
// The incoming attribute set may have come from a speculatable intrinsic, but
// is being replaced with a library call which is not allowed to be
// speculatable.
CI->setAttributes(Attrs.removeAttribute(B.getContext(),
AttributeList::FunctionIndex,
Attribute::Speculatable));
// We also need to merge with the callee's attributes, which may contain ABI
// attributes.
AttributeList NewAttrs = AttributeList::get(
B.getContext(),
makeArrayRef(
{Attrs.removeAttribute(B.getContext(), AttributeList::FunctionIndex,
Attribute::Speculatable),
CI->getCalledFunction()->getAttributes()}));
CI->setAttributes(NewAttrs);
if (const Function *F =
dyn_cast<Function>(Callee.getCallee()->stripPointerCasts()))
CI->setCallingConv(F->getCallingConv());

View File

@ -15,7 +15,7 @@ declare float @exp2f(float)
define double @test_simplify1(i32 %x) {
; LDEXP32-LABEL: @test_simplify1(
; LDEXP32-NEXT: [[LDEXP:%.*]] = call double @ldexp(double 1.000000e+00, i32 [[X:%.*]])
; LDEXP32-NEXT: [[LDEXP:%.*]] = call double @ldexp(double 1.000000e+00, i32 signext [[X:%.*]])
; LDEXP32-NEXT: ret double [[LDEXP]]
;
; LDEXP16-LABEL: @test_simplify1(
@ -24,7 +24,7 @@ define double @test_simplify1(i32 %x) {
; LDEXP16-NEXT: ret double [[RET]]
;
; NOLDEXPF-LABEL: @test_simplify1(
; NOLDEXPF-NEXT: [[LDEXP:%.*]] = call double @ldexp(double 1.000000e+00, i32 [[X:%.*]])
; NOLDEXPF-NEXT: [[LDEXP:%.*]] = call double @ldexp(double 1.000000e+00, i32 signext [[X:%.*]])
; NOLDEXPF-NEXT: ret double [[LDEXP]]
;
; NOLDEXP-LABEL: @test_simplify1(
@ -40,16 +40,16 @@ define double @test_simplify1(i32 %x) {
define double @test_simplify2(i16 signext %x) {
; LDEXP32-LABEL: @test_simplify2(
; LDEXP32-NEXT: [[TMP1:%.*]] = sext i16 [[X:%.*]] to i32
; LDEXP32-NEXT: [[LDEXP:%.*]] = call double @ldexp(double 1.000000e+00, i32 [[TMP1]])
; LDEXP32-NEXT: [[LDEXP:%.*]] = call double @ldexp(double 1.000000e+00, i32 signext [[TMP1]])
; LDEXP32-NEXT: ret double [[LDEXP]]
;
; LDEXP16-LABEL: @test_simplify2(
; LDEXP16-NEXT: [[LDEXP:%.*]] = call double @ldexp(double 1.000000e+00, i16 [[X:%.*]])
; LDEXP16-NEXT: [[LDEXP:%.*]] = call double @ldexp(double 1.000000e+00, i16 signext [[X:%.*]])
; LDEXP16-NEXT: ret double [[LDEXP]]
;
; NOLDEXPF-LABEL: @test_simplify2(
; NOLDEXPF-NEXT: [[TMP1:%.*]] = sext i16 [[X:%.*]] to i32
; NOLDEXPF-NEXT: [[LDEXP:%.*]] = call double @ldexp(double 1.000000e+00, i32 [[TMP1]])
; NOLDEXPF-NEXT: [[LDEXP:%.*]] = call double @ldexp(double 1.000000e+00, i32 signext [[TMP1]])
; NOLDEXPF-NEXT: ret double [[LDEXP]]
;
; NOLDEXP-LABEL: @test_simplify2(
@ -65,17 +65,17 @@ define double @test_simplify2(i16 signext %x) {
define double @test_simplify3(i8 signext %x) {
; LDEXP32-LABEL: @test_simplify3(
; LDEXP32-NEXT: [[TMP1:%.*]] = sext i8 [[X:%.*]] to i32
; LDEXP32-NEXT: [[LDEXP:%.*]] = call double @ldexp(double 1.000000e+00, i32 [[TMP1]])
; LDEXP32-NEXT: [[LDEXP:%.*]] = call double @ldexp(double 1.000000e+00, i32 signext [[TMP1]])
; LDEXP32-NEXT: ret double [[LDEXP]]
;
; LDEXP16-LABEL: @test_simplify3(
; LDEXP16-NEXT: [[TMP1:%.*]] = sext i8 [[X:%.*]] to i16
; LDEXP16-NEXT: [[LDEXP:%.*]] = call double @ldexp(double 1.000000e+00, i16 [[TMP1]])
; LDEXP16-NEXT: [[LDEXP:%.*]] = call double @ldexp(double 1.000000e+00, i16 signext [[TMP1]])
; LDEXP16-NEXT: ret double [[LDEXP]]
;
; NOLDEXPF-LABEL: @test_simplify3(
; NOLDEXPF-NEXT: [[TMP1:%.*]] = sext i8 [[X:%.*]] to i32
; NOLDEXPF-NEXT: [[LDEXP:%.*]] = call double @ldexp(double 1.000000e+00, i32 [[TMP1]])
; NOLDEXPF-NEXT: [[LDEXP:%.*]] = call double @ldexp(double 1.000000e+00, i32 signext [[TMP1]])
; NOLDEXPF-NEXT: ret double [[LDEXP]]
;
; NOLDEXP-LABEL: @test_simplify3(
@ -90,7 +90,7 @@ define double @test_simplify3(i8 signext %x) {
define float @test_simplify4(i32 %x) {
; LDEXP32-LABEL: @test_simplify4(
; LDEXP32-NEXT: [[LDEXPF:%.*]] = call float @ldexpf(float 1.000000e+00, i32 [[X:%.*]])
; LDEXP32-NEXT: [[LDEXPF:%.*]] = call float @ldexpf(float 1.000000e+00, i32 signext [[X:%.*]])
; LDEXP32-NEXT: ret float [[LDEXPF]]
;
; LDEXP16-LABEL: @test_simplify4(
@ -144,7 +144,7 @@ define double @test_no_simplify1(i32 %x) {
define double @test_simplify6(i16 zeroext %x) {
; LDEXP32-LABEL: @test_simplify6(
; LDEXP32-NEXT: [[TMP1:%.*]] = zext i16 [[X:%.*]] to i32
; LDEXP32-NEXT: [[LDEXP:%.*]] = call double @ldexp(double 1.000000e+00, i32 [[TMP1]])
; LDEXP32-NEXT: [[LDEXP:%.*]] = call double @ldexp(double 1.000000e+00, i32 signext [[TMP1]])
; LDEXP32-NEXT: ret double [[LDEXP]]
;
; LDEXP16-LABEL: @test_simplify6(
@ -154,7 +154,7 @@ define double @test_simplify6(i16 zeroext %x) {
;
; NOLDEXPF-LABEL: @test_simplify6(
; NOLDEXPF-NEXT: [[TMP1:%.*]] = zext i16 [[X:%.*]] to i32
; NOLDEXPF-NEXT: [[LDEXP:%.*]] = call double @ldexp(double 1.000000e+00, i32 [[TMP1]])
; NOLDEXPF-NEXT: [[LDEXP:%.*]] = call double @ldexp(double 1.000000e+00, i32 signext [[TMP1]])
; NOLDEXPF-NEXT: ret double [[LDEXP]]
;
; NOLDEXP-LABEL: @test_simplify6(
@ -170,17 +170,17 @@ define double @test_simplify6(i16 zeroext %x) {
define double @test_simplify7(i8 zeroext %x) {
; LDEXP32-LABEL: @test_simplify7(
; LDEXP32-NEXT: [[TMP1:%.*]] = zext i8 [[X:%.*]] to i32
; LDEXP32-NEXT: [[LDEXP:%.*]] = call double @ldexp(double 1.000000e+00, i32 [[TMP1]])
; LDEXP32-NEXT: [[LDEXP:%.*]] = call double @ldexp(double 1.000000e+00, i32 signext [[TMP1]])
; LDEXP32-NEXT: ret double [[LDEXP]]
;
; LDEXP16-LABEL: @test_simplify7(
; LDEXP16-NEXT: [[TMP1:%.*]] = zext i8 [[X:%.*]] to i16
; LDEXP16-NEXT: [[LDEXP:%.*]] = call double @ldexp(double 1.000000e+00, i16 [[TMP1]])
; LDEXP16-NEXT: [[LDEXP:%.*]] = call double @ldexp(double 1.000000e+00, i16 signext [[TMP1]])
; LDEXP16-NEXT: ret double [[LDEXP]]
;
; NOLDEXPF-LABEL: @test_simplify7(
; NOLDEXPF-NEXT: [[TMP1:%.*]] = zext i8 [[X:%.*]] to i32
; NOLDEXPF-NEXT: [[LDEXP:%.*]] = call double @ldexp(double 1.000000e+00, i32 [[TMP1]])
; NOLDEXPF-NEXT: [[LDEXP:%.*]] = call double @ldexp(double 1.000000e+00, i32 signext [[TMP1]])
; NOLDEXPF-NEXT: ret double [[LDEXP]]
;
; NOLDEXP-LABEL: @test_simplify7(
@ -196,12 +196,12 @@ define double @test_simplify7(i8 zeroext %x) {
define float @test_simplify8(i8 zeroext %x) {
; LDEXP32-LABEL: @test_simplify8(
; LDEXP32-NEXT: [[TMP1:%.*]] = zext i8 [[X:%.*]] to i32
; LDEXP32-NEXT: [[LDEXPF:%.*]] = call float @ldexpf(float 1.000000e+00, i32 [[TMP1]])
; LDEXP32-NEXT: [[LDEXPF:%.*]] = call float @ldexpf(float 1.000000e+00, i32 signext [[TMP1]])
; LDEXP32-NEXT: ret float [[LDEXPF]]
;
; LDEXP16-LABEL: @test_simplify8(
; LDEXP16-NEXT: [[TMP1:%.*]] = zext i8 [[X:%.*]] to i16
; LDEXP16-NEXT: [[LDEXPF:%.*]] = call float @ldexpf(float 1.000000e+00, i16 [[TMP1]])
; LDEXP16-NEXT: [[LDEXPF:%.*]] = call float @ldexpf(float 1.000000e+00, i16 signext [[TMP1]])
; LDEXP16-NEXT: ret float [[LDEXPF]]
;
; NOLDEXPF-LABEL: @test_simplify8(
@ -225,17 +225,17 @@ declare float @llvm.exp2.f32(float)
define double @test_simplify9(i8 zeroext %x) {
; LDEXP32-LABEL: @test_simplify9(
; LDEXP32-NEXT: [[TMP1:%.*]] = zext i8 [[X:%.*]] to i32
; LDEXP32-NEXT: [[LDEXP:%.*]] = call double @ldexp(double 1.000000e+00, i32 [[TMP1]])
; LDEXP32-NEXT: [[LDEXP:%.*]] = call double @ldexp(double 1.000000e+00, i32 signext [[TMP1]])
; LDEXP32-NEXT: ret double [[LDEXP]]
;
; LDEXP16-LABEL: @test_simplify9(
; LDEXP16-NEXT: [[TMP1:%.*]] = zext i8 [[X:%.*]] to i16
; LDEXP16-NEXT: [[LDEXP:%.*]] = call double @ldexp(double 1.000000e+00, i16 [[TMP1]])
; LDEXP16-NEXT: [[LDEXP:%.*]] = call double @ldexp(double 1.000000e+00, i16 signext [[TMP1]])
; LDEXP16-NEXT: ret double [[LDEXP]]
;
; NOLDEXPF-LABEL: @test_simplify9(
; NOLDEXPF-NEXT: [[TMP1:%.*]] = zext i8 [[X:%.*]] to i32
; NOLDEXPF-NEXT: [[LDEXP:%.*]] = call double @ldexp(double 1.000000e+00, i32 [[TMP1]])
; NOLDEXPF-NEXT: [[LDEXP:%.*]] = call double @ldexp(double 1.000000e+00, i32 signext [[TMP1]])
; NOLDEXPF-NEXT: ret double [[LDEXP]]
;
; NOLDEXP-LABEL: @test_simplify9(
@ -251,12 +251,12 @@ define double @test_simplify9(i8 zeroext %x) {
define float @test_simplify10(i8 zeroext %x) {
; LDEXP32-LABEL: @test_simplify10(
; LDEXP32-NEXT: [[TMP1:%.*]] = zext i8 [[X:%.*]] to i32
; LDEXP32-NEXT: [[LDEXPF:%.*]] = call float @ldexpf(float 1.000000e+00, i32 [[TMP1]])
; LDEXP32-NEXT: [[LDEXPF:%.*]] = call float @ldexpf(float 1.000000e+00, i32 signext [[TMP1]])
; LDEXP32-NEXT: ret float [[LDEXPF]]
;
; LDEXP16-LABEL: @test_simplify10(
; LDEXP16-NEXT: [[TMP1:%.*]] = zext i8 [[X:%.*]] to i16
; LDEXP16-NEXT: [[LDEXPF:%.*]] = call float @ldexpf(float 1.000000e+00, i16 [[TMP1]])
; LDEXP16-NEXT: [[LDEXPF:%.*]] = call float @ldexpf(float 1.000000e+00, i16 signext [[TMP1]])
; LDEXP16-NEXT: ret float [[LDEXPF]]
;
; NOLDEXPF-LABEL: @test_simplify10(

View File

@ -51,7 +51,7 @@ define double @pow_uitofp_double_const_base_fast(i31 %x) {
define double @pow_sitofp_double_const_base_2_fast(i32 %x) {
; CHECK-LABEL: @pow_sitofp_double_const_base_2_fast(
; CHECK-NEXT: [[LDEXPF:%.*]] = call afn float @ldexpf(float 1.000000e+00, i32 [[X:%.*]])
; CHECK-NEXT: [[LDEXPF:%.*]] = call afn float @ldexpf(float 1.000000e+00, i32 signext [[X:%.*]])
; CHECK-NEXT: [[RES:%.*]] = fpext float [[LDEXPF]] to double
; CHECK-NEXT: ret double [[RES]]
;
@ -78,7 +78,7 @@ define double @pow_sitofp_double_const_base_power_of_2_fast(i32 %x) {
define double @pow_uitofp_const_base_2_fast(i31 %x) {
; CHECK-LABEL: @pow_uitofp_const_base_2_fast(
; CHECK-NEXT: [[TMP1:%.*]] = zext i31 [[X:%.*]] to i32
; CHECK-NEXT: [[LDEXPF:%.*]] = call afn float @ldexpf(float 1.000000e+00, i32 [[TMP1]])
; CHECK-NEXT: [[LDEXPF:%.*]] = call afn float @ldexpf(float 1.000000e+00, i32 signext [[TMP1]])
; CHECK-NEXT: [[RES:%.*]] = fpext float [[LDEXPF]] to double
; CHECK-NEXT: ret double [[RES]]
;
@ -343,7 +343,7 @@ define double @pow_uitofp_const_base_no_fast(i32 %x) {
define double @pow_sitofp_const_base_2_no_fast(i32 %x) {
; CHECK-LABEL: @pow_sitofp_const_base_2_no_fast(
; CHECK-NEXT: [[LDEXPF:%.*]] = call float @ldexpf(float 1.000000e+00, i32 [[X:%.*]])
; CHECK-NEXT: [[LDEXPF:%.*]] = call float @ldexpf(float 1.000000e+00, i32 signext [[X:%.*]])
; CHECK-NEXT: [[RES:%.*]] = fpext float [[LDEXPF]] to double
; CHECK-NEXT: ret double [[RES]]
;

View File

@ -57,7 +57,7 @@ define double @pow_uitofp_double_const_base_fast(i15 %x) {
define double @pow_sitofp_double_const_base_2_fast(i16 %x) {
; CHECK-LABEL: @pow_sitofp_double_const_base_2_fast(
; CHECK-NEXT: [[LDEXPF:%.*]] = call afn float @ldexpf(float 1.000000e+00, i16 [[X:%.*]])
; CHECK-NEXT: [[LDEXPF:%.*]] = call afn float @ldexpf(float 1.000000e+00, i16 signext [[X:%.*]])
; CHECK-NEXT: [[RES:%.*]] = fpext float [[LDEXPF]] to double
; CHECK-NEXT: ret double [[RES]]
;
@ -84,7 +84,7 @@ define double @pow_sitofp_double_const_base_power_of_2_fast(i16 %x) {
define double @pow_uitofp_const_base_2_fast(i15 %x) {
; CHECK-LABEL: @pow_uitofp_const_base_2_fast(
; CHECK-NEXT: [[TMP1:%.*]] = zext i15 [[X:%.*]] to i16
; CHECK-NEXT: [[LDEXPF:%.*]] = call afn float @ldexpf(float 1.000000e+00, i16 [[TMP1]])
; CHECK-NEXT: [[LDEXPF:%.*]] = call afn float @ldexpf(float 1.000000e+00, i16 signext [[TMP1]])
; CHECK-NEXT: [[RES:%.*]] = fpext float [[LDEXPF]] to double
; CHECK-NEXT: ret double [[RES]]
;
@ -322,7 +322,7 @@ define double @pow_uitofp_const_base_no_fast(i16 %x) {
define double @pow_sitofp_const_base_2_no_fast(i16 %x) {
; CHECK-LABEL: @pow_sitofp_const_base_2_no_fast(
; CHECK-NEXT: [[LDEXPF:%.*]] = call float @ldexpf(float 1.000000e+00, i16 [[X:%.*]])
; CHECK-NEXT: [[LDEXPF:%.*]] = call float @ldexpf(float 1.000000e+00, i16 signext [[X:%.*]])
; CHECK-NEXT: [[RES:%.*]] = fpext float [[LDEXPF]] to double
; CHECK-NEXT: ret double [[RES]]
;

View File

@ -190,7 +190,7 @@ define double @fake_exp2(double %x) {
}
define double @fake_ldexp(i32 %x) {
; CHECK32-LABEL: @fake_ldexp(
; CHECK32-NEXT: [[Z:%.*]] = call double @ldexp(double 1.0{{.*}}, i32 %x)
; CHECK32-NEXT: [[Z:%.*]] = call double @ldexp(double 1.0{{.*}}, i32 signext %x)
; CHECK32-NEXT: ret double [[Z]]
; CHECK16-LABEL: @fake_ldexp(
@ -205,11 +205,11 @@ define double @fake_ldexp(i32 %x) {
define double @fake_ldexp_16(i16 %x) {
; CHECK32-LABEL: @fake_ldexp_16(
; CHECK32-NEXT: [[Y:%.*]] = sext i16 %x to i32
; CHECK32-NEXT: [[Z:%.*]] = call double @ldexp(double 1.0{{.*}}, i32 [[Y]])
; CHECK32-NEXT: [[Z:%.*]] = call double @ldexp(double 1.0{{.*}}, i32 signext [[Y]])
; CHECK32-NEXT: ret double [[Z]]
; CHECK16-LABEL: @fake_ldexp_16(
; CHECK16-NEXT: [[Z:%.*]] = call double @ldexp(double 1.0{{.*}}, i16 %x)
; CHECK16-NEXT: [[Z:%.*]] = call double @ldexp(double 1.0{{.*}}, i16 signext %x)
; CHECK16-NEXT: ret double [[Z]]
%y = sitofp i16 %x to double
@ -217,6 +217,8 @@ define double @fake_ldexp_16(i16 %x) {
ret double %z
}
; CHECK: declare double @ldexp(double, i{{16|32}} signext)
attributes #0 = { nobuiltin }
attributes #1 = { builtin }