Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SimplifyLibCalls] Tranform log(pow(x, y)) -> y*log(x).
This one is enabled only under -ffast-math. There are cases where the difference between the value computed and the correct value is huge even for ffast-math, e.g. as Steven pointed out: x = -1, y = -4 log(pow(-1), 4) = 0 4*log(-1) = NaN I checked what GCC does and apparently they do the same optimization (which result in the dramatic difference). Future work might try to make this (slightly) less worse. Differential Revision: http://reviews.llvm.org/D14400 llvm-svn: 254263
- Loading branch information
Showing
4 changed files
with
87 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
; 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: %pow = call double @llvm.pow.f64(double %x, double %y) | ||
; CHECK: %call = call double @log(double %pow) | ||
; CHECK: ret double %call | ||
; CHECK: } | ||
|
||
declare double @log(double) #0 | ||
declare double @llvm.pow.f64(double, double) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
; 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 double @log(double %x) #0 | ||
; CHECK: %mul = fmul fast double %log, %y | ||
; CHECK: ret double %mul | ||
; CHECK: } | ||
|
||
declare double @log(double) #0 | ||
declare double @llvm.pow.f64(double, double) | ||
|
||
attributes #0 = { "unsafe-fp-math"="true" } |