[llvm] de36d39 - [InstCombine] Avoid passing pow attributes to sqrt
Sanjay Patel via llvm-commits
llvm-commits at lists.llvm.org
Mon Nov 7 09:15:11 PST 2022
Author: Miguel Saldivar
Date: 2022-11-07T12:07:37-05:00
New Revision: de36d39e24249feabe18f845b1868a16b798110a
URL: https://github.com/llvm/llvm-project/commit/de36d39e24249feabe18f845b1868a16b798110a
DIFF: https://github.com/llvm/llvm-project/commit/de36d39e24249feabe18f845b1868a16b798110a.diff
LOG: [InstCombine] Avoid passing pow attributes to sqrt
As described in issue #58475, we could pass the attributes of pow to sqrt and crash.
Differential Revision: https://reviews.llvm.org/D137454
Added:
llvm/test/Transforms/InstCombine/pow-to-sqrt.ll
Modified:
llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp b/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
index 6dcf5a3c6813..9b5d0b8f5daa 100644
--- a/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
+++ b/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
@@ -2164,8 +2164,8 @@ Value *LibCallSimplifier::optimizePow(CallInst *Pow, IRBuilderBase &B) {
return nullptr;
ExpoF = &ExpoI;
- Sqrt = getSqrtCall(Base, Pow->getCalledFunction()->getAttributes(),
- Pow->doesNotAccessMemory(), M, B, TLI);
+ Sqrt = getSqrtCall(Base, AttributeList(), Pow->doesNotAccessMemory(), M,
+ B, TLI);
if (!Sqrt)
return nullptr;
}
diff --git a/llvm/test/Transforms/InstCombine/pow-to-sqrt.ll b/llvm/test/Transforms/InstCombine/pow-to-sqrt.ll
new file mode 100644
index 000000000000..2805456c89e8
--- /dev/null
+++ b/llvm/test/Transforms/InstCombine/pow-to-sqrt.ll
@@ -0,0 +1,14 @@
+; RUN: opt < %s -passes=instcombine -S | FileCheck %s
+; This is a check to assure the attributes of `pow` do
+; not get passed to sqrt.
+
+define void @pow_to_sqrt(double %x) {
+; CHECK-LABEL: @pow_to_sqrt(
+; CHECK-NEXT: [[SQRT:%.*]] = call afn double @sqrt(double [[X:%.*]])
+; CHECK-NEXT: ret void
+;
+ %call = call afn double @pow(double %x, double 1.5)
+ ret void
+}
+
+declare double @pow(double noundef, double noundef)
More information about the llvm-commits
mailing list