diff --git a/llvm/lib/Transforms/Utils/BuildLibCalls.cpp b/llvm/lib/Transforms/Utils/BuildLibCalls.cpp --- a/llvm/lib/Transforms/Utils/BuildLibCalls.cpp +++ b/llvm/lib/Transforms/Utils/BuildLibCalls.cpp @@ -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 @@ // 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(Callee.getCallee()->stripPointerCasts())) CI->setCallingConv(F->getCallingConv()); diff --git a/llvm/test/Transforms/InstCombine/exp2-1.ll b/llvm/test/Transforms/InstCombine/exp2-1.ll --- a/llvm/test/Transforms/InstCombine/exp2-1.ll +++ b/llvm/test/Transforms/InstCombine/exp2-1.ll @@ -15,7 +15,7 @@ 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 @@ ; 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_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_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 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_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 @@ ; ; 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_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 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 @@ 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 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( diff --git a/llvm/test/Transforms/InstCombine/pow_fp_int.ll b/llvm/test/Transforms/InstCombine/pow_fp_int.ll --- a/llvm/test/Transforms/InstCombine/pow_fp_int.ll +++ b/llvm/test/Transforms/InstCombine/pow_fp_int.ll @@ -51,7 +51,7 @@ 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_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_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]] ; diff --git a/llvm/test/Transforms/InstCombine/pow_fp_int16.ll b/llvm/test/Transforms/InstCombine/pow_fp_int16.ll --- a/llvm/test/Transforms/InstCombine/pow_fp_int16.ll +++ b/llvm/test/Transforms/InstCombine/pow_fp_int16.ll @@ -57,7 +57,7 @@ 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_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_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]] ; diff --git a/llvm/test/Transforms/InstCombine/simplify-libcalls.ll b/llvm/test/Transforms/InstCombine/simplify-libcalls.ll --- a/llvm/test/Transforms/InstCombine/simplify-libcalls.ll +++ b/llvm/test/Transforms/InstCombine/simplify-libcalls.ll @@ -190,7 +190,7 @@ } 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_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 @@ ret double %z } +; CHECK: declare double @ldexp(double, i{{16|32}} signext) + attributes #0 = { nobuiltin } attributes #1 = { builtin }