[PATCH] D67300: [ConstantFolding] Fold constant calls to log2()
Evandro Menezes via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Sep 6 13:32:44 PDT 2019
evandro created this revision.
evandro added reviewers: spatel, efriedma, xbolva00.
Herald added subscribers: llvm-commits, hiraditya.
Herald added a project: LLVM.
evandro added a parent revision: D67199: [InstCombine] Expand the simplification of log().
Somehow, folding calls to `log2()` with a constant was missing.
Repository:
rL LLVM
https://reviews.llvm.org/D67300
Files:
llvm/lib/Analysis/ConstantFolding.cpp
llvm/test/Analysis/ConstantFolding/math-1.ll
Index: llvm/test/Analysis/ConstantFolding/math-1.ll
===================================================================
--- llvm/test/Analysis/ConstantFolding/math-1.ll
+++ llvm/test/Analysis/ConstantFolding/math-1.ll
@@ -92,14 +92,14 @@
ret double %res
}
-; FIXME
+; FIXME: exp10() is not widely supported.
declare float @exp10f(float)
define float @f_exp10f() {
; CHECK-LABEL: @f_exp10f(
-; CHECK-NEXT: [[RES:%.*]] = tail call fast float @exp10f(float 1.000000e+00)
+; CHECK-NEXT: [[RES:%.*]] = tail call float @exp10f(float 1.000000e+00)
; CHECK-NEXT: ret float [[RES]]
;
- %res = tail call fast float @exp10f(float 1.0)
+ %res = tail call float @exp10f(float 1.0)
ret float %res
}
@@ -121,12 +121,10 @@
ret double %res
}
-; FIXME
declare float @log2f(float)
define float @f_log2f() {
; CHECK-LABEL: @f_log2f(
-; CHECK-NEXT: [[RES:%.*]] = tail call fast float @log2f(float 1.000000e+00)
-; CHECK-NEXT: ret float [[RES]]
+; CHECK-NEXT: ret float 0.000000e+00
;
%res = tail call fast float @log2f(float 1.0)
ret float %res
Index: llvm/lib/Analysis/ConstantFolding.cpp
===================================================================
--- llvm/lib/Analysis/ConstantFolding.cpp
+++ llvm/lib/Analysis/ConstantFolding.cpp
@@ -1490,6 +1490,7 @@
Name == "fmod" || Name == "fmodf";
case 'l':
return Name == "log" || Name == "logf" ||
+ Name == "log2" || Name == "log2f" ||
Name == "log10" || Name == "log10f";
case 'p':
return Name == "pow" || Name == "powf";
@@ -1868,6 +1869,13 @@
if (V > 0.0 && TLI->has(Func))
return ConstantFoldFP(log, V, Ty);
break;
+ case LibFunc_log2:
+ case LibFunc_log2f:
+ case LibFunc_log2_finite:
+ case LibFunc_log2f_finite:
+ if (V > 0.0 && TLI->has(Func))
+ return ConstantFoldFP(Log2, V, Ty);
+ break;
case LibFunc_log10:
case LibFunc_log10f:
case LibFunc_log10_finite:
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D67300.219161.patch
Type: text/x-patch
Size: 1970 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190906/ff480aaf/attachment.bin>
More information about the llvm-commits
mailing list