mirror of
https://github.com/RPCSX/llvm.git
synced 2024-12-04 01:43:06 +00:00
fe89a6bcf0
Summary: This pass shrink-wraps a condition to some library calls where the call result is not used. For example: sqrt(val); is transformed to if (val < 0) sqrt(val); Even if the result of library call is not being used, the compiler cannot safely delete the call because the function can set errno on error conditions. Note in many functions, the error condition solely depends on the incoming parameter. In this optimization, we can generate the condition can lead to the errno to shrink-wrap the call. Since the chances of hitting the error condition is low, the runtime call is effectively eliminated. These partially dead calls are usually results of C++ abstraction penalty exposed by inlining. This optimization hits 108 times in 19 C/C++ programs in SPEC2006. Reviewers: hfinkel, mehdi_amini, davidxl Subscribers: modocache, mgorny, mehdi_amini, xur, llvm-commits, beanz Differential Revision: https://reviews.llvm.org/D24414 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@284542 91177308-0d34-0410-b5e6-96231b3b80d8
242 lines
11 KiB
LLVM
242 lines
11 KiB
LLVM
; RUN: opt < %s -libcalls-shrinkwrap -S | FileCheck %s
|
|
; New PM
|
|
; RUN: opt < %s -passes=libcalls-shrinkwrap -S | FileCheck %s
|
|
|
|
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
|
|
target triple = "x86_64-unknown-linux-gnu"
|
|
|
|
define void @test_range_error(double %value) {
|
|
entry:
|
|
%call_0 = call double @cosh(double %value)
|
|
; CHECK: [[COND1:%[0-9]+]] = fcmp olt double %value, -7.100000e+02
|
|
; CHECK: [[COND2:%[0-9]+]] = fcmp ogt double %value, 7.100000e+02
|
|
; CHECK: [[COND:%[0-9]+]] = or i1 [[COND2]], [[COND1]]
|
|
; CHECK: br i1 [[COND]], label %[[CALL_LABEL:cdce.call[0-9]*]], label %[[END_LABEL:cdce.end[0-9]*]], !prof ![[BRANCH_WEIGHT:[0-9]+]]
|
|
; CHECK: [[CALL_LABEL]]:
|
|
; CHECK-NEXT: %call_0 = call double @cosh(double %value)
|
|
; CHECK-NEXT: br label %[[END_LABEL]]
|
|
; CHECK: [[END_LABEL]]:
|
|
|
|
%call_1 = call double @exp(double %value)
|
|
; CHECK: [[COND1:%[0-9]+]] = fcmp olt double %value, -7.450000e+02
|
|
; CHECK: [[COND2:%[0-9]+]] = fcmp ogt double %value, 7.090000e+02
|
|
; CHECK: [[COND:%[0-9]+]] = or i1 [[COND2]], [[COND1]]
|
|
; CHECK: br i1 [[COND]], label %[[CALL_LABEL:cdce.call[0-9]*]], label %[[END_LABEL:cdce.end[0-9]*]], !prof ![[BRANCH_WEIGHT]]
|
|
; CHECK: [[CALL_LABEL]]:
|
|
; CHECK-NEXT: %call_1 = call double @exp(double %value)
|
|
; CHECK-NEXT: br label %[[END_LABEL]]
|
|
; CHECK: [[END_LABEL]]:
|
|
|
|
%call_3 = call double @exp2(double %value)
|
|
; CHECK: [[COND1:%[0-9]+]] = fcmp olt double %value, -1.074000e+03
|
|
; CHECK: [[COND2:%[0-9]+]] = fcmp ogt double %value, 1.023000e+03
|
|
; CHECK: [[COND:%[0-9]+]] = or i1 [[COND2]], [[COND1]]
|
|
; CHECK: br i1 [[COND]], label %[[CALL_LABEL:cdce.call[0-9]*]], label %[[END_LABEL:cdce.end[0-9]*]], !prof ![[BRANCH_WEIGHT]]
|
|
; CHECK: [[CALL_LABEL]]:
|
|
; CHECK-NEXT: %call_3 = call double @exp2(double %value)
|
|
; CHECK-NEXT: br label %[[END_LABEL]]
|
|
; CHECK: [[END_LABEL]]:
|
|
|
|
%call_4 = call double @sinh(double %value)
|
|
; CHECK: [[COND1:%[0-9]+]] = fcmp olt double %value, -7.100000e+02
|
|
; CHECK: [[COND2:%[0-9]+]] = fcmp ogt double %value, 7.100000e+02
|
|
; CHECK: [[COND:%[0-9]+]] = or i1 [[COND2]], [[COND1]]
|
|
; CHECK: br i1 [[COND]], label %[[CALL_LABEL:cdce.call[0-9]*]], label %[[END_LABEL:cdce.end[0-9]*]], !prof ![[BRANCH_WEIGHT]]
|
|
; CHECK: [[CALL_LABEL]]:
|
|
; CHECK-NEXT: %call_4 = call double @sinh(double %value)
|
|
; CHECK-NEXT: br label %[[END_LABEL]]
|
|
; CHECK: [[END_LABEL]]:
|
|
|
|
%call_5 = call double @expm1(double %value)
|
|
; CHECK: [[COND:%[0-9]+]] = fcmp ogt double %value, 7.090000e+02
|
|
; CHECK: br i1 [[COND]], label %[[CALL_LABEL:cdce.call[0-9]*]], label %[[END_LABEL:cdce.end[0-9]*]], !prof ![[BRANCH_WEIGHT]]
|
|
; CHECK: [[CALL_LABEL]]:
|
|
; CHECK-NEXT: %call_5 = call double @expm1(double %value)
|
|
; CHECK-NEXT: br label %[[END_LABEL]]
|
|
; CHECK: [[END_LABEL]]:
|
|
|
|
ret void
|
|
}
|
|
|
|
declare double @cosh(double)
|
|
declare double @exp(double)
|
|
declare double @exp2(double)
|
|
declare double @sinh(double)
|
|
declare double @expm1(double)
|
|
|
|
define void @test_domain_error(double %value) {
|
|
entry:
|
|
%call_00 = call double @acos(double %value)
|
|
; CHECK: [[COND1:%[0-9]+]] = fcmp ogt double %value, 1.000000e+00
|
|
; CHECK: [[COND2:%[0-9]+]] = fcmp olt double %value, -1.000000e+00
|
|
; CHECK: [[COND:%[0-9]+]] = or i1 [[COND2]], [[COND1]]
|
|
; CHECK: br i1 [[COND]], label %[[CALL_LABEL:cdce.call[0-9]*]], label %[[END_LABEL:cdce.end[0-9]*]], !prof ![[BRANCH_WEIGHT]]
|
|
; CHECK: [[CALL_LABEL]]:
|
|
; CHECK-NEXT: %call_00 = call double @acos(double %value)
|
|
; CHECK-NEXT: br label %[[END_LABEL]]
|
|
; CHECK: [[END_LABEL]]:
|
|
|
|
%call_01 = call double @asin(double %value)
|
|
; CHECK: [[COND1:%[0-9]+]] = fcmp ogt double %value, 1.000000e+00
|
|
; CHECK: [[COND2:%[0-9]+]] = fcmp olt double %value, -1.000000e+00
|
|
; CHECK: [[COND:%[0-9]+]] = or i1 [[COND2]], [[COND1]]
|
|
; CHECK: br i1 [[COND]], label %[[CALL_LABEL:cdce.call[0-9]*]], label %[[END_LABEL:cdce.end[0-9]*]], !prof ![[BRANCH_WEIGHT]]
|
|
; CHECK: [[CALL_LABEL]]:
|
|
; CHECK-NEXT: %call_01 = call double @asin(double %value)
|
|
; CHECK-NEXT: br label %[[END_LABEL]]
|
|
; CHECK: [[END_LABEL]]:
|
|
|
|
%call_02 = call double @cos(double %value)
|
|
; CHECK: [[COND1:%[0-9]+]] = fcmp oeq double %value, 0xFFF0000000000000
|
|
; CHECK: [[COND2:%[0-9]+]] = fcmp oeq double %value, 0x7FF0000000000000
|
|
; CHECK: [[COND:%[0-9]+]] = or i1 [[COND2]], [[COND1]]
|
|
; CHECK: br i1 [[COND]], label %[[CALL_LABEL:cdce.call[0-9]*]], label %[[END_LABEL:cdce.end[0-9]*]], !prof ![[BRANCH_WEIGHT]]
|
|
; CHECK: [[CALL_LABEL]]:
|
|
; CHECK-NEXT: %call_02 = call double @cos(double %value)
|
|
; CHECK-NEXT: br label %[[END_LABEL]]
|
|
; CHECK: [[END_LABEL]]:
|
|
|
|
%call_03 = call double @sin(double %value)
|
|
; CHECK: [[COND1:%[0-9]+]] = fcmp oeq double %value, 0xFFF0000000000000
|
|
; CHECK: [[COND2:%[0-9]+]] = fcmp oeq double %value, 0x7FF0000000000000
|
|
; CHECK: [[COND:%[0-9]+]] = or i1 [[COND2]], [[COND1]]
|
|
; CHECK: br i1 [[COND]], label %[[CALL_LABEL:cdce.call[0-9]*]], label %[[END_LABEL:cdce.end[0-9]*]], !prof ![[BRANCH_WEIGHT]]
|
|
; CHECK: [[CALL_LABEL]]:
|
|
; CHECK-NEXT: %call_03 = call double @sin(double %value)
|
|
; CHECK-NEXT: br label %[[END_LABEL]]
|
|
; CHECK: [[END_LABEL]]:
|
|
|
|
%call_04 = call double @acosh(double %value)
|
|
; CHECK: [[COND:%[0-9]+]] = fcmp olt double %value, 1.000000e+00
|
|
; CHECK: br i1 [[COND]], label %[[CALL_LABEL:cdce.call[0-9]*]], label %[[END_LABEL:cdce.end[0-9]*]], !prof ![[BRANCH_WEIGHT]]
|
|
; CHECK: [[CALL_LABEL]]:
|
|
; CHECK-NEXT: %call_04 = call double @acosh(double %value)
|
|
; CHECK-NEXT: br label %[[END_LABEL]]
|
|
; CHECK: [[END_LABEL]]:
|
|
|
|
%call_05 = call double @sqrt(double %value)
|
|
; CHECK: [[COND:%[0-9]+]] = fcmp olt double %value, 0.000000e+00
|
|
; CHECK: br i1 [[COND]], label %[[CALL_LABEL:cdce.call[0-9]*]], label %[[END_LABEL:cdce.end[0-9]*]], !prof ![[BRANCH_WEIGHT]]
|
|
; CHECK: [[CALL_LABEL]]:
|
|
; CHECK-NEXT: %call_05 = call double @sqrt(double %value)
|
|
; CHECK-NEXT: br label %[[END_LABEL]]
|
|
; CHECK: [[END_LABEL]]:
|
|
|
|
%call_06 = call double @atanh(double %value)
|
|
; CHECK: [[COND1:%[0-9]+]] = fcmp oge double %value, 1.000000e+00
|
|
; CHECK: [[COND2:%[0-9]+]] = fcmp ole double %value, -1.000000e+00
|
|
; CHECK: [[COND:%[0-9]+]] = or i1 [[COND2]], [[COND1]]
|
|
; CHECK: br i1 [[COND]], label %[[CALL_LABEL:cdce.call[0-9]*]], label %[[END_LABEL:cdce.end[0-9]*]], !prof ![[BRANCH_WEIGHT]]
|
|
; CHECK: [[CALL_LABEL]]:
|
|
; CHECK-NEXT: %call_06 = call double @atanh(double %value)
|
|
; CHECK-NEXT: br label %[[END_LABEL]]
|
|
; CHECK: [[END_LABEL]]:
|
|
|
|
%call_07 = call double @log(double %value)
|
|
; CHECK: [[COND:%[0-9]+]] = fcmp ole double %value, 0.000000e+00
|
|
; CHECK: br i1 [[COND]], label %[[CALL_LABEL:cdce.call[0-9]*]], label %[[END_LABEL:cdce.end[0-9]*]], !prof ![[BRANCH_WEIGHT]]
|
|
; CHECK: [[CALL_LABEL]]:
|
|
; CHECK-NEXT: %call_07 = call double @log(double %value)
|
|
; CHECK-NEXT: br label %[[END_LABEL]]
|
|
; CHECK: [[END_LABEL]]:
|
|
|
|
%call_08 = call double @log10(double %value)
|
|
; CHECK: [[COND:%[0-9]+]] = fcmp ole double %value, 0.000000e+00
|
|
; CHECK: br i1 [[COND]], label %[[CALL_LABEL:cdce.call[0-9]*]], label %[[END_LABEL:cdce.end[0-9]*]], !prof ![[BRANCH_WEIGHT]]
|
|
; CHECK: [[CALL_LABEL]]:
|
|
; CHECK-NEXT: %call_08 = call double @log10(double %value)
|
|
; CHECK-NEXT: br label %[[END_LABEL]]
|
|
; CHECK: [[END_LABEL]]:
|
|
|
|
%call_09 = call double @log2(double %value)
|
|
; CHECK: [[COND:%[0-9]+]] = fcmp ole double %value, 0.000000e+00
|
|
; CHECK: br i1 [[COND]], label %[[CALL_LABEL:cdce.call[0-9]*]], label %[[END_LABEL:cdce.end[0-9]*]], !prof ![[BRANCH_WEIGHT]]
|
|
; CHECK: [[CALL_LABEL]]:
|
|
; CHECK-NEXT: %call_09 = call double @log2(double %value)
|
|
; CHECK-NEXT: br label %[[END_LABEL]]
|
|
; CHECK: [[END_LABEL]]:
|
|
|
|
%call_10 = call double @logb(double %value)
|
|
; CHECK: [[COND:%[0-9]+]] = fcmp ole double %value, 0.000000e+00
|
|
; CHECK: br i1 [[COND]], label %[[CALL_LABEL:cdce.call[0-9]*]], label %[[END_LABEL:cdce.end[0-9]*]], !prof ![[BRANCH_WEIGHT]]
|
|
; CHECK: [[CALL_LABEL]]:
|
|
; CHECK-NEXT: %call_10 = call double @logb(double %value)
|
|
; CHECK-NEXT: br label %[[END_LABEL]]
|
|
; CHECK: [[END_LABEL]]:
|
|
|
|
%call_11 = call double @log1p(double %value)
|
|
; CHECK: [[COND:%[0-9]+]] = fcmp ole double %value, -1.000000e+00
|
|
; CHECK: br i1 [[COND]], label %[[CALL_LABEL:cdce.call[0-9]*]], label %[[END_LABEL:cdce.end[0-9]*]], !prof ![[BRANCH_WEIGHT]]
|
|
; CHECK: [[CALL_LABEL]]:
|
|
; CHECK-NEXT: %call_11 = call double @log1p(double %value)
|
|
; CHECK-NEXT: br label %[[END_LABEL]]
|
|
; CHECK: [[END_LABEL]]:
|
|
|
|
ret void
|
|
}
|
|
|
|
declare double @acos(double)
|
|
declare double @asin(double)
|
|
declare double @cos(double)
|
|
declare double @sin(double)
|
|
declare double @acosh(double)
|
|
declare double @sqrt(double)
|
|
declare double @atanh(double)
|
|
declare double @log(double)
|
|
declare double @log10(double)
|
|
declare double @log2(double)
|
|
declare double @logb(double)
|
|
declare double @log1p(double)
|
|
|
|
define void @test_pow(i32 %int_val, double %exp) {
|
|
%call = call double @pow(double 2.500000e+00, double %exp)
|
|
; CHECK: [[COND:%[0-9]+]] = fcmp ogt double %exp, 1.270000e+02
|
|
; CHECK: br i1 [[COND]], label %[[CALL_LABEL:cdce.call[0-9]*]], label %[[END_LABEL:cdce.end[0-9]*]], !prof ![[BRANCH_WEIGHT]]
|
|
; CHECK: [[CALL_LABEL]]:
|
|
; CHECK-NEXT: %call = call double @pow(double 2.500000e+00, double %exp)
|
|
; CHECK-NEXT: br label %[[END_LABEL]]
|
|
; CHECK: [[END_LABEL]]:
|
|
|
|
%conv = sitofp i32 %int_val to double
|
|
%call1 = call double @pow(double %conv, double %exp)
|
|
; CHECK: [[COND1:%[0-9]+]] = fcmp ogt double %exp, 3.200000e+01
|
|
; CHECK: [[COND2:%[0-9]+]] = fcmp ole double %conv, 0.000000e+00
|
|
; CHECK: [[COND:%[0-9]+]] = or i1 [[COND2]], [[COND1]]
|
|
; CHECK: br i1 [[COND]], label %[[CALL_LABEL:cdce.call[0-9]*]], label %[[END_LABEL:cdce.end[0-9]*]], !prof ![[BRANCH_WEIGHT]]
|
|
; CHECK: [[CALL_LABEL]]:
|
|
; CHECK-NEXT: %call1 = call double @pow(double %conv, double %exp)
|
|
; CHECK-NEXT: br label %[[END_LABEL]]
|
|
; CHECK: [[END_LABEL]]:
|
|
|
|
%conv2 = trunc i32 %int_val to i8
|
|
%conv3 = uitofp i8 %conv2 to double
|
|
%call4 = call double @pow(double %conv3, double %exp)
|
|
; CHECK: [[COND1:%[0-9]+]] = fcmp ogt double %exp, 1.280000e+02
|
|
; CHECK: [[COND2:%[0-9]+]] = fcmp ole double %conv3, 0.000000e+00
|
|
; CHECK: [[COND:%[0-9]+]] = or i1 [[COND2]], [[COND1]]
|
|
; CHECK: br i1 [[COND]], label %[[CALL_LABEL:cdce.call[0-9]*]], label %[[END_LABEL:cdce.end[0-9]*]], !prof ![[BRANCH_WEIGHT]]
|
|
; CHECK: [[CALL_LABEL]]:
|
|
; CHECK-NEXT: %call4 = call double @pow(double %conv3, double %exp)
|
|
; CHECK-NEXT: br label %[[END_LABEL]]
|
|
; CHECK: [[END_LABEL]]:
|
|
|
|
|
|
%conv5 = trunc i32 %int_val to i16
|
|
%conv6 = uitofp i16 %conv5 to double
|
|
%call7 = call double @pow(double %conv6, double %exp)
|
|
; CHECK: [[COND1:%[0-9]+]] = fcmp ogt double %exp, 6.400000e+01
|
|
; CHECK: [[COND2:%[0-9]+]] = fcmp ole double %conv6, 0.000000e+00
|
|
; CHECK: [[COND:%[0-9]+]] = or i1 [[COND2]], [[COND1]]
|
|
; CHECK: br i1 [[COND]], label %[[CALL_LABEL:cdce.call[0-9]*]], label %[[END_LABEL:cdce.end[0-9]*]], !prof ![[BRANCH_WEIGHT]]
|
|
; CHECK: [[CALL_LABEL]]:
|
|
; CHECK-NEXT: %call7 = call double @pow(double %conv6, double %exp)
|
|
; CHECK-NEXT: br label %[[END_LABEL]]
|
|
; CHECK: [[END_LABEL]]:
|
|
|
|
ret void
|
|
}
|
|
|
|
declare double @pow(double, double)
|
|
|
|
; CHECK: ![[BRANCH_WEIGHT]] = !{!"branch_weights", i32 1, i32 2000}
|