mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-10-25 05:52:53 +02:00
14a74b66f7
This patch adds optional fast-math-flags (the same that apply to fmul/fadd/fsub/fdiv/frem/fcmp) to call instructions in IR. Follow-up patches would use these flags in LibCallSimplifier, add support to clang, and extend FMF to the DAG for calls. Motivating example: %y = fmul fast float %x, %x %z = tail call float @sqrtf(float %y) We'd like to be able to optimize sqrt(x*x) into fabs(x). We do this today using a function-wide attribute for unsafe-math, but we really want to trigger on the instructions themselves: %z = tail call fast float @sqrtf(float %y) because in an LTO build it's possible that calls with fast semantics have been inlined into a function with non-fast semantics. The code changes and tests are based on the recent commits that added "notail": http://reviews.llvm.org/rL252368 and added FMF to fcmp: http://reviews.llvm.org/rL241901 Differential Revision: http://reviews.llvm.org/D14707 llvm-svn: 255555
42 lines
1.0 KiB
LLVM
42 lines
1.0 KiB
LLVM
; RUN: opt < %s -instcombine -S | FileCheck %s
|
|
|
|
define double @mylog(double %x, double %y) #0 {
|
|
entry:
|
|
%pow = call double @llvm.pow.f64(double %x, double %y)
|
|
%call = call double @log(double %pow) #0
|
|
ret double %call
|
|
}
|
|
|
|
; CHECK-LABEL: define double @mylog(
|
|
; CHECK: %log = call fast double @log(double %x) #0
|
|
; CHECK: %mul = fmul fast double %log, %y
|
|
; CHECK: ret double %mul
|
|
; CHECK: }
|
|
|
|
define double @test2(double ()* %fptr, double %p1) #0 {
|
|
%call1 = call double %fptr()
|
|
%pow = call double @log(double %call1)
|
|
ret double %pow
|
|
}
|
|
|
|
; CHECK-LABEL: @test2
|
|
; CHECK: log
|
|
|
|
define double @test3(double %x) #0 {
|
|
%call2 = call double @exp2(double %x) #0
|
|
%call3 = call double @log(double %call2) #0
|
|
ret double %call3
|
|
}
|
|
|
|
; CHECK-LABEL: @test3
|
|
; CHECK: %call2 = call double @exp2(double %x) #0
|
|
; CHECK: %logmul = fmul fast double %x, 0x3FE62E42FEFA39EF
|
|
; CHECK: ret double %logmul
|
|
; CHECK: }
|
|
|
|
declare double @log(double) #0
|
|
declare double @exp2(double) #0
|
|
declare double @llvm.pow.f64(double, double)
|
|
|
|
attributes #0 = { "unsafe-fp-math"="true" }
|