[PATCH] D137454: [InstCombine] Avoid passing pow attributes to sqrt
Miguel Saldivar via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Nov 4 16:05:45 PDT 2022
Saldivarcher updated this revision to Diff 473361.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D137454/new/
https://reviews.llvm.org/D137454
Files:
llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
llvm/test/Transforms/InstCombine/pow-to-sqrt.ll
Index: llvm/test/Transforms/InstCombine/pow-to-sqrt.ll
===================================================================
--- /dev/null
+++ 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)
Index: llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
===================================================================
--- llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
+++ llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
@@ -2099,6 +2099,7 @@
Module *M = Pow->getModule();
bool AllowApprox = Pow->hasApproxFunc();
bool Ignored;
+ AttributeList Attrs; // Attributes are only meaningful on the original call
// Propagate the math semantics from the call to any created instructions.
IRBuilderBase::FastMathFlagGuard Guard(B);
@@ -2160,8 +2161,7 @@
return nullptr;
ExpoF = &ExpoI;
- Sqrt = getSqrtCall(Base, Pow->getCalledFunction()->getAttributes(),
- Pow->doesNotAccessMemory(), M, B, TLI);
+ Sqrt = getSqrtCall(Base, Attrs, Pow->doesNotAccessMemory(), M, B, TLI);
if (!Sqrt)
return nullptr;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D137454.473361.patch
Type: text/x-patch
Size: 1524 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20221104/63682088/attachment.bin>
More information about the llvm-commits
mailing list