[llvm] aa57c1c - [InstCombine] fix bug in pow expansion
Sanjay Patel via llvm-commits
llvm-commits at lists.llvm.org
Tue Sep 15 06:30:14 PDT 2020
Author: Sanjay Patel
Date: 2020-09-15T09:29:48-04:00
New Revision: aa57c1c967078a8c02e7fc2c837853dbd7cc66f4
URL: https://github.com/llvm/llvm-project/commit/aa57c1c967078a8c02e7fc2c837853dbd7cc66f4
DIFF: https://github.com/llvm/llvm-project/commit/aa57c1c967078a8c02e7fc2c837853dbd7cc66f4.diff
LOG: [InstCombine] fix bug in pow expansion
There at least one other bug related to pow -> sqrt transforms:
http://lists.llvm.org/pipermail/llvm-dev/2020-September/145051.html
...but we probably can't solve that without fixing this first.
Added:
Modified:
llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
llvm/test/Transforms/InstCombine/pow-4.ll
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp b/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
index 34eb9e1b8124..60b7da7e64fe 100644
--- a/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
+++ b/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
@@ -1748,6 +1748,8 @@ Value *LibCallSimplifier::optimizePow(CallInst *Pow, IRBuilderBase &B) {
Sqrt = getSqrtCall(Base, Pow->getCalledFunction()->getAttributes(),
Pow->doesNotAccessMemory(), M, B, TLI);
+ if (!Sqrt)
+ return nullptr;
}
// We will memoize intermediate products of the Addition Chain.
diff --git a/llvm/test/Transforms/InstCombine/pow-4.ll b/llvm/test/Transforms/InstCombine/pow-4.ll
index e68dfb857caa..23cc2d801a16 100644
--- a/llvm/test/Transforms/InstCombine/pow-4.ll
+++ b/llvm/test/Transforms/InstCombine/pow-4.ll
@@ -152,7 +152,6 @@ define double @test_simplify_neg_16_5(double %x) {
}
; pow(x, 16.5) with double
-; FIXME: This is wrong without sqrt.
define double @test_simplify_16_5_libcall(double %x) {
; SQRT-LABEL: @test_simplify_16_5_libcall(
@@ -165,18 +164,14 @@ define double @test_simplify_16_5_libcall(double %x) {
; SQRT-NEXT: ret double [[TMP4]]
;
; NOSQRT-LABEL: @test_simplify_16_5_libcall(
-; NOSQRT-NEXT: [[SQUARE:%.*]] = fmul fast double [[X:%.*]], [[X]]
-; NOSQRT-NEXT: [[TMP1:%.*]] = fmul fast double [[SQUARE]], [[SQUARE]]
-; NOSQRT-NEXT: [[TMP2:%.*]] = fmul fast double [[TMP1]], [[TMP1]]
-; NOSQRT-NEXT: [[TMP3:%.*]] = fmul fast double [[TMP2]], [[TMP2]]
-; NOSQRT-NEXT: ret double [[TMP3]]
+; NOSQRT-NEXT: [[TMP1:%.*]] = call fast double @pow(double [[X:%.*]], double 1.650000e+01)
+; NOSQRT-NEXT: ret double [[TMP1]]
;
%1 = call fast double @pow(double %x, double 1.650000e+01)
ret double %1
}
; pow(x, -16.5) with double
-; FIXME: This is wrong without sqrt.
define double @test_simplify_neg_16_5_libcall(double %x) {
; SQRT-LABEL: @test_simplify_neg_16_5_libcall(
@@ -190,12 +185,8 @@ define double @test_simplify_neg_16_5_libcall(double %x) {
; SQRT-NEXT: ret double [[RECIPROCAL]]
;
; NOSQRT-LABEL: @test_simplify_neg_16_5_libcall(
-; NOSQRT-NEXT: [[SQUARE:%.*]] = fmul fast double [[X:%.*]], [[X]]
-; NOSQRT-NEXT: [[TMP1:%.*]] = fmul fast double [[SQUARE]], [[SQUARE]]
-; NOSQRT-NEXT: [[TMP2:%.*]] = fmul fast double [[TMP1]], [[TMP1]]
-; NOSQRT-NEXT: [[TMP3:%.*]] = fmul fast double [[TMP2]], [[TMP2]]
-; NOSQRT-NEXT: [[RECIPROCAL:%.*]] = fdiv fast double 1.000000e+00, [[TMP3]]
-; NOSQRT-NEXT: ret double [[RECIPROCAL]]
+; NOSQRT-NEXT: [[TMP1:%.*]] = call fast double @pow(double [[X:%.*]], double -1.650000e+01)
+; NOSQRT-NEXT: ret double [[TMP1]]
;
%1 = call fast double @pow(double %x, double -1.650000e+01)
ret double %1
More information about the llvm-commits
mailing list